Пример #1
0
        public void SetColor(uint red, uint green, uint blue)
        {
            try
            {
                _device.Leds[(uint)StatusSign.Led.eLedColor.Red].Brightness =
                    (StatusSign.Led.eBrightnessPercentageValues)SimplSharpDeviceHelper.PercentToUshort(red);
            }
            catch (InvalidOperationException)
            {
                Debug.Console(1, this, "Error converting value to Red LED brightness. value: {0}", red);
            }
            try
            {
                _device.Leds[(uint)StatusSign.Led.eLedColor.Green].Brightness =
                    (StatusSign.Led.eBrightnessPercentageValues)SimplSharpDeviceHelper.PercentToUshort(green);
            }
            catch (InvalidOperationException)
            {
                Debug.Console(1, this, "Error converting value to Green LED brightness. value: {0}", green);
            }

            try
            {
                _device.Leds[(uint)StatusSign.Led.eLedColor.Blue].Brightness =
                    (StatusSign.Led.eBrightnessPercentageValues)SimplSharpDeviceHelper.PercentToUshort(blue);
            }
            catch (InvalidOperationException)
            {
                Debug.Console(1, this, "Error converting value to Blue LED brightness. value: {0}", blue);
            }
        }
Пример #2
0
        // using ctimer to simulate ramping of slider scene is Selected on UI
        public void SimulateLoadRamp(IRoom allRoomRef, int lightIndex, float rampTo)
        {
            LightDevice light       = _allLightDevices[lightIndex];
            float       light1Level = SimplSharpDeviceHelper.UshortToPercent(light.LoadLevel);

            ushort levelValue1;

            for (float i = light1Level; i < rampTo; i++)
            {
                levelValue1 = SimplSharpDeviceHelper.PercentToUshort(i);

                allRoomLights.DimmableLights[lightIndex].LightIsAtLevel((sig, component) => { sig.UShortValue = levelValue1; });

                light.LoadLevel = levelValue1;
            }

            for (float i = light1Level; i > rampTo; i--)
            {
                levelValue1 = SimplSharpDeviceHelper.PercentToUshort(i);

                allRoomLights.DimmableLights[lightIndex].LightIsAtLevel((sig, component) => { sig.UShortValue = levelValue1; });

                light.LoadLevel = levelValue1;
            }
        }
Пример #3
0
        // using ctimer to simulate ramping of slider when light is turn on/off
        public void SimulateOnOffLightRamp(object sender, string status)
        {
            LightDevice light = (LightDevice)((DimmableLight)sender).UserObject;

            float vOut = SimplSharpDeviceHelper.UshortToPercent(light.LoadLevel);

            ushort newLevelValue;

            if (status == "On")
            {
                for (float i = vOut; i < 100; i++)
                {
                    ushort levelValue = SimplSharpDeviceHelper.PercentToUshort(i);
                    ((DimmableLight)sender).LightIsAtLevel((sig, component) => { sig.UShortValue = levelValue; });
                }

                newLevelValue   = SimplSharpDeviceHelper.PercentToUshort(100);
                light.LoadLevel = newLevelValue;
            }
            else
            {
                for (float i = vOut; i > 0; i--)
                {
                    ushort levelValue = SimplSharpDeviceHelper.PercentToUshort(i);
                    ((DimmableLight)sender).LightIsAtLevel((sig, component) => { sig.UShortValue = levelValue; });
                }

                newLevelValue   = SimplSharpDeviceHelper.PercentToUshort(0);
                light.LoadLevel = newLevelValue;
            }
        }
Пример #4
0
        private void LightingScene_AllOn(object sender, UIEventArgs e)
        {
            ushort levelAllValue = SimplSharpDeviceHelper.PercentToUshort(100);

            for (int i = 0; i < _allLights.DimmableLoad.Length; i++)
            {
                _allLights.DimmableLoad[i].Level_Feedback((sig, component) => { sig.UShortValue = levelAllValue; });
            }
        }
Пример #5
0
        /// <summary>
        /// Constructor of the Control System Class. Make sure the constructor always exists.
        /// If it doesn't exit, the code will not run on your 3-Series processor.
        /// </summary>
        public ControlSystem()
            : base()
        {
            // Set the number of threads which you want to use in your program - At this point the threads cannot be created but we should
            // define the max number of threads which we will use in the system.
            // the right number depends on your project; do not make this number unnecessarily large
            Thread.MaxNumberOfUserThreads = 20;

            xp            = new XpanelForSmartGraphics(0xaa, this);
            xp.SigChange += new SigEventHandler(xp_SigChange);
            xp.Register();

            gateway                            = new CenRfgwEx(0x03, this);
            lampDimmer                         = new ClwLdimex1(0x03, gateway);
            lampDimmer.Description             = "Bedroom lamp dimmer"; // this is what shows in the IP table description field
            lampDimmer.LoadStateChange        += new LoadEventHandler(lampDimmer_LoadStateChange);
            lampDimmer.ParameterRaiseLowerRate = SimplSharpDeviceHelper.SecondsToUshort(4.0f);
            //        ^^^^^^^^^^^^^^^^^^^^ - this is a very helpful class

            wallDimmer = new ClwDelvexE(0x04, gateway);
            wallDimmer.DimmerRemoteButtonSettings.ParameterBargraphBehavior           = ClwDimExDimmerRemoteButtonSettings.eBargraphBehavior.AlwaysOn;
            wallDimmer.DimmerRemoteButtonSettings.ParameterBargraphTimeout            = SimplSharpDeviceHelper.SecondsToUshort(2.0f);
            wallDimmer.DimmerRemoteButtonSettings.ParameterRemoteDoubleTapTime        = SimplSharpDeviceHelper.SecondsToUshort(0.5f);
            wallDimmer.DimmerRemoteButtonSettings.ParameterRemoteHoldTime             = SimplSharpDeviceHelper.SecondsToUshort(0.5f);
            wallDimmer.DimmerRemoteButtonSettings.ParameterRemoteWaitForDoubleTap     = eRemoteWaitForDoubleTap.No;
            wallDimmer.DimmerRemoteButtonSettings.ParameterReservedButtonForLocalMode = 0;
            wallDimmer.DimmerUISettings.ParameterButtonLogic     = eButtonLogic.Remote;
            wallDimmer.DimmerUISettings.ParameterLEDOnLevel      = ushort.MaxValue;
            wallDimmer.DimmerUISettings.ParameterNightLightLevel = SimplSharpDeviceHelper.PercentToUshort(10.0f);
            wallDimmer.ParameterDimmerDelayedOffTime             = SimplSharpDeviceHelper.SecondsToUshort(1.0f);
            wallDimmer.ParameterOffFadeTime    = SimplSharpDeviceHelper.SecondsToUshort(0.5f);
            wallDimmer.ParameterPresetFadeTime = SimplSharpDeviceHelper.SecondsToUshort(1.0f);
            wallDimmer.ParameterRaiseLowerRate = SimplSharpDeviceHelper.SecondsToUshort(3.0f);
            wallDimmer.DimmingLoads[1].ParameterDimmerMinLevel = ushort.MinValue;
            wallDimmer.DimmingLoads[1].ParameterDimmerMaxLevel = ushort.MaxValue;
            wallDimmer.ButtonStateChange += new ButtonEventHandler(wallDimmer_ButtonStateChange);
            wallDimmer.LoadStateChange   += new LoadEventHandler(wallDimmer_LoadStateChange);

            // registering the gateway after adding all of the devices will register everything at once
            gateway.Register();
        }
        private void Initialize()
        {
            mySwamp.TemperatureReportingEnable();
            mySwamp.AllZonesDoorbellSource.UShortValue = 16;
            mySwamp.Zones[1].Name.StringValue          = "Main Guest Bedroom";
            mySwamp.Zones[2].Name.StringValue          = "Master Bedroom";
            mySwamp.Zones[3].Name.StringValue          = "Upper Deck";
            mySwamp.Zones[4].Name.StringValue          = "Dining Room";
            mySwamp.Zones[5].Name.StringValue          = "Basement Rec Room";
            mySwamp.Zones[6].Name.StringValue          = "Workout Room";
            mySwamp.Zones[7].Name.StringValue          = "Kitchen";
            mySwamp.Zones[8].Name.StringValue          = "Library";
            mySwamp.Sources[1].Name.StringValue        = "VCR51 - Apple TV";
            mySwamp.Sources[2].Name.StringValue        = "SAT52 - Shared TIVO";
            mySwamp.Sources[3].Name.StringValue        = "<unused>";
            mySwamp.Sources[4].Name.StringValue        = "SAT53 - Shared TIVO";
            mySwamp.Sources[5].Name.StringValue        = "SAT51 - Shared TIVO";
            mySwamp.Sources[6].Name.StringValue        = "DVD51 - Shared KScape";
            mySwamp.Sources[7].Name.StringValue        = "CAM1 - CAM1";
            mySwamp.Sources[8].Name.StringValue        = "<unused>";
            mySwamp.Sources[16].Name.StringValue       = "Doorbell Chime";

            foreach (Zone zone in mySwamp.Zones)
            {
                zone.Balance.UShortValue = 0;           // -50% to +50%
                zone.Bass.UShortValue    = 1;           // -12dB to +12dB  -- This is UShort - how do I set UShort to negative value?
                zone.CrestronDRCOff();
                zone.DoorbellEnableOn();
                zone.DoorbellVolume.UShortValue = SimplSharpDeviceHelper.PercentToUshort(60);
                zone.LoudnessOn();
                zone.MaxVolume.UShortValue = SimplSharpDeviceHelper.PercentToUshort(100);
                zone.MinVolume.UShortValue = SimplSharpDeviceHelper.PercentToUshort(0);
                zone.MonoOff();
                zone.MuteOff();
                zone.Source.UShortValue        = 0;
                zone.StartupVolume.UShortValue = SimplSharpDeviceHelper.PercentToUshort(40);
                zone.Treble.UShortValue        = 0;     // -12dB to +12dB  -- This is UShort - how do I set UShort to negative value?
            }
        }
Пример #7
0
        /// <summary>
        /// ControlSystem Constructor. Starting point for the SIMPL#Pro program.
        /// Use the constructor to:
        /// * Initialize the maximum number of threads (max = 400)
        /// * Register devices
        /// * Register event handlers
        /// * Add Console Commands
        ///
        /// Please be aware that the constructor needs to exit quickly; if it doesn't
        /// exit in time, the SIMPL#Pro program will exit.
        ///
        /// You cannot send / receive data in the constructor
        /// </summary>
        public ControlSystem()
            : base()
        {
            try
            {
                Thread.MaxNumberOfUserThreads = 20;
                //System.Security.Cryptography.SHA1.Create();

                //register device
                myKeypad = new C2nCbdP(0x25, this);
                myKeypad.ButtonStateChange += (device, args) =>
                {
                    var btn = args.Button;
                    var uo  = btn.UserObject;

                    CrestronConsole.PrintLine("Event sig: {0}, Type: {1}, State: {2}", btn.Number, btn.GetType(),
                                              btn.State);

                    if (btn.State == eButtonState.Pressed)
                    {
                        switch (btn.Number)
                        {
                        case 1:
                            if (myDimmer.DinLoads[2].LevelOut.UShortValue > 0)
                            {
                                myDimmer.DinLoads[2].LevelIn.UShortValue = SimplSharpDeviceHelper.PercentToUshort(0f);
                                myKeypad.Feedbacks[1].State = false;
                            }
                            else
                            {
                                myDimmer.DinLoads[2].LevelIn.UShortValue =
                                    SimplSharpDeviceHelper.PercentToUshort(100f);
                                myKeypad.Feedbacks[1].State = true;
                            }
                            break;

                        case 2:
                            if (myDimmer.DinLoads[3].LevelOut.UShortValue > 0)
                            {
                                myDimmer.DinLoads[3].LevelIn.UShortValue = SimplSharpDeviceHelper.PercentToUshort(0f);
                                myKeypad.Feedbacks[2].State = false;
                            }
                            else
                            {
                                myDimmer.DinLoads[3].LevelIn.UShortValue =
                                    SimplSharpDeviceHelper.PercentToUshort(100f);
                                myKeypad.Feedbacks[2].State = true;
                            }
                            break;

                        case 5:
                            myRelay.SwitchedLoads[1].FullOn();
                            myRelay.SwitchedLoads[2].FullOff();
                            break;

                        case 6:
                            myRelay.SwitchedLoads[2].FullOn();
                            myRelay.SwitchedLoads[1].FullOff();
                            break;

                        case 7:
                            myRelay.SwitchedLoads[3].FullOn();
                            myRelay.SwitchedLoads[4].FullOff();
                            break;

                        case 8:
                            myRelay.SwitchedLoads[4].FullOn();
                            myRelay.SwitchedLoads[3].FullOff();
                            break;

                        default:
                            break;
                        }
                    }
                };

                if (myKeypad.Register() != eDeviceRegistrationUnRegistrationResponse.Success)
                {
                    CrestronConsole.PrintLine(" Unable to register for keypad ");
                    CrestronConsole.PrintLine("myKeypad {0} failed registration. Cause: {1}", 0x25, myKeypad.RegistrationFailureReason);
                    ErrorLog.Error("myKeypad {0} failed registration. Cause: {1}", 0x25, myKeypad.RegistrationFailureReason);
                }
                else
                {
                    CrestronConsole.PrintLine(" Keypad successfully registered ");
                }

                myKeypad2 = new C2niCb(0x26, this);
                myKeypad2.ButtonStateChange += (device, args) =>
                {
                    var btn = args.Button;
                    var uo  = btn.UserObject;

                    CrestronConsole.PrintLine("Event keypad 2 sig: {0}, Type: {1}, State: {2}", btn.Number,
                                              btn.GetType(), btn.State);

                    if (btn.State == eButtonState.Pressed)
                    {
                        switch (btn.Number)
                        {
                        case 2:
                            if (myDimmer.DinLoads[1].LevelOut.UShortValue > 0)
                            {
                                myDimmer.DinLoads[1].LevelIn.UShortValue = SimplSharpDeviceHelper.PercentToUshort(0f);
                                myKeypad2.Feedbacks[1].State             = false;
                                myKeypad2.Feedbacks[2].State             = false;
                            }
                            else
                            {
                                myDimmer.DinLoads[1].LevelIn.UShortValue =
                                    SimplSharpDeviceHelper.PercentToUshort(100f);
                                myKeypad2.Feedbacks[1].State = true;
                                myKeypad2.Feedbacks[2].State = true;
                            }
                            break;

                        case 9:
                            myRelay.SwitchedLoads[5].FullOn();
                            myRelay.SwitchedLoads[6].FullOff();
                            break;

                        case 11:
                            myRelay.SwitchedLoads[6].FullOn();
                            myRelay.SwitchedLoads[5].FullOff();
                            break;

                        default:
                            break;
                        }
                    }
                };

                if (myKeypad2.Register() != eDeviceRegistrationUnRegistrationResponse.Success)
                {
                    CrestronConsole.PrintLine(" Unable to register for keypad2 ");
                    CrestronConsole.PrintLine("myKeypad2 {0} failed registration. Cause: {1}", 0x26, myKeypad2.RegistrationFailureReason);
                    ErrorLog.Error("myKeypad2 {0} failed registration. Cause: {1}", 0x26, myKeypad2.RegistrationFailureReason);
                }
                else
                {
                    CrestronConsole.PrintLine(" Keypad2 successfully registered ");
                }

                myDimmer = new Din1DimU4(0x0A, this);
                // Now register the event handlers
                myDimmer.OverrideEventHandler += (device, overrideEvent) =>
                {
                    switch (overrideEvent)
                    {
                    case eOverrideEvents.External:
                        CrestronConsole.PrintLine(" Device  reports external override event. State is {0} ",
                                                  myDimmer.InExternalOverrideFeedback.BoolValue);
                        break;

                    case eOverrideEvents.Manual:
                        CrestronConsole.PrintLine(" Device  reports manual override event. State is {0} ",
                                                  myDimmer.InManualOverrideFeedback.BoolValue);
                        break;
                    }
                };
                myDimmer.OnlineStatusChange += (currentDevice, args) => CrestronConsole.PrintLine(" Din1DimU4 state {0} ", args.DeviceOnLine ? "Online" : "Offline");
                myDimmer.BaseEvent          += (device, args) =>
                {
                    //CrestronConsole.PrintLine("dimmer {0}", args.EventId);
                    switch (args.EventId)
                    {
                    case DinLoadBaseClass.LevelOutFeedbackEventId:
                        CrestronConsole.PrintLine(" Level out changed for output {0} ", args.Index);
                        CrestronConsole.PrintLine(" Value of load is {0} ",
                                                  myDimmer.DinLoads[(uint)args.Index].LevelOut.UShortValue);
                        //myDimmer.DinLoads[(uint)args.Index].LevelIn.UShortValue = myDimmer.DinLoads[(uint)args.Index].LevelOut.UShortValue;
                        break;

                    case DinLoadBaseClass.NoAcPowerFeedbackEventId:
                        CrestronConsole.PrintLine(" NoAcPowerFeedbackEventId fired. State is {0} ",
                                                  myDimmer.NoAcPower.BoolValue);
                        break;
                    }
                };

                // Need to set parameters before we register the device
                foreach (DinDimmableLoad dimmableLoad in myDimmer.DinLoads)
                {
                    dimmableLoad.ParameterDimmable = eDimmable.No;
                }
                // Register the device now
                if (myDimmer.Register() != eDeviceRegistrationUnRegistrationResponse.Success)
                {
                    CrestronConsole.PrintLine(" Unable to register for dimmer ");
                    CrestronConsole.PrintLine("myDimmer {0} failed registration. Cause: {1}", 0x0A, myDimmer.RegistrationFailureReason);
                    ErrorLog.Error("myDimmer {0} failed registration. Cause: {1}", 0x0A, myDimmer.RegistrationFailureReason);
                }
                else
                {
                    CrestronConsole.PrintLine(" Dimmer successfully registered ");
                }

                myRelay = new Din8Sw8i(0x92, this);
                myRelay.OverrideEventHandler += (device, overrideEvent) =>
                {
                    switch (overrideEvent)
                    {
                    case eOverrideEvents.External:
                        CrestronConsole.PrintLine(" Device relay reports external override event. State is {0} ",
                                                  myRelay.InExternalOverrideFeedback.BoolValue);
                        break;

                    case eOverrideEvents.Manual:
                        CrestronConsole.PrintLine(" Device relay reports manual override event. State is {0} ",
                                                  myRelay.InManualOverrideFeedback.BoolValue);
                        break;
                    }
                };
                myRelay.OnlineStatusChange += (currentDevice, args) => CrestronConsole.PrintLine(" Din8Sw8i  state {0} ", args.DeviceOnLine ? "Online" : "Offline");
                myRelay.BaseEvent          += (device, args) =>
                {
                    CrestronConsole.PrintLine("relay {0}", args.EventId);
                    switch (args.EventId)
                    {
                        //case DinLoadBaseClass.LevelOutFeedbackEventId:
                        //    CrestronConsole.PrintLine(" relay Level out changed for output {0} ", args.Index);
                        //    //CrestronConsole.PrintLine(" Value of load is {0} ", myRelay.DinLoads[(uint)args.Index].LevelOut.UShortValue);
                        //    break;
                        //case DinLoadBaseClass.NoAcPowerFeedbackEventId:
                        //    CrestronConsole.PrintLine(" NoAcPowerFeedbackEventId fired. State is {0} ", myRelay.NoAcPower.BoolValue);
                        //    break;
                    }
                };
                myRelay.LoadStateChange += (lightingObject, args) =>
                {
                    CrestronConsole.PrintLine("load relay {0}", args.EventId);

                    // use this structure to react to the different events
                    switch (args.EventId)
                    {
                    case LoadEventIds.IsOnEventId:
                        CrestronConsole.PrintLine(" relay Level out changed for output {0} ", args.Load.Number);
                        CrestronConsole.PrintLine(" Value of load is {0} ",
                                                  myRelay.SwitchedLoads[args.Load.Number].IsOn);
                        //xp.BooleanInput[1].BoolValue = !lampDimmer.DimmingLoads[1].IsOn;
                        //xp.BooleanInput[2].BoolValue = lampDimmer.DimmingLoads[1].IsOn;
                        break;

                    case LoadEventIds.LevelChangeEventId:
                        //xp.UShortInput[1].UShortValue = lampDimmer.DimmingLoads[1].LevelFeedback.UShortValue;
                        break;

                    case LoadEventIds.LevelInputChangedEventId:
                        //xp.UShortInput[1].CreateRamp(lampDimmer.DimmingLoads[1].Level.RampingInformation);
                        break;

                    default:
                        break;
                    }
                };

                // Register the device now
                if (myRelay.Register() != eDeviceRegistrationUnRegistrationResponse.Success)
                {
                    CrestronConsole.PrintLine(" Unable to register for relay ");
                    CrestronConsole.PrintLine("myRelay {0} failed registration. Cause: {1}", 0x92, myRelay.RegistrationFailureReason);
                    ErrorLog.Error("myRelay {0} failed registration. Cause: {1}", 0x92, myRelay.RegistrationFailureReason);
                }
                else
                {
                    CrestronConsole.PrintLine(" Relay successfully registered ");
                }

                //Subscribe to the controller events (System, Program, and Ethernet)
                CrestronEnvironment.SystemEventHandler += systemEventType =>
                {
                    switch (systemEventType)
                    {
                    case (eSystemEventType.DiskInserted):
                        //Removable media was detected on the system
                        break;

                    case (eSystemEventType.DiskRemoved):
                        //Removable media was detached from the system
                        break;

                    case (eSystemEventType.Rebooting):
                        //The system is rebooting.
                        //Very limited time to preform clean up and save any settings to disk.
                        break;
                    }
                };
                CrestronEnvironment.ProgramStatusEventHandler += programStatusEventType =>
                {
                    switch (programStatusEventType)
                    {
                    case (eProgramStatusEventType.Paused):
                        //The program has been paused.  Pause all user threads/timers as needed.
                        break;

                    case (eProgramStatusEventType.Resumed):
                        //The program has been resumed. Resume all the user threads/timers as needed.
                        break;

                    case (eProgramStatusEventType.Stopping):
                        //The program has been stopped.
                        //Close all threads.
                        //Shutdown all Client/Servers in the system.
                        //General cleanup.
                        //Unsubscribe to all System Monitor events
                        break;
                    }
                };
                CrestronEnvironment.EthernetEventHandler += ethernetEventArgs =>
                {
                    switch (ethernetEventArgs.EthernetEventType)
                    {
                    //Determine the event type Link Up or Link Down
                    case (eEthernetEventType.LinkDown):
                        //Next need to determine which adapter the event is for.
                        //LAN is the adapter is the port connected to external networks.
                        if (ethernetEventArgs.EthernetAdapter == EthernetAdapterType.EthernetLANAdapter)
                        {
                            //
                        }
                        break;

                    case (eEthernetEventType.LinkUp):
                        if (ethernetEventArgs.EthernetAdapter == EthernetAdapterType.EthernetLANAdapter)
                        {
                        }
                        break;
                    }
                };

                //my console command
                CrestronConsole.AddNewConsoleCommand(Hello, "hello", "hello command", ConsoleAccessLevelEnum.AccessOperator);
            }
            catch (Exception e)
            {
                ErrorLog.Error("Error in the constructor: {0}", e.Message);
            }
        }
Пример #8
0
        private void Light_Off(object sender, UIEventArgs e)
        {
            ushort levelValue = SimplSharpDeviceHelper.PercentToUshort(0);

            ((DimmableLoad)sender).Level_Feedback((sig, component) => { sig.UShortValue = levelValue; });
        }