import time, sys import pygame from dl.communicator import DottedLandscapeCommunicator led_panel_initialized = False clock, screen = None, None leds_x, leds_y, amount_of_channels = 0, 0, 0 circle_radius = 6 circle_spacing = 10 window_margins = (30, 30) print "Panel: waiting for connections to determine panel size" dlc = DottedLandscapeCommunicator() dlc.connect('127.0.0.1', 2323) def on_receive(data): global led_panel_initialized, leds_x, leds_y, dlc h, w = dlc.panel_height, dlc.panel_width if not led_panel_initialized or leds_x != w or leds_y != h: global screen, clock, amount_of_channels width, height = w, h amount_of_channels = dlc.channels print "Panel: received new width, height", w, h, "on %s channels" % amount_of_channels pygame.init() # get the panel size and set the window width accordingly leds_x, leds_y = w, h width, height = w * circle_radius + w * circle_spacing + 2 * window_margins[0], \ h * circle_radius + h * circle_spacing + 2 * window_margins[1]
(r"/a/get-all-animations", GetAllAnimationsHandler), ] + SocketIORouter.urls, **settings) if __name__ == "__main__": import sys try: print "trying to connect via port 80" application.listen(80) except: print "... failed. Backing up to 8888" application.listen(8888) # http_server = tornado.httpserver.HTTPServer(application) # http_server.listen(8888) # http_server.bind(8888) # http_server.start(2) # Forks multiple sub-processes ioloopy = tornado.ioloop.IOLoop.instance() DL_COMMUNICATOR.connect('127.0.0.1', 2323) ioloopy.add_handler(DL_COMMUNICATOR.receive_socket.fileno(), notify_clients_on_panel_change, ioloopy.READ | ioloopy.ERROR) # Send one empty frame. This defines the panel so that other components # get frame information and can start running packet = DL_COMMUNICATOR.encode_partial_frame(0, 0, [0, 0, 0]) DL_COMMUNICATOR.send(packet) ioloopy.start()
def send_partial(self, x, y, r, g, b): liblo.send(self.__target, "/dl/plot", x, y, r, g, b) if __name__ == '__main__': # foo = 'a' # while foo != 'q': # foo = raw_input('> ') # sc.write([int(foo) for i in xrange(0, 8)]) # sc.close() osc = OscRouter() dlc = DottedLandscapeCommunicator() dlc.connect('127.0.0.1', 2323, accept_partial_frames=True) done = False while not done: # get any incoming data from the DL server data = dlc.check_for_data() if not data: continue headers, payload = data if headers[0] == dlc.dl_MAGIC_FRAME_PARTIAL: print "Osc got a partial frame!", len(payload) osc.send_partial(*payload) elif headers[0] == dlc.dl_MAGIC_FRAME_FULL: