Ejemplo n.º 1
0
 def __init__(self, channels, dmx_runner, has_simulator, max_show_time):
     self.channels = channels  # channels = HexServers
     self.one_channel = (len(self.channels) == 1)  # Boolean
     self.dmx_runner = dmx_runner  # sACN / DMX King
     self.has_simulator = has_simulator
     self.simulator = SimulatorModel(frame_rate=10,
                                     hostname="localhost",
                                     port=4444) if has_simulator else None
     self.max_show_time = max_show_time
     self.reset_channel_2 = True
Ejemplo n.º 2
0
    )

    args = parser.parse_args()

    if args.list:
        logging.info("Available shows: %s",
                     ', '.join([name for (name, cls) in shows.load_shows()]))
        sys.exit(0)

    if args.simulator:
        sim_host = "localhost"
        sim_port = 4444
        logging.info(f'Using TriSimulator at {sim_host}:{sim_port}')

        model = SimulatorModel(sim_host,
                               port=sim_port,
                               model_json='./data/pixel_map.json')
        triangle_grid = triangle_grid.make_tri(model, 11)
    else:
        logging.info("Starting SACN")
        from model.sacn_model import sACN
        model = sACN(max_dmx=800, model_json="./data/pixel_map.json")

        triangle_grid = triangle_grid.make_tri(model, 3)

    app = TriangleServer(triangle_grid, args)
    try:
        app.start()  # start related service threads
        app.go_web()  # enter main blocking event loop
    except Exception:
        logging.exception("Unhandled exception running TRI!")
Ejemplo n.º 3
0
class ChannelRunner(object):
    """1. Morph each channel between current and next frames
       2. Interpolate two channels together
       3. send signals to LEDs
       4. Put 2nd channel out of phase with the first and trigger restarting 2nd show"""
    def __init__(self, channels, dmx_runner, has_simulator, max_show_time):
        self.channels = channels  # channels = HexServers
        self.one_channel = (len(self.channels) == 1)  # Boolean
        self.dmx_runner = dmx_runner  # sACN / DMX King
        self.has_simulator = has_simulator
        self.simulator = SimulatorModel(frame_rate=10,
                                        hostname="localhost",
                                        port=4444) if has_simulator else None
        self.max_show_time = max_show_time
        self.reset_channel_2 = True

    def start(self):
        for channel in self.channels:
            channel.start()  # start related service threads

    def go(self):
        """Run a micro-frame:
           Interpolates all pixels between the hex_model's current color & next frame color as fast as possible
           Interpolation fraction = time.now() between when the last frame finished and the show's yield / delay time
           Fast interpolation turns on LEDs more gradually,
           but may strain the processor
        """
        for channel in self.channels:
            channel.set_interp_frame()  # Set the interp_frames

        if not self.one_channel:
            # ease in-out cubic works; keep it, but does not interact well with dimming
            fract_channel1 = color.get_ease_in_out_cubic(
                self.channels[0].get_show_intensity())  # 0.0-1.0
            channel1_hex_model, channel2_hex_model = self.channels[
                0].hex_model, self.channels[1].hex_model

            # Two Channels require channel interpolation
            for coord in channel1_hex_model.all_cells():
                pixel1, pixel2 = channel1_hex_model.get_pixel(
                    coord), channel2_hex_model.get_pixel(coord)
                if pixel1.cell_exists():
                    interp_color = color.interp_color(pixel2.interp_frame,
                                                      pixel1.interp_frame,
                                                      fract_channel1)
                    if self.dmx_runner is not None:
                        self.dmx_runner.set(
                            pixel1,
                            interp_color)  # Queue up one pixel's DMX signal
                    if self.simulator:
                        self.simulator.set(
                            pixel1.get_coord(),
                            interp_color)  # Queue up visualizer colors

            self.check_reset_channel_2()  # Force channel 2 to reset if time

        else:
            # One Channel just dumps the single channel
            fract_channel1 = self.channels[0].get_show_intensity()  # 0.0-1.0
            for pixel in self.channels[0].hex_model.all_onscreen_pixels():
                dimmed_interp_color = color.dim_color(pixel.interp_frame,
                                                      fract_channel1)
                if self.dmx_runner is not None:
                    self.dmx_runner.set(
                        pixel,
                        dimmed_interp_color)  # Queue up one pixel's DMX signal
                if self.simulator:
                    self.simulator.set(
                        pixel.get_coord(),
                        dimmed_interp_color)  # Queue up visualizer colors

        if self.dmx_runner is not None:
            self.dmx_runner.go()  # Dump all DMX signals on to LEDs
        if self.simulator:
            self.simulator.go()  # Try to dump signals to visualizer

    def stop(self):
        for channel in self.channels:
            channel.stop()

    def check_reset_channel_2(self):
        """Check and flip the trigger switch to reset channel 2's show"""
        channel_0_show_fract = self.channels[
            0].show_runner.show_runtime / self.max_show_time  # 0-2

        if not self.reset_channel_2 and (0.5 <= channel_0_show_fract < 1.0):
            self.channels[1].show_runner.force_next_show()
            self.reset_channel_2 = True

        if self.reset_channel_2 and (1.25 < channel_0_show_fract < 2.0):
            self.reset_channel_2 = False
Ejemplo n.º 4
0
        print("Available shows:")
        print(', '.join([s[0] for s in shows.load_shows()]))
        sys.exit(0)

    sim_host = "localhost"
    sim_port = 4444  # base port number

    print("Using Square Simulator at {}:{}-{}".format(
        sim_host, sim_port, sim_port + NUM_CHANNELS - 1))

    from model.simulator import SimulatorModel
    # Get ready for DUAL channels
    # Each channel (app) has its own ShowRunner and SimulatorModel
    channels = []  # array of channel objects
    for i in range(NUM_CHANNELS):
        model = SimulatorModel(sim_host, i, port=sim_port + i)
        full_square = square.load_squares(model)
        channels.append(SquareServer(full_square, model, args))

    try:
        for channel in channels:
            channel.start()  # start related service threads

        while True:
            # Force channel 1 out of phase with channel 2 by 50%
            channels[1].runner.show_runtime = (
                channels[0].runner.show_runtime +
                (SHOW_TIME / 2.0)) % SHOW_TIME
            time.sleep(1)

    except KeyboardInterrupt: