Skip to content

Commit 20c1ac4

Browse files
committed
RCSwitch: add send from r10r
* Removed trailing whitespaces, retabbed, reformatted * Updated Makefile * Added some more files to gitignore
1 parent 5e45bd3 commit 20c1ac4

File tree

3 files changed

+49
-8
lines changed

3 files changed

+49
-8
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
test
1+
send
22
daemon
3+
*.o
4+
*.swp

Makefile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ DESCRIPTION = "RCSwitch on Raspberry Pi"
22
LICENSE = "GPL"
33
VERSION = 1.0
44

5-
CC = g++
6-
CFLAGS += -lwiringPi
5+
CXXFLAGS += -Wall
6+
CXXFLAGS += -lwiringPi
77

88
default: daemon
99

10-
daemon: daemon.cpp
11-
$(CC) -Wall daemon.cpp RCSwitch.cpp -o daemon $(CFLAGS)
10+
daemon: RCSwitch.o daemon.o
11+
$(CXX) $+ -o $@ $(CXXFLAGS) $(LDFLAGS)
1212

13-
test: test.cpp
14-
$(CC) -Wall test.cpp RCSwitch.cpp -o test $(CFLAGS)
13+
send: RCSwitch.o send.o
14+
$(CXX) $+ -o $@ $(CXXFLAGS) $(LDFLAGS)
1515

1616
clean:
17-
rm -f test daemon
17+
rm -f *.o send daemon

send.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Usage: ./send <systemCode> <unitCode> <command>
3+
* Command is 0 for OFF and 1 for ON
4+
*/
5+
6+
#include "RCSwitch.h"
7+
#include <stdlib.h>
8+
#include <stdio.h>
9+
10+
int main(int argc, char *argv[]) {
11+
12+
/*
13+
* output PIN is hardcoded for testing purposes
14+
* see https://projects.drogon.net/raspberry-pi/wiringpi/pins/
15+
* for pin mapping of the raspberry pi GPIO connector
16+
*/
17+
int PIN = 0;
18+
char* systemCode = argv[1];
19+
int unitCode = atoi(argv[2]);
20+
int command = atoi(argv[3]);
21+
22+
if (wiringPiSetup () == -1) return 1;
23+
printf("sending systemCode[%s] unitCode[%i] command[%i]\n", systemCode, unitCode, command);
24+
RCSwitch mySwitch = RCSwitch();
25+
mySwitch.enableTransmit(PIN);
26+
27+
switch(command) {
28+
case 1:
29+
mySwitch.switchOn(systemCode, unitCode);
30+
break;
31+
case 0:
32+
mySwitch.switchOff(systemCode, unitCode);
33+
break;
34+
default:
35+
printf("command[%i] is unsupported\n", command);
36+
return -1;
37+
}
38+
return 0;
39+
}

0 commit comments

Comments
 (0)