jp112

AskSinPPDimmer2Ch4Button

Nov 7th, 2018
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.57 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 <AskSinPP.h>
  12. #include <LowPower.h>
  13. #include <Dimmer.h>
  14.  
  15. // we use a Pro Mini
  16. // Arduino pin for the LED
  17. // D4 == PIN 4 on Pro Mini
  18. #define LED_PIN 4
  19. // Arduino pin for the config button
  20. // B0 == PIN 8 on Pro Mini
  21. #define CONFIG_BUTTON_PIN 8
  22.  
  23. #define DIMMER_PIN 5
  24. #define BTN1       A0
  25. #define BTN2       A1
  26. #define BTN3       7
  27. #define BTN4       9
  28. // number of available peers per channel
  29. #define PEERS_PER_CHANNEL 4
  30.  
  31. // all library classes are placed in the namespace 'as'
  32. using namespace as;
  33.  
  34. // define all device properties
  35. const struct DeviceInfo PROGMEM devinfo = {
  36.   {0x11, 0x12, 0x22},     // Device ID
  37.   "papa111222",           // Device Serial
  38.   {0x00, 0x59},           // Device Model
  39.   0x25,                   // Firmware Version
  40.   as::DeviceType::Dimmer, // Device Type
  41.   {0x01, 0x00}            // Info Bytes
  42. };
  43.  
  44. /**
  45.    Configure the used hardware
  46. */
  47. typedef AvrSPI<10, 11, 12, 13> SPIType;
  48. typedef Radio<SPIType, 2> RadioType;
  49. typedef StatusLed<LED_PIN> LedType;
  50. typedef AskSin<LedType, NoBattery, RadioType> HalType;
  51. typedef DimmerChannel<HalType, PEERS_PER_CHANNEL> ChannelType;
  52. typedef DimmerDevice<HalType, ChannelType, 2, 1, PWM8<> > DimmerType;
  53.  
  54. HalType hal;
  55. DimmerType sdev(devinfo, 0x20);
  56. ConfigButton<DimmerType> cfgBtn(sdev);
  57. InternalButton<DimmerType> btn1(sdev, 3);
  58. InternalButton<DimmerType> btn2(sdev, 4);
  59. InternalButton<DimmerType> btn3(sdev, 5);
  60. InternalButton<DimmerType> btn4(sdev, 6);
  61.  
  62. void setup () {
  63.   buttonISR(btn1, BTN1);
  64.   buttonISR(btn2, BTN2);
  65.   buttonISR(btn3, BTN3);
  66.   buttonISR(btn4, BTN4);
  67.   DINIT(57600, ASKSIN_PLUS_PLUS_IDENTIFIER);
  68.   if ( sdev.init(hal, DIMMER_PIN) ) {
  69.     HMID devid;
  70.     sdev.getDeviceID(devid);
  71.     sdev.channel(1).peer(Peer(devid, 3), Peer(devid, 4));
  72.     sdev.channel(2).peer(Peer(devid, 5), Peer(devid, 6));
  73.   }
  74.   buttonISR(cfgBtn, CONFIG_BUTTON_PIN);
  75.   sdev.initDone();
  76. }
  77.  
  78. void loop() {
  79.   bool worked = hal.runready();
  80.   bool poll = sdev.pollRadio();
  81.   if ( worked == false && poll == false ) {
  82.     // hal.activity.savePower<Idle<true> >(hal);
  83.   }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment