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)
This commit is contained in:
Dave Jones
2015-09-18 13:12:36 +01:00
parent 14f9d843e3
commit 0d7c7e28fc
2 changed files with 118 additions and 46 deletions

View File

@@ -12,11 +12,17 @@ class GPIODevice(object):
if pin is None:
raise GPIODeviceError('No GPIO pin number given')
self._pin = pin
self._active_state = 1
self._inactive_state = 0
@property
def pin(self):
return self._pin
@property
def is_active(self):
return GPIO.input(self.pin) == self._active_state
_GPIO_THREADS = set()
def _gpio_threads_shutdown():