forked from pimatic/homeduino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrfcontrol_command.h
88 lines (80 loc) · 1.99 KB
/
rfcontrol_command.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
#include <RFControl.h>
void rfcontrol_command_send();
void rfcontrol_command_receive();
void rfcontrol_loop() {
if(RFControl::hasData()) {
unsigned int *timings;
unsigned int timings_size;
RFControl::getRaw(&timings, &timings_size);
unsigned int buckets[8];
unsigned int pulse_length_divider = RFControl::getPulseLengthDivider();
RFControl::compressTimings(buckets, timings, timings_size);
Serial.print("RF receive ");
for(unsigned int i=0; i < 8; i++) {
unsigned long bucket = buckets[i] * pulse_length_divider;
Serial.print(bucket);
Serial.write(' ');
}
for(unsigned int i=0; i < timings_size; i++) {
Serial.write('0' + timings[i]);
}
Serial.print("\r\n");
RFControl::continueReceiving();
}
}
void rfcontrol_command() {
char* arg = sCmd.next();
if(arg == NULL) {
argument_error();
return;
}
if (strcmp(arg, "send") == 0) {
rfcontrol_command_send();
} else if (strcmp(arg, "receive") == 0) {
rfcontrol_command_receive();
} else {
argument_error();
}
}
void rfcontrol_command_receive() {
char* arg = sCmd.next();
if(arg == NULL) {
argument_error();
return;
}
int interrupt_pin = atoi(arg);
RFControl::startReceiving(interrupt_pin);
Serial.print("ACK\r\n");
}
void rfcontrol_command_send() {
char* arg = sCmd.next();
if(arg == NULL) {
argument_error();
return;
}
int transmitter_pin = atoi(arg);
arg = sCmd.next();
if(arg == NULL) {
argument_error();
return;
}
int repeats = atoi(arg);
// read pulse lengths
unsigned long buckets[8];
for(unsigned int i = 0; i < 8; i++) {
arg = sCmd.next();
if(arg == NULL) {
argument_error();
return;
}
buckets[i] = strtoul(arg, NULL, 10);
}
//read pulse sequence
arg = sCmd.next();
if(arg == NULL) {
argument_error();
return;
}
RFControl::sendByCompressedTimings(transmitter_pin, buckets, arg, repeats);
Serial.print("ACK\r\n");
}