Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
121 lines (99 sloc) 3.28 KB
//- -----------------------------------------------------------------------------------------------------------------------
// AskSin++
// 2017-07-26 papa Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/
// 2019-03-01 jp112sdl 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 <MultiChannelDevice.h>
#include <Remote.h>
#define LED_PIN 4
#define CONFIG_BUTTON_PIN 8
#define TRG_PIN 9
#define SEND_ON_EDGE FALLING // FALLING -> senden bei Pegelwechsel von HIGH auf LOW
// RISING -> senden bei Pegelwechsel von LOW auf HIGH
// 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 = {
{0x00, 0xdc, 0x01}, // Device ID
"HMJPDB0001", // Device Serial
{0x00, 0xDC}, // Device Model
0x16, // Firmware Version
as::DeviceType::Remote, // Device Type
{0x01, 0x00} // Info Bytes
};
/**
Configure the used hardware
*/
typedef AvrSPI<10, 11, 12, 13> SPIType;
typedef Radio<SPIType, 2> RadioType;
typedef StatusLed<LED_PIN> LedType;
typedef AskSin<LedType, BatterySensor, RadioType> HalType;
class Hal : public HalType {
// extra clock to count button press events
AlarmClock btncounter;
public:
void init (const HMID& id) {
HalType::init(id);
// get new battery value after 50 key press
battery.init(50, btncounter);
battery.low(22);
battery.critical(19);
}
void sendPeer () {
--btncounter;
}
bool runready () {
return HalType::runready() || btncounter.runready();
}
};
DEFREGISTER(DBReg0, MASTERID_REGS, DREG_LEDMODE, DREG_TRANSMITTRYMAX, DREG_LOCALRESETDISABLE)
class DBList0 : public RegList0<DBReg0> {
public:
DBList0(uint16_t addr) : RegList0<DBReg0>(addr) {}
void defaults () {
clear();
ledMode(1);
transmitDevTryMax(6);
localResetDisable(false);
}
};
typedef RemoteChannel<Hal, PEERS_PER_CHANNEL, DBList0> ChannelType;
typedef MultiChannelDevice<Hal, ChannelType, 1, DBList0> RemoteType;
Hal hal;
RemoteType sdev(devinfo, 0x20);
ConfigButton<RemoteType> cfgBtn(sdev);
volatile bool isr = false;
static void isr1 () {
isr = true;
}
void setup () {
DINIT(57600, ASKSIN_PLUS_PLUS_IDENTIFIER);
sdev.init(hal);
pinMode(TRG_PIN, INPUT_PULLUP);
if ( digitalPinToInterrupt(TRG_PIN) == NOT_AN_INTERRUPT )
enableInterrupt(TRG_PIN, isr1, SEND_ON_EDGE);
else
attachInterrupt(digitalPinToInterrupt(TRG_PIN), isr1, SEND_ON_EDGE);
buttonISR(cfgBtn, CONFIG_BUTTON_PIN);
sdev.initDone();
}
void loop() {
bool worked = hal.runready();
bool poll = sdev.pollRadio();
if ( worked == false && poll == false ) {
hal.activity.savePower<Sleep<>>(hal);
}
if (isr == true) {
isr = false;
_delay_ms(50); //DEBOUNCE
sdev.channel(1).state(Button::released);
}
}
You can’t perform that action at this time.