Advertisement
jp112

AskSinPPDimmer2Button

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