led.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. keypress_confirm(cfg, f'{prompt}. OK?', default_yes=True, do_exit=True)
  23. confirm_or_exit('This script will interactively test LED functionality')
  24. led = LEDControl(enabled=True)
  25. atexit.register(led.stop)
  26. confirm_or_exit('LED should now be turned off')
  27. led.set('busy')
  28. confirm_or_exit('LED should now be signaling busy (rapid flashing)')
  29. led.set('standby')
  30. confirm_or_exit('LED should now be signaling standby (slow flashing)')
  31. led.set('error')
  32. confirm_or_exit('LED should now be signaling error (insistent flashing)')
  33. led.set('off')
  34. confirm_or_exit('LED should now be turned off')
  35. led.stop()
  36. confirm_or_exit(f'LED should now be in its original state [trigger={led.board.trigger_reset}]')