Skip to content

Commit

Permalink
RPIO v0.10.0
Browse files Browse the repository at this point in the history
  * Auto-cleanup on exit (also shuts down ``wait_for_interrupts(threaded=True)``)
  * Bugfix in cpuinfo.c: correctly trim over-voltage header
  * rpio-curses: help shows raspberry sysinfo
  * switched argument ordering of wait_for_interrupts to (``wait_for_interrupts(threaded=False, epoll_timeout=1)``)
  * Added ``RPIO.Exceptions``
  • Loading branch information
Chris Hager committed Mar 14, 2013
1 parent 25e7552 commit 79a7aaa
Show file tree
Hide file tree
Showing 22 changed files with 199 additions and 134 deletions.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,4 @@ Links
* http://pypi.python.org/pypi/RPi.GPIO
* http://www.raspberrypi.org/wp-content/uploads/2012/02/BCM2835-ARM-Peripherals.pdf
* http://www.kernel.org/doc/Documentation/gpio.txt
* `semver versioning standard <http://semver.org/>`_
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.10.0
27 changes: 9 additions & 18 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
rpio (0.9.6) unstable; urgency=low

* RC 0.9.5 had critical bugs. Fixed now.

-- Chris Hager <[email protected]> Wed, 13 Mar 2013 21:30:14 +0100

rpio (0.9.5) unstable; urgency=low
rpio (0.10.0) unstable; urgency=low

* Cleanup
* Auto-cleanup on exit (also shuts down ``wait_for_interrupts(threaded=True)``)
* Bugfix in cpuinfo.c: correctly trim over-voltage header
* rpio-curses: help shows raspberry sysinfo
* switched argument ordering of wait_for_interrupts to (``wait_for_interrupts(threaded=False, epoll_timeout=1)``)

-- Chris Hager <[email protected]> Wed, 13 Mar 2013 02:24:08 +0100
-- Chris Hager <[email protected]> Thu, 14 Mar 2013 15:42:59 +0100

rpio (0.9.4) unstable; urgency=low
rpio (0.9.6) unstable; urgency=low

* Debounce timeout for interrupts (Closes: #XXXXXX)
* Debounce timeout for interrupts
* Threaded argument for wait_for_interrupts()
* Refactoring

-- Chris Hager <[email protected]> Tue, 12 Mar 2013 22:34:04 +0100

rpio (0.9.2) unstable; urgency=low

* Initial PWM release. (Closes: #XXXXXX)

-- Chris Hager <[email protected]> Tue, 12 Mar 2013 17:59:56 +0100
-- Chris Hager <[email protected]> Wed, 13 Mar 2013 21:30:14 +0100
2 changes: 1 addition & 1 deletion documentation/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
# built documents.
#
# The short X.Y version.
version = '0.9.6'
version = '0.10.0'
# The full version, including alpha/beta/rc tags.
release = version

Expand Down
12 changes: 10 additions & 2 deletions documentation/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Or from Github but without Git::
$ cd RPIO-master
$ sudo python setup.py install

Debian packages are available at `metachris.github.com/rpio/download <http://metachris.github.com/rpio/download/latest/>`_.
Debian packages are available at `metachris.github.com/rpio/download <http://metachris.github.com/rpio/download/>`_.

After the installation you can use ``import RPIO`` as well as the command-line tool ``rpio``.

Expand All @@ -84,6 +84,7 @@ Links
* http://pypi.python.org/pypi/RPi.GPIO
* http://www.raspberrypi.org/wp-content/uploads/2012/02/BCM2835-ARM-Peripherals.pdf
* http://www.kernel.org/doc/Documentation/gpio.txt
* `semver versioning standard <http://semver.org/>`_


License & Copyright
Expand Down Expand Up @@ -112,6 +113,13 @@ License & Copyright
Changes
-------

* v0.10.0

* Auto-cleanup on exit (also shuts down ``wait_for_interrupts(threaded=True)``)
* Bugfix in cpuinfo.c: correctly trim over-voltage header
* rpio-curses: help shows raspberry sysinfo
* switched argument ordering of wait_for_interrupts to (``wait_for_interrupts(threaded=False, epoll_timeout=1)``)

* v0.9.6

* Added ``debounce_timeout_ms`` argument to ``RPIO.add_interrupt_callback(..)``
Expand All @@ -121,7 +129,7 @@ Changes
* Added ``RPIO.close_tcp_client(fileno)``
* Debian .deb package builds
* License changed to GNU Lesser General Public License v3 or later (LGPLv3+)
* ``RPIO.sysinfo()`` returns is_overclocked (improved detection in cpuinfo.c)
* Improved detection in cpuinfo.c

* v0.9.1

Expand Down
56 changes: 36 additions & 20 deletions documentation/source/rpio_py.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,21 @@ GPIO & TCP Interrupts
---------------------

``RPIO`` can listen for two kinds of interrupts: ``GPIO`` and ``TCP``. GPIO interrupts happen
when the state on a specific GPIO input changes. TCP interrupts happen when a TCP client
connects to the built-in TCP server and sends a message.
when the state on a specific GPIO input changes. TCP interrupts happen when a TCP socket client
sends a message.


.. method:: RPIO.wait_for_interrupts(threaded=False, epoll_timeout=1)

This is the main blocking loop which, while active, will listen for interrupts and start
your custom callbacks. At some point in your script you need to start this to receive interrupt
callbacks. This blocking method is perfectly suited as "the endless loop that keeps your script
running".

With the argument ``threaded=True``, this method starts in the background while your script
continues in the main thread (RPIO will automatically shut down the thread when your script exits)::

RPIO.wait_for_interrupts(threaded=True)


.. _ref-rpio-py-interrupts:
Expand All @@ -33,12 +46,16 @@ or pull-down resistor.

.. method:: RPIO.add_interrupt_callback(gpio_id, callback, edge='both', pull_up_down=RPIO.PUD_OFF, threaded_callback=False, debounce_timeout_ms=None)

Adds a callback to receive notifications when a GPIO changes it's value. Possible ``pull_up_down`` values are
``RPIO.PUD_UP``, ``RPIO.PUD_DOWN`` and ``RPIO.PUD_OFF`` (default). Possible edges are ``rising``,
``falling`` and ``both`` (default). The values passed to the callback are of type integer, and either ``0`` or ``1``.
A callback might look like this: ``def gpio_callback(gpio_id, value):``.
Adds a callback to receive notifications when a GPIO changes it's state from 0 to 1 or vice versa.

If ``debounce_timeout_ms`` is set, interrupt callbacks will not be started until the specified milliseconds have passed since the last interrupt. Adjust this to your needs (typically between 10ms and 100ms).
* Possible edges are ``rising``, ``falling`` and ``both`` (default).
* Possible ``pull_up_down`` values are ``RPIO.PUD_UP``, ``RPIO.PUD_DOWN`` and ``RPIO.PUD_OFF`` (default).
* If ``threaded_callback`` is ``True``, the callback will be started inside a thread. Else the callback will block RPIO from waiting for interrupts until it has finished (in the meantime no further callbacks are dispatched).
* If ``debounce_timeout_ms`` is set, interrupt callbacks will not be started until the specified milliseconds have passed since the last interrupt. Adjust this to your needs (typically between 10ms and 100ms).

The callback receives two arguments: the gpio number and the value (an integer, either ``0`` (Low) or ``1`` (High)). A callback typically looks like this::

def gpio_callback(gpio_id, value):


.. method:: RPIO.del_interrupt_callback(gpio_id)
Expand Down Expand Up @@ -93,14 +110,11 @@ The following example shows how to listen for some GPIO and TCP interrupts::
# TCP socket server callback on port 8080
RPIO.add_tcp_callback(8080, socket_callback)

# Start the blocking epoll loop, and cleanup interfaces on exit
try:
RPIO.wait_for_interrupts()
finally:
RPIO.cleanup_interrupts()
# Blocking main epoll loop
RPIO.wait_for_interrupts()


If you want to receive a callback inside a Thread (to not block RPIO from returning to wait
To receive a callback inside a Thread (and not block RPIO from returning to wait
for interrupts), set ``threaded_callback`` to ``True`` when adding it::

# for GPIO interrupts
Expand All @@ -116,15 +130,17 @@ to ``add_interrupt_callback(..)`` like this::
RPIO.add_interrupt_callback(7, do_something, debounce_timeout_ms=100)


``wait_for_interrupts()`` is a blocking method which, while running, will listen for
interrupts and start the callbacks. You can add the argument ``threaded=True`` to put
``wait_for_interrupts()`` in a thread to run in the background::
``wait_for_interrupts()`` listens for interrupts and dispatches the callbacks.
You can add the argument ``threaded=True`` to have it run in a thread and your
script continue. Since v0.10.0, RPIO automatically shuts down everything nicely
when your script quits.

::

RPIO.wait_for_interrupts(threaded=True)

To stop ``wait_for_interrupts(..)``, call ``RPIO.stop_waiting_for_interrupts()``. After using
``RPIO.wait_for_interrupts()`` you should call ``RPIO.cleanup_interrupts()`` before your
program quits, to shut everything down cleanly.

To stop ``wait_for_interrupts(..)``, call ``RPIO.stop_waiting_for_interrupts()``.


.. _ref-rpio-py-rpigpio:
Expand Down Expand Up @@ -221,6 +237,6 @@ Interrupt Handling
* ``RPIO.add_tcp_callback(port, callback, threaded_callback=False)``
* ``RPIO.del_interrupt_callback(gpio_id)``
* ``RPIO.close_tcp_client(fileno)``
* ``RPIO.wait_for_interrupts(epoll_timeout=1, threaded=False)``
* ``RPIO.wait_for_interrupts(threaded=False, epoll_timeout=1)``
* ``RPIO.stop_waiting_for_interrupts()``
* implemented with ``epoll``
19 changes: 8 additions & 11 deletions examples/example1_interrupts.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#import logging
#log_format = '%(levelname)s | %(asctime)-15s | %(message)s'
#logging.basicConfig(format=log_format, level=logging.DEBUG)

"""
Example of how to use GPIO and TCP interrupts with RPIO.
RPIO Documentation: http://pythonhosted.org/RPIO
"""
import RPIO


Expand All @@ -15,16 +15,13 @@ def socket_callback(socket, val):
RPIO.close_tcp_client(socket.fileno())


# Add two GPIO interrupt callbacks (second one with a debouce timeout of 100ms)
# Two GPIO interrupt callbacks (second one with a debouce timeout of 100ms)
RPIO.add_interrupt_callback(17, gpio_callback)
RPIO.add_interrupt_callback(14, gpio_callback, edge='rising', \
debounce_timeout_ms=100)

# Add one TCP interrupt callback (opens socket server at port 8080)
# One TCP interrupt callback (opens socket server at port 8080)
RPIO.add_tcp_callback(8080, socket_callback)

# Wait for interrupts indefinitely, and clean up before quitting
try:
RPIO.wait_for_interrupts()
finally:
RPIO.cleanup()
# Starts waiting for interrupts (exit with Ctrl+C)
RPIO.wait_for_interrupts()
4 changes: 4 additions & 0 deletions examples/example2_gpio.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Examples of how to use RPIO as a drop-in replacement for RPi.GPIO
RPIO Documentation: http://pythonhosted.org/RPIO
"""
import RPIO

# set up input channel without pull-up
Expand Down
11 changes: 4 additions & 7 deletions examples/example3_pwm_servo.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
"""
This example demonstrates how to easily control servos.
Demonstration of how to control servo pulses with RPIO.PWM
RPIO Documentation: http://pythonhosted.org/RPIO
"""
from RPIO import PWM

servo = PWM.Servo()

# Set servo on GPIO17 to 1200µs (1.2ms)
# Add servo pulse for GPIO 17 with 1200µs (1.2ms)
servo.set_servo(17, 1200)

...

# Set servo on GPIO17 to 2000µs (2.0ms)
# Add servo pulse for GPIO 17 with 2000µs (2.0ms)
servo.set_servo(17, 2000)

...

# Clear servo on GPIO17
servo.stop_servo(17)
6 changes: 5 additions & 1 deletion examples/example4_pwm_lowlevel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
"""
This example uses lower-level PWM control methods.
This example uses lower-level PWM control methods of RPIO.PWM. The default
settings include a subcycle time of 20ms and a pulse-width increment
granularity of 10us.
RPIO Documentation: http://pythonhosted.org/RPIO
"""
import RPIO.PWM as PWM

Expand Down
14 changes: 8 additions & 6 deletions fabfile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
You can see all commands with `$ fab -l`. Typical usages:
$ fab upload build_gpio test_gpio
$ fab upload build
$ fab upload build_pwm
$ fab upload test
$ fab build_deb
Expand All @@ -22,7 +22,7 @@ def _get_cur_version():


def clean():
run("rm -rf /tmp/source/")
run("sudo rm -rf /tmp/source/")


def upload():
Expand Down Expand Up @@ -96,6 +96,7 @@ def upload_deb():
print " $ ./gen_version_index.sh %s" % v
print " $ ./gen_index.sh"
print " $ git status"
print " $ git add ."
print " $ git commit -am 'Debian packages for RPIO %s" % v
print " $ git push"

Expand Down Expand Up @@ -181,7 +182,7 @@ def upload_to_pypi():
""" Upload sdist and bdist_eggs to pypi """
# DO_UPLOAD provides a safety mechanism to avoid accidental pushes to pypi.
# Set it to "upload" to actually push to pypi; else it only does a dry-run.
DO_UPLOAD = "" # "upload"
DO_UPLOAD = "upload"

# One more safety input and then we are ready to go :)
x = prompt("Are you sure to upload the current version to pypi?")
Expand All @@ -190,13 +191,14 @@ def upload_to_pypi():
return

local("rm -rf dist")
local("python setup.py sdist %s" % DO_UPLOAD)
fn = local("ls dist/", capture=True)
version = fn[5:-7]
local("python setup.py sdist")
version = _get_cur_version()
fn = "RPIO-%s.tar.gz" % version
put("dist/%s" % fn, "/tmp/")
with cd("/tmp"):
run("tar -xf /tmp/%s" % fn)
with cd("/tmp/RPIO-%s" % version):
run("python2.6 setup.py bdist_egg %s" % DO_UPLOAD)
run("python2.7 setup.py bdist_egg %s" % DO_UPLOAD)
run("python3.2 setup.py bdist_egg %s" % DO_UPLOAD)
local("python setup.py sdist %s" % DO_UPLOAD)
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def read(fname):

setup(
name="RPIO",
version="0.9.6",
version="0.10.0",
package_dir={"": "source"},
packages=['RPIO', 'RPIO.PWM'],
ext_modules=[
Expand All @@ -27,7 +27,7 @@ def read(fname):
author="Chris Hager",
author_email="[email protected]",

license="MIT",
license="LGPLv3+",
keywords=["raspberry", "raspberry pi", "interrupts", "gpio", "rpio"],
classifiers=[
"Development Status :: 4 - Beta",
Expand Down
34 changes: 34 additions & 0 deletions source/RPIO/Exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This file is part of RPIO.
#
# Copyright
#
# Copyright (C) 2013 Chris Hager <[email protected]>
#
# License
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser 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 Lesser General Public License for more details at
# <http://www.gnu.org/licenses/lgpl-3.0-standalone.html>
#
# Documentation
#
# http://pythonhosted.org/RPIO
#
"""
This module contains all the exceptions used by the C GPIO wrapper.
"""
import RPIO._GPIO as _GPIO

WrongDirectionException = _GPIO.WrongDirectionException
InvalidModeException = _GPIO.InvalidModeException
InvalidDirectionException = _GPIO.InvalidDirectionException
InvalidChannelException = _GPIO.InvalidChannelException
InvalidPullException = _GPIO.InvalidPullException
ModeNotSetException = _GPIO.ModeNotSetException
Loading

0 comments on commit 79a7aaa

Please sign in to comment.