-
Notifications
You must be signed in to change notification settings - Fork 0
/
RF24SensorNet.h
104 lines (87 loc) · 3.17 KB
/
RF24SensorNet.h
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
101
102
103
104
/*
RF24SensorNet
A library for sending standard sensor and actuator
messages between nodes connected using RF24Network.
--
Peter Hardy <[email protected]>
*/
#ifndef __RF24_SENSOR_NET_H__
#define __RF24_SENSOR_NET_H__
#if ARDUINO < 100
#include <WProgram.h>
#else
#include <Arduino.h>
#endif
#include <stdbool.h>
#include "RF24SensorNet_types.h"
class RF24Network;
/* Maximum RF24 payload size. RF24Network truncates anything longer. */
const char MAX_PAYLOAD=24;
long readVcc();
class RF24SensorNet
{
public:
RF24SensorNet(RF24Network& network);
void addInfoReadHandler(infoReadHandler handler);
void addInfoWriteHandler(infoWriteHandler handler);
void addInfoRcvHandler(infoRcvHandler handler);
bool readInfo(uint16_t toAddr);
bool writeInfo(uint16_t toAddr, uint16_t newAddr);
bool sendInfo(uint16_t toAddr);
void addPowerReadHandler(powerReadHandler handler);
void addPowerRcvHandler(powerRcvHandler handler);
bool readPower(uint16_t toAddr);
bool sendPower(uint16_t toAddr, bool battery, bool solar,
uint16_t vcc, uint16_t vs);
void addSwitchReadHandler(switchReadHandler handler);
void addSwitchWriteHandler(switchWriteHandler handler);
void addSwitchRcvHandler(switchRcvHandler handler);
bool readSwitch(uint16_t toAddr, uint16_t id);
bool writeSwitch(uint16_t toAddr, uint16_t id,
bool state, uint32_t timer);
bool sendSwitch(uint16_t toAddr, uint16_t id,
bool state, uint32_t timer);
void addRgbReadHandler(rgbReadHandler handler);
void addRgbWriteHandler(rgbWriteHandler handler);
void addRgbRcvHandler(rgbRcvHandler handler);
bool readRgb(uint16_t toAddr, uint16_t id);
bool writeRgb(uint16_t toAddr, uint16_t id,
char rgb[3], uint32_t timer);
bool sendRgb(uint16_t toAddr, uint16_t id,
char rgb[3], uint32_t timer);
void addTempReadHandler(tempReadHandler handler);
void addTempRcvHandler(tempRcvHandler handler);
bool readTemp(uint16_t toAddr, uint16_t id);
bool sendTemp(uint16_t toAddr, uint16_t id, int16_t temp);
void addHumidReadHandler(humidReadHandler handler);
void addHumidRcvHandler(humidRcvHandler handler);
bool readHumid(uint16_t toAddr, uint16_t id);
bool sendHumid(uint16_t toAddr, uint16_t id, uint16_t humidity);
void begin();
void update(void);
private:
RF24Network& _network;
infoReadHandler _infoReadHandler;
infoWriteHandler _infoWriteHandler;
infoRcvHandler _infoRcvHandler;
powerReadHandler _powerReadHandler;
powerRcvHandler _powerRcvHandler;
switchReadHandler _switchReadHandler;
switchWriteHandler _switchWriteHandler;
switchRcvHandler _switchRcvHandler;
rgbReadHandler _rgbReadHandler;
rgbWriteHandler _rgbWriteHandler;
rgbRcvHandler _rgbRcvHandler;
tempReadHandler _tempReadHandler;
tempRcvHandler _tempRcvHandler;
humidReadHandler _humidReadHandler;
humidRcvHandler _humidRcvHandler;
void _infoHandler(RF24NetworkHeader header);
void _powerHandler(RF24NetworkHeader header);
void _switchHandler(RF24NetworkHeader header);
void _rgbHandler(RF24NetworkHeader header);
void _tempHandler(RF24NetworkHeader header);
void _humidHandler(RF24NetworkHeader header);
bool _write(uint16_t toAddr, uint16_t type, const void* message);
};
#endif