From 18af8e9b5f82943f9a4fcb6b88869244ecd85ce5 Mon Sep 17 00:00:00 2001 From: David Michel Date: Tue, 13 Aug 2013 07:59:01 +0000 Subject: [PATCH 1/8] added python binding --- Makefile | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 8059493..b0f338a 100644 --- a/Makefile +++ b/Makefile @@ -41,10 +41,22 @@ CFLAGS = $(DEBUG) -Wall $(INCLUDE) -Winline -pipe SRC = geniePi.c + +# Python binding using Swig +############################################################################## + +SWIG_INTERFACE = geniePi.i +SWIG_WRAP_SRC = geniePi_wrap.c +SWIG_WRAP_OBJ = $(SWIG_WRAP_SRC:.c=.o) +SWIG_WRAP = $(SWIG_WRAP_SRC) $(SWIG_WRAP_OBJ) +SWIG_LIB = _geniePi.so +SWIG_PYTHON_SRC = geniePi.py + + # May not need to alter anything below this line ############################################################################### -OBJ = $(SRC:.c=.o) +OBJ = $(SRC:.c=.o) #all: $(STATIC) all: $(DYNAMIC) @@ -63,9 +75,14 @@ $(DYNAMIC): $(OBJ) @echo [Compile] $< @$(CC) -c $(CFLAGS) $< -o $@ +swig: + swig -python $(SWIG_INTERFACE) + gcc -c $(SRC) $(SWIG_WRAP_SRC) -I/usr/include/python2.7 + ld -shared $(OBJ) $(SWIG_WRAP_OBJ) -o $(SWIG_LIB) + .PHONEY: clean clean: - rm -f $(OBJ) *~ core tags *.bak Makefile.bak libgeniePi.* + rm -f $(OBJ) $(SWIG_PYTHON_SRC) $(SWIG_WRAP) $(SWIG_LIB) *~ core tags *.bak Makefile.bak libgeniePi.* .PHONEY: tags tags: $(SRC) From 276f034095b59f82b98a53767aeff5542ce84541 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 13 Aug 2013 09:36:28 +0100 Subject: [PATCH 2/8] added python binding using Swig --- Makefile | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 8059493..b0f338a 100644 --- a/Makefile +++ b/Makefile @@ -41,10 +41,22 @@ CFLAGS = $(DEBUG) -Wall $(INCLUDE) -Winline -pipe SRC = geniePi.c + +# Python binding using Swig +############################################################################## + +SWIG_INTERFACE = geniePi.i +SWIG_WRAP_SRC = geniePi_wrap.c +SWIG_WRAP_OBJ = $(SWIG_WRAP_SRC:.c=.o) +SWIG_WRAP = $(SWIG_WRAP_SRC) $(SWIG_WRAP_OBJ) +SWIG_LIB = _geniePi.so +SWIG_PYTHON_SRC = geniePi.py + + # May not need to alter anything below this line ############################################################################### -OBJ = $(SRC:.c=.o) +OBJ = $(SRC:.c=.o) #all: $(STATIC) all: $(DYNAMIC) @@ -63,9 +75,14 @@ $(DYNAMIC): $(OBJ) @echo [Compile] $< @$(CC) -c $(CFLAGS) $< -o $@ +swig: + swig -python $(SWIG_INTERFACE) + gcc -c $(SRC) $(SWIG_WRAP_SRC) -I/usr/include/python2.7 + ld -shared $(OBJ) $(SWIG_WRAP_OBJ) -o $(SWIG_LIB) + .PHONEY: clean clean: - rm -f $(OBJ) *~ core tags *.bak Makefile.bak libgeniePi.* + rm -f $(OBJ) $(SWIG_PYTHON_SRC) $(SWIG_WRAP) $(SWIG_LIB) *~ core tags *.bak Makefile.bak libgeniePi.* .PHONEY: tags tags: $(SRC) From 7b3205f6c4beeb9056e9d76390a4e820b01bca97 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 13 Aug 2013 09:37:27 +0100 Subject: [PATCH 3/8] added python binding using Swig --- geniePi.i | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 geniePi.i diff --git a/geniePi.i b/geniePi.i new file mode 100644 index 0000000..e9ed81f --- /dev/null +++ b/geniePi.i @@ -0,0 +1,9 @@ +%module geniePi +%{ +/* Parse the header file to generate wrappers */ +#include "geniePi.h" +%} + +/* Parse the header file to generate wrappers */ +%include "geniePi.h" + From ab9106a51066239da8826fcfb6f037ef9094ceed Mon Sep 17 00:00:00 2001 From: David Michel Date: Tue, 13 Aug 2013 13:52:05 +0100 Subject: [PATCH 4/8] added setup.py for easy installation of Python module --- Makefile | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index b0f338a..ad79780 100644 --- a/Makefile +++ b/Makefile @@ -39,7 +39,7 @@ CFLAGS = $(DEBUG) -Wall $(INCLUDE) -Winline -pipe #LIBS = -lpthread -SRC = geniePi.c +SRC = geniePi.c # Python binding using Swig @@ -67,7 +67,7 @@ $(STATIC): $(OBJ) @ranlib $(STATIC) # @size $(STATIC) -$(DYNAMIC): $(OBJ) +$(DYNAMIC): $(OBJ) swig @echo "[Link (Dynamic)]" @$(CC) -shared -Wl,-soname,libgeniePi.so -o libgeniePi.so -lpthread $(OBJ) @@ -76,13 +76,14 @@ $(DYNAMIC): $(OBJ) @$(CC) -c $(CFLAGS) $< -o $@ swig: + @echo "Making Python bindings" swig -python $(SWIG_INTERFACE) gcc -c $(SRC) $(SWIG_WRAP_SRC) -I/usr/include/python2.7 ld -shared $(OBJ) $(SWIG_WRAP_OBJ) -o $(SWIG_LIB) .PHONEY: clean clean: - rm -f $(OBJ) $(SWIG_PYTHON_SRC) $(SWIG_WRAP) $(SWIG_LIB) *~ core tags *.bak Makefile.bak libgeniePi.* + rm -rf $(OBJ) $(SWIG_PYTHON_SRC) $(SWIG_WRAP) $(SWIG_LIB) *~ core tags *.bak Makefile.bak libgeniePi.* build .PHONEY: tags tags: $(SRC) @@ -101,6 +102,7 @@ install: $(TARGET) @install -m 0644 geniePi.h $(DESTDIR)$(PREFIX)/include # @install -m 0755 libgeniePi.a $(DESTDIR)$(PREFIX)/lib @install -m 0755 libgeniePi.so $(DESTDIR)$(PREFIX)/lib + $(shell sudo python setup.py install) .PHONEY: uninstall uninstall: From 16e41acc32cd198e4e1bfb05e210a13473429425 Mon Sep 17 00:00:00 2001 From: David Michel Date: Tue, 13 Aug 2013 13:53:09 +0100 Subject: [PATCH 5/8] added setup.py for easy installation of Python module --- setup.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 setup.py diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..407b3e0 --- /dev/null +++ b/setup.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python + +from distutils.core import setup + +setup(name='geniePi', + version='1.0', + description='Python bindings for the ViSi-Genie-RaspPi-Library, a C library for interfacing 4D Systems displays with a Raspberry Pi', + author='David Michel', + author_email='dmichel76@googlemail.com', + url='https://github.com/dmichel76/ViSi-Genie-RaspPi-Library', + py_modules=['geniePi'], + ) From 3d20cc5f1e48890c759b8b293e7bdeda7d06a5a4 Mon Sep 17 00:00:00 2001 From: David Michel Date: Wed, 14 Aug 2013 20:36:14 +0000 Subject: [PATCH 6/8] fixed setup.py to include so library in egg --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 407b3e0..af1425d 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -from distutils.core import setup +from setuptools import setup, find_packages setup(name='geniePi', version='1.0', @@ -9,4 +9,5 @@ author_email='dmichel76@googlemail.com', url='https://github.com/dmichel76/ViSi-Genie-RaspPi-Library', py_modules=['geniePi'], + data_files=[('.',['_geniePi.so'])], ) From f819434e275af44481e5b736297e4eb56e42f413 Mon Sep 17 00:00:00 2001 From: dmichel76 Date: Thu, 10 Apr 2014 12:36:01 +0100 Subject: [PATCH 7/8] Update README.md added more info regarding the python binding addition --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b08d2d5..0645dbf 100644 --- a/README.md +++ b/README.md @@ -9,12 +9,18 @@ Library for the Raspberry Pi to allow easy communication between 4D Intelligent This library is also required for the Raspberry Pi demo programs. +This is C library with a Pythn bindings that uses the compiled shared library. + ## Installation of Genie Pi Library on the Raspberry Pi ======================================================= - make + It is necessary to install swig prior to attempt the installtion as it is the tool used to generate the python binding. + sudo apt-get install swig + + make + sudo make install ## To Uninstall Genie Pi Library From c7395dcf99e6505f3f5fc05571332d1d83ba0bf2 Mon Sep 17 00:00:00 2001 From: dmichel76 Date: Thu, 10 Apr 2014 12:44:11 +0100 Subject: [PATCH 8/8] Update README.md added python example code reformatted the entry to add code markups --- README.md | 48 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 0645dbf..9bd1420 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,7 @@ ![image](http://www.4dsystems.com.au/imagenes/header.png) ViSi-Genie-RaspPi-Library -==================== - +======================== 4D Systems Raspberry Pi Library for Visi-Genie Library for the Raspberry Pi to allow easy communication between 4D Intelligent Display modules running ViSi-Genie programmed from Workshop 4, and the Raspberry Pi. @@ -14,26 +13,28 @@ This is C library with a Pythn bindings that uses the compiled shared library. ## Installation of Genie Pi Library on the Raspberry Pi ======================================================= - - It is necessary to install swig prior to attempt the installtion as it is the tool used to generate the python binding. - +It is necessary to install swig prior to attempt the installtion as it is the tool used to generate the python binding. + +``` sudo apt-get install swig make sudo make install +``` ## To Uninstall Genie Pi Library ================================= +``` sudo make uninstall - +``` ## To Install wiringPi library (Required for some applications/demos) ===================================================================== * Connect your raspberry Pi up to the Internet and download WiringPi library from github: - +``` cd git clone git://git.drogon.net/wiringPi @@ -41,7 +42,7 @@ This is C library with a Pythn bindings that uses the compiled shared library. cd wiringPi ./build - +``` * This will then download and install the wiringPi library, assuming you have git installed on your Raspberry Pi already. @@ -52,11 +53,15 @@ This is C library with a Pythn bindings that uses the compiled shared library. ================================================================================= * From terminal, launch leafpad (or your chosen editor) with root: +``` sudo leafpad +``` * Nagivate to /boot/cmdline.txt and remove the following text (LEAVE everything else intact) +``` kgdboc=ttyAMA0,115200 console=tty1 +``` * Save the file, overwriting the existing one. @@ -64,8 +69,35 @@ This is C library with a Pythn bindings that uses the compiled shared library. * Comment out the bottom line by putting a '#' symbol at the start of it, where the bottom line is: +``` T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100 +``` * Save the file, overwriting the existing one * Reboot your Raspberry Pi + + +## Examples +=========== +Examples for using the C library are available here on Github: + +https://github.com/4dsystems?tab=repositories + +Here is a little example on how to use the python binding: + +```python +import geniePi as gp +import time + +reply = gp.genieReplyStruct() + +if gp.genieSetup("/dev/ttyAMA0",115200) < 0: + print "rgb: Can't initialise Genie Display\n" + +while True: + while gp.genieReplyAvail(): + gp.genieGetReply(reply) + print reply.cmd, reply.object, reply.index, reply.data + time.sleep(1) +```