jp112

HM-PB-3-FM.ino

Nov 14th, 2018
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.82 KB | None | 0 0
  1. //- -----------------------------------------------------------------------------------------------------------------------
  2. // AskSin++
  3. // 2016-10-31 papa Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/
  4. //- -----------------------------------------------------------------------------------------------------------------------
  5.  
  6. // define this to read the device id, serial and device type from bootloader section
  7. // #define USE_OTA_BOOTLOADER
  8.  
  9. #define EI_NOTEXTERNAL
  10. #include <EnableInterrupt.h>
  11. #include <SPI.h>  // after including SPI Library - we can use LibSPI class
  12. #include <AskSinPP.h>
  13. #include <LowPower.h>
  14.  
  15. #include <MultiChannelDevice.h>
  16. #include <Remote.h>
  17.  
  18.  
  19. // we use a Pro Mini
  20. // Arduino pin for the LED
  21. // D4 == PIN 4 on Pro Mini
  22. #define LED_PIN 4
  23. #define LED_PIN2 5
  24. // Arduino pin for the config button
  25. // B0 == PIN 8 on Pro Mini
  26. #define CONFIG_BUTTON_PIN 8
  27. // Arduino pins for the buttons
  28. // A0,A1,A2,A3 == PIN 14,15,16,17 on Pro Mini
  29. #define BTN1_PIN 14
  30. #define BTN2_PIN 15
  31. #define BTN2_PIN 16
  32.  
  33.  
  34. // number of available peers per channel
  35. #define PEERS_PER_CHANNEL 10
  36.  
  37. // all library classes are placed in the namespace 'as'
  38. using namespace as;
  39.  
  40. // define all device properties
  41. const struct DeviceInfo PROGMEM devinfo = {
  42.   {0x02, 0xBF, 0x01},     // Device ID
  43.   "JPPB2FM001",           // Device Serial
  44.   {0x00, 0xBF},           // Device Model
  45.   0x14,                   // Firmware Version
  46.   as::DeviceType::Remote, // Device Type
  47.   {0x00, 0x00}            // Info Bytes
  48. };
  49.  
  50. /**
  51.    Configure the used hardware
  52. */
  53. typedef LibSPI<10> SPIType;
  54. typedef Radio<SPIType, 2> RadioType;
  55. typedef DualStatusLed<5, 4> LedType;
  56. typedef AskSin<LedType, BatterySensor, RadioType> HalType;
  57. class Hal : public HalType {
  58.     // extra clock to count button press events
  59.     AlarmClock btncounter;
  60.   public:
  61.     void init (const HMID& id) {
  62.       HalType::init(id);
  63.       // get new battery value after 50 key press
  64.       battery.init(50, btncounter);
  65.       battery.low(22);
  66.       battery.critical(19);
  67.     }
  68.  
  69.     void sendPeer () {
  70.       --btncounter;
  71.     }
  72.  
  73.     bool runready () {
  74.       return HalType::runready() || btncounter.runready();
  75.     }
  76. };
  77.  
  78. typedef RemoteChannel<Hal, PEERS_PER_CHANNEL, List0> ChannelType;
  79. typedef MultiChannelDevice<Hal, ChannelType, 3> RemoteType;
  80.  
  81. Hal hal;
  82. RemoteType sdev(devinfo, 0x20);
  83. ConfigButton<RemoteType> cfgBtn(sdev);
  84.  
  85. void setup () {
  86.   DINIT(57600, ASKSIN_PLUS_PLUS_IDENTIFIER);
  87.   sdev.init(hal);
  88.   remoteISR(sdev, 1, BTN1_PIN);
  89.   remoteISR(sdev, 2, BTN2_PIN);
  90.   remoteISR(sdev, 3, BTN3_PIN);
  91.   buttonISR(cfgBtn, CONFIG_BUTTON_PIN);
  92.   sdev.initDone();
  93. }
  94.  
  95. void loop() {
  96.   bool worked = hal.runready();
  97.   bool poll = sdev.pollRadio();
  98.   if (worked == false && poll == false ) {
  99.     hal.activity.savePower<Idle<>>(hal);
  100.   }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment