mirror of
https://github.com/KevinMidboe/python-gpiozero.git
synced 2026-04-25 00:13:49 +00:00
Fix #107
Add forward_device and backward_device to Motor, left_motor and right_motor to Robot, and ensure all CompositeDevice descendents have a proper close() method and closed property. Also, add a few more _check_open calls around the place to make sure GPIODeviceClosed is properly raised in response to read and writing values.
This commit is contained in:
@@ -31,6 +31,10 @@ class LEDBoard(SourceMixin, CompositeDevice):
|
||||
for led in self.leds:
|
||||
led.close()
|
||||
|
||||
@property
|
||||
def closed(self):
|
||||
return all(led.closed for led in self.leds)
|
||||
|
||||
@property
|
||||
def leds(self):
|
||||
"""
|
||||
@@ -188,6 +192,10 @@ class TrafficLightsBuzzer(SourceMixin, CompositeDevice):
|
||||
self.buzzer.close()
|
||||
self.button.close()
|
||||
|
||||
@property
|
||||
def closed(self):
|
||||
return all(o.closed for o in self.all)
|
||||
|
||||
@property
|
||||
def all(self):
|
||||
"""
|
||||
@@ -305,6 +313,24 @@ class Robot(SourceMixin, CompositeDevice):
|
||||
self._left.close()
|
||||
self._right.close()
|
||||
|
||||
@property
|
||||
def closed(self):
|
||||
return self._left.closed and self._right.closed
|
||||
|
||||
@property
|
||||
def left_motor(self):
|
||||
"""
|
||||
Returns the `Motor` device representing the robot's left motor.
|
||||
"""
|
||||
return self._left
|
||||
|
||||
@property
|
||||
def right_motor(self):
|
||||
"""
|
||||
Returns the `Motor` device representing the robot's right motor.
|
||||
"""
|
||||
return self._right
|
||||
|
||||
@property
|
||||
def value(self):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user