#!/usr/bin/env python3

# The DMX USB Pro in Hunt A11 is currently set to DMX address "A.001", so the first
# DMX universe value will be the first dimmer channel, second will be the second, etc.

import argparse
import time
import numpy as np

import dmxusbpro
#================================================================

# The following section is run when this is loaded as a script.
if __name__ == "__main__":

    # Initialize the command parser.
    parser = argparse.ArgumentParser( description = """Simple test program to operate an Enttec DMXUSB Pro.""")
    parser.add_argument( '-v', '--verbose', action='store_true', help='Enable more detailed output.' )
    parser.add_argument( '--debug', action='store_true', help='Enable debugging output.' )
    parser.add_argument( '-p', '--port', default='/dev/ttyUSB0', help='Serial port name (default: %(default)s).')
    parser.add_argument( '-m', '--mode', default='black', help='Set a named mode (default: %(default)s).')
    
    # Parse the command line, returning a Namespace.
    args = parser.parse_args()

    # Convert the Namespace to a set of keyword arguments and initialize the
    # client object.  Note that it will ignore extraneous values, e.g., from
    # additional command argument inputs unneeded by this object.
    dmx = dmxusbpro.DMXUSBPro(**vars(args))
    dmx.open_serial_port()

    # Each mode sets a range of the universe values.  With a DMX
    # address of 1, the DMX USB Pro occupies the first four channels.
    # The universe array is larger because the protocol requires a
    # minimum of 25 values.
    if args.mode == 'black':
        dmx.universe[0:4] = [0, 0, 0, 0]

    elif args.mode == 'white':
        dmx.universe[0:4] = [255, 255, 255, 255]

    # This is the right light as viewed from outside, i.e. stage left.
    elif args.mode == 'right':
        dmx.universe[0:4] = [255, 0, 0, 0]

    # This is the left light as viewed from outside, i.e. stage right.        
    elif args.mode == 'left':
        dmx.universe[0:4] = [0, 255, 0, 0]

    # update the lights
    dmx.send_universe()
    
    # Close the port.
    dmx.close_serial_port()
    
