-
Notifications
You must be signed in to change notification settings - Fork 329
Expand file tree
/
Copy pathcodesend.cpp
More file actions
62 lines (49 loc) · 2.2 KB
/
codesend.cpp
File metadata and controls
62 lines (49 loc) · 2.2 KB
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
/*
Usage: ./codesend decimalcode [protocol] [pulselength]
decimalcode - As decoded by RFSniffer
protocol - According to rc-switch definitions
pulselength - pulselength in microseconds
'codesend' hacked from 'send' by @justy
- The provided rc_switch 'send' command uses the form systemCode, unitCode, command
which is not suitable for our purposes. Instead, we call
send(code, length); // where length is always 24 and code is simply the code
we find using the RF_sniffer.ino Arduino sketch.
(Use RF_Sniffer.ino to check that RF signals are being produced by the RPi's transmitter
or your remote control)
*/
#include "../rc-switch/RCSwitch.h"
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
// This pin is not the first pin on the RPi GPIO header!
// Consult https://projects.drogon.net/raspberry-pi/wiringpi/pins/
// for more information.
int PIN = 0;
// Parse the first parameter to this command as an integer
int protocol = 0; // A value of 0 will use rc-switch's default value
int pulseLength = 0;
int repeatTransmit = 0;
// If no command line argument is given, print the help text
if (argc == 1) {
printf("Usage: %s decimalcode [protocol] [pulselength] [repeatTransmit]\n", argv[0]);
printf("decimalcode\t- As decoded by RFSniffer\n");
printf("protocol\t- According to rc-switch definitions\n");
printf("pulselength\t- pulselength in microseconds\n");
printf("repeatTransmit\t- How often to repeat the code. Defaults to 10.\n");
return -1;
}
// Change protocol and pulse length accroding to parameters
int code = atoi(argv[1]);
if (argc >= 3) protocol = atoi(argv[2]);
if (argc >= 4) pulseLength = atoi(argv[3]);
if (argc >= 5) repeatTransmit = atoi(argv[4]);
if (wiringPiSetup () == -1) return 1;
printf("sending code[%i]\n", code);
RCSwitch mySwitch = RCSwitch();
if (protocol != 0) mySwitch.setProtocol(protocol);
if (pulseLength != 0) mySwitch.setPulseLength(pulseLength);
if (repeatTransmit != 0) mySwitch.setRepeatTransmit(repeatTransmit);
mySwitch.enableTransmit(PIN);
mySwitch.send(code, 24);
return 0;
}