From 4676ea28514ef8332051355fc0d9d3d59c71f351 Mon Sep 17 00:00:00 2001 From: Tom Wilkie Date: Mon, 5 May 2014 20:20:06 +0000 Subject: [PATCH 1/5] Add swig interface definition and makefile stanzas to build python bindings. --- .gitignore | 6 ++++++ Makefile | 15 +++++++++++++-- RCSwitch.h | 2 +- rcswitch.i | 12 ++++++++++++ 4 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 rcswitch.i diff --git a/.gitignore b/.gitignore index 5761abc..a1bcea0 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,7 @@ *.o +*~ +*.so +*.cxx +\#* +rcswitch.py +*.pyc diff --git a/Makefile b/Makefile index 28fe0f3..9cbe668 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,18 @@ -all: send +B1;2cCXXFLAGS=-O2 -fPIC + +call: send + +rcswitch_wrap.cxx: RCSwitch.h rcswitch.i + swig -c++ -python rcswitch.i + +rcswitch_wrap.o: rcswitch_wrap.cxx + $(CXX) $(CXXFLAGS) -c $+ -o $@ -I/usr/include/python2.7 + +_rcswitch.so: rcswitch_wrap.o RCSwitch.o + $(CXX) -shared $(LDFLAGS) $+ -o $@ -lwiringPi send: RCSwitch.o send.o $(CXX) $(CXXFLAGS) $(LDFLAGS) $+ -o $@ -lwiringPi clean: - $(RM) *.o send + $(RM) *.o *.so *.pyc *.cxx send diff --git a/RCSwitch.h b/RCSwitch.h index f762ebc..eb4c113 100644 --- a/RCSwitch.h +++ b/RCSwitch.h @@ -30,7 +30,7 @@ #else #include #include - #define NULL 0 + #include #define CHANGE 1 #ifdef __cplusplus extern "C"{ diff --git a/rcswitch.i b/rcswitch.i new file mode 100644 index 0000000..4ad8c5e --- /dev/null +++ b/rcswitch.i @@ -0,0 +1,12 @@ +%module rcswitch + +%{ +#define SWIG_FILE_WITH_INIT +#include "RCSwitch.h" +%} + +%include "RCSwitch.h" + +%init %{ + if (wiringPiSetup () == -1) return; + %} From 1e3fb019a4adb54c487098277e71d66c8d654cb6 Mon Sep 17 00:00:00 2001 From: Tom Wilkie Date: Tue, 6 May 2014 08:09:08 +0000 Subject: [PATCH 2/5] Add python example and fix typo in last commit --- Makefile | 2 +- send.py | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100755 send.py diff --git a/Makefile b/Makefile index 9cbe668..371afd8 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -B1;2cCXXFLAGS=-O2 -fPIC +CXXFLAGS=-O2 -fPIC call: send diff --git a/send.py b/send.py new file mode 100755 index 0000000..0c822ed --- /dev/null +++ b/send.py @@ -0,0 +1,24 @@ +#!/usr/bin/python + +import sys +import rcswitch + +PIN = 3 + +def main(argv): + switch = rcswitch.RCSwitch() + switch.enableTransmit(PIN) + + system_code = argv[1] + unit_code = int(argv[2]) + command = int(argv[3]) + + print 'sending systemCode[%s] unitCode[%i] command[%i]' % (system_code, unit_code, command) + + if command == 0: + switch.switchOff(system_code, unit_code) + elif command == 1: + switch.switchOn(system_code, unit_code) + +if __name__ == '__main__': + main(sys.argv) From af94743b403f8086d64b96db017efc848f9d3e58 Mon Sep 17 00:00:00 2001 From: Tom Wilkie Date: Tue, 6 May 2014 08:10:45 +0000 Subject: [PATCH 3/5] Another typo --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 371afd8..9a4e853 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ CXXFLAGS=-O2 -fPIC -call: send +all: send rcswitch_wrap.cxx: RCSwitch.h rcswitch.i swig -c++ -python rcswitch.i From 7bf9b40ac9f06ef39d190d6560f8c14fba70a325 Mon Sep 17 00:00:00 2001 From: Tom Wilkie Date: Wed, 7 May 2014 19:26:01 +0000 Subject: [PATCH 4/5] Add install target to Makefile --- Makefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Makefile b/Makefile index 9a4e853..c283cba 100644 --- a/Makefile +++ b/Makefile @@ -16,3 +16,8 @@ send: RCSwitch.o send.o clean: $(RM) *.o *.so *.pyc *.cxx send + +install: + mkdir -p /usr/lib/python2.7/dist-packages + cp rcswitch.py /usr/lib/python2.7/dist-packages + cp _rcswitch.so /usr/lib/python2.7/dist-packages \ No newline at end of file From 5a8fc87602b25af9d42bed9c317ce55d8aa3d12c Mon Sep 17 00:00:00 2001 From: Tom Wilkie Date: Thu, 15 Jan 2015 18:38:57 +0000 Subject: [PATCH 5/5] Add python bindings to make all target --- .gitignore | 1 + Makefile | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index a1bcea0..de5e5c0 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ \#* rcswitch.py *.pyc +send diff --git a/Makefile b/Makefile index c283cba..4c3b68e 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ CXXFLAGS=-O2 -fPIC -all: send +all: send _rcswitch.so rcswitch_wrap.cxx: RCSwitch.h rcswitch.i swig -c++ -python rcswitch.i