Commit Graph

68 Commits

Author SHA1 Message Date
Dave Jones
6b7a3c8851 Fix #25
Add a nice __repr__ to the GPIODevice base class.

This isn't much but generally I think `__repr__` implementations should
be deliberately simple: firstly, they're frequently used for debugging
so if they're at all complex you risk making a debugging tool buggy
(very annoying!). Secondly, if you pour too much info into them you risk
making the debugging output cluttered, so I tend to prefer keeping it to
straight-forward simple to retrieve/calculate info without excessive
detail (if the user wants more, they can always query it directly).

There is one refinement here: in SmoothedInputDevice, `__repr__` is
tweaked to ensure that when partial is False (the default), and the
queue isn't filled, `__repr__` doesn't block (because it should *never*
block).
2015-09-23 14:07:17 +01:00
Ben Nuttall
d869d1e092 Merge pull request #30 from waveform80/flexible-events-opt-params
Flexible events opt params
2015-09-23 13:50:23 +01:00
Ben Nuttall
25b5756b8c Merge pull request #29 from waveform80/output-toggle
Fix #23
2015-09-23 13:50:01 +01:00
Dave Jones
4e33052703 Fix #28
Re-order the test bindings to prefer using no parameters if possible
2015-09-23 13:47:32 +01:00
Dave Jones
7c647ec616 Fix #23
Add OutputDevice.toggle method with locking for correct threaded
operation
2015-09-23 13:38:37 +01:00
Ben Nuttall
e805eedd13 Add properties for leds and all on boards 2015-09-23 11:42:06 +01:00
Ben Nuttall
4a7d60f6a3 Release v0.4.0 v0.4.0 2015-09-23 11:20:43 +01:00
Ben Nuttall
bb33b9aff3 Fix PiTraffic and TrafficHat 2015-09-23 11:16:42 +01:00
Ben Nuttall
2d999f82ab Merge branch 'master' of github.com:rpi-distro/python-gpiozero 2015-09-23 11:15:17 +01:00
Ben Nuttall
5b846a53ca Merge pull request #24 from waveform80/flexible-events
Flexible events
2015-09-23 11:14:39 +01:00
Dave Jones
5c12d8c2e0 Flexible events
Permit event callbacks to accept no parameters, or a single parameter
providing the source input object
2015-09-22 23:20:29 +01:00
Dave Jones
b81d9ed875 Fix missing comma in __init__ 2015-09-22 22:08:06 +01:00
Ben Nuttall
8fe2a9d8ca Add missing comma 2015-09-22 18:23:56 +01:00
Ben Nuttall
b878905f4d Version bump 2015-09-22 18:07:32 +01:00
Ben Nuttall
65d363b7ed Tidy up 2015-09-22 17:52:19 +01:00
Ben Nuttall
b16127dd39 Add PiTraffic back in (was accidentally deleted in e474215) 2015-09-22 17:18:38 +01:00
Ben Nuttall
1bc5a5fa92 Release v0.3.0 v0.3.0 2015-09-22 16:34:25 +01:00
Ben Nuttall
74045c794a Merge pull request #21 from waveform80/tidy-boards
Minor cleanup in boards
2015-09-22 15:25:47 +01:00
Dave Jones
3df061b1bd Minor cleanup in boards
super calls weren't specified correctly, and there's no need to convert
to lists for adding tuples - tuples add to tuples just fine, just not
lists.
2015-09-22 15:05:11 +01:00
Ben Nuttall
03a14c0db5 Merge pull request #20 from waveform80/when-active-when-inactive
Nicely named event attributes
2015-09-22 14:48:08 +01:00
Dave Jones
0c208efff8 Merge branch 'master' into when-active-when-inactive
Conflicts:
	gpiozero/devices.py
	gpiozero/input_devices.py
2015-09-22 12:55:56 +01:00
Dave Jones
b1913e5e39 Add events to all input devices
Fairly major tidy up of the hierarchy as well. There's now a trivial
base class: InputDevice which simply permits reading of state.
WaitableInputDevice descends from this and introduces waitable events
and callbacks, and provides a hook for calling them but needs further
machinery to activate that hook.

DigitalInputDevice (crap name?) descends from WaitableInputDevice and
uses the standard RPi.GPIO callback mechanisms to handle events. This is
intended for use with trivial on/off devices with predictably small
bounce times.

Next is SmoothedInputDevice (crap name?) which also descends from
WaitableInputDevice. This includes a background threaded queue which
constantly monitors the state of the device and provides a running mean
of its state. This is compared to a threshold for determining active /
inactive state. This is intended for use with on/off devices that
"jitter" a lot and for which a running average is therefore appropriate
or for devices which provide an effectively analog readout (like
charging capacitor timings).

MonitorSensor and LightSensor now descend from SmoothedInputDevice, and
Button descends from DigitalInputDevice. All "concrete" classes provide
event aliases appropriate to their function (e.g. when_dark,
when_pressed, etc.)
2015-09-22 12:48:09 +01:00
Ben Nuttall
ae1c31e313 pep8 cleanup 2015-09-22 09:36:25 +01:00
Ben Nuttall
41c1bfb18f Initial commit of basic Robot class 2015-09-21 21:11:56 +01:00
Ben Nuttall
e4742150c4 Add Ryanteck TrafficHat based on FishDish (untested) 2015-09-21 18:40:06 +01:00
Ben Nuttall
840953fd81 Refactor and add blink method to all boards 2015-09-21 18:22:49 +01:00
Ben Nuttall
be48a96e3e Blink defaults to 1 second on/off 2015-09-21 17:55:19 +01:00
Ben Nuttall
2172ed78db Add missing Buzzer import 2015-09-21 17:44:45 +01:00
Ben Nuttall
2de3d9a26b Merge pull request #18 from Gadgetoid/patch-1
Update __init__.py
2015-09-21 17:33:56 +01:00
Ben Nuttall
4403348917 Use super over re-implentation for PiTraffic 2015-09-21 17:30:11 +01:00
Ben Nuttall
8223e56162 Make FishDish Button pull down 2015-09-21 17:18:20 +01:00
Ben Nuttall
d5f3e849a4 Prefix lights and all properties and convert lists to tuples 2015-09-21 17:14:33 +01:00
Philip Howard
9019452973 Update __init__.py
Added rogue missing comma!
2015-09-21 17:00:09 +01:00
Ben Nuttall
5669a98b42 Expose add-on board classes to the module 2015-09-21 15:29:54 +01:00
Ben Nuttall
6d29aaa590 Implement common add-on boards, re: #17 2015-09-21 15:28:01 +01:00
Ben Nuttall
4d7f9eeeb3 Merge pull request #16 from waveform80/when-light-when-dark
When light when dark
2015-09-21 13:26:00 +01:00
Dave Jones
9c64a1dc2f Update the docs with an example
Simple demo of when_dark / when_light
2015-09-21 12:04:51 +01:00
Dave Jones
e9a970ae5c Experiment with LightSensor
Remove wait_for_input, add_callback and remove_callback from the base
InputDevice class and add specific things for LightSensor:
wait_for_light and wait_for_dark to wait on those events occurring, and
when_light and when_dark which can be set to callbacks to call on those
events occurring.
2015-09-21 11:57:50 +01:00
Ben Nuttall
2c0fb7eada Merge pull request #15 from waveform80/doc-tidy
Doc corrections
2015-09-21 11:28:57 +01:00
Ben Nuttall
a07f89c561 Release v0.2.0 v0.2.0 2015-09-21 11:20:21 +01:00
Ben Nuttall
6c98086bff Remove callback before adding a new one 2015-09-21 11:19:21 +01:00
Dave Jones
4a8e17deac Doc corrections
Tidy up wrapping and replace all references to gpio_components with
gpiozero
2015-09-21 08:33:03 +01:00
Ben Nuttall
9219b01081 Merge pull request #14 from waveform80/light-sensor-queue
Light sensor queue
2015-09-20 22:28:00 +01:00
Ben Nuttall
3900827734 Merge pull request #13 from waveform80/fix-threads
Shut down GPIO threads nicely
2015-09-20 22:27:36 +01:00
Dave Jones
0d7c7e28fc Lots of fixes
* Move `is_active` to `GPIODevice`; it's equally applicable to inputs
  and outputs so there's no point having it just in inputs
* Flip the pull-up status for `MotionSensor` (it was backwards leading
  to reversed readings from the sensor)
* Add a `threshold` to `MotionSensor` (optional), and `value` (similar
  to `LightSensor`)
* Also expose `pull_up` as a simple bool property
* Rejig `LightSensor` so it also derives from `InputDevice` (it inherits
  enough to make it worthwhile) and so that its API is similar to
  `MotionSensor` (a `value` property with a `*_detected` property, and a
  background threaded queue which constantly monitors values)
2015-09-20 19:41:19 +01:00
Dave Jones
14f9d843e3 Merge branch 'fix-threads' 2015-09-18 13:08:12 +01:00
Dave Jones
e2ddad6fea Shut down GPIO threads nicely
The motion sensor queue doesn't shut down properly at script end at the
moment and prevents the interpreter shutting down. This is because it's
a non-daemon thread so `__del__` never gets run and so on.

This is a bit of a major PR - I can split it up if you want. Firstly it
makes a common base class called `GPIODevice` for both `InputDevice` and
`OutputDevice`. This just takes care of the read-only pin stuff. Next it
makes a `GPIOThread` class that ensures its a daemon thread, and which
also ensures proper cleanup on shutdown.

Finally, it fixes `MotionSensor` to use the new `GPIOThread` class
(tested this time! Works nicely) and adds the `blink` method to the
`LED` class (which also works nicely this time).
2015-09-18 12:45:30 +01:00
Ben Nuttall
c810730cf5 Merge pull request #11 from waveform80/auto-cleanup
Ensure GPIO.cleanup is called
2015-09-17 22:21:57 +01:00
Dave Jones
481193497a Ensure GPIO.cleanup is called
Small patch to ensure GPIO.cleanup is always called on interpreter
shutdown. This just means the library will "play nice" with whatever
comes afterward.
2015-09-17 18:51:56 +01:00
Ben Nuttall
4c2796e0da Merge pull request #9 from waveform80/pin-read-only
Fix #8
2015-09-17 11:11:51 +01:00