Beispiel #1
0
def main():
    global SRT_FILENAME, AUDIO_FILENAME, MAX_BRIGHTNESS, TICK_TIME, DEBUG, VERBOSE
    parser = argparse.ArgumentParser(description="LushRoom sound and light command-line player")
    # group = parser.add_mutually_exclusive_group()
    # group.add_argument("-v", "--verbose", action="store_true")
    # group.add_argument("-q", "--quiet", action="store_true")
    parser.add_argument("-s","--srt", default=SRT_FILENAME, help=".srt file name for lighting events")
    parser.add_argument("-a","--audio", default=AUDIO_FILENAME, help="audio file for sound stream")
    parser.add_argument("-b","--brightness", default=MAX_BRIGHTNESS, help="maximum brightness")
    parser.add_argument("-t","--time", default=TICK_TIME, help="time between events")

    args = parser.parse_args()

    print('args: ', args)
    print('args.srt: ', args.srt)
    SRT_FILENAME = args.srt

    # global ipcon

    ipcon.connect(HOST, PORT)

    # Register Enumerate Callback
    ipcon.register_callback(IPConnection.CALLBACK_ENUMERATE, cb_enumerate)

    # Trigger Enumerate
    ipcon.enumerate()

    sleep(2)

    if VERBOSE:
        print("tfIds: ", tfIDs)

    dmxcount = 0
    for tf in tfIDs:
        # try:
        if True:
            # print(len(tf[0]))

            if len(tf[0])<=3: # if the device UID is 3 characters it is a bricklet
                if tf[1] in deviceIDs:
                    print('printed tfIds: ', tf[0],tf[1], getIdentifier(tf))
                if tf[1] == 285: # DMX Bricklet
                    if dmxcount == 0:
                        print("Registering %s as slave DMX device for capturing DMX frames" % tf[0])
                        dmx = BrickletDMX(tf[0], ipcon)
                        dmx.set_dmx_mode(BrickletDMX.DMX_MODE_SLAVE)
                        dmx.register_callback(BrickletDMX.CALLBACK_FRAME, dmxread_callback)
                        dmx.set_frame_callback_config(False, False, True, False)
                        signal.signal(signal.SIGINT, signal_handler)

                    dmxcount += 1

    while True:
        pass
Beispiel #2
0
    def initDMX(self):
        # configure Tinkerforge DMX
        try:
            self.ipcon.connect(HOST, PORT)

            # Register Enumerate Callback
            self.ipcon.register_callback(IPConnection.CALLBACK_ENUMERATE,
                                         self.cb_enumerate)

            # Trigger Enumerate
            self.ipcon.enumerate()

            # Likely wait for the tinkerforge brickd to finish doing its thing
            sleep(0.7)

            if DEBUG:
                print("Tinkerforge enumerated IDs", self.tfIDs)

            dmxcount = 0
            for tf in self.tfIDs:
                if len(
                        tf[0]
                ) <= 3:  # if the device UID is 3 characters it is a bricklet
                    if tf[1] in self.deviceIDs:
                        if VERBOSE:
                            print(tf[0], tf[1], self.getIdentifier(tf))
                    if tf[1] == 285:  # DMX Bricklet
                        if dmxcount == 0:
                            print(
                                "Registering %s as slave DMX device for playing DMX frames"
                                % tf[0])
                            self.dmx = BrickletDMX(tf[0], self.ipcon)
                            self.dmx.set_dmx_mode(self.dmx.DMX_MODE_MASTER)
                            self.dmx.set_frame_duration(DMX_FRAME_DURATION)
                        dmxcount += 1

            if dmxcount < 1:
                if LIGHTING_MSGS:
                    print("No DMX devices found.")
        except Exception as e:
            print(
                "Could not create connection to Tinkerforge DMX. DMX lighting is now disabled"
            )
            print("Why: ", e)
            self.PLAY_DMX = False
Beispiel #3
0
    for tf in tfIDs:
        # try:
        if True:
            # print(len(tf[0]))

            if len(
                    tf[0]
            ) <= 3:  # if the device UID is 3 characters it is a bricklet
                if tf[1] in deviceIDs:
                    print(tf[0], tf[1], getIdentifier(tf))
                if tf[1] == 285:  # DMX Bricklet
                    if dmxcount == 0:
                        print(
                            "Registering %s as slave DMX device for capturing DMX frames"
                            % tf[0])
                        dmx = BrickletDMX(tf[0], ipcon)
                        # dmx.set_dmx_mode(BrickletDMX.DMX_MODE_SLAVE)
                        dmx.set_dmx_mode(dmx.DMX_MODE_MASTER)
                        # dmx.register_callback(BrickletDMX.CALLBACK_FRAME, dmxread_callback)
                        # dmx.set_frame_callback_config(False, False, True, False)
                        signal.signal(signal.SIGINT, signal_handler)

                    dmxcount += 1

    # print(dir(dmx))
    print("Time before running scheduler", time(), perf_counter())
    for sub in subs:
        # print(dir(sub))
        # print(sub.index, dir(sub.shift), sub.position, sub.split_timestamps)

        hours, minutes, seconds, milliseconds = time_convert(sub.start)
Beispiel #4
0
def main():
    global subs, player, bridge, scheduler, ipcon, dmx
    global SRT_FILENAME, AUDIO_FILENAME, MAX_BRIGHTNESS, TICK_TIME, HUE_IP_ADDRESS, DEBUG, VERBOSE
    parser = argparse.ArgumentParser(description="LushRoom sound and light command-line player. \
        Press Esc to exit, P to pause and R to resume.")
    group = parser.add_mutually_exclusive_group()
    group.add_argument("-v", "--verbose", action="store_true")
    group.add_argument("-q", "--quiet", action="store_true")
    parser.add_argument("-d", "--debug", action="store_true")
    parser.add_argument("-s","--srt", default=SRT_FILENAME, help=".srt file name for lighting events")
    parser.add_argument("-a","--audio", default=AUDIO_FILENAME, help="audio file for sound stream")
    parser.add_argument("-b","--brightness", default=MAX_BRIGHTNESS, help="maximum brightness")
    parser.add_argument("-t","--time", default=TICK_TIME, help="time between events")
    parser.add_argument("--hue", default=HUE_IP_ADDRESS, help="Philips Hue bridge IP address")

    args = parser.parse_args()

    MAX_BRIGHTNESS = int(args.brightness)
    SRT_FILENAME = args.srt
    AUDIO_FILENAME = args.audio
    TICK_TIME = float(args.time)
    HUE_IP_ADDRESS = args.hue
    VERBOSE = args.verbose
    DEBUG = args.debug

    if DEBUG:
        print(args)


    ipcon.connect(HOST, PORT)

    # Register Enumerate Callback
    ipcon.register_callback(IPConnection.CALLBACK_ENUMERATE, cb_enumerate)

    # Trigger Enumerate
    ipcon.enumerate()

    sleep(2)

    if DEBUG:
        print(tfIDs)

    dmxcount = 0
    for tf in tfIDs:
        # try:
        if True:
            # print(len(tf[0]))

            if len(tf[0])<=3: # if the device UID is 3 characters it is a bricklet
                if tf[1] in deviceIDs:
                    if VERBOSE:
                        print(tf[0],tf[1], getIdentifier(tf))
                if tf[1] == 285: # DMX Bricklet
                    if dmxcount == 0:
                        print("Registering %s as slave DMX device for capturing DMX frames" % tf[0])
                        dmx = BrickletDMX(tf[0], ipcon)
                        dmx.set_dmx_mode(dmx.DMX_MODE_MASTER)
                        # channels = int((int(MAX_BRIGHTNESS)/255.0)*ones(512,)*255)
                        # dmx.write_frame([255,255])
                        sleep(1)
                        # channels = int((int(MAX_BRIGHTNESS)/255.0)*zeros(512,)*255)
                        # dmx.write_frame(channels)
                    dmxcount += 1

    if PLAY_AUDIO:
        player = vlc.MediaPlayer(AUDIO_FILENAME)
        event_manager = player.event_manager()
        event_manager.event_attach(vlc.EventType.MediaPlayerEndReached, end_callback)

    if PLAY_HUE:
        # b = Bridge('lushroom-hue.local')
        bridge = Bridge(HUE_IP_ADDRESS)
        # If the app is not registered and the button is not pressed, press the button and call connect() (this only needs to be run a single time)
        bridge.connect()
        # Get the bridge state (This returns the full dictionary that you can explore)
        bridge.get_api()
        lights = bridge.lights
        # Print light names
        for l in lights:
            print(l.name)
            #print(dir(l))
        for l in lights:
            # print(dir(l))
            l.on = False
        sleep(1)
        for l in lights:
            l.on = True
            l.brightness = MAX_BRIGHTNESS

        # Get a dictionary with the light name as the key
        light_names = bridge.get_light_objects('name')
        print("Light names:", light_names)

    subs = srtopen(SRT_FILENAME)

    print("Number of lighting events",len(subs))
    # print("PLAY_HUE", PLAY_HUE)


    scheduler = BackgroundScheduler()
    scheduler.add_job(tick, 'interval', seconds=TICK_TIME, misfire_grace_time=10, max_instances=4096, coalesce=True)
    if PLAY_AUDIO:
        player.play()
    scheduler.start(paused=False)

    with keyboard.Listener(
        # on_press=on_press,
        on_release=on_release, suppress=False) as listener:
        try:
            listener.join()
        except ExitException as e:
            print("Exiting ...")
Beispiel #5
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

HOST = "localhost"
PORT = 4223
UID = "XYZ"  # Change XYZ to the UID of your DMX Bricklet

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_dmx import BrickletDMX

if __name__ == "__main__":
    ipcon = IPConnection()  # Create IP connection
    dmx = BrickletDMX(UID, ipcon)  # Create device object

    ipcon.connect(HOST, PORT)  # Connect to brickd
    # Don't use device before ipcon is connected

    # Configure Bricklet as DMX master
    dmx.set_dmx_mode(dmx.DMX_MODE_MASTER)

    # Write DMX frame with 3 channels
    dmx.write_frame([255, 128, 0])

    input("Press key to exit\n")  # Use raw_input() in Python 2
    ipcon.disconnect()
Beispiel #6
0
    def __init__(self, parent=None):
        QMainWindow.__init__(self, parent)

        self.setupUi(self)
        self.setWindowTitle('DMX Test Tool by LauerSystems')

        # create and setup ipcon

        self.ipcon = IPConnection()
        self.ipcon.connect(HOST, PORT)
        self.ipcon.register_callback(IPConnection.CALLBACK_ENUMERATE,
                                     self.qtcb_ipcon_enumerate.emit)
        self.ipcon.register_callback(IPConnection.CALLBACK_CONNECTED,
                                     self.qtcb_ipcon_connected.emit)

        self.dmx = BrickletDMX(UID_DMX, self.ipcon)
        self.label_image.setText("Started!")

        #Configs
        self.wait_for_first_read = True

        self.qtcb_frame_started.connect(self.cb_frame_started)
        self.qtcb_frame.connect(self.cb_frame)

        self.dmx.set_dmx_mode(BrickletDMX.DMX_MODE_MASTER)
        print("DMX Mode [0=Master; 1=Slave]: " + str(self.dmx.get_dmx_mode()))
        self.dmx.set_frame_duration(200)
        print("Frame Duration [ms]: " + str(self.dmx.get_frame_duration()))

        self.address_spinboxes = []
        self.address_slider = []
        print("Config Ende")

        for i in range(20):
            spinbox = QSpinBox()
            spinbox.setMinimum(0)
            spinbox.setMaximum(255)

            slider = QSlider(Qt.Horizontal)
            slider.setMinimum(0)
            slider.setMaximum(255)

            spinbox.valueChanged.connect(slider.setValue)
            slider.valueChanged.connect(spinbox.setValue)

            def get_frame_value_changed_func(i):
                return lambda x: self.frame_value_changed(i, x)

            slider.valueChanged.connect(get_frame_value_changed_func(i))

            self.address_table.setCellWidget(i, 0, spinbox)
            self.address_table.setCellWidget(i, 1, slider)

            self.address_spinboxes.append(spinbox)
            self.address_slider.append(slider)
            print("Erzeuge Set: " + str(i))

        self.address_table.horizontalHeader().setStretchLastSection(True)
        self.address_table.show()

        self.current_frame = [0] * 512

        print(self.current_frame)

        self.dmx.register_callback(self.dmx.CALLBACK_FRAME_STARTED,
                                   self.qtcb_frame_started.emit)
        self.dmx.register_callback(self.dmx.CALLBACK_FRAME,
                                   self.qtcb_frame.emit)
        self.dmx.set_frame_callback_config(True, False, True, False)
Beispiel #7
0
def main():
    global hue_list, bridge, SRT_FILENAME, HUE_IP_ADDRESS, MAX_BRIGHTNESS
    global DMX_INTERVAL, INTERVAL, TRANSITION_TIME, HUE_IP_ADDRESS, DEBUG, VERBOSE
    global subs, srtFile
    global ipcon, tfIDs, dmx

    f1 = Figlet(font='standard')
    print(f1.renderText('LushRoom'))
    f2 = Figlet(font='standard')
    print(f2.renderText('OSC live record'))

    parser = argparse.ArgumentParser()
    parser.add_argument("--ip",
                        default="127.0.0.1",
                        help="OSC ip address to listen to")
    parser.add_argument("--port",
                        type=int,
                        default=8000,
                        help="OSC port to listen to")
    parser.add_argument("-s",
                        "--srt",
                        default=SRT_FILENAME,
                        help=".srt file name for lighting events")
    parser.add_argument("-b",
                        "--brightness",
                        default=MAX_BRIGHTNESS,
                        help="maximum brightness")
    parser.add_argument("-i",
                        "--interval",
                        default=INTERVAL,
                        help="sampling interval for Philips Hue events")
    parser.add_argument("-d",
                        "--dmx_interval",
                        default=DMX_INTERVAL,
                        help="sampling interval for DMX events")
    parser.add_argument("-t",
                        "--transition_time",
                        default=TRANSITION_TIME,
                        help="transition time between Philips Hue events")
    parser.add_argument("--hue",
                        default=HUE_IP_ADDRESS,
                        help="Philips Hue bridge IP address")

    args = parser.parse_args()

    print(args)

    MAX_BRIGHTNESS = int(args.brightness)
    SRT_FILENAME = args.srt
    INTERVAL = float(args.interval)
    DMX_INTERVAL = float(args.dmx_interval)
    TRANSITION_TIME = float(args.transition_time)
    HUE_IP_ADDRESS = args.hue
    # VERBOSE = args.verbose
    # DEBUG = args.debug

    if SRT_FILENAME != "":
        print("Start recording the %s subtitles track for light events." %
              SRT_FILENAME)
        srtFile = SubRipFile(path=SRT_FILENAME)

    if PLAY_HUE:
        bridge = Bridge(HUE_IP_ADDRESS)
        bridge.connect()
        bridge.get_api()
        lights = bridge.lights
        for l in lights:
            print(l.name)
        for l in lights:
            l.on = True
            l.brightness = MAX_BRIGHTNESS

        light_names = bridge.get_light_objects('name')
        print("Light names:", light_names)

        if PLAY_HUE:
            hue_list = hue_build_lookup_table(lights)
        # else:
        #     hue_list = [[0],['1'],[2],[3],[4],[5],[6],[7],[8],[9]]
        print(hue_list)

    if PLAY_DMX:

        ipcon.connect(HOST, PORT)

        # Register Enumerate Callback
        ipcon.register_callback(IPConnection.CALLBACK_ENUMERATE, cb_enumerate)

        # Trigger Enumerate
        ipcon.enumerate()

        sleep(2)

        if DEBUG:
            print(tfIDs)

        dmxcount = 0
        for tf in tfIDs:
            # try:
            if True:
                # print(len(tf[0]))

                if len(
                        tf[0]
                ) <= 3:  # if the device UID is 3 characters it is a bricklet
                    if tf[1] in deviceIDs:
                        if VERBOSE:
                            print(tf[0], tf[1], getIdentifier(tf))
                    if tf[1] == 285:  # DMX Bricklet
                        if dmxcount == 0:
                            print(
                                "Registering %s as slave DMX device for capturing DMX frames"
                                % tf[0])
                            dmx = BrickletDMX(tf[0], ipcon)
                            dmx.set_dmx_mode(dmx.DMX_MODE_MASTER)
                            # channels = int((int(MAX_BRIGHTNESS)/255.0)*ones(512,)*255)
                            # dmx.write_frame([255,255])
                            sleep(1)
                            # channels = int((int(MAX_BRIGHTNESS)/255.0)*zeros(512,)*255)
                            # dmx.write_frame(channels)
                        dmxcount += 1

    disp = dispatcher.Dispatcher()
    # print(dir(dispatcher))

    for h in range(512):
        disp.map("/hue%s" % h, play_record_hue, "%s" % h)

    for h in range(512):
        disp.map("/dmx%s" % h, play_record_dmx, "%s" % h)

    server = osc_server.ThreadingOSCUDPServer((args.ip, args.port), disp)
    print("Serving OSC on {}".format(server.server_address))
    signal.signal(signal.SIGINT, signal_handler)
    server.serve_forever()