led.py: add ‘on’ state

This commit is contained in:
The MMGen Project 2026-09-09 18:33:59 +00:00
commit 2d84015e5e
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
2 changed files with 11 additions and 4 deletions

View file

@ -184,9 +184,9 @@ class LEDControl:
if self.debug:
msg(f'led_loop({on_secs}, {off_secs})')
if not on_secs:
if not off_secs: # 'on' or 'off'
with open(self.board.control, 'w') as fp:
fp.write('0\n')
fp.write('255\n' if on_secs else '0\n')
while True:
if self.ev_sleep(3600):
return
@ -205,6 +205,7 @@ class LEDControl:
def set(self, state): # pylint: disable=method-hidden
lt = namedtuple('led_timings', ['on_secs', 'off_secs'])
timings = {
'on': lt(1, 0),
'off': lt(0, 0),
'standby': lt(2.2, 0.2),
'busy': lt(0.06, 0.06),

View file

@ -22,19 +22,25 @@ opts_data = {
cfg = Config(opts_data=opts_data)
led = LEDControl(enabled=True)
def confirm_or_exit(prompt):
keypress_confirm(cfg, f'{prompt}. OK?', default_yes=True, do_exit=True)
confirm_or_exit('This script will interactively test LED functionality')
led = LEDControl(enabled=True)
color = led.board.color.capitalize()
atexit.register(led.stop)
led.set('off')
confirm_or_exit(f'{color} LED should now be turned off')
led.set('on')
confirm_or_exit(f'{color} LED should now be turned on')
led.set('busy')
confirm_or_exit(f'{color} LED should now be signaling busy (rapid flashing)')