Exemplo n.º 1
0
        public static void LinkToApi(this PepperDash.Essentials.Devices.Common.IRSetTopBoxBase stbDevice, BasicTriList trilist, uint joinStart, string joinMapKey)
        {
            SetTopBoxControllerJoinMap joinMap = new SetTopBoxControllerJoinMap();
            var joinMapSerialized = JoinMapHelper.GetSerializedJoinMapForDevice(joinMapKey);

            if (!string.IsNullOrEmpty(joinMapSerialized))
            {
                joinMap = JsonConvert.DeserializeObject <SetTopBoxControllerJoinMap>(joinMapSerialized);
            }

            joinMap.OffsetJoinNumbers(joinStart);

            Debug.Console(1, "Linking to Trilist '{0}'", trilist.ID.ToString("X"));
            Debug.Console(0, "Linking to Display: {0}", stbDevice.Name);

            trilist.StringInput[joinMap.Name].StringValue = stbDevice.Name;

            var stbBase = stbDevice as ISetTopBoxControls;

            if (stbBase != null)
            {
                trilist.BooleanInput[joinMap.HasDpad].BoolValue    = stbBase.HasDpad;
                trilist.BooleanInput[joinMap.HasNumeric].BoolValue = stbBase.HasNumeric;
                trilist.BooleanInput[joinMap.HasDvr].BoolValue     = stbBase.HasDvr;
                trilist.BooleanInput[joinMap.HasPresets].BoolValue = stbBase.HasPresets;

                trilist.SetBoolSigAction(joinMap.DvrList, (b) => stbBase.DvrList(b));
                trilist.SetBoolSigAction(joinMap.Replay, (b) => stbBase.Replay(b));

                trilist.SetStringSigAction(joinMap.LoadPresets, (s) => stbBase.LoadPresets(s));
            }

            var stbPower = stbDevice as IPower;

            if (stbPower != null)
            {
                trilist.SetSigTrueAction(joinMap.PowerOn, () => stbPower.PowerOn());
                trilist.SetSigTrueAction(joinMap.PowerOff, () => stbPower.PowerOff());
                trilist.SetSigTrueAction(joinMap.PowerToggle, () => stbPower.PowerToggle());
            }

            var stbDPad = stbDevice as IDPad;

            if (stbDPad != null)
            {
                trilist.SetBoolSigAction(joinMap.Up, (b) => stbDPad.Up(b));
                trilist.SetBoolSigAction(joinMap.Down, (b) => stbDPad.Down(b));
                trilist.SetBoolSigAction(joinMap.Left, (b) => stbDPad.Left(b));
                trilist.SetBoolSigAction(joinMap.Right, (b) => stbDPad.Right(b));
                trilist.SetBoolSigAction(joinMap.Select, (b) => stbDPad.Select(b));
                trilist.SetBoolSigAction(joinMap.Menu, (b) => stbDPad.Menu(b));
                trilist.SetBoolSigAction(joinMap.Exit, (b) => stbDPad.Exit(b));
            }

            var stbChannel = stbDevice as IChannel;

            if (stbChannel != null)
            {
                trilist.SetBoolSigAction(joinMap.ChannelUp, (b) => stbChannel.ChannelUp(b));
                trilist.SetBoolSigAction(joinMap.ChannelDown, (b) => stbChannel.ChannelDown(b));
                trilist.SetBoolSigAction(joinMap.LastChannel, (b) => stbChannel.LastChannel(b));
                trilist.SetBoolSigAction(joinMap.Guide, (b) => stbChannel.Guide(b));
                trilist.SetBoolSigAction(joinMap.Info, (b) => stbChannel.Info(b));
                trilist.SetBoolSigAction(joinMap.Exit, (b) => stbChannel.Exit(b));
            }

            var stbColor = stbDevice as IColor;

            if (stbColor != null)
            {
                trilist.SetBoolSigAction(joinMap.Red, (b) => stbColor.Red(b));
                trilist.SetBoolSigAction(joinMap.Green, (b) => stbColor.Green(b));
                trilist.SetBoolSigAction(joinMap.Yellow, (b) => stbColor.Yellow(b));
                trilist.SetBoolSigAction(joinMap.Blue, (b) => stbColor.Blue(b));
            }

            var stbKeypad = stbDevice as ISetTopBoxNumericKeypad;

            if (stbKeypad != null)
            {
                trilist.StringInput[joinMap.KeypadAccessoryButton1Label].StringValue = stbKeypad.KeypadAccessoryButton1Label;
                trilist.StringInput[joinMap.KeypadAccessoryButton2Label].StringValue = stbKeypad.KeypadAccessoryButton2Label;

                trilist.BooleanInput[joinMap.HasKeypadAccessoryButton1].BoolValue = stbKeypad.HasKeypadAccessoryButton1;
                trilist.BooleanInput[joinMap.HasKeypadAccessoryButton2].BoolValue = stbKeypad.HasKeypadAccessoryButton2;

                trilist.SetBoolSigAction(joinMap.Digit0, (b) => stbKeypad.Digit0(b));
                trilist.SetBoolSigAction(joinMap.Digit1, (b) => stbKeypad.Digit1(b));
                trilist.SetBoolSigAction(joinMap.Digit2, (b) => stbKeypad.Digit2(b));
                trilist.SetBoolSigAction(joinMap.Digit3, (b) => stbKeypad.Digit3(b));
                trilist.SetBoolSigAction(joinMap.Digit4, (b) => stbKeypad.Digit4(b));
                trilist.SetBoolSigAction(joinMap.Digit5, (b) => stbKeypad.Digit5(b));
                trilist.SetBoolSigAction(joinMap.Digit6, (b) => stbKeypad.Digit6(b));
                trilist.SetBoolSigAction(joinMap.Digit7, (b) => stbKeypad.Digit7(b));
                trilist.SetBoolSigAction(joinMap.Digit8, (b) => stbKeypad.Digit8(b));
                trilist.SetBoolSigAction(joinMap.Digit9, (b) => stbKeypad.Digit9(b));
                trilist.SetBoolSigAction(joinMap.KeypadAccessoryButton1Press, (b) => stbKeypad.KeypadAccessoryButton1(b));
                trilist.SetBoolSigAction(joinMap.KeypadAccessoryButton2Press, (b) => stbKeypad.KeypadAccessoryButton1(b));
                trilist.SetBoolSigAction(joinMap.Dash, (b) => stbKeypad.Dash(b));
                trilist.SetBoolSigAction(joinMap.KeypadEnter, (b) => stbKeypad.KeypadEnter(b));
            }

            var stbTransport = stbDevice as ITransport;

            if (stbTransport != null)
            {
                trilist.SetBoolSigAction(joinMap.Play, (b) => stbTransport.Play(b));
                trilist.SetBoolSigAction(joinMap.Pause, (b) => stbTransport.Pause(b));
                trilist.SetBoolSigAction(joinMap.Rewind, (b) => stbTransport.Rewind(b));
                trilist.SetBoolSigAction(joinMap.FFwd, (b) => stbTransport.FFwd(b));
                trilist.SetBoolSigAction(joinMap.ChapMinus, (b) => stbTransport.ChapMinus(b));
                trilist.SetBoolSigAction(joinMap.ChapPlus, (b) => stbTransport.ChapPlus(b));
                trilist.SetBoolSigAction(joinMap.Stop, (b) => stbTransport.Stop(b));
                trilist.SetBoolSigAction(joinMap.Record, (b) => stbTransport.Record(b));
            }
        }
Exemplo n.º 2
0
        public static IKeyed GetDevice(DeviceConfig dc)
        {
            var key        = dc.Key;
            var name       = dc.Name;
            var type       = dc.Type;
            var properties = dc.Properties;
            var propAnon   = new {};

            JsonConvert.DeserializeAnonymousType(dc.Properties.ToString(), propAnon);

            var typeName  = dc.Type.ToLower();
            var groupName = dc.Group.ToLower();

            if (typeName == "appletv")
            {
                var irCont = IRPortHelper.GetIrOutputPortController(dc);
                return(new AppleTV(key, name, irCont));
            }
            else if (typeName == "analogwaylivecore")
            {
                var comm  = CommFactory.CreateCommForDevice(dc);
                var props = JsonConvert.DeserializeObject <AnalogWayLiveCorePropertiesConfig>(
                    properties.ToString());
                return(new AnalogWayLiveCore(key, name, comm, props));
            }
            else if (typeName == "basicirdisplay")
            {
                var ir = IRPortHelper.GetIrPort(properties);
                if (ir != null)
                {
                    var display = new BasicIrDisplay(key, name, ir.Port, ir.FileName);
                    display.IrPulseTime = 200;       // Set default pulse time for IR commands.
                    return(display);
                }
            }

            else if (typeName == "biamptesira")
            {
                var comm  = CommFactory.CreateCommForDevice(dc);
                var props = JsonConvert.DeserializeObject <BiampTesiraFortePropertiesConfig>(
                    properties.ToString());
                return(new BiampTesiraForteDsp(key, name, comm, props));
            }


            else if (typeName == "cameravisca")
            {
                var comm  = CommFactory.CreateCommForDevice(dc);
                var props = JsonConvert.DeserializeObject <Cameras.CameraPropertiesConfig>(
                    properties.ToString());
                return(new Cameras.CameraVisca(key, name, comm, props));
            }

            else if (typeName == "cenrfgwex")
            {
                return(CenRfgwController.GetNewExGatewayController(key, name,
                                                                   properties.Value <string>("id"), properties.Value <string>("gatewayType")));
            }

            else if (typeName == "cenerfgwpoe")
            {
                return(CenRfgwController.GetNewErGatewayController(key, name,
                                                                   properties.Value <string>("id"), properties.Value <string>("gatewayType")));
            }

            else if (groupName == "discplayer")             // (typeName == "irbluray")
            {
                if (properties["control"]["method"].Value <string>() == "ir")
                {
                    var irCont = IRPortHelper.GetIrOutputPortController(dc);
                    return(new IRBlurayBase(key, name, irCont));
                }
                else if (properties["control"]["method"].Value <string>() == "com")
                {
                    Debug.Console(0, "[{0}] COM Device type not implemented YET!", key);
                }
            }
            else if (typeName == "digitallogger")
            {
                // var comm = CommFactory.CreateCommForDevice(dc);
                var props = JsonConvert.DeserializeObject <DigitalLoggerPropertiesConfig>(
                    properties.ToString());
                return(new DigitalLogger(key, name, props));
            }
            else if (typeName == "genericaudiooutwithvolume")
            {
                var zone = dc.Properties.Value <uint>("zone");
                return(new GenericAudioOutWithVolume(key, name,
                                                     dc.Properties.Value <string>("volumeDeviceKey"), zone));
            }

            else if (groupName == "genericsource")
            {
                return(new GenericSource(key, name));
            }

            else if (typeName == "inroompc")
            {
                return(new Core.Devices.InRoomPc(key, name));
            }

            else if (typeName == "laptop")
            {
                return(new Core.Devices.Laptop(key, name));
            }

            else if (typeName == "mockvc")
            {
                return(new VideoCodec.MockVC(dc));
            }

            else if (typeName == "mockac")
            {
                var props = JsonConvert.DeserializeObject <AudioCodec.MockAcPropertiesConfig>(properties.ToString());
                return(new AudioCodec.MockAC(key, name, props));
            }

            else if (typeName.StartsWith("ciscospark"))
            {
                var comm = CommFactory.CreateCommForDevice(dc);
                return(new VideoCodec.Cisco.CiscoSparkCodec(dc, comm));
            }

            else if (typeName == "zoomroom")
            {
                var comm = CommFactory.CreateCommForDevice(dc);
                return(new VideoCodec.ZoomRoom.ZoomRoom(dc, comm));
            }

            else if (typeName == "digitalinput")
            {
                var props = JsonConvert.DeserializeObject <IOPortConfig>(properties.ToString());

                IDigitalInputPorts portDevice;

                if (props.PortDeviceKey == "processor")
                {
                    portDevice = Global.ControlSystem as IDigitalInputPorts;
                }
                else
                {
                    portDevice = DeviceManager.GetDeviceForKey(props.PortDeviceKey) as IDigitalInputPorts;
                }

                if (portDevice == null)
                {
                    Debug.Console(0, "ERROR: Unable to add digital input device with key '{0}'. Port Device does not support digital inputs", key);
                }
                else
                {
                    var cs = (portDevice as CrestronControlSystem);
                    if (cs == null)
                    {
                        Debug.Console(0, "ERROR: Port device for [{0}] is not control system", props.PortDeviceKey);
                        return(null);
                    }

                    if (cs.SupportsVersiport)
                    {
                        Debug.Console(1, "Attempting to add Digital Input device to Versiport port '{0}'", props.PortNumber);

                        if (props.PortNumber > cs.NumberOfVersiPorts)
                        {
                            Debug.Console(0, "WARNING: Cannot add Vesiport {0} on {1}. Out of range",
                                          props.PortNumber, props.PortDeviceKey);
                            return(null);
                        }

                        Versiport vp = cs.VersiPorts[props.PortNumber];

                        if (!vp.Registered)
                        {
                            var regSuccess = vp.Register();
                            if (regSuccess == eDeviceRegistrationUnRegistrationResponse.Success)
                            {
                                Debug.Console(1, "Successfully Created Digital Input Device on Versiport");
                                return(new GenericVersiportDigitalInputDevice(key, vp, props));
                            }
                            else
                            {
                                Debug.Console(0, "WARNING: Attempt to register versiport {0} on device with key '{1}' failed: {2}",
                                              props.PortNumber, props.PortDeviceKey, regSuccess);
                                return(null);
                            }
                        }
                    }
                    else if (cs.SupportsDigitalInput)
                    {
                        Debug.Console(1, "Attempting to add Digital Input device to Digital Input port '{0}'", props.PortNumber);

                        if (props.PortNumber > cs.NumberOfDigitalInputPorts)
                        {
                            Debug.Console(0, "WARNING: Cannot register DIO port {0} on {1}. Out of range",
                                          props.PortNumber, props.PortDeviceKey);
                            return(null);
                        }

                        DigitalInput digitalInput = cs.DigitalInputPorts[props.PortNumber];

                        if (!digitalInput.Registered)
                        {
                            if (digitalInput.Register() == eDeviceRegistrationUnRegistrationResponse.Success)
                            {
                                Debug.Console(1, "Successfully Created Digital Input Device on Digital Input");
                                return(new GenericDigitalInputDevice(key, digitalInput));
                            }
                            else
                            {
                                Debug.Console(0, "WARNING: Attempt to register digital input {0} on device with key '{1}' failed.",
                                              props.PortNumber, props.PortDeviceKey);
                            }
                        }
                    }
                }
            }

            else if (typeName == "relayoutput")
            {
                var props = JsonConvert.DeserializeObject <IOPortConfig>(properties.ToString());

                IRelayPorts portDevice;

                if (props.PortDeviceKey == "processor")
                {
                    portDevice = Global.ControlSystem as IRelayPorts;
                }
                else
                {
                    portDevice = DeviceManager.GetDeviceForKey(props.PortDeviceKey) as IRelayPorts;
                }

                if (portDevice == null)
                {
                    Debug.Console(0, "Unable to add relay device with key '{0}'. Port Device does not support relays", key);
                }
                else
                {
                    var cs = (portDevice as CrestronControlSystem);

                    if (cs != null)
                    {
                        // The relay is on a control system processor
                        if (!cs.SupportsRelay || props.PortNumber > cs.NumberOfRelayPorts)
                        {
                            Debug.Console(0, "Port Device: {0} does not support relays or does not have enough relays");
                            return(null);
                        }
                    }
                    else
                    {
                        // The relay is on another device type

                        if (props.PortNumber > portDevice.NumberOfRelayPorts)
                        {
                            Debug.Console(0, "Port Device: {0} does not have enough relays");
                            return(null);
                        }
                    }

                    Relay relay = portDevice.RelayPorts[props.PortNumber];

                    if (!relay.Registered)
                    {
                        if (relay.Register() == eDeviceRegistrationUnRegistrationResponse.Success)
                        {
                            return(new GenericRelayDevice(key, relay));
                        }
                        else
                        {
                            Debug.Console(0, "Attempt to register relay {0} on device with key '{1}' failed.", props.PortNumber, props.PortDeviceKey);
                        }
                    }
                    else
                    {
                        return(new GenericRelayDevice(key, relay));
                    }

                    // Future: Check if portDevice is 3-series card or other non control system that supports versiports
                }
            }

            else if (typeName == "microphoneprivacycontroller")
            {
                var props = JsonConvert.DeserializeObject <Core.Privacy.MicrophonePrivacyControllerConfig>(properties.ToString());

                return(new Core.Privacy.MicrophonePrivacyController(key, props));
            }
            else if (typeName == "roku")
            {
                var irCont = IRPortHelper.GetIrOutputPortController(dc);
                return(new Roku2(key, name, irCont));
            }

            else if (groupName == "settopbox") //(typeName == "irstbbase")
            {
                var irCont = IRPortHelper.GetIrOutputPortController(dc);
                var config = dc.Properties.ToObject <SetTopBoxPropertiesConfig>();
                var stb    = new IRSetTopBoxBase(key, name, irCont, config);

                //stb.HasDvr = properties.Value<bool>("hasDvr");
                var listName = properties.Value <string>("presetsList");
                if (listName != null)
                {
                    stb.LoadPresets(listName);
                }
                return(stb);
            }
            else if (typeName == "tvonecorio")
            {
                var comm  = CommFactory.CreateCommForDevice(dc);
                var props = JsonConvert.DeserializeObject <TVOneCorioPropertiesConfig>(
                    properties.ToString());
                return(new TVOneCorio(key, name, comm, props));
            }


            else if (typeName == "glsoirccn")
            {
                var comm = CommFactory.GetControlPropertiesConfig(dc);

                GlsOccupancySensorBase occSensor = null;

                occSensor = new GlsOirCCn(comm.CresnetIdInt, Global.ControlSystem);

                if (occSensor != null)
                {
                    return(new GlsOccupancySensorBaseController(key, name, occSensor));
                }
                else
                {
                    Debug.Console(0, "ERROR: Unable to create Occupancy Sensor Device. Key: '{0}'", key);
                }
            }

            else if (typeName == "glsodtccn")
            {
                var comm = CommFactory.GetControlPropertiesConfig(dc);

                var occSensor = new GlsOdtCCn(comm.CresnetIdInt, Global.ControlSystem);

                if (occSensor != null)
                {
                    return(new GlsOdtOccupancySensorController(key, name, occSensor));
                }
                else
                {
                    Debug.Console(0, "ERROR: Unable to create Occupancy Sensor Device. Key: '{0}'", key);
                }
            }

            else if (groupName == "lighting")
            {
                if (typeName == "lutronqs")
                {
                    var comm = CommFactory.CreateCommForDevice(dc);

                    var props = JsonConvert.DeserializeObject <Environment.Lutron.LutronQuantumPropertiesConfig>(properties.ToString());

                    return(new Environment.Lutron.LutronQuantumArea(key, name, comm, props));
                }
                else if (typeName == "din8sw8")
                {
                    var comm = CommFactory.GetControlPropertiesConfig(dc);

                    return(new Environment.Lighting.Din8sw8Controller(key, comm.CresnetIdInt));
                }
            }

            else if (groupName == "environment")
            {
                if (typeName == "shadecontroller")
                {
                    var props = JsonConvert.DeserializeObject <Core.Shades.ShadeControllerConfigProperties>(properties.ToString());

                    return(new Core.Shades.ShadeController(key, name, props));
                }
                else if (typeName == "relaycontrolledshade")
                {
                    var props = JsonConvert.DeserializeObject <Environment.Somfy.RelayControlledShadeConfigProperties>(properties.ToString());

                    return(new Environment.Somfy.RelayControlledShade(key, name, props));
                }
            }

            return(null);
        }