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

Users who have contributed to this file

116 lines (92 sloc) 2.98 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
// number of relays by defining the device
#define HM_LC_SW1_SM 0x00,0x02
#define CFG_LOWACTIVE_BYTE 0x00
#define CFG_LOWACTIVE_ON 0x01
#define CFG_LOWACTIVE_OFF 0x00
#define DEVICE_CONFIG CFG_LOWACTIVE_OFF
#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
#define RELAY1_PIN 5
// 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 = {
{0x00, 0xeb, 0x02}, // Device ID
"JPSw1CT001", // Device Serial
{0x00, 0xeb}, // 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>, 4> SwitchType;
Hal hal;
SwitchType sdev(devinfo, 0x20);
ConfigToggleButton<SwitchType> cfgBtn(sdev);
// if A0 and A1 connected
// we use LOW for ON and HIGH for OFF
bool checkLowActive () {
pinMode(14, OUTPUT); // A0
pinMode(15, INPUT_PULLUP); // A1
digitalWrite(15, HIGH);
digitalWrite(14, LOW);
bool result = digitalRead(15) == LOW;
digitalWrite(14, HIGH);
return result;
}
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 initModelType () {
uint8_t model[2];
sdev.getDeviceModel(model);
sdev.channels(1);
}
void setup () {
DINIT(57600, ASKSIN_PLUS_PLUS_IDENTIFIER);
bool first = sdev.init(hal);
bool low = (sdev.getConfigByte(CFG_LOWACTIVE_BYTE) == CFG_LOWACTIVE_ON) || checkLowActive();
sdev.channel(1).init(RELAY1_PIN, low);
buttonISR(cfgBtn, CONFIG_BUTTON_PIN);
initModelType();
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.