Skip to content

Commit 7dd5364

Browse files
committed
Implemented dependency check between ShutdownButton and StatusLed
* untested * If a ShutdownButton and a StatusLed are both configured and use the same led pin, the status that the led should have in case a shutdown request (blinking shutdown led) is cancelled is set at the ShutdownButton
1 parent 799511b commit 7dd5364

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

components/gpio_control/GPIODevices/shutdown_button.py

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def __init__(self, pin, action=lambda *args: None, name=None, bouncetime=500, an
1515
led_pin=None, hold_time=3.0, pull_up_down='pull_up', iteration_time=.2):
1616
self.led_pin = led_pin
1717
self.iteration_time = iteration_time
18+
self.led_state_shutdown_cancelled = GPIO.LOW
1819
if self.led_pin is not None:
1920
GPIO.setup(self.led_pin, GPIO.OUT)
2021
super(ShutdownButton, self).__init__(pin=pin, action=action, name=name, bouncetime=bouncetime,

components/gpio_control/gpio_control.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,18 @@ def get_all_devices(self, config):
101101
self.logger.info('Device {} not enabled'.format(section))
102102
return self.devices
103103

104+
# Sets the led value at the shutdown button that should be used in case of the shutdown
105+
# sequence is cancelled if StatusLED and ShutdownLED use the sampe GPIO
106+
def checkDevicesDependencies(self):
107+
for dev in self.devices:
108+
if isinstance(dev, ShutdownButton):
109+
shutdownButtonFound = dev
110+
elif isinstance(dev, StatusLED):
111+
statusLedFound = dev
112+
if statusLedFound and shutdownButtonFound:
113+
if statusLedFound.pin == shutdownButtonFound.led_pin:
114+
shutdownButtonFound.led_state_shutdown_cancelled = GPIO.HIGH
115+
104116
def print_all_devices(self):
105117
for dev in self.devices:
106118
print(dev)
@@ -125,8 +137,6 @@ def gpio_loop(self):
125137
gpio_controler = gpio_control(phoniebox_function_calls)
126138

127139
devices = gpio_controler.get_all_devices(config)
128-
# Sets the led value at the shutdown button that should be used in case of the shutdown
129-
# sequence is cancelled if StatusLED and ShutdownLED use the same GPIO
130140
gpio_controler.checkDevicesDependencies()
131141
gpio_controler.print_all_devices()
132142
gpio_controler.gpio_loop()

0 commit comments

Comments
 (0)