Skip to content

Commit

Permalink
added exmaples
Browse files Browse the repository at this point in the history
  • Loading branch information
jp112sdl committed Feb 7, 2018
1 parent 4f364d7 commit 98f8438
Show file tree
Hide file tree
Showing 5 changed files with 552 additions and 80 deletions.
116 changes: 116 additions & 0 deletions examples/HM-LC-Sw1-Pl-CT-R1/HM-LC-Sw1-Pl-CT-R1.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
//- -----------------------------------------------------------------------------------------------------------------------
// 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, 0x01}, // 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<4>, 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);
}
}
96 changes: 96 additions & 0 deletions examples/HM-Sen-DB-PCB/HM-Sen-DB-PCB.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
//- -----------------------------------------------------------------------------------------------------------------------
// AskSin++
// 2017-07-26 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 <MultiChannelDevice.h>
#include <Remote.h>

// Arduino pin for the config button
// B0 == PIN 8
#define CONFIG_BUTTON_PIN 8
// Arduino pins for the buttons
// A0 == PIN 14
#define SENS_PIN 14


// 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 DualStatusLed<5,4> 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();
}
};

typedef RemoteChannel<Hal,PEERS_PER_CHANNEL,List0> ChannelType;
typedef MultiChannelDevice<Hal,ChannelType,1> RemoteType;

Hal hal;
RemoteType sdev(devinfo,0x20);
ConfigButton<RemoteType> cfgBtn(sdev);

void setup () {
DINIT(57600,ASKSIN_PLUS_PLUS_IDENTIFIER);
sdev.init(hal);
remoteISR(sdev,1,BTN1_PIN);
buttonISR(cfgBtn,CONFIG_BUTTON_PIN);
sdev.initDone();
}

void loop() {
bool pinchanged = false;
for( int i=1; i<=sdev.channels(); ++i ) {
if( sdev.channel(i).checkpin() == true) {
pinchanged = true;
}
}
bool worked = hal.runready();
bool poll = sdev.pollRadio();
if( pinchanged == false && worked == false && poll == false ) {
hal.activity.savePower<Sleep<>>(hal);
}
}
Loading

0 comments on commit 98f8438

Please sign in to comment.