Skip to content

Commit

Permalink
reworked structure, updated install and readme, I think this is ready…
Browse files Browse the repository at this point in the history
… to go
  • Loading branch information
Thomas Preston committed Jun 14, 2013
1 parent 68852b6 commit b239b07
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 49 deletions.
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@ After a reboot the /dev/spidev* devices should appear but they require special
privileges to access them. You'll need to add a udev rule (udev monitors and
configures devices) and set up groups by running `spidev-setup.sh'.

### 2. Building and installing the distribution egg
You'll need to install the Python 3 setup tools.
### 2. Building and installing
Python automatically builds the source, generates the egg file and installs.

$ sudo aptitude install python3-setuptools
$ sudo python3 setup.py install

A Python egg can be distributed on it's own but for the time being we'll build
one from source and install it using easy_install3.
Examples
========

$ python3 setup.py bdist_egg
$ easy_install3 dist/pifacecommon-1.0-py3.2.egg

Alternatively we could have just run `python3 setup.py install' but I'm hoping
to distribute the eggs on their own (in a .deb) soon.
$ python3
>>> import pifacecommon
>>> pifacecommon.init()
>>> pifacecommon.write(0xAA, pifacecommon.GPIOA)
>>> pifacecommon.read(pifacecommon.GPIOA)
0xAA
File renamed without changes.
File renamed without changes.
15 changes: 3 additions & 12 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,22 @@ then
fi

# unblacklist spi
./scripts/unblacklist-spi-bcm2708.sh
./bin/unblacklist-spi-bcm2708.sh
if [ $? -ne 0 ]
then
printf "Failed to unblacklist spi-bcm2708.\nExiting...\n"
exit 1
fi

# set up spidev permissions
./scripts/spidev-setup.sh
./bin/spidev-setup.sh
if [ $? -ne 0 ]
then
printf "Failed to setup spidev.\nExiting...\n"
exit 1
fi

# install python library

# install python3 setup tools
#aptitude install python3-setuptools
apt-get install -y python3-setuptools # apt-get is slightly faster

printf "Building egg...\n"
python3 setup.py bdist_egg

# tp - ultimately I want to just distribute the egg
printf "Installing pifacecommon...\n"
easy_install3 dist/pifacecommon-1.0-py3.2.egg
python3 setup.py install
printf "Done!\n"
86 changes: 86 additions & 0 deletions pifacecommon/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# -*- coding: utf-8 -*-
"""Provides common I/O methods for interfacing with PiFace Products
Copyright (C) 2013 Thomas Preston <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http:https://www.gnu.org/licenses/>.
"""
# constants
from .core import (
MAX_BOARDS,
IODIRA,
IODIRB,
IPOLA,
IPOLB,
GPINTENA,
GPINTENB,
DEFVALA,
DEFVALB,
INTCONA,
INTCONB,
IOCON,
GPPUA,
GPPUB,
INTFA,
INTFB,
INTCAPA,
INTCAPB,
GPIOA,
GPIOB,
BANK_OFF,
BANK_ON,
INT_MIRROR_ON,
INT_MIRROR_OFF,
SEQOP_OFF,
SEQOP_ON,
DISSLW_ON,
DISSLW_OFF,
HAEN_ON,
HAEN_OFF,
ODR_ON,
ODR_OFF,
INTPOL_HIGH,
INTPOL_LOW,
IN_EVENT_DIR_ON,
IN_EVENT_DIR_OFF,
IN_EVENT_DIR_BOTH,
)

# classes
from .core import (
DigitalPort,
DigitalInputPort,
DigitalOutputPort,
DigitalItem,
DigitalInputItem,
DigitalOutputItem,
InputFunctionMap,
)

# functions
from .core import (
init,
deinit,
get_bit_mask,
get_bit_num,
read_bit,
write_bit,
read,
write,
spisend,
sleep_microseconds,
wait_for_interrupt,
clear_interrupts,
enable_interrupts,
disable_interrupts,
)
File renamed without changes.
21 changes: 12 additions & 9 deletions pifacecommon.py → pifacecommon/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import time
from abc import ABCMeta
from fcntl import ioctl
from asm_generic_ioctl import _IOW
from .asm_generic_ioctl import _IOW

# spi stuff requires Python 3
assert sys.version_info.major >= 3, \
Expand Down Expand Up @@ -365,7 +365,7 @@ def spisend(bytes_to_send):
len=ctypes.sizeof(wbuffer))

# send the spi command (with a little help from asm-generic
iomsg = _IOW(SPI_IOC_MAGIC, 0, ctypes.c_char*ctypes.sizeof(transfer))
iomsg = _IOW(SPI_IOC_MAGIC, 0, ctypes.c_char * ctypes.sizeof(transfer))
ioctl(spidev_fd, iomsg, ctypes.addressof(transfer))
return ctypes.string_at(rbuffer, ctypes.sizeof(rbuffer))

Expand Down Expand Up @@ -436,14 +436,15 @@ def _call_mapped_input_functions(port, input_func_map):
Returns whether the wait_for_input function should keep waiting for input
"""
if port == GPIOA:
intflag = INTFA
intflag = INTFA
intcapture = INTCAPA
else:
intflag = INTFB
intcapture = INTCAPB

for board_i in range(MAX_BOARDS):
this_board_ifm = [m for m in input_func_map if m['board_num'] == board_i]
this_board_ifm = \
[m for m in input_func_map if m['board_num'] == board_i]

# read the interrupt status of this PiFace board
# interrupt bit (int_bit) - bit map showing what caused the interrupt
Expand All @@ -452,7 +453,7 @@ def _call_mapped_input_functions(port, input_func_map):
if int_flag_bit == 0:
continue # The interrupt has not been flagged on this board
int_bit_num = get_bit_num(int_flag_bit)

# interrupt byte (int_byte) - snapshot of in port when int occured
int_byte = read(intcapture, board_i)

Expand Down Expand Up @@ -498,15 +499,16 @@ def enable_interrupts(port):
_set_gpio_interrupt_edge()
except Timeout as e:
raise InterruptEnableException(
"There was an error bringing gpio%d into userspace. %s" % \
"There was an error bringing gpio%d into userspace. %s" %
(GPIO_INTERRUPT_PIN, e.message)
)


def _bring_gpio_interrupt_into_userspace():
try:
# is it already there?
with open(GPIO_INTERRUPT_DEVICE_VALUE): return
with open(GPIO_INTERRUPT_DEVICE_VALUE):
return
except IOError:
# no, bring it into userspace
with open(GPIO_EXPORT_FILE, 'w') as export_file:
Expand All @@ -533,10 +535,11 @@ def _wait_until_file_exists(filename):
time_limit = start_time + FILE_IO_TIMEOUT
while time.time() < time_limit:
try:
with open(filename): return
with open(filename):
return
except IOError:
pass

raise Timeout("Waiting too long for %s." % filename)


Expand Down
35 changes: 17 additions & 18 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,20 @@
author='Thomas Preston',
author_email='[email protected]',
url='http:https://pi.cs.man.ac.uk/interface.htm',
py_modules=['pifacecommon', 'asm_generic_ioctl'],
long_description="""\
pifacecommon provides common classes, functions and variables to various
piface related modules.
""",
classifiers=[
"License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)",
"Programming Language :: Python",
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Topic :: Software Development :: Libraries :: Python Modules",
],
keywords='piface raspberrypi openlx',
license='GPLv3+',
install_requires=[
'setuptools',
],
)
packages=['pifacecommon'],
long_description="pifacecommon provides common classes, functions and"
"variables to various piface related modules.",
classifiers=[
"License :: OSI Approved :: GNU Affero General Public License v3 or "
"later (AGPLv3+)",
"Programming Language :: Python",
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Topic :: Software Development :: Libraries :: Python Modules",
],
keywords='piface raspberrypi openlx',
license='GPLv3+',
install_requires=[
'setuptools',
],
)

0 comments on commit b239b07

Please sign in to comment.