led.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/env python3
  2. import sys, os, atexit
  3. pn = os.path.abspath(os.path.dirname(sys.argv[0]))
  4. parpar = os.path.dirname(os.path.dirname(pn))
  5. os.chdir(parpar)
  6. sys.path[0] = os.curdir
  7. from mmgen.cfg import Config
  8. from mmgen.util import msg
  9. from mmgen.ui import keypress_confirm
  10. from mmgen.led import LEDControl
  11. opts_data = {
  12. 'text': {
  13. 'desc': 'Interactively test LED functionality',
  14. 'usage': 'command',
  15. 'options': """
  16. -h, --help Print this help message
  17. """,
  18. }
  19. }
  20. cfg = Config(opts_data=opts_data)
  21. def confirm_or_exit(prompt):
  22. if not keypress_confirm(cfg, f'{prompt}. OK?', default_yes=True):
  23. msg('Exiting at user request')
  24. sys.exit(1)
  25. confirm_or_exit('This script will interactively test LED functionality')
  26. led = LEDControl(enabled=True)
  27. atexit.register(led.stop)
  28. confirm_or_exit('LED should now be turned off')
  29. led.set('busy')
  30. confirm_or_exit('LED should now be signaling busy (rapid flashing)')
  31. led.set('standby')
  32. confirm_or_exit('LED should now be signaling standby (slow flashing)')
  33. led.set('error')
  34. confirm_or_exit('LED should now be signaling error (insistent flashing)')
  35. led.set('off')
  36. confirm_or_exit('LED should now be turned off')
  37. led.stop()
  38. confirm_or_exit(f'LED should now be in its original state [trigger={led.board.trigger_reset}]')