samplebase.py 4.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import argparse
  2. import time
  3. import sys
  4. import os
  5. sys.path.append(os.path.abspath(os.path.dirname(__file__) + '/..'))
  6. from rgbmatrix import RGBMatrix, RGBMatrixOptions
  7. class SampleBase(object):
  8. def __init__(self, *args, **kwargs):
  9. self.parser = argparse.ArgumentParser()
  10. self.parser.add_argument("-r", "--led-rows", action="store", help="Display rows. 16 for 16x32, 32 for 32x32. Default: 32", default=32, type=int)
  11. self.parser.add_argument("--led-cols", action="store", help="Panel columns. Typically 32 or 64. (Default: 32)", default=32, type=int)
  12. self.parser.add_argument("-c", "--led-chain", action="store", help="Daisy-chained boards. Default: 1.", default=1, type=int)
  13. self.parser.add_argument("-P", "--led-parallel", action="store", help="For Plus-models or RPi2: parallel chains. 1..3. Default: 1", default=1, type=int)
  14. self.parser.add_argument("-p", "--led-pwm-bits", action="store", help="Bits used for PWM. Something between 1..11. Default: 11", default=11, type=int)
  15. self.parser.add_argument("-b", "--led-brightness", action="store", help="Sets brightness level. Default: 100. Range: 1..100", default=100, type=int)
  16. self.parser.add_argument("-m", "--led-gpio-mapping", help="Hardware Mapping: regular, adafruit-hat, adafruit-hat-pwm" , choices=['regular', 'regular-pi1', 'adafruit-hat', 'adafruit-hat-pwm'], type=str)
  17. self.parser.add_argument("--led-scan-mode", action="store", help="Progressive or interlaced scan. 0 Progressive, 1 Interlaced (default)", default=1, choices=range(2), type=int)
  18. self.parser.add_argument("--led-pwm-lsb-nanoseconds", action="store", help="Base time-unit for the on-time in the lowest significant bit in nanoseconds. Default: 130", default=130, type=int)
  19. self.parser.add_argument("--led-show-refresh", action="store_true", help="Shows the current refresh rate of the LED panel")
  20. self.parser.add_argument("--led-slowdown-gpio", action="store", help="Slow down writing to GPIO. Range: 0..4. Default: 1", default=1, type=int)
  21. self.parser.add_argument("--led-no-hardware-pulse", action="store", help="Don't use hardware pin-pulse generation")
  22. self.parser.add_argument("--led-rgb-sequence", action="store", help="Switch if your matrix has led colors swapped. Default: RGB", default="RGB", type=str)
  23. self.parser.add_argument("--led-pixel-mapper", action="store", help="Apply pixel mappers. e.g \"Rotate:90\"", default="", type=str)
  24. self.parser.add_argument("--led-row-addr-type", action="store", help="0 = default; 1=AB-addressed panels; 2=row direct; 3=ABC-addressed panels; 4 = ABC Shift + DE direct", default=0, type=int, choices=[0,1,2,3,4])
  25. self.parser.add_argument("--led-multiplexing", action="store", help="Multiplexing type: 0=direct; 1=strip; 2=checker; 3=spiral; 4=ZStripe; 5=ZnMirrorZStripe; 6=coreman; 7=Kaler2Scan; 8=ZStripeUneven... (Default: 0)", default=0, type=int)
  26. self.parser.add_argument("--led-panel-type", action="store", help="Needed to initialize special panels. Supported: 'FM6126A'", default="", type=str)
  27. self.parser.add_argument("--led-no-drop-privs", dest="drop_privileges", help="Don't drop privileges from 'root' after initializing the hardware.", action='store_false')
  28. self.parser.set_defaults(drop_privileges=True)
  29. def usleep(self, value):
  30. time.sleep(value / 1000000.0)
  31. def run(self):
  32. print("Running")
  33. def process(self):
  34. self.args = self.parser.parse_args()
  35. options = RGBMatrixOptions()
  36. if self.args.led_gpio_mapping != None:
  37. options.hardware_mapping = self.args.led_gpio_mapping
  38. options.rows = self.args.led_rows
  39. options.cols = self.args.led_cols
  40. options.chain_length = self.args.led_chain
  41. options.parallel = self.args.led_parallel
  42. options.row_address_type = self.args.led_row_addr_type
  43. options.multiplexing = self.args.led_multiplexing
  44. options.pwm_bits = self.args.led_pwm_bits
  45. options.brightness = self.args.led_brightness
  46. options.pwm_lsb_nanoseconds = self.args.led_pwm_lsb_nanoseconds
  47. options.led_rgb_sequence = self.args.led_rgb_sequence
  48. options.pixel_mapper_config = self.args.led_pixel_mapper
  49. options.panel_type = self.args.led_panel_type
  50. if self.args.led_show_refresh:
  51. options.show_refresh_rate = 1
  52. if self.args.led_slowdown_gpio != None:
  53. options.gpio_slowdown = self.args.led_slowdown_gpio
  54. if self.args.led_no_hardware_pulse:
  55. options.disable_hardware_pulsing = True
  56. if not self.args.drop_privileges:
  57. options.drop_privileges=False
  58. self.matrix = RGBMatrix(options = options)
  59. try:
  60. # Start loop
  61. print("Press CTRL-C to stop sample")
  62. self.run()
  63. except KeyboardInterrupt:
  64. print("Exiting\n")
  65. sys.exit(0)
  66. return True