LEDControl.binfo: add color attribute

This commit is contained in:
The MMGen Project 2025-09-09 11:27:04 +00:00
commit e41249aa04
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
3 changed files with 29 additions and 17 deletions

View file

@ -40,38 +40,46 @@ class LEDControl:
control,
trigger = None,
trigger_dfl = 'heartbeat',
trigger_disable = 'none'):
trigger_disable = 'none',
color = 'colored'):
self.name = name
self.control = control
self.trigger = trigger
self.trigger_dfl = trigger_dfl
self.trigger_reset = trigger_dfl
self.trigger_disable = trigger_disable
self.color = color
boards = {
'raspi_pi': binfo(
name = 'Raspberry Pi',
control = '/sys/class/leds/led0/brightness',
trigger = '/sys/class/leds/led0/trigger',
trigger_dfl = 'mmc0'),
trigger_dfl = 'mmc0',
color = 'red'),
'orange_pi': binfo(
name = 'Orange Pi (Armbian)',
control = '/sys/class/leds/orangepi:red:status/brightness'),
control = '/sys/class/leds/orangepi:red:status/brightness',
color = 'red'),
'orange_pi_5': binfo(
name = 'Orange Pi 5 (Armbian)',
control = '/sys/class/leds/status_led/brightness'),
control = '/sys/class/leds/status_led/brightness',
color = 'red'),
'rock_pi': binfo(
name = 'Rock Pi (Armbian)',
control = '/sys/class/leds/status/brightness',
trigger = '/sys/class/leds/status/trigger'),
trigger = '/sys/class/leds/status/trigger',
color = 'blue'),
'rock_5': binfo(
name = 'Rock 5 (Armbian)',
control = '/sys/class/leds/user-led2/brightness',
trigger = '/sys/class/leds/user-led2/trigger'),
trigger = '/sys/class/leds/user-led2/trigger',
color = 'blue'),
'banana_pi_f3': binfo(
name = 'Banana Pi F3 (Armbian)',
control = '/sys/class/leds/sys-led/brightness',
trigger = '/sys/class/leds/sys-led/trigger'),
trigger = '/sys/class/leds/sys-led/trigger',
color = 'green'),
'dummy': binfo(
name = 'Fake Board',
control = '/tmp/led_status',

View file

@ -1034,11 +1034,13 @@ class CmdTestAutosignLive(CmdTestAutosignBTC):
return
try:
LEDControl(enabled=True, simulate=self.simulate_led)
led = LEDControl(enabled=True, simulate=self.simulate_led)
except Exception as e:
msg(str(e))
die(2, 'LEDControl initialization failed')
self.color = led.board.color
def run_setup_mmgen(self):
return self.run_setup(mn_type='mmgen', use_dfl_wallet=None)
@ -1046,7 +1048,7 @@ class CmdTestAutosignLive(CmdTestAutosignBTC):
return self.do_sign_live()
def sign_live_led(self):
return self.do_sign_live(['--led'], 'The LED should start blinking slowly now')
return self.do_sign_live(['--led'], f'The {self.color} LED should start blinking slowly now')
def sign_live_stealth_led(self):
return self.do_sign_live(['--stealth-led'], 'You should see no LED activity now')
@ -1067,7 +1069,7 @@ class CmdTestAutosignLive(CmdTestAutosignBTC):
if led_opts:
opts_msg = '' + ' '.join(led_opts) + ''
info_msg = 'Running ‘mmgen-autosign wait’ with {}. {}'.format(opts_msg, led_msg)
insert_msg = 'Insert removable device and watch for fast LED activity during signing'
insert_msg = f'Insert removable device and watch for fast {self.color} LED activity during signing'
else:
opts_msg = 'no LED'
info_msg = 'Running ‘mmgen-autosign wait’'
@ -1098,7 +1100,7 @@ class CmdTestAutosignLive(CmdTestAutosignBTC):
t.kill(2) # 2 = SIGINT
if self.simulate_led and led_opts:
t.expect('Stopping LED')
t.expect(f'Resetting {self.color} LED')
return t
class CmdTestAutosignLiveSimulate(CmdTestAutosignLive):

View file

@ -30,26 +30,28 @@ confirm_or_exit('This script will interactively test LED functionality')
led = LEDControl(enabled=True)
color = led.board.color.capitalize()
atexit.register(led.stop)
confirm_or_exit('LED should now be turned off')
confirm_or_exit(f'{color} LED should now be turned off')
led.set('busy')
confirm_or_exit('LED should now be signaling busy (rapid flashing)')
confirm_or_exit(f'{color} LED should now be signaling busy (rapid flashing)')
led.set('standby')
confirm_or_exit('LED should now be signaling standby (slow flashing)')
confirm_or_exit(f'{color} LED should now be signaling standby (slow flashing)')
led.set('error')
confirm_or_exit('LED should now be signaling error (insistent flashing)')
confirm_or_exit(f'{color} LED should now be signaling error (insistent flashing)')
led.set('off')
confirm_or_exit('LED should now be turned off')
confirm_or_exit(f'{color} LED should now be turned off')
led.stop()
confirm_or_exit(f'LED should now be in its original state [trigger={led.board.trigger_reset}]')
confirm_or_exit(f'{color} LED should now be in its original state [trigger={led.board.trigger_reset}]')