-
Notifications
You must be signed in to change notification settings - Fork 0
/
RF24SensorNet_switch.cpp
73 lines (60 loc) · 1.51 KB
/
RF24SensorNet_switch.cpp
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
/*
RF24SensorNet
A library for sending standard sensor and actuator
messages between nodes connected using RF24Network.
Handling for switch packets - on/off switches attached to nodes.
--
Peter Hardy <[email protected]>
*/
#ifndef __RF24_SENSOR_NET_SWITCH_H__
#define __RF24_SENSOR_NET_SWITCH_H__
#if ARDUINO < 100
#include <WProgram.h>
#else
#include <Arduino.h>
#endif
#include "RF24Network.h"
#include "RF24SensorNet.h"
#include "RF24SensorNet_types.h"
void RF24SensorNet::addSwitchReadHandler(switchReadHandler handler)
{
_switchReadHandler = handler;
}
void RF24SensorNet::addSwitchWriteHandler(switchWriteHandler handler)
{
_switchWriteHandler = handler;
}
void RF24SensorNet::addSwitchRcvHandler(switchRcvHandler handler)
{
_switchRcvHandler = handler;
}
bool RF24SensorNet::writeSwitch(uint16_t toAddr, uint16_t id,
bool state, uint32_t timer)
{
pkt_switch_t payload;
payload.id = id;
payload.state = state;
payload.timer = timer;
bool ok = _write(toAddr, PKT_SWITCH+64, &payload);
return ok;
}
bool RF24SensorNet::readSwitch(uint16_t toAddr, uint16_t id)
{
pkt_switch_t payload;
payload.id = id;
payload.state = 0;
payload.timer = 0;
bool ok = _write(toAddr, PKT_SWITCH+32, &payload);
return ok;
}
bool RF24SensorNet::sendSwitch(uint16_t toAddr, uint16_t id,
bool state, uint32_t timer)
{
pkt_switch_t payload;
payload.id = id;
payload.state = state;
payload.timer = timer;
bool ok = _write(toAddr, PKT_SWITCH, &payload);
return ok;
}
#endif