Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python binding #1

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 23 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -55,17 +66,24 @@ $(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)

.c.o:
@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)
Expand All @@ -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:
Expand Down
52 changes: 45 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,48 @@
![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

cd wiringPi

./build

```

* This will then download and install the wiringPi library, assuming you have git installed on your Raspberry Pi already.

Expand All @@ -46,20 +53,51 @@ 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.

* Navigate and edit /etc/inittab

* 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)
```
9 changes: 9 additions & 0 deletions geniePi.i
Original file line number Diff line number Diff line change
@@ -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"

13 changes: 13 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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'])],
)