Skip to content

Respect StatusLED configuration at ShutdownLED when shutdown sequence is cancelled and the led share the same GPIO #1997

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: develop
Choose a base branch
from
4 changes: 3 additions & 1 deletion 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 Expand Up @@ -55,7 +56,8 @@ def callbackFunctionHandler(self, *args):
self.when_pressed(*args)
else:
# switch off LED if pressing was cancelled early (during flashing)
self.set_led(GPIO.LOW)
self.set_led(self.led_state_shutdown_cancelled)


def __repr__(self):
return '<ShutdownButton-{}(pin={},hold_time={},iteration_time={},led_pin={},edge={},bouncetime={},antibouncehack={},pull_up_down={})>'.format(
Expand Down
14 changes: 14 additions & 0 deletions components/gpio_control/gpio_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,19 @@ 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):
shutdownButtonFound = statusLedFound = None
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 All @@ -125,5 +138,6 @@ def gpio_loop(self):
gpio_controler = gpio_control(phoniebox_function_calls)

devices = gpio_controler.get_all_devices(config)
gpio_controler.checkDevicesDependencies()
gpio_controler.print_all_devices()
gpio_controler.gpio_loop()
7 changes: 4 additions & 3 deletions components/gpio_control/test/gpio_settings_test.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ PinUp: 16
PinDown: 19
timeBase: 0.1
; timeBase only for rotary encoder
functionCallDown: functionCallVolD
functionCallUp: functionCallVolU
functionCall1: functionCallVolU
functionCall2: functionCallVolD
functionCallTwoButtons: functionCallVol0
; functionCallTwoButtons only for TwoButtonControl
; functionCallButton: functionCallPlayerPause ; only for RotaryEncoderClickable
Expand All @@ -39,6 +39,7 @@ hold_time: 2
iteration_time: 0.2
; led_pin: <GPIO no. of attached LED>, if LED used
functionCall: functionCallShutdown
led_pin : 12

[Volume0]
enabled: False
Expand Down Expand Up @@ -85,4 +86,4 @@ pull_up_down: pull_up
[StatusLED]
enabled: True
Type: StatusLED
Pin: 14
Pin: 12
6 changes: 4 additions & 2 deletions components/gpio_control/test/test_gpio_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import logging

from mock import patch, MagicMock
from gpio_control import gpio_control
with patch('os.system', return_value=0):
from gpio_control import gpio_control
import function_calls

# def test_functionCallTwoButtonsOnlyBtn2Pressed(btn1Mock, btn2Mock, functionCall1Mock, functionCall2Mock,
Expand All @@ -29,11 +30,12 @@

def testMain():
config = configparser.ConfigParser()
config.read('./gpio_settings_test.ini')
config.read('./test/gpio_settings_test.ini')

phoniebox_function_calls = function_calls.phoniebox_function_calls()
gpio_controler = gpio_control(phoniebox_function_calls)

devices = gpio_controler.get_all_devices(config)
gpio_controler.checkDevicesDependencies()
gpio_controler.print_all_devices()
pass