Skip to content

Commit

Permalink
added examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jp112sdl committed Feb 4, 2018
1 parent 43fed84 commit da110be
Show file tree
Hide file tree
Showing 3 changed files with 329 additions and 0 deletions.
105 changes: 105 additions & 0 deletions examples/HM-PB-2-WM55/HM-PB-2-WM55.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
//- -----------------------------------------------------------------------------------------------------------------------
// 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 <SPI.h> // after including SPI Library - we can use LibSPI class
#include <AskSinPP.h>
#include <LowPower.h>

#include <MultiChannelDevice.h>
#include <Remote.h>


// we use a Pro Mini
// Arduino pin for the LED
// D4 == PIN 4 on Pro Mini
#define LED_PIN 4
#define LED_PIN2 5
// Arduino pin for the config button
// B0 == PIN 8 on Pro Mini
#define CONFIG_BUTTON_PIN 8
// Arduino pins for the buttons
// A0,A1,A2,A3 == PIN 14,15,16,17 on Pro Mini
#define BTN1_PIN 14
#define BTN2_PIN 15


// 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 = {
{0x72,0x6B,0x12}, // Device ID
"JPPB200001", // Device Serial
{0x00,0x6B}, // Device Model
0x14, // Firmware Version
as::DeviceType::Remote, // Device Type
{0x00,0x00} // Info Bytes
};

/**
* Configure the used hardware
*/
typedef LibSPI<10> 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,2> 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);
remoteISR(sdev,2,BTN2_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);
}
}
115 changes: 115 additions & 0 deletions examples/HM-PB-6-WM55/HM-PB-6-WM55.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
//- -----------------------------------------------------------------------------------------------------------------------
// 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 <MultiChannelDevice.h>
#include <Remote.h>


// we use a Pro Mini
// Arduino pin for the LED
// D4/D5 == PIN 4/5
#define LED_GREEN 4
#define LED_RED 5
// Arduino pin for the config button
// B0 == PIN 8
#define CONFIG_BUTTON_PIN 8
// Arduino pins for the buttons
#define BTN01_PIN 14 // PC0
#define BTN02_PIN 3 // PD3
#define BTN03_PIN 15 // PC1
#define BTN04_PIN 7 // PD7
#define BTN05_PIN 9 // PB1
#define BTN06_PIN 6 // PD6



// 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 = {
{0x04,0xa9,0x00}, // Device ID
"HMRC00da00", // Device Serial
{0x00,0xA9}, // Device Model
0x01, // Firmware Version
as::DeviceType::Remote, // Device Type
{0x00,0x00} // Info Bytes
};

/**
* Configure the used hardware
*/
typedef AvrSPI<10,11,12,13> SPIType;
typedef Radio<SPIType,2> RadioType;
typedef DualStatusLed<LED_RED,LED_GREEN> 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,6> 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,BTN01_PIN);
remoteISR(sdev,2,BTN02_PIN);
remoteISR(sdev,3,BTN03_PIN);
remoteISR(sdev,4,BTN04_PIN);
remoteISR(sdev,5,BTN05_PIN);
remoteISR(sdev,6,BTN06_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);
}
}
109 changes: 109 additions & 0 deletions examples/HM-PBI-4-FM/HM-PBI-4-FM.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
//- -----------------------------------------------------------------------------------------------------------------------
// 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 <SPI.h> // after including SPI Library - we can use LibSPI class
#include <AskSinPP.h>
#include <LowPower.h>

#include <MultiChannelDevice.h>
#include <Remote.h>


// we use a Pro Mini
// Arduino pin for the LED
// D4 == PIN 4 on Pro Mini
#define LED_PIN 4
#define LED_PIN2 5
// Arduino pin for the config button
// B0 == PIN 8 on Pro Mini
#define CONFIG_BUTTON_PIN 8
// Arduino pins for the buttons
// A0,A1,A2,A3 == PIN 14,15,16,17 on Pro Mini
#define BTN1_PIN 14
#define BTN2_PIN 15
#define BTN3_PIN 16
#define BTN4_PIN 17


// 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 = {
{0x78,0x90,0x12}, // Device ID
"JPPBI4FM01", // Device Serial
{0x00,0x34}, // Device Model
0x01, // Firmware Version
as::DeviceType::Remote, // Device Type
{0x00,0x00} // Info Bytes
};

/**
* Configure the used hardware
*/
typedef LibSPI<10> 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,4> 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);
remoteISR(sdev,2,BTN2_PIN);
remoteISR(sdev,3,BTN3_PIN);
remoteISR(sdev,4,BTN4_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);
}
}

0 comments on commit da110be

Please sign in to comment.