diff --git a/.gitignore b/.gitignore index f6062b6..25c2fbe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ -test +send daemon +*.o +*.swp diff --git a/Makefile b/Makefile index fc6912b..7cb16b2 100644 --- a/Makefile +++ b/Makefile @@ -2,16 +2,16 @@ DESCRIPTION = "RCSwitch on Raspberry Pi" LICENSE = "GPL" VERSION = 1.0 -CC = g++ -CFLAGS += -lwiringPi +CXXFLAGS += -Wall +CXXFLAGS += -lwiringPi default: daemon -daemon: daemon.cpp - $(CC) -Wall daemon.cpp RCSwitch.cpp -o daemon $(CFLAGS) +daemon: RCSwitch.o daemon.o + $(CXX) $+ -o $@ $(CXXFLAGS) $(LDFLAGS) -test: test.cpp - $(CC) -Wall test.cpp RCSwitch.cpp -o test $(CFLAGS) +send: RCSwitch.o send.o + $(CXX) $+ -o $@ $(CXXFLAGS) $(LDFLAGS) clean: - rm -f test daemon + rm -f *.o send daemon diff --git a/send.cpp b/send.cpp new file mode 100644 index 0000000..4206671 --- /dev/null +++ b/send.cpp @@ -0,0 +1,39 @@ +/* + * Usage: ./send + * Command is 0 for OFF and 1 for ON + */ + +#include "RCSwitch.h" +#include +#include + +int main(int argc, char *argv[]) { + + /* + * output PIN is hardcoded for testing purposes + * see https://projects.drogon.net/raspberry-pi/wiringpi/pins/ + * for pin mapping of the raspberry pi GPIO connector + */ + int PIN = 0; + char* systemCode = argv[1]; + int unitCode = atoi(argv[2]); + int command = atoi(argv[3]); + + if (wiringPiSetup () == -1) return 1; + printf("sending systemCode[%s] unitCode[%i] command[%i]\n", systemCode, unitCode, command); + RCSwitch mySwitch = RCSwitch(); + mySwitch.enableTransmit(PIN); + + switch(command) { + case 1: + mySwitch.switchOn(systemCode, unitCode); + break; + case 0: + mySwitch.switchOff(systemCode, unitCode); + break; + default: + printf("command[%i] is unsupported\n", command); + return -1; + } + return 0; +}