screen = pygame.display.set_mode((width, height)) # , pygame.OPENGL) pygame.display.set_caption("LED Panel Sim %sx%s" % (w, h) ) clock = pygame.time.Clock() led_panel_initialized = True evt = pygame.event.Event(pygame.USEREVENT, {'data': data}) try: pygame.event.post(evt) except pygame.error: print "skip frame" pygame.event.clear() try: while not led_panel_initialized: _, data = dlc.check_for_data() if data: on_receive(data) time.sleep(0.5) except KeyboardInterrupt: b.stop() sys.exit(1) done = False while done == False: # limit cpu usage (max 10 frames per second) clock.tick(100) # get any incoming data from the DL server _, data = dlc.check_for_data() if data: on_receive(data)
if __name__ == '__main__': dlc = DottedLandscapeCommunicator() dlc.connect('127.0.0.1', 2323) last_packet_received = 0 done = False idle_time = 15 last_frame = None now = time.time() vars = {'frame_duration': 0.5, 'frame_counter': 0} # will be updated by the visualization algorithms visualization, vars = select_random_visualization() while not done: # get any incoming data from the DL server headers, payload = dlc.check_for_data() # panel is up, but there is nothing happening if not payload and dlc.panel_width: now = time.time() if now - last_packet_received > idle_time: frame, alive, vars = visualization(dlc.panel_width, dlc.panel_height, vars) last_frame = frame dlc.send(dlc.encode_full_frame(frame)) vars['frame_counter'] += 1 # new random visualization if not alive: visualization, vars = select_random_visualization()