Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //- -----------------------------------------------------------------------------------------------------------------------
- // AskSin++
- // 2016-10-31 papa Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/
- //- -----------------------------------------------------------------------------------------------------------------------
- // define this to read the device id, serial and device type from bootloader section
- // #define USE_OTA_BOOTLOADER
- #define EI_NOTEXTERNAL
- #include <EnableInterrupt.h>
- #include <AskSinPP.h>
- #include <LowPower.h>
- #include <Register.h>
- #include <ThreeState.h>
- // we use a Pro Mini
- // Arduino pin for the LED
- // D4 == PIN 4 on Pro Mini
- #define LED1_PIN 4
- #define LED2_PIN 5
- // Arduino pin for the config button
- // B0 == PIN 8 on Pro Mini
- #define CONFIG_BUTTON_PIN 8
- #define SENS11_PIN 14
- #define SENS12_PIN 15
- #define SENS21_PIN 16
- #define SENS22_PIN 17
- #define SENS31_PIN 3
- #define SENS32_PIN 6
- #define SENS41_PIN 7
- #define SENS42_PIN 9
- // number of available peers per channel
- #define PEERS_PER_CHANNEL 10
- // all library classes are placed in the namespace 'as'
- using namespace as;
- // define all device properties
- const struct DeviceInfo PROGMEM devinfo = {
- {0x09,0x56,0x34}, // Device ID
- "papa222111", // Device Serial
- {0x00,0xC3}, // Device Model
- 0x22, // Firmware Version
- as::DeviceType::ThreeStateSensor, // Device Type
- {0x01,0x00} // Info Bytes
- };
- /**
- * Configure the used hardware
- */
- typedef AvrSPI<10,11,12,13> SPIType;
- typedef Radio<SPIType,2> RadioType;
- typedef DualStatusLed<LED2_PIN,LED1_PIN> LedType;
- typedef AskSin<LedType,BatterySensor,RadioType> BaseHal;
- class Hal : public BaseHal {
- public:
- void init (const HMID& id) {
- BaseHal::init(id);
- // measure battery every 1h
- battery.init(seconds2ticks(60UL*60),sysclock);
- }
- } hal;
- DEFREGISTER(Reg0,DREG_INTKEY,DREG_CYCLICINFOMSG,MASTERID_REGS,DREG_TRANSMITTRYMAX,DREG_SABOTAGEMSG)
- class RHSList0 : public RegList0<Reg0> {
- public:
- RHSList0(uint16_t addr) : RegList0<Reg0>(addr) {}
- void defaults () {
- clear();
- cycleInfoMsg(true);
- transmitDevTryMax(6);
- sabotageMsg(true);
- }
- };
- DEFREGISTER(Reg1,CREG_AES_ACTIVE,CREG_MSGFORPOS,CREG_EVENTDELAYTIME,CREG_LEDONTIME,CREG_TRANSMITTRYMAX)
- class RHSList1 : public RegList1<Reg1> {
- public:
- RHSList1 (uint16_t addr) : RegList1<Reg1>(addr) {}
- void defaults () {
- clear();
- msgForPosA(1); // CLOSED
- msgForPosB(2); // OPEN
- msgForPosC(3); // TILTED
- // aesActive(false);
- // eventDelaytime(0);
- ledOntime(100);
- transmitTryMax(6);
- }
- };
- typedef ThreeStateChannel<Hal,RHSList0,RHSList1,DefList4,PEERS_PER_CHANNEL> ChannelType;
- typedef ThreeStateDevice<Hal,ChannelType,4,RHSList0> RHSType;
- RHSType sdev(devinfo,0x20);
- ConfigButton<RHSType> cfgBtn(sdev);
- void setup () {
- DINIT(57600,ASKSIN_PLUS_PLUS_IDENTIFIER);
- sdev.init(hal);
- buttonISR(cfgBtn,CONFIG_BUTTON_PIN);
- const uint8_t posmap[4] = {Position::State::PosB,Position::State::PosC,Position::State::PosA,Position::State::PosB};
- sdev.channel(1).init(SENS11_PIN,SENS12_PIN,posmap);
- sdev.channel(2).init(SENS21_PIN,SENS22_PIN,posmap);
- sdev.channel(3).init(SENS31_PIN,SENS32_PIN,posmap);
- sdev.channel(4).init(SENS41_PIN,SENS42_PIN,posmap);
- sdev.initDone();
- }
- void loop() {
- bool worked = hal.runready();
- bool poll = sdev.pollRadio();
- if( worked == false && poll == false ) {
- // deep discharge protection
- // if we drop below critical battery level - switch off all and sleep forever
- if( hal.battery.critical() ) {
- // this call will never return
- hal.activity.sleepForever(hal);
- }
- // if nothing to do - go sleep
- hal.activity.savePower<Sleep<> >(hal);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment