Skip to content

Commit

Permalink
Implemented dependency check between ShutdownButton and StatusLed
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
topas-rec committed May 10, 2023
1 parent 799511b commit 8713fe4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions components/gpio_control/GPIODevices/shutdown_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def __init__(self, pin, action=lambda *args: None, name=None, bouncetime=500, an
led_pin=None, hold_time=3.0, pull_up_down='pull_up', iteration_time=.2):
self.led_pin = led_pin
self.iteration_time = iteration_time
self.led_state_shutdown_cancelled = GPIO.LOW
if self.led_pin is not None:
GPIO.setup(self.led_pin, GPIO.OUT)
super(ShutdownButton, self).__init__(pin=pin, action=action, name=name, bouncetime=bouncetime,
Expand Down
12 changes: 12 additions & 0 deletions components/gpio_control/gpio_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@ def get_all_devices(self, config):
self.logger.info('Device {} not enabled'.format(section))
return self.devices

# Sets the led value at the shutdown button that should be used in case of the shutdown
# sequence is cancelled if StatusLED and ShutdownLED use the sampe GPIO
def checkDevicesDependencies(self):
for dev in self.devices:
if isinstance(dev, ShutdownButton):
shutdownButtonFound = dev
elif isinstance(dev, StatusLED):
statusLedFound = dev
if statusLedFound and shutdownButtonFound:
if statusLedFound.pin == shutdownButtonFound.led_pin:
shutdownButtonFound.led_state_shutdown_cancelled = GPIO.HIGH

def print_all_devices(self):
for dev in self.devices:
print(dev)
Expand Down

0 comments on commit 8713fe4

Please sign in to comment.