diff --git a/Makefile b/Makefile index 8059493..a07709d 100644 --- a/Makefile +++ b/Makefile @@ -39,12 +39,23 @@ CFLAGS = $(DEBUG) -Wall $(INCLUDE) -Winline -pipe #LIBS = -lpthread -SRC = geniePi.c +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) @@ -55,7 +66,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) @@ -63,9 +74,16 @@ $(DYNAMIC): $(OBJ) @echo [Compile] $< @$(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) *~ 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) @@ -84,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 + python setup.py install .PHONEY: uninstall uninstall: diff --git a/README.md b/README.md index b08d2d5..9bd1420 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,40 @@ ![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. 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 ======================================================= - +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 @@ -35,7 +42,7 @@ This library is also required for the Raspberry Pi demo programs. cd wiringPi ./build - +``` * This will then download and install the wiringPi library, assuming you have git installed on your Raspberry Pi already. @@ -46,11 +53,15 @@ This library is also required for the Raspberry Pi demo programs. ================================================================================= * 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. @@ -58,8 +69,35 @@ This library is also required for the Raspberry Pi demo programs. * 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) +``` 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" + diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..af1425d --- /dev/null +++ b/setup.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python + +from setuptools import setup, find_packages + +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'], + data_files=[('.',['_geniePi.so'])], + )