view_message.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Commandline Wrapper
  4. # Thomas Wenzlaff
  5. # See LICENSE.rst for details.
  6. import time
  7. import argparse
  8. from luma.led_matrix.device import max7219
  9. from luma.core.interface.serial import spi, noop
  10. from luma.core.legacy import show_message
  11. from luma.core.legacy.font import proportional, CP437_FONT
  12. def output(n, block_orientation, rotate, inreverse, text):
  13. # create matrix device
  14. serial = spi(port=0, device=0, gpio=noop())
  15. device = max7219(serial, cascaded=n or 1, block_orientation=block_orientation,
  16. rotate=rotate or 0, blocks_arranged_in_reverse_order=inreverse)
  17. print(text)
  18. show_message(device, text, fill="white", font=proportional(CP437_FONT), scroll_delay=0.05)
  19. time.sleep(1)
  20. if __name__ == "__main__":
  21. parser = argparse.ArgumentParser(description='view_message arguments',
  22. formatter_class=argparse.ArgumentDefaultsHelpFormatter)
  23. parser.add_argument('--cascaded', '-n', type=int, default=1, help='Number of cascaded MAX7219 LED matrices')
  24. parser.add_argument('--block-orientation', type=int, default=0, choices=[0, 90, -90], help='Corrects block orientation when wired vertically')
  25. parser.add_argument('--rotate', type=int, default=0, choices=[0, 1, 2, 3], help='Rotate display 0=0°, 1=90°, 2=180°, 3=270°')
  26. parser.add_argument('--reverse-order', type=bool, default=False, help='Set to true if blocks are in reverse order')
  27. parser.add_argument('--text', '-t', default='>>> No text set', help='Set text message')
  28. args = parser.parse_args()
  29. try:
  30. output(args.cascaded, args.block_orientation, args.rotate, args.reverse_order, args.text)
  31. except KeyboardInterrupt:
  32. pass