Commit Graph

342 Commits

Author SHA1 Message Date
Ben Nuttall b97e97909c Add flash method to output devices and boards, close #22 2015-09-23 15:31:06 +01:00
Ben Nuttall 931571b85d Add toggle to boards 2015-09-23 14:44:41 +01:00
Ben Nuttall 3a19d8f5ab Merge branch 'master' of github.com:rpi-distro/python-gpiozero 2015-09-23 14:18:44 +01:00
Ben Nuttall 5e0a56b11c Make buzzer blink, close #19 2015-09-23 14:18:40 +01:00
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
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 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
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 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 2015-09-22 16:34:25 +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
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
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 a07f89c561 Release 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 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 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
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
Dave Jones 1219d99ded Fix #8
Make the pin property a read-only property
2015-09-17 10:50:23 +01:00
Ben Nuttall df1eb2dffd Merge branch 'motion-queue' of git://github.com/waveform80/gpio-zero into waveform80-motion-queue 2015-09-15 17:57:43 +01:00
Ben Nuttall abdc215175 Rename to gpiozero and tidy up 2015-09-15 17:53:08 +01:00