-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend.cpp
43 lines (38 loc) · 1.14 KB
/
send.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
#include "RCSwitch.h"
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
// If no command line argument is given, print the help text
if (argc < 3) {
printf("Usage: %s <gpio pin> <code word> [repeat count]\n", argv[0]);
printf("Sample: %s 0 010111110010101011100011 3\n", argv[0]);
return -1;
}
// Parse arguments
int pin = atoi(argv[1]); // see https://projects.drogon.net/raspberry-pi/wiringpi/pins/
char *codeWord = argv[2]; // 24-bit binary code to send
int repeat = 1; // number of times to repeat the message
if (argc >= 4) {
repeat = atoi(argv[3]);
}
// Configure RCSwitch
if (wiringPiSetup () == -1) return 1;
printf("sending code word [%s] via GPIO pin %i\n", codeWord, pin);
RCSwitch mySwitch = RCSwitch();
mySwitch.setRepeatTransmit(4);
mySwitch.enableTransmit(pin);
// Send message
for (int i = 0; i < repeat; ++i) {
#if not defined( DisableProtocolA )
// Send first group
mySwitch.setProtocol(7);
mySwitch.send(codeWord);
#endif
#if not defined( DisableProtocolB )
// Send second group
mySwitch.setProtocol(8);
mySwitch.send(codeWord);
#endif
}
return 0;
}