-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathHM-RC-2-PBU-FM.ino
100 lines (84 loc) · 2.68 KB
/
HM-RC-2-PBU-FM.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//- -----------------------------------------------------------------------------------------------------------------------
// AskSin++
// 2016-10-31 papa Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/
//- -----------------------------------------------------------------------------------------------------------------------
// ci-test=yes board=328p aes=no
// 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 = {
{0x02,0xE0,0x01}, // Device ID
"JPRC2FM001", // Device Serial
{0x00,0xE0}, // 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<LED_PIN2, 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();
}
};
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 worked = hal.runready();
bool poll = sdev.pollRadio();
if( worked == false && poll == false ) {
hal.activity.savePower<Idle<>>(hal);
}
}