def __init__(self, config): from rgbmatrix import RGBMatrix, RGBMatrixOptions options = RGBMatrixOptions() options.rows = config.getint('rows') options.cols = config.getint('cols') options.hardware_mapping = config['led_hardware_mapping'] options.chain_length = config.getint('led_chain') options.parallel = config.getint('led_parallel') options.pwm_bits = config.getint('led_pwm_bits') options.brightness = config.getint('led_brightness') options.pwm_lsb_nanoseconds = config.getint('led_pwm_lsb_nanoseconds') options.inverse_colors = config.getboolean('led_inverse') options.led_rgb_sequence = config['led_rgb_sequence'] options.pixel_mapper_config = config['led_pixel_mapper'] options.row_address_type = config.getint('led_row_addr_type') options.multiplexing = config.getint('led_multiplexing') options.scan_mode = config.getint('led_scan_mode') options.gpio_slowdown = config.getint('led_slowdown_gpio') options.disable_hardware_pulsing = config.getboolean( 'led_no_hardware_pulse') options.show_refresh_rate = config.getboolean('led_show_refresh') options.pwm_dither_bits = config.getint('led_pwm_dither_bits') #options.panel_type = config['led_panel_type'] self.matrix = RGBMatrix(options=options) self.offscreen_canvas = self.matrix.CreateFrameCanvas()
def led_matrix_options(args): options = RGBMatrixOptions() if args.led_gpio_mapping != None: options.hardware_mapping = args.led_gpio_mapping options.rows = args.led_rows options.cols = args.led_cols options.chain_length = args.led_chain options.parallel = args.led_parallel options.row_address_type = args.led_row_addr_type options.multiplexing = args.led_multiplexing options.pwm_bits = args.led_pwm_bits options.brightness = args.led_brightness options.pwm_lsb_nanoseconds = args.led_pwm_lsb_nanoseconds options.led_rgb_sequence = args.led_rgb_sequence if args.led_show_refresh: options.show_refresh_rate = 1 if args.led_slowdown_gpio != None: options.gpio_slowdown = args.led_slowdown_gpio if args.led_no_hardware_pulse: options.disable_hardware_pulsing = True return options
def matrix_options(): ''' Params: options - Display Board connection options matrix - Sets the options Returns: matrix, offscreen_canvas ''' options = RGBMatrixOptions() options.rows = 16 options.cols = 32 options.gpio_slowdown = 4 options.brightness = 100 options.chain_length = 1 options.parallel = 1 options.row_address_type = 0 options.pwm_bits = 11 options.pwm_lsb_nanoseconds = 130 options.led_rgb_sequence = 'RGB' options.pixel_mapper_config = '' #options.panel_type = '' # -> supported: str('FM6126A') options.show_refresh_rate = 0 #options.hardware_mapping = 'regular' matrix = RGBMatrix(options = options) offscreen_canvas = matrix.CreateFrameCanvas() return (matrix, offscreen_canvas)
def process(self): self.args = self.parser.parse_args() options = RGBMatrixOptions() if self.args.led_gpio_mapping != None: options.hardware_mapping = self.args.led_gpio_mapping if self.args.led_slowdown_gpio != None: options.gpio_slowdown = self.args.led_slowdown_gpio options.pwm_lsb_nanoseconds = self.args.led_pwm_lsb_nanoseconds options.pwm_bits = self.args.led_pwm_bits options.rows = self.args.led_rows options.cols = self.args.led_cols options.brightness = self.args.led_brightness if self.args.led_show_refresh: options.show_refresh_rate = 1 if self.args.led_no_hardware_pulse: options.disable_hardware_pulsing = True self.matrix = RGBMatrix(options=options) try: # Start loop print("Press CTRL-C to stop sample") self.run() except KeyboardInterrupt: print("Exiting\n") sys.exit(0) return True
def display_image(image_file): print("hi") image = Image.open(image_file) # Configuration for the matrix options = RGBMatrixOptions() options.rows = 32 options.cols = 64 options.chain_length = 1 options.parallel = 1 options.hardware_mapping = 'adafruit-hat' # If you have an Adafruit HAT: 'adafruit-hat' options.brightness = 100 options.show_refresh_rate = 1 matrix = RGBMatrix(options=options) # Make image fit our screen. image.thumbnail((matrix.width, matrix.height), Image.ANTIALIAS) matrix.SetImage(image.convert('RGB')) try: print("Press CTRL-C to stop.") while True: time.sleep(100) except KeyboardInterrupt: sys.exit(0)
def led_matrix_options(args): options = RGBMatrixOptions() if args.led_gpio_mapping != None: options.hardware_mapping = args.led_gpio_mapping options.rows = args.led_rows options.cols = args.led_cols options.chain_length = args.led_chain options.parallel = args.led_parallel options.row_address_type = args.led_row_addr_type options.multiplexing = args.led_multiplexing options.pwm_bits = args.led_pwm_bits options.brightness = args.led_brightness options.pwm_lsb_nanoseconds = args.led_pwm_lsb_nanoseconds options.led_rgb_sequence = args.led_rgb_sequence try: options.pixel_mapper_config = args.led_pixel_mapper except AttributeError: debug.warning("Your compiled RGB Matrix Library is out of date.") debug.warning("The --led-pixel-mapper argument will not work until it is updated.") if args.led_show_refresh: options.show_refresh_rate = 1 if args.led_slowdown_gpio != None: options.gpio_slowdown = args.led_slowdown_gpio if args.led_no_hardware_pulse: options.disable_hardware_pulsing = True return options
def init_matrix(): global _state options = RGBMatrixOptions() options.hardware_mapping = const.scr_led_gpio_mapping options.rows = const.scr_led_rows options.cols = const.scr_led_cols options.chain_length = const.scr_led_chain options.parallel = const.scr_led_parallel options.row_address_type = const.scr_row_address_type options.multiplexing = const.scr_led_multiplexing options.pwm_bits = const.scr_led_pwm_bits options.brightness = _state.currentBrightness options.pwm_lsb_nanoseconds = const.scr_led_pwm_lsb_nanoseconds options.led_rgb_sequence = const.scr_led_rgb_sequence if const.scr_led_show_refresh: options.show_refresh_rate = 1 if const.scr_led_slowdown_gpio is not None: options.gpio_slowdown = const.scr_led_slowdown_gpio if const.scr_led_no_hardware_pulse: options.disable_hardware_pulsing = True options.pixel_mapper_config = const.scr_pixel_mapper_config # https://github.com/hzeller/rpi-rgb-led-matrix/issues/679#issuecomment-423268899 _state.matrix = RGBMatrix(options=options) for fontFilename in ["10x20", "6x9", "5x8"]: font = graphics.Font() font.LoadFont("{}/{}.bdf".format(const.scr_fonts_dir, fontFilename)) _state.fonts.append(font) logger.debug("matrix canvas initialized")
def process(self): self.args = self.parser.parse_args() options = RGBMatrixOptions() options.hardware_mapping = "adafruit-hat" options.rows = self.args.led_rows options.cols = self.args.led_cols options.chain_length = self.args.led_chain options.parallel = self.args.led_parallel options.row_address_type = self.args.led_row_addr_type options.multiplexing = self.args.led_multiplexing options.pwm_bits = self.args.led_pwm_bits options.brightness = self.args.led_brightness options.pwm_lsb_nanoseconds = self.args.led_pwm_lsb_nanoseconds options.led_rgb_sequence = self.args.led_rgb_sequence options.pixel_mapper_config = self.args.led_pixel_mapper if self.args.led_show_refresh: options.show_refresh_rate = 1 if self.args.led_slowdown_gpio != None: options.gpio_slowdown = self.args.led_slowdown_gpio options.disable_hardware_pulsing = True self.matrix = RGBMatrix(options=options) try: # Start loop print("Press CTRL-C to stop sample") self.run() except KeyboardInterrupt: print("Exiting\n") sys.exit(0) return True
def process(self): self.args = self.parser.parse_args() options = RGBMatrixOptions() if self.args.led_gpio_mapping is not None: options.hardware_mapping = self.args.led_gpio_mapping options.rows = self.args.led_rows options.cols = self.args.led_cols options.chain_length = self.args.led_chain options.parallel = self.args.led_parallel options.row_address_type = self.args.led_row_addr_type options.multiplexing = self.args.led_multiplexing options.pwm_bits = self.args.led_pwm_bits options.brightness = self.args.led_brightness options.pwm_lsb_nanoseconds = self.args.led_pwm_lsb_nanoseconds options.led_rgb_sequence = self.args.led_rgb_sequence options.pixel_mapper_config = self.args.led_pixel_mapper if self.args.led_show_refresh: options.show_refresh_rate = 1 if self.args.led_slowdown_gpio is not None: options.gpio_slowdown = self.args.led_slowdown_gpio if self.args.led_no_hardware_pulse: options.disable_hardware_pulsing = True self.matrix = RGBMatrix(options=options) return True
def __init__(self, options, font=defaultFont): self._logger = LogManager.get_logger(__name__) self._logger.debug("Initializing display with '{0}'".format(options)) matrix_options = RGBMatrixOptions() matrix_options.hardware_mapping = options.led_gpio_mapping matrix_options.rows = options.led_rows matrix_options.cols = options.led_cols matrix_options.chain_length = options.led_chain matrix_options.parallel = options.led_parallel matrix_options.row_address_type = options.led_row_addr_type matrix_options.multiplexing = options.led_multiplexing matrix_options.pwm_bits = options.led_pwm_bits matrix_options.brightness = options.led_brightness matrix_options.pwm_lsb_nanoseconds = options.led_pwm_lsb_nanoseconds matrix_options.led_rgb_sequence = options.led_rgb_sequence matrix_options.show_refresh_rate = options.led_show_refresh matrix_options.gpio_slowdown = options.led_slowdown_gpio matrix_options.disable_hardware_pulsing = options.led_no_hardware_pulse self._matrix = RGBMatrix(options = matrix_options) self._offscreen_canvas = self._matrix.CreateFrameCanvas() self._font = font
def init_matrix(self): args = self.parser.parse_args() options = RGBMatrixOptions() if args.led_gpio_mapping != None: options.hardware_mapping = args.led_gpio_mapping options.rows = args.led_rows options.cols = args.led_cols options.chain_length = args.led_chain options.parallel = args.led_parallel options.row_address_type = args.led_row_addr_type options.multiplexing = args.led_multiplexing options.pwm_bits = args.led_pwm_bits options.brightness = args.led_brightness options.pwm_lsb_nanoseconds = args.led_pwm_lsb_nanoseconds options.led_rgb_sequence = args.led_rgb_sequence options.pixel_mapper_config = args.led_pixel_mapper # Gave error that no options named panel_type existed #options.panel_type = args.led_panel_type if args.led_show_refresh: options.show_refresh_rate = 1 if args.led_slowdown_gpio != None: options.gpio_slowdown = args.led_slowdown_gpio if args.led_no_hardware_pulse: options.disable_hardware_pulsing = True return RGBMatrix(options=options)
def process(self): self.args = self.parser.parse_args() options = RGBMatrixOptions() if self.args.led_gpio_mapping != None: options.hardware_mapping = self.args.led_gpio_mapping options.rows = self.args.led_rows options.chain_length = self.args.led_chain options.parallel = self.args.led_parallel options.pwm_bits = self.args.led_pwm_bits options.brightness = self.args.led_brightness options.pwm_lsb_nanoseconds = self.args.led_pwm_lsb_nanoseconds if self.args.led_show_refresh: options.show_refresh_rate = 1 if self.args.led_slowdown_gpio != None: options.gpio_slowdown = self.args.led_slowdown_gpio if self.args.led_no_hardware_pulse: options.disable_hardware_pulsing = True self.matrix = RGBMatrix(options = options) try: # Start loop print("Press CTRL-C to stop sample") self.run() except KeyboardInterrupt: print("Exiting\n") sys.exit(0) return True
def setup(self): self.args = self.parser.parse_args() options = RGBMatrixOptions() if self.args.led_gpio_mapping != None: options.hardware_mapping = self.args.led_gpio_mapping options.rows = self.args.led_rows options.cols = self.args.led_cols options.chain_length = self.args.led_chain options.parallel = self.args.led_parallel options.pwm_bits = self.args.led_pwm_bits options.brightness = self.args.led_brightness options.pwm_lsb_nanoseconds = self.args.led_pwm_lsb_nanoseconds options.led_rgb_sequence = self.args.led_rgb_sequence options.pixel_mapper_config = self.args.led_pixel_mapper options.row_address_type = 0 options.multiplexing = 0 options.show_refresh_rate = 0 options.disable_hardware_pulsing = 0 if self.args.led_show_refresh: options.show_refresh_rate = 1 # ラズパイ判別 model = subprocess.run(["cat", "/proc/device-tree/model"], encoding='utf-8', stdout=subprocess.PIPE) # Pi4の場合, SetImageのunsafeを有効, gpio速度低下 if "Raspberry Pi 4" in model.stdout: self.unsafe = False if self.args.led_slowdown_gpio < 2: options.gpio_slowdown = 3 else: options.gpio_slowdown = self.args.led_slowdown_gpio else: self.unsafe = True options.gpio_slowdown = self.args.led_slowdown_gpio self.matrix = RGBMatrix(options=options)
def initialize_and_run(self): self.args = self.parser.parse_args() logging_level = logging.getLevelName(self.args.log_level) self.logging = logging.basicConfig(level=logging_level, format='%(asctime)-15s [%(levelname)s] (%(threadName)-10s) %(message)s', ) logging.info("Initializing LED matrix...") options = RGBMatrixOptions() if self.args.led_gpio_mapping != None: options.hardware_mapping = self.args.led_gpio_mapping options.rows = self.args.led_rows options.chain_length = self.args.led_chain options.parallel = self.args.led_parallel options.pwm_bits = self.args.led_pwm_bits options.brightness = self.args.led_brightness options.pwm_lsb_nanoseconds = self.args.led_pwm_lsb_nanoseconds options.led_rgb_sequence = self.args.led_rgb_sequence if self.args.led_show_refresh: options.show_refresh_rate = 1 if self.args.led_slowdown_gpio != None: options.gpio_slowdown = self.args.led_slowdown_gpio if self.args.led_no_hardware_pulse: options.disable_hardware_pulsing = True self.matrix = RGBMatrix(options = options) #self.led_pulse_cache = FanoutCache(self.args.cache_location, shards=20, timeout=1) self.columns = self.args.led_rows * self.args.led_chain self.rows = 32 # TODO: configure me self.pulse_events_url = "http://192.168.1.7:9201/events" # TODO: configure me self.target_fps = 24. self.time_per_frame_ms = (1 / self.target_fps) * 1000. self.draw_state = DrawState() self.stop_event = threading.Event() try: # Start loop print("Press CTRL-C to stop sample") self.run() except KeyboardInterrupt: print("Exiting\n") self.stop_event.set() sys.exit(0) return True
def screen_init(): # Configuration for the matrix options = RGBMatrixOptions() options.rows = 32 options.cols = 64 options.chain_length = 1 options.parallel = 1 options.hardware_mapping = 'adafruit-hat' # If you have an Adafruit HAT: 'adafruit-hat' options.brightness = 100 options.show_refresh_rate = 1 global matrix matrix = RGBMatrix(options=options)
def gen_options(cfg): options = RGBMatrixOptions() options.chain_length = int(cfg['display']['chain']) options.rows = int(cfg['display']['rows']) options.cols = int(cfg['display']['cols']) options.brightness = float(cfg['display']['brightness']) options.hardware_mapping = cfg['display']['hardware_mapping'] options.show_refresh_rate = int( cfg['display']['debug']['show_refresh_rate']) return options
def __init__(self, *, rows=32, columns=64, chain=1, brightness=80, gpio_mapping="adafruit-hat-pwm", parallel=1, pwm_bits=11, panel_type="", rgb_sequence="rgb", show_refresh=False, slowdown_gpio=None, no_hardware_pulse=False, pwm_lsb_nanoseconds=130, row_addr_type=0, multiplexing=0, pixel_mapper=""): options = RGBMatrixOptions() options.drop_privileges = 0 options.daemon = 0 options.hardware_mapping = gpio_mapping options.rows = rows options.cols = columns options.chain_length = chain options.parallel = parallel options.pwm_bits = pwm_bits options.brightness = brightness options.panel_type = panel_type options.led_rgb_sequence = rgb_sequence options.pwm_lsb_nanoseconds = pwm_lsb_nanoseconds options.row_address_type = row_addr_type options.multiplexing = multiplexing options.pixel_mapper_config = pixel_mapper if show_refresh: options.show_refresh_rate = 1 if slowdown_gpio is not None: options.gpio_slowdown = slowdown_gpio if no_hardware_pulse: options.disable_hardware_pulsing = True self._matrix = RGBMatrix(options=options) self._buffer = self._matrix.CreateFrameCanvas() self._background = (0, 0, 0) self._position = (0, 0)
def rgbmatrix_options_factory(config): """Build RGBMatrix options object.""" options = RGBMatrixOptions() if config['led-gpio-mapping'] != None: options.hardware_mapping = config['led-gpio-mapping'] options.rows = config['led-rows'] options.chain_length = config['led-chain'] options.parallel = config['led-parallel'] options.pwm_bits = config['led-pwm-bits'] options.brightness = config['led-brightness'] options.pwm_lsb_nanoseconds = config['led-pwm-lsb-nanoseconds'] if config['led-show-refresh']: options.show_refresh_rate = 1 if config['led-slowdown-gpio'] != None: options.gpio_slowdown = config['led-slowdown-gpio'] if config['led-no-hardware-pulse']: options.disable_hardware_pulsing = True return options
def __init__(self): print("__init__") options = RGBMatrixOptions() options.hardware_mapping = "adafruit-hat-pwm" options.rows = 32 options.cols = 64 options.chain_length = 1 options.parallel = 1 options.row_address_type = 0 options.multiplexing = 0 options.pwm_bits = 11 options.brightness = 100 options.disable_hardware_pulsing = 0 #options.pwm_lsb_nanoseconds = 130 options.pwm_lsb_nanoseconds = 500 # 400=Good options.led_rgb_sequence = "RGB" options.pixel_mapper_config = "" options.show_refresh_rate = 0 options.gpio_slowdown = 0 options.daemon = 0 options.drop_privileges = False self.matrix = RGBMatrix(options=options) self.offscreen_canvas = self.matrix.CreateFrameCanvas() self.font = graphics.Font() self.fontSmall = graphics.Font() # Setup Fonts # Get fonts from here: https://github.com/dk/ibm-vio-os2-fonts #self.font.LoadFont("../../../fonts/10x20.bdf") #self.font.LoadFont("ibm-vio-12x20-r-iso10646-1-20.bdf") self.fontSmall.LoadFont( "fonts/ibm-vio-6x10-r-iso10646-1-10-modified.bdf") self.font.LoadFont("fonts/ibm-vio-12x30-r-iso10646-1-30-modified.bdf") #self.font.LoadFont("fonts/ibm-vio-10x21-r-iso10646-1-21.bdf") #self.font.LoadFont("fonts/ibm-vio-12x22-r-iso10646-1-22-modified.bdf") #self.font.LoadFont("../../../fonts/helvR12.bdf") self.matrix.brightness = 100 #self.textColor = graphics.Color(255, 0, 0) logger.info("display adafruit hat init complete")
def canvas_init(self, arg): options = RGBMatrixOptions() options.rows = arg.led_rows fontsize_book = int(arg.font_main[0]) if arg.font_main else 16 fontsize_bold = int(arg.font_bold[0]) if arg.font_bold else 16 self.FELD_LOOP = [ "man", "design", "branding", "advertising", "typography", "photography", "illustration", "editorial", "video", "print", "web" ] self.ANIMATION_TIME = arg.animation_time[ 0] if arg.animation_time else 10 self.YSHIFT = arg.yshift[0] if arg.yshift else 5 self.PREFIX = arg.prefx[0] if arg.prefx else "Feld" self.SUFFIX = arg.suffx[0] if arg.suffx else "" self.MAIN_COLOR = graphics.Color(255, 255, 255) self.MARGIN_LEFT = arg.margin_left[0] if arg.margin_left else 0 self.MARGIN_TOP = arg.margin_top[0] if arg.margin_top else ( options.rows + fontsize_bold) / 2 self.FONT_MAIN = graphics.Font() self.FONT_MAIN.LoadFont("libs/myfont/weights/font_" + str(fontsize_book) + "_book.bdf") self.FONT_BOLD = graphics.Font() self.FONT_BOLD.LoadFont("libs/myfont/weights/font_" + str(fontsize_bold) + "_bold.bdf") self.SPACE_AFTER_PREFIX = arg.space_after_prefix[ 0] if arg.space_after_prefix else 0 self.SPACE_BEFORE_SUFFIX = arg.space_before_suffix[ 0] if arg.space_before_suffix else 0 if arg.led_gpio_mapping != None: options.hardware_mapping = arg.led_gpio_mapping options.chain_length = arg.led_chain options.parallel = arg.led_parallel options.pwm_bits = arg.led_pwm_bits options.brightness = arg.led_brightness options.pwm_lsb_nanoseconds = arg.led_pwm_lsb_nanoseconds options.led_rgb_sequence = arg.led_rgb_sequence if arg.led_show_refresh: options.show_refresh_rate = 1 if arg.led_slowdown_gpio != None: options.gpio_slowdown = arg.led_slowdown_gpio if arg.led_no_hardware_pulse: options.disable_hardware_pulsing = True return RGBMatrix(options=options)
def process(self): """Process command-line input and initiate the RGB matrix with those options before calling the subclass code.""" self.args = self.parser.parse_args() options = RGBMatrixOptions() if self.args.led_gpio_mapping is not None: options.hardware_mapping = self.args.led_gpio_mapping options.rows = self.args.led_rows options.cols = self.args.led_cols options.chain_length = self.args.led_chain options.parallel = self.args.led_parallel options.row_address_type = self.args.led_row_addr_type options.multiplexing = self.args.led_multiplexing options.pwm_bits = self.args.led_pwm_bits options.brightness = self.args.led_brightness options.pwm_lsb_nanoseconds = self.args.led_pwm_lsb_nanoseconds options.led_rgb_sequence = self.args.led_rgb_sequence options.pixel_mapper_config = self.args.led_pixel_mapper if self.args.led_show_refresh: options.show_refresh_rate = 1 if self.args.led_slowdown_gpio is not None: options.gpio_slowdown = self.args.led_slowdown_gpio if self.args.led_no_hardware_pulse: options.disable_hardware_pulsing = True # Don't drop root status; lets us maintain I2C access, etc. # For some reason this isn't working from command line. options.drop_privileges = False signal.signal(signal.SIGTERM, self.signal_handler) signal.signal(signal.SIGINT, self.signal_handler) self.matrix = RGBMatrix(options=options) try: self.run() except KeyboardInterrupt: sys.exit(0) return True
def getOptions(self): options = RGBMatrixOptions() options.hardware_mapping = "regular" options.rows = 16 options.cols = 32 options.chain_length = 1 options.parallel = 1 options.row_address_type = 0 options.multiplexing = 0 options.pwm_bits = 11 options.brightness = 50 options.pwm_lsb_nanoseconds = 130 options.led_rgb_sequence = "RGB" options.show_refresh_rate = 0 options.gpio_slowdown = 4 options.disable_hardware_pulsing = False options.scan_mode = 1 return options
def rgbmatrix_options_factory(config): """Build RGBMatrix options object.""" options = RGBMatrixOptions() if config["led-gpio-mapping"] is not None: options.hardware_mapping = config["led-gpio-mapping"] options.rows = config["led-rows"] options.cols = config["led-cols"] options.chain_length = config["led-chain"] options.parallel = config["led-parallel"] options.pwm_bits = config["led-pwm-bits"] options.brightness = config["led-brightness"] options.pwm_lsb_nanoseconds = config["led-pwm-lsb-nanoseconds"] if config["led-show-refresh"]: options.show_refresh_rate = 1 if config["led-slowdown-gpio"] is not None: options.gpio_slowdown = config["led-slowdown-gpio"] if config["led-no-hardware-pulse"]: options.disable_hardware_pulsing = True if config["led-pixel-mapper"]: options.pixel_mapper_config = config["led-pixel-mapper"] return options
def rgbmatrix_options(): options = RGBMatrixOptions() options.multiplexing = 0 options.row_address_type = 0 options.brightness = 100 options.rows = led_panel_height options.cols = led_panel_width options.chain_length = 1 options.parallel = 1 options.hardware_mapping = 'regular' options.inverse_colors = False options.led_rgb_sequence = "RGB" options.gpio_slowdown = 3 options.pwm_lsb_nanoseconds = 150 options.show_refresh_rate = 0 options.disable_hardware_pulsing = True options.scan_mode = 0 options.pwm_bits = 11 options.daemon = 0 options.drop_privileges = 0 return options
def rgbmatrix_options(): options = RGBMatrixOptions() options.multiplexing = 6 options.row_address_type = 0 options.brightness = 80 options.rows = number_of_rows_per_panel options.cols = number_of_columns_per_panel options.chain_length = number_of_panels options.parallel = parallel options.hardware_mapping = 'regular' options.inverse_colors = False options.led_rgb_sequence = "BGR" options.gpio_slowdown = 1 options.pwm_lsb_nanoseconds = 130 options.show_refresh_rate = 0 options.disable_hardware_pulsing = False options.scan_mode = 0 options.pwm_bits = 11 options.daemon = 0 options.drop_privileges = 0 return options
def __init__(self, LEDFormat): logging.info('Initialising LEDMatrix') options = RGBMatrixOptions() options.hardware_mapping = LEDFormat['matrixDriver'] options.rows = LEDFormat['matrixRows'] options.cols = LEDFormat['matrixCols'] options.chain_length = LEDFormat['matrixCount'] options.pixel_mapper_config = LEDFormat['matrixMapper'] options.row_address_type = 0 options.multiplexing = 0 options.pwm_bits = 11 options.brightness = 100 options.pwm_lsb_nanoseconds = 130 options.led_rgb_sequence = "RGB" options.show_refresh_rate = 0 self.__MatrixID = RGBMatrix(options = options) self.__MatrixID.Clear() xsize = self.__MatrixID.width ysize = self.__MatrixID.height self.__LEDXSize = xsize self.__LEDYSize = ysize self.__LEDXMax = xsize - 1 self.__LEDYMax = ysize - 1 self.__DrawOnMatrix = True self.__MatrixCanvas = Canvas((self.__LEDXSize, self.__LEDYSize)) self.__FadeMatrixCanvas = Canvas((self.__LEDXSize, self.__LEDYSize)) self.__MatrixBuffer = self.__MatrixID.CreateFrameCanvas()
def process(self): options = RGBMatrixOptions() if self.args['led_gpio_mapping'] is not None: options.hardware_mapping = self.args['led_gpio_mapping'] options.rows = self.args['led_rows'] options.cols = self.args['led_cols'] options.chain_length = self.args['led_chain'] options.parallel = self.args['led_parallel'] options.row_address_type = self.args['led_row_addr_type'] options.multiplexing = self.args['led_multiplexing'] options.pwm_bits = self.args['led_pwm_bits'] options.brightness = self.args['led_brightness'] options.pwm_lsb_nanoseconds = self.args['led_pwm_lsb_nanoseconds'] options.led_rgb_sequence = self.args['led_rgb_sequence'] options.pixel_mapper_config = self.args['led_pixel_mapper'] options.panel_type = self.args['led_panel_type'] if self.args['led_show_refresh']: options.show_refresh_rate = 1 if self.args['led_slowdown_gpio'] is not None: options.gpio_slowdown = self.args['led_slowdown_gpio'] if self.args['led_no_hardware_pulse']: options.disable_hardware_pulsing = True self.matrix = RGBMatrix(options=options) try: print('Press CTRL-C to stops') self.run() except KeyboardInterrupt: print('Exiting\n') sys.exit(0) return True
def process(self): self.args = self.parser.parse_args() options = RGBMatrixOptions() if self.args.led_gpio_mapping != None: options.hardware_mapping = self.args.led_gpio_mapping options.rows = NUM_ROWS options.cols = NUM_COLS options.chain_length = CHAIN_LEN options.parallel = self.args.led_parallel options.row_address_type = self.args.led_row_addr_type options.multiplexing = self.args.led_multiplexing options.pwm_bits = self.args.led_pwm_bits options.brightness = BRIGHTNESS options.pwm_lsb_nanoseconds = self.args.led_pwm_lsb_nanoseconds options.led_rgb_sequence = self.args.led_rgb_sequence options.pixel_mapper_config = self.args.led_pixel_mapper # options.panel_type = self.args.led_panel_type if self.args.led_show_refresh: options.show_refresh_rate = 1 options.gpio_slowdown = GPIO_SLOWDOWN if self.args.led_no_hardware_pulse: options.disable_hardware_pulsing = True self.matrix = RGBMatrix(options=options) try: # Start loop print("Press CTRL-C to stop sample") self.run() except KeyboardInterrupt: print("Exiting\n") sys.exit(0) return True
def init_leds(): options = RGBMatrixOptions() options.hardware_mapping = 'regular' options.rows = 32 options.cols = 64 options.chain_length = 1 options.parallel = 1 options.row_address_type = 0 options.multiplexing = 0 options.brightness = 85 options.pwm_bits = 8 options.pwm_lsb_nanoseconds = 130 options.led_rgb_sequence = 'RGB' options.pixel_mapper_config = '' options.panel_type = '' options.limit_refresh_rate_hz = 0 # no fps limit decreases the cpu usage options.show_refresh_rate = 0 options.gpio_slowdown = 4 options.disable_hardware_pulsing = False options.drop_privileges = False return RGBMatrix(options=options)
def rgbmatrix_options(): options = RGBMatrixOptions() options.multiplexing = 1 options.row_address_type = 0 options.brightness = 60 options.rows = 64 options.cols = 64 options.chain_length = 1 options.parallel = 1 options.hardware_mapping = 'regular' options.inverse_colors = False options.led_rgb_sequence = "GBR" options.gpio_slowdown = 4 options.pwm_lsb_nanoseconds = 50 options.show_refresh_rate = 1 options.disable_hardware_pulsing = False options.scan_mode = 1 options.pwm_bits = 11 # options.daemon = 0 # options.drop_privileges = 0 # options.pixel_mapper_config = "U-mapper;Rotate:90" options.pixel_mapper_config = "Rotate:90" return RGBMatrix(options=options)
from rgbmatrix import RGBMatrix, RGBMatrixOptions from PIL import Image if len(sys.argv) < 2: sys.exit("Require an image argument") else: image_file = sys.argv[1] image = Image.open(image_file) # Configuration for the matrix options = RGBMatrixOptions() options.rows = 32 options.cols = 64 options.chain_length = 2 options.hardware_mapping = 'adafruit-hat-pwm' options.pixel_mapper_config = 'U-mapper;Rotate:90' options.show_refresh_rate = 1 matrix = RGBMatrix(options=options) # Make image fit our screen. image.thumbnail((matrix.width, matrix.height), Image.ANTIALIAS) matrix.SetImage(image.convert('RGB')) try: print("Press CTRL-C to stop.") while True: time.sleep(100) except KeyboardInterrupt: sys.exit(0)
def setup(self): """ Returns False on success, True on error """ parser = argparse.ArgumentParser() # RGB matrix standards parser.add_argument( "-r", "--led-rows", action="store", help="Display rows. 32 for 32x32, 64 for 64x64. Default: 64", default=64, type=int, ) parser.add_argument( "--led-cols", action="store", help="Panel columns. Typically 32 or 64. (Default: 64)", default=64, type=int, ) parser.add_argument( "-c", "--led-chain", action="store", help="Daisy-chained boards. Default: 6.", default=6, type=int, ) parser.add_argument( "-P", "--led-parallel", action="store", help="For Plus-models or RPi2: parallel chains. 1..3. Default: 1", default=1, type=int, ) parser.add_argument( "-p", "--led-pwm-bits", action="store", help="Bits used for PWM. Something between 1..11. Default: 11", default=11, type=int, ) parser.add_argument( "-b", "--led-brightness", action="store", help="Sets brightness level. Default: 100. Range: 1..100", default=100, type=int, ) 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, ) 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, ) 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, ) parser.add_argument( "--led-show-refresh", action="store_true", help="Shows the current refresh rate of the LED panel", ) parser.add_argument( "--led-slowdown-gpio", action="store", help="Slow down writing to GPIO. Range: 0..4. Default: 3", default=4, # For Pi 4 w/6 matrices type=int, ) parser.add_argument( "--led-no-hardware-pulse", action="store", help="Don't use hardware pin-pulse generation", ) parser.add_argument( "--led-rgb-sequence", action="store", help="Switch if your matrix has led colors swapped. Default: RGB", default="RGB", type=str, ) parser.add_argument( "--led-pixel-mapper", action="store", help='Apply pixel mappers. e.g "Rotate:90"', default="", type=str, ) 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], ) 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, ) parser.add_argument( "--led-panel-type", action="store", help="Needed to initialize special panels. Supported: 'FM6126A'", default="", type=str, ) parser.add_argument( "--led-no-drop-privs", dest="drop_privileges", help= "Don't drop privileges from 'root' after initializing the hardware.", action="store_false", ) # Extra args unique to this program parser.add_argument( "-i", action="store", help="Image filename for texture map. Default: maps/earth.jpg", default="maps/earth.jpg", type=str, ) parser.add_argument( "-v", dest="pointy", help="Orient cube with vertices at top & bottom.", action="store_true", ) parser.add_argument( "-s", action="store", help="Spin time in seconds/revolution. Default: 10.0", default=10.0, type=float, ) parser.add_argument( "-a", action="store", help="Antialiasing samples/axis. Default: 1", default=1, type=int, ) parser.add_argument( "-t", action="store", help="Run time in seconds. Default: run indefinitely", default=-1.0, type=float, ) parser.add_argument( "-f", action="store", help="Fade in/out time in seconds. Default: 0.0", default=0.0, type=float, ) parser.add_argument( "-e", action="store", help="Edge-to-edge measure of matrix.", default=1.0, type=float, ) parser.add_argument( "-E", action="store", help="Edge-to-edge measure of opposite cube faces.", default=1.0, type=float, ) parser.set_defaults(drop_privileges=True) parser.set_defaults(pointy=False) args = parser.parse_args() if args.led_rows != args.led_cols: print( os.path.basename(__file__) + ": error: led rows and columns must match") return True if args.led_chain * args.led_parallel != 6: print( os.path.basename(__file__) + ": error: total chained * parallel matrices must equal 6") return True options = RGBMatrixOptions() if args.led_gpio_mapping is not None: options.hardware_mapping = args.led_gpio_mapping options.rows = args.led_rows options.cols = args.led_cols options.chain_length = args.led_chain options.parallel = args.led_parallel options.row_address_type = args.led_row_addr_type options.multiplexing = args.led_multiplexing options.pwm_bits = args.led_pwm_bits options.brightness = args.led_brightness options.pwm_lsb_nanoseconds = args.led_pwm_lsb_nanoseconds options.led_rgb_sequence = args.led_rgb_sequence options.pixel_mapper_config = args.led_pixel_mapper options.panel_type = args.led_panel_type if args.led_show_refresh: options.show_refresh_rate = 1 if args.led_slowdown_gpio is not None: options.gpio_slowdown = args.led_slowdown_gpio if args.led_no_hardware_pulse: options.disable_hardware_pulsing = True if not args.drop_privileges: options.drop_privileges = False self.matrix = RGBMatrix(options=options) self.canvas = self.matrix.CreateFrameCanvas() self.matrix_size = args.led_rows self.chain_length = args.led_chain self.max_brightness = args.led_brightness self.run_time = args.t self.fade_time = args.f self.samples_per_pixel = args.a * args.a matrix_measure = args.e cube_measure = args.E self.spin_time = args.s try: image = Image.open(args.i) except FileNotFoundError: print( os.path.basename(__file__) + ": error: image file " + args.i + " not found") return True self.map_width = image.size[0] map_height = image.size[1] self.map_data = image.tobytes() # Longitude and latitude tables are 1-dimensional, # can do that because we iterate every pixel every frame. pixels = self.matrix.width * self.matrix.height subpixels = pixels * self.samples_per_pixel self.longitude = [0.0 for _ in range(subpixels)] self.latitude = [0 for _ in range(subpixels)] # imgbuf holds result for one face of cube self.imgbuf = bytearray(self.matrix_size * self.matrix_size * 3) coords = POINTY_COORDS if args.pointy else SQUARE_COORDS # Fill the longitude & latitude tables, one per subpixel. ll_index = 0 # Index into longitude[] and latitude[] arrays ratio = matrix_measure / cube_measure # Scale ratio offset = ((1.0 - ratio) + ratio / (self.matrix_size * args.a)) * 0.5 # Axis offset for face in range(6): upper_left = coords[VERTS[face][0]] upper_right = coords[VERTS[face][1]] lower_left = coords[VERTS[face][2]] for ypix in range(self.matrix_size): # For each pixel Y... for xpix in range(self.matrix_size): # For each pixel X... for yaa in range(args.a): # " antialiased sample Y... yfactor = offset + ratio * (ypix * args.a + yaa) / ( self.matrix_size * args.a) for xaa in range(args.a): # " antialiased sample X... xfactor = offset + ratio * ( xpix * args.a + xaa) / (self.matrix_size * args.a) # Figure out the pixel's 3D position in space... x3d = (upper_left[0] + (lower_left[0] - upper_left[0]) * yfactor + (upper_right[0] - upper_left[0]) * xfactor) y3d = (upper_left[1] + (lower_left[1] - upper_left[1]) * yfactor + (upper_right[1] - upper_left[1]) * xfactor) z3d = (upper_left[2] + (lower_left[2] - upper_left[2]) * yfactor + (upper_right[2] - upper_left[2]) * xfactor) # Then convert to polar coords on a sphere... self.longitude[ll_index] = ( (math.pi + math.atan2(-z3d, x3d)) / (math.pi * 2.0) * self.map_width) % self.map_width self.latitude[ll_index] = int( (math.pi * 0.5 - math.atan2( y3d, math.sqrt(x3d * x3d + z3d * z3d))) / math.pi * map_height) ll_index += 1 return False