mirror of
https://github.com/KevinMidboe/python-gpiozero.git
synced 2025-10-29 09:40:36 +00:00
Add implementation for StatusBoard
This commit is contained in:
@@ -81,6 +81,7 @@ from .boards import (
|
||||
PiTraffic,
|
||||
PiStop,
|
||||
StatusZero,
|
||||
StatusBoard,
|
||||
SnowPi,
|
||||
TrafficLightsBuzzer,
|
||||
FishDish,
|
||||
|
||||
@@ -796,27 +796,99 @@ class PiStop(TrafficLights):
|
||||
|
||||
|
||||
class StatusZero(LEDBoard):
|
||||
def __init__(self, *names, **kwargs):
|
||||
"""
|
||||
Extends :class:`LEDBoard` for The Pi Hut's `STATUS Zero`_: a Pi Zero sized
|
||||
add-on board with three sets of red/green LEDs to provide a status
|
||||
indicator.
|
||||
|
||||
The following example designates the first strip the label "wifi" and the
|
||||
second "raining", and turns them green and red respectfully::
|
||||
|
||||
from gpiozero import StatusZero
|
||||
|
||||
status = StatusZero('wifi', 'raining')
|
||||
status.wifi.green.on()
|
||||
status.raining.red.on()
|
||||
|
||||
:param str \*labels:
|
||||
Specify the names of the labels you wish to designate the strips to.
|
||||
You can list up to three labels. If no labels are given, three strips
|
||||
will be initialised with names 'one', 'two', and 'three'. If some, but
|
||||
not all strips are given labels, any remaining strips will not be
|
||||
initialised.
|
||||
|
||||
.. _STATUS Zero: https://thepihut.com/statuszero
|
||||
"""
|
||||
def __init__(self, *labels, **kwargs):
|
||||
pins = (
|
||||
(4, 17),
|
||||
(27, 22),
|
||||
(10, 9),
|
||||
)
|
||||
if len(names) == 0:
|
||||
names = ['one', 'two', 'three', 'four', 'five'][:len(pins)]
|
||||
elif len(names) > len(pins):
|
||||
if len(labels) == 0:
|
||||
labels = ['one', 'two', 'three'][:len(pins)]
|
||||
elif len(labels) > len(pins):
|
||||
raise ValueError
|
||||
strips = OrderedDict()
|
||||
for index, name in enumerate(names):
|
||||
for index, label in enumerate(labels):
|
||||
green, red = pins[index]
|
||||
strips[name] = LEDBoard(green=green, red=red, **kwargs)
|
||||
strips[label] = LEDBoard(red=red, green=green, **kwargs)
|
||||
super(StatusZero, self).__init__(_order=strips.keys(), **strips)
|
||||
|
||||
|
||||
class StatusBoard(CompositeOutputDevice):
|
||||
"""
|
||||
Extends :class:`CompositeOutputDevice` for The Pi Hut's `STATUS`_ board: a
|
||||
HAT sized add-on board with five sets of red/green LEDs and buttons to
|
||||
provide a status indicator with additional input.
|
||||
|
||||
The following example designates the first strip the label "wifi" and the
|
||||
second "raining", turns the wifi green and then activates the button to
|
||||
toggle its lights when pressed::
|
||||
|
||||
from gpiozero import StatusBoard
|
||||
|
||||
status = StatusBoard('wifi', 'raining')
|
||||
status.wifi.lights.green.on()
|
||||
status.wifi.button.when_pressed = status.wifi.lights.toggle
|
||||
|
||||
:param str \*labels:
|
||||
Specify the names of the labels you wish to designate the strips to.
|
||||
You can list up to three labels. If no labels are given, three strips
|
||||
will be initialised with names 'one', 'two', and 'three'. If some, but
|
||||
not all strips are given labels, any remaining strips will not be
|
||||
initialised.
|
||||
|
||||
.. _STATUS: https://thepihut.com/status
|
||||
"""
|
||||
def __init__(self, *labels, **kwargs):
|
||||
pins = (
|
||||
(4, 17, 14),
|
||||
(27, 22, 19),
|
||||
(10, 9, 15),
|
||||
(11, 5, 26),
|
||||
(6, 13, 18),
|
||||
)
|
||||
if len(labels) == 0:
|
||||
labels = ['one', 'two', 'three', 'four', 'five'][:len(pins)]
|
||||
elif len(labels) > len(pins):
|
||||
raise ValueError
|
||||
strips = OrderedDict()
|
||||
for index, label in enumerate(labels):
|
||||
green, red, button = pins[index]
|
||||
strips[label] = CompositeOutputDevice(
|
||||
button=Button(button),
|
||||
lights=LEDBoard(
|
||||
red=red, green=green, _order=('red', 'green'), **kwargs
|
||||
), _order=('button', 'lights'), **kwargs)
|
||||
super(StatusBoard, self).__init__(_order=strips.keys(), **strips)
|
||||
|
||||
|
||||
class SnowPi(LEDBoard):
|
||||
"""
|
||||
Extends :class:`LEDBoard` for the `Ryanteck SnowPi`_ board.
|
||||
|
||||
|
||||
The SnowPi pins are fixed and therefore there's no need to specify them
|
||||
when constructing this class. The following example turns on the eyes, sets
|
||||
the nose pulsing, and the arms blinking::
|
||||
|
||||
Reference in New Issue
Block a user