Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
1 contributor

Users who have contributed to this file

97 lines (79 sloc) 2.66 KB
//- -----------------------------------------------------------------------------------------------------------------------
// 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 <Switch.h>
// we use a Pro Mini
// Arduino pin for the LED
// D4 == PIN 4 on Pro Mini
#define LED_PIN 4
// Arduino pin for the config button
// B0 == PIN 8 on Pro Mini
#define CONFIG_BUTTON_PIN 8
//set to 0x01 if the RELAY should be switched on LOW level
#define LOW_ACTIVE 0x00
#define RELAY1_PIN 17 //A3
#define RELAY2_PIN 16 //A2
#define BUTTON1_PIN 6
#define BUTTON2_PIN 3
// number of available peers per channel
#define PEERS_PER_CHANNEL 8
// all library classes are placed in the namespace 'as'
using namespace as;
// define all device properties
const struct DeviceInfo PROGMEM devinfo = {
{0x12, 0x09, 0x00}, // Device ID
"JPLCSw2001", // Device Serial
{0x00, 0x09}, // Device Model
0x24, // Firmware Version
as::DeviceType::Switch, // Device Type
{0x01, 0x00} // Info Bytes
};
/**
Configure the used hardware
*/
typedef AvrSPI<10, 11, 12, 13> RadioSPI;
typedef AskSin<StatusLed<LED_PIN>, NoBattery, Radio<RadioSPI, 2> > Hal;
// setup the device with channel type and number of channels
typedef MultiChannelDevice<Hal, SwitchChannel<Hal, PEERS_PER_CHANNEL, List0>, 2> SwitchType;
Hal hal;
SwitchType sdev(devinfo, 0x20);
ConfigButton<SwitchType> cfgBtn(sdev);
InternalButton<SwitchType> btn1(sdev, 1);
InternalButton<SwitchType> btn2(sdev, 2);
void initPeerings (bool first) {
// create internal peerings - CCU2 needs this
if ( first == true ) {
HMID devid;
sdev.getDeviceID(devid);
for ( uint8_t i = 1; i <= sdev.channels(); ++i ) {
Peer ipeer(devid, i);
sdev.channel(i).peer(ipeer);
}
}
}
void setup () {
DINIT(57600, ASKSIN_PLUS_PLUS_IDENTIFIER);
bool first = sdev.init(hal);
sdev.channel(1).init(RELAY1_PIN, LOW_ACTIVE);
sdev.channel(2).init(RELAY2_PIN, LOW_ACTIVE);
buttonISR(cfgBtn, CONFIG_BUTTON_PIN);
buttonISR(btn1, BUTTON1_PIN);
buttonISR(btn2, BUTTON2_PIN);
sdev.channels(2);
initPeerings(first);
sdev.initDone();
}
void loop() {
bool worked = hal.runready();
bool poll = sdev.pollRadio();
if ( worked == false && poll == false ) {
hal.activity.savePower<Idle<> >(hal);
}
}
You can’t perform that action at this time.