Skip to content
This repository has been archived by the owner on Oct 15, 2021. It is now read-only.

Add python bindings and example #11

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
*.o
*~
*.so
*.cxx
\#*
rcswitch.py
*.pyc
send
20 changes: 18 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
all: send
CXXFLAGS=-O2 -fPIC

all: send _rcswitch.so

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

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
2 changes: 1 addition & 1 deletion RCSwitch.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#else
#include <wiringPi.h>
#include <stdint.h>
#define NULL 0
#include <stddef.h>
#define CHANGE 1
#ifdef __cplusplus
extern "C"{
Expand Down
12 changes: 12 additions & 0 deletions rcswitch.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
%module rcswitch

%{
#define SWIG_FILE_WITH_INIT
#include "RCSwitch.h"
%}

%include "RCSwitch.h"

%init %{
if (wiringPiSetup () == -1) return;
%}
24 changes: 24 additions & 0 deletions send.py
Original file line number Diff line number Diff line change
@@ -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)