jp112

HM-LC-SW4-SM with 8 channels

Oct 11th, 2018
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.70 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. // number of relays by defining the device
  10. #define EI_NOTEXTERNAL
  11. #include <EnableInterrupt.h>
  12. #include <AskSinPP.h>
  13. #include <LowPower.h>
  14.  
  15. #include <Switch.h>
  16.  
  17.  
  18. // we use a Pro Mini
  19. // Arduino pin for the LED
  20. // D4 == PIN 4 on Pro Mini
  21. #define LED_PIN 4
  22. // Arduino pin for the config button
  23. // B0 == PIN 8 on Pro Mini
  24. #define CONFIG_BUTTON_PIN 8
  25.  
  26. #define RELAY1_PIN 14
  27. #define RELAY2_PIN 15
  28. #define RELAY3_PIN 16
  29. #define RELAY4_PIN 17
  30. #define RELAY5_PIN 7
  31. #define RELAY6_PIN 9
  32. #define RELAY7_PIN 6
  33. #define RELAY8_PIN 5
  34.  
  35.  
  36. // number of available peers per channel
  37. #define PEERS_PER_CHANNEL 8
  38.  
  39.  
  40. // all library classes are placed in the namespace 'as'
  41. using namespace as;
  42.  
  43. // define all device properties
  44. const struct DeviceInfo PROGMEM devinfo = {
  45.   {0x42, 0x44, 0x46},     // Device ID
  46.   "papa000000",           // Device Serial
  47.   {0x00, 0x03},        // Device Model
  48.   0x16,                   // Firmware Version
  49.   as::DeviceType::Switch, // Device Type
  50.   {0x01, 0x00}            // Info Bytes
  51. };
  52.  
  53. /**
  54.    Configure the used hardware
  55. */
  56. typedef AvrSPI<10, 11, 12, 13> RadioSPI;
  57. typedef AskSin<StatusLed<LED_PIN>, NoBattery, Radio<RadioSPI, 2> > Hal;
  58.  
  59. // setup the device with channel type and number of channels
  60. typedef MultiChannelDevice<Hal, SwitchChannel<Hal, PEERS_PER_CHANNEL, List0>, 8> SwitchType;
  61.  
  62. Hal hal;
  63. SwitchType sdev(devinfo, 0x20);
  64.  
  65. ConfigButton<SwitchType> cfgBtn(sdev);
  66.  
  67.  
  68. void setup () {
  69.   DINIT(57600, ASKSIN_PLUS_PLUS_IDENTIFIER);
  70.   sdev.init(hal);
  71.   sdev.channel(1).init(RELAY1_PIN, false);
  72.   sdev.channel(2).init(RELAY2_PIN, false);
  73.   sdev.channel(3).init(RELAY3_PIN, false);
  74.   sdev.channel(4).init(RELAY4_PIN, false);
  75.   sdev.channel(5).init(RELAY5_PIN, false);
  76.   sdev.channel(6).init(RELAY6_PIN, false);
  77.   sdev.channel(7).init(RELAY7_PIN, false);
  78.   sdev.channel(8).init(RELAY8_PIN, false);
  79.  
  80.   buttonISR(cfgBtn, CONFIG_BUTTON_PIN);
  81.   HMID devid;
  82.   sdev.getDeviceID(devid);
  83.   for ( uint8_t i = 1; i <= sdev.channels(); ++i ) {
  84.     Peer ipeer(devid, i);
  85.     sdev.channel(i).peer(ipeer);
  86.   }
  87.   sdev.initDone();
  88. }
  89.  
  90. void loop() {
  91.   bool worked = hal.runready();
  92.   bool poll = sdev.pollRadio();
  93.   if ( worked == false && poll == false ) {
  94.     hal.activity.savePower<Idle<> >(hal);
  95.   }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment