async def graphics(manager, conf): # Frame number used for animations frameno = 0 pixel_strs = {} while manager.any_alive: frameno = get_frameno() pixel_strs = OrderedDict() if not conf.args.do_single: for size, pix_map_normlized in conf.maps.items(): pixel_list = direct_rainbows(pix_map_normlized, frameno) pixel_strs[size] = pix_array2text(*pixel_list) await manager.wait_for_workers_idle_async() for server_id, server_panel_info in conf.panels.items(): if server_id not in manager.sessions: logging.debug( "server id %s not found in manager coroutines: %s" % ( server_id, manager.sessions.keys(), )) continue if server_id not in manager.cmd_queues: logging.debug( "server id %s not found in manager command queues: %s" % ( server_id, manager.cmd_queues.keys(), )) continue for panel_number, size in server_panel_info: if conf.args.do_single: pixel_str = pix_array2text(frameno, 255, 127) await manager.chunk_payload_with_linenum_async( server_id, "M2603", {"Q": panel_number}, pixel_str) else: assert size in pixel_strs, \ ( "Your panel configuration specifies a size %s but " "your map configuration does not contain a " "matching entry, only %s" ) % ( size, conf.maps.keys() ) pixel_str = pixel_strs.get(size) if not pixel_str: logging.warning("empty pixel_str generated: %s" % pixel_str) await manager.chunk_payload_with_linenum_async( server_id, "M2600", {"Q": panel_number}, pixel_str) logging.debug("gfx %s fn %s" % (server_id, frameno)) await manager.chunk_payload_with_linenum_async( server_id, "M2610", None, None)
def main(): telecortex.graphics.IMG_SIZE = 100 telecortex.graphics.DOT_RADIUS = 1 conf = TeleCortexManagerConfig( name="session", description=( "draw a single rainbow spanning onto telecortex controllers"), default_config='dome_overhead') conf.parser.add_argument('--enable-preview', default=False, action='store_true') conf.parse_args() logging.debug("\n\n\nnew session at %s" % datetime.now().isoformat()) pixel_map_cache = OrderedDict() pixel_map_cache['smol'] = normalize_pix_map(PIXEL_MAP_SMOL) pixel_map_cache['big'] = normalize_pix_map(PIXEL_MAP_BIG) img = get_square_canvas() if conf.args.enable_preview: cv2_setup_main_window(img) manager = conf.setup_manager() while manager: frameno = get_frameno() fill_rainbows(img, frameno) pixel_list_smol = interpolate_pixel_map(img, pixel_map_cache['smol'], INTERPOLATION_TYPE) pixel_list_big = interpolate_pixel_map(img, pixel_map_cache['big'], INTERPOLATION_TYPE) pixel_str_smol = pix_array2text(*pixel_list_smol) pixel_str_big = pix_array2text(*pixel_list_big) for server_id, server_panel_info in conf.panels.items(): if not manager.sessions.get(server_id): continue for panel_number, panel_name in server_panel_info: if panel_name.startswith('big'): pixel_str = pixel_str_big elif panel_name.startswith('smol'): pixel_str = pixel_str_smol manager.sessions[server_id].chunk_payload_with_linenum( "M2600", {"Q": panel_number}, pixel_str) manager.sessions[server_id].send_cmd_with_linenum('M2610') if conf.args.enable_preview: if cv2_show_preview(img, pixel_map_cache): break
async def graphics(manager, conf): pixel_map_cache = OrderedDict() pixel_str_cache = OrderedDict() img = get_square_canvas() if conf.args.enable_preview: cv2_setup_main_window(img) while manager.any_alive: frameno = get_frameno() fill_rainbows(img, frameno) for server_id, server_panel_info in conf.panels.items(): if server_id not in manager.sessions: continue for panel_number, map_name in server_panel_info: if (server_id, panel_number) not in pixel_map_cache.keys(): if map_name not in conf.maps: raise UserWarning( 'Panel map_name %s not in known mappings: %s' % ( map_name, conf.maps.keys() ) ) panel_map = conf.maps[map_name] pixel_map_cache[(server_id, panel_number)] = panel_map panel_map = pixel_map_cache.get((server_id, panel_number)) pixel_list = interpolate_pixel_map( img, panel_map, INTERPOLATION_TYPE ) pixel_str_cache[(server_id, panel_number)] = \ pix_array2text(*pixel_list) await manager.wait_for_workers_idle_async() for (server_id, panel_number), pixel_str in pixel_str_cache.items(): await manager.chunk_payload_with_linenum_async( server_id, "M2600", {"Q": panel_number}, pixel_str ) for server_id, server_panel_info in conf.panels.items(): if server_id not in manager.sessions: continue await manager.chunk_payload_with_linenum_async( server_id, 'M2610', None, None) if conf.args.enable_preview: if cv2_show_preview(img, conf.maps): break
def main(): """ Main. Enumerate serial ports Select board by pid/vid Rend some perpendicular rainbowz Respond to microcontroller """ telecortex.graphics.IMG_SIZE = 64 telecortex.graphics.DOT_RADIUS = 1 conf = TeleCortexSessionConfig( name="interpolate_opencv", description="draw interpolated maps using opencv", default_config='dome_overhead') conf.parser.add_argument('--serial-dev', ) conf.parser.add_argument('--serial-baud', default=DEFAULT_BAUD) conf.parser.add_argument('--enable-preview', default=False, action='store_true') conf.parse_args() logging.debug("\n\n\nnew session at %s" % datetime.now().isoformat()) target_device = conf.args.serial_dev if target_device is None: target_device = find_serial_dev(TEENSY_VID) if not target_device: raise UserWarning("target device not found") else: logging.debug("target_device: %s" % target_device) logging.debug("baud: %s" % conf.args.serial_baud) # img = cv2.imread( # '/Users/derwent/Documents/GitHub/touch_dome/Images/test_image.jpg', # cv2.IMREAD_COLOR) img = get_square_canvas() if conf.args.enable_preview: cv2_setup_main_window(img) with serial.Serial(port=target_device, baudrate=DEFAULT_BAUD, timeout=1) as ser: sesh = conf.setup_session(ser) while sesh: frameno = get_frameno() fill_rainbows(img, frameno) if conf.args.config == 'goggles': pixel_list_goggle = interpolate_pixel_map( img, MAPS_GOGGLE['goggle'], INTERPOLATION_TYPE) pixel_str_goggle = pix_array2text(*pixel_list_goggle) else: pixel_list_smol = interpolate_pixel_map( img, MAPS_DOME['smol'], INTERPOLATION_TYPE) pixel_list_big = interpolate_pixel_map(img, MAPS_DOME['big'], INTERPOLATION_TYPE) pixel_str_smol = pix_array2text(*pixel_list_smol) pixel_str_big = pix_array2text(*pixel_list_big) for panel, map_name in conf.panels[0]: if map_name.startswith('big'): pixel_str = pixel_str_big elif map_name.startswith('smol'): pixel_str = pixel_str_smol elif map_name.startswith('goggle'): pixel_str = pixel_str_goggle sesh.chunk_payload_with_linenum("M2600", {"Q": panel}, pixel_str) sesh.send_cmd_with_linenum("M2610") if conf.args.enable_preview: if cv2_show_preview(img, MAPS_DOME): break