-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRCSocketTransmitter.cpp
56 lines (50 loc) · 1.35 KB
/
RCSocketTransmitter.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
/**
@author Matthias Bernard
@date 2016
*/
#include "RCSocketTransmitter.hpp"
#include "RCSocketTransmitterHelper.hpp"
namespace RCSocket {
RCSocketTransmitter::RCSocketTransmitter(const int timing, const int pin, const int systemCode) : timing(timing), pin(pin), inverted(0), dataFrame{ZERO, ZERO, ZERO, ZERO, ZERO, FLOAT, FLOAT, FLOAT, FLOAT, FLOAT, ZERO, ZERO, SYNC} {
initTransmitter(pin);
setSystemCode(systemCode);
}
/**
* set 5 bit width system code
* @param systemCode for examble 0b10101
*/
void RCSocketTransmitter::setSystemCode(const int systemCode){
for(int i = 0; i < 5; i++){
dataFrame[i] = (systemCode&(1<<i)) ? ZERO : FLOAT;
}
}
/**
* select socket to operate on
* @param socketID
*/
void RCSocketTransmitter::selectSocket(const int socketID){
if(socketID >= 5 || socketID < 0 )
return;
dataFrame[5 + socketID] = ZERO;
}
/**
* switch selected socket on
* @param socketID socket to switch on
*/
void RCSocketTransmitter::switchOn(const int socketID){
selectSocket(socketID);
dataFrame[10] = ZERO;
dataFrame[11] = FLOAT;
transmit(dataFrame, pin, timing);
}
/**
* switch selected socket off
* @param socketID socket to switch off
*/
void RCSocketTransmitter::switchOff(const int socketID){
selectSocket(socketID);
dataFrame[10] = FLOAT;
dataFrame[11] = ZERO;
transmit(dataFrame, pin, timing);
}
}