forked from arjhun/arduino-sf501remote
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sf501-remote.h
93 lines (70 loc) · 2.67 KB
/
sf501-remote.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
/*
sf501-remote, a library to control sf501 remotes by flamingo/ smartwares.eu
Arjen Klaverstijn - https://github.com/arjhun - http://www.arjenklaverstijn.com
Project repo: https://github.com/arjhun/arduino-sf501remote
version 0.0.1
This library was inspired by rf-switch: https://github.com/sui77/rc-switch
*/
#ifndef SF501REMOTE_H
#define SF501REMOTE_H
struct Sf501Packet {
int remoteId;
int channel;
boolean state;
};
class Sf501Remote
{
public:
/*
- packet consists of
Preamble (1 pulse) - Data (64 pulses) - End (1 pulse)
- Data format:
32 bits data section
remoteId : a 16 bit value enabling 65535 different remotes on this system
uknown data: 8 bits are empty on all remotes, no clue where this is for...
button: 4 bits a decimal value of 1 is switch on a 0 is switch off
channel: 4bits maximum of 15 buttons/channels per remote, higher values will be discarded by this library
Pulses are around 200µS.
|¯¯¯|_______________________________________
preamble = 1 pulse high 14 pulses low
|¯¯¯|______|¯¯¯|_____________________
data 0 = 1 pulse high & 2 pulses low, 1 pulses high & 7 pulses low
|¯¯¯|_____________________|¯¯¯|______
data 1 = 1 pulse high & 7 pulses low, 1 pulse high & 2 pulses low
|¯¯¯|
end = 1 pulse high
*/
void startTransmitter(int pin);
void sendCommand(int remoteId, int channel, int onOff, int repeat = 4);
void sendPacket(Sf501Packet packet, int repeat = 4);
void sendRaw(unsigned long command, int repeat = 4);
void switchAll(int remoteId, int numChannels, int onOff, int repeat = 4);
#ifndef NO_RECEIVER
void startReceiver(int pin);
void stopReceiver();
boolean packetAvailable();
Sf501Packet getPacket();
static unsigned long getRawData();
void nextPacket();
#endif
private:
//globals vars
const static int _pulseLength = 190;
const static long _beginPulses = 14, _shortPulses = 2, _longPulses = 7, _waitPulses = 55, _maxPulses = 400;
const static int _min_packets = 3;
const static int _error = 100;
const static int _numBits = 32;
//transmitter vars
void _pulse(), _pulseStart(), _pulseLong(), _pulseShort();
int _pin;
#ifndef NO_RECEIVER
//receiver vars
int _rPin;
volatile static unsigned long _message;
static Sf501Packet _packet;
volatile static boolean _messageReady;
static boolean _checkPulse(long pulseLength, long comp);
static void _pulseReceived();
#endif
};
#endif