Skip to content

Commit

Permalink
Added check for state in shutdown button handler (MiczFlor#1984)
Browse files Browse the repository at this point in the history
* Handler gets called when pushing AND releasing the button
* The handler should be called only when the button is pressed, as configured here: https://github.com/MiczFlor/RPi-Jukebox-RFID/blob/develop/components/gpio_control/GPIODevices/simple_button.py#L86
  • Loading branch information
topas-rec authored and AlvinSchiller committed Dec 21, 2023
1 parent 0b0c29a commit 114e90e
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions components/gpio_control/GPIODevices/shutdown_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,28 @@ def set_led(self, status):
logger.debug('cannot set LED to {}: no LED pin defined'.format(status))

def callbackFunctionHandler(self, *args):
logger.debug('ShutdownButton pressed, ensuring long press for {} seconds, checking each {}s'.format(
self.hold_time, self.iteration_time
))
t_passed = 0
led_state = True
while t_passed < self.hold_time:
self.set_led(led_state)
time.sleep(self.iteration_time)
t_passed += self.iteration_time
led_state = not led_state
if not self.is_pressed:
break
if t_passed >= self.hold_time:
# trippel off period to indicate command accepted
self.set_led(GPIO.HIGH)
time.sleep(.6)
# leave it on for the moment, it will be off when the system is down
self.when_pressed(*args)
else:
# switch off LED if pressing was cancelled early (during flashing)
self.set_led(GPIO.LOW)
if self.is_pressed: # Should not be necessary, but handler gets called on rising edge too
logger.debug('ShutdownButton pressed, ensuring long press for {} seconds, checking each {}s'.format(
self.hold_time, self.iteration_time
))
t_passed = 0
led_state = True
while t_passed < self.hold_time:
self.set_led(led_state)
time.sleep(self.iteration_time)
t_passed += self.iteration_time
led_state = not led_state
if not self.is_pressed:
break
if t_passed >= self.hold_time:
# trippel off period to indicate command accepted
self.set_led(GPIO.HIGH)
time.sleep(.6)
# leave it on for the moment, it will be off when the system is down
self.when_pressed(*args)
else:
# switch off LED if pressing was cancelled early (during flashing)
self.set_led(GPIO.LOW)

def __repr__(self):
return '<ShutdownButton-{}(pin={},hold_time={},iteration_time={},led_pin={},edge={},bouncetime={},antibouncehack={},pull_up_down={})>'.format(
Expand Down

0 comments on commit 114e90e

Please sign in to comment.