Exemple #1
0
        public void StopRaise()
        {
            if (_crestronLoad.Type == eLoadType.Dimmer)
            {
                currentState = loadState.StopRaise;

                var            messageHub   = MessageHub.Instance;
                LoadRaiseEvent raiseMessage = new LoadRaiseEvent(this);
                messageHub.Publish <LoadRaiseEvent>(raiseMessage);

                ((BasicDimmingLoad)_crestronLoad).Raise.BoolValue = false;
            }
        }
Exemple #2
0
        public void Raise()
        {
            if (_crestronLoad.Type == eLoadType.Switch)
            {
                if (this.Level == 0)
                {
                    FullOn();
                }
            }
            else if (_crestronLoad.Type == eLoadType.Dimmer)
            {
                currentState         = loadState.Raise;
                expectedMessageCount = 3;

                var            messageHub   = MessageHub.Instance;
                LoadRaiseEvent raiseMessage = new LoadRaiseEvent(this);
                messageHub.Publish <LoadRaiseEvent>(raiseMessage);

                ((BasicDimmingLoad)_crestronLoad).Raise.BoolValue = true;
            }
        }
        public void ProcessLoadRaiseEvent(LoadRaiseEvent raiseEvent)
        {
            if (pagedLoads != null)
            {
                var index = pagedLoads.FindIndex(x => x.LoadID == raiseEvent.Load.LoadID);

                if (index >= 0)
                {
                    var load = pagedLoads[index];

                    if (load.IsRamping)
                    {
                        this._view.RaiseLoad((uint)index, load.RaiseLowerRate);
                    }
                    if (!load.IsRamping)
                    {
                        this._view.StopRampLoad((uint)index);
                    }
                }
            }
        }
Exemple #4
0
        void load_LoadEventHandler(LightingBase currentDevice, LoadEventArgs args)
        {
            var hub = MessageHub.Instance;

            if (EventIds.ContainsKey(args.EventId))
            {
                CrestronConsole.PrintLine("MessgeID: {0} Device {1}: {2}", sequence++, currentDevice.ID, EventIds[args.EventId]);
            }

            // use this structure to react to the different events
            switch (args.EventId)
            {
            case LoadEventIds.IsOnEventId:
                if (args.Load is SwitchedLoad)
                {
                    // this._ison = ((SwitchedLoad)(args.Load)).IsOn;

                    LoadOnEvent message = new LoadOnEvent(this);
                    message.IsOn = this.IsOn();

                    hub.Publish <LoadOnEvent>(message);
                }
                else if (args.Load is BasicDimmingLoad)
                {
                    LoadOnEvent mess = new LoadOnEvent(this);
                    mess.IsOn = this.IsOn();

                    hub.Publish <LoadOnEvent>(mess);
                    break;
                }

                break;

            case LoadEventIds.LevelChangeEventId:

                var dimmer = ((ClwDimmingLoad)(args.Load));
                _levelFB = dimmer.LevelFeedback.UShortValue;

                CrestronConsole.PrintLine("Processing Ramp Level Event: {0}", _levelFB);

                if (currentState == loadState.Raise || currentState == loadState.Lower ||
                    currentState == loadState.StopLower || currentState == loadState.StopRaise)
                {
                    if (expectedMessageCount == 3)
                    {
                        CrestronConsole.PrintLine("Start Ramp Level: {0}", _levelFB);
                        //Swallow the initial Level Message (for now);
                        expectedMessageCount--;
                        break;
                    }
                    else if (expectedMessageCount == 2)
                    {
                        expectedMessageCount--;
                        break;
                        //Next to last message (pulse)
                    }
                    else if (expectedMessageCount == 1)
                    {
                        //Final state (store in Level);
                        CrestronConsole.PrintLine("End Ramp Level: {0}", _levelFB);
                        expectedMessageCount--;
                        _level = dimmer.LevelFeedback.UShortValue;
                        SetLevelFB(_level);
                        currentState = loadState.Steady;
                        break;
                    }
                }
                else if (currentState == loadState.Toggle)
                {
                    if (expectedMessageCount == 2)
                    {
                        //Swallow first level
                        expectedMessageCount--;
                        break;
                    }
                    else if (expectedMessageCount == 1)
                    {
                        CrestronConsole.PrintLine("End State based on Toggle: {0}", _levelFB);
                        expectedMessageCount--;
                        _level = dimmer.LevelFeedback.UShortValue;
                        SetLevelFB(_level);
                        currentState = loadState.Steady;
                        break;
                    }
                }
                else
                {
                    if (currentState == loadState.Steady)
                    {
                        CrestronConsole.PrintLine("Toggle state encountered: {0}", _levelFB);
                        currentState         = loadState.Toggle;
                        expectedMessageCount = 1;
                        break;
                    }
                }

                break;

            case LoadEventIds.LevelInputChangedEventId:

                break;

            case LoadEventIds.PresetLoadIsAtEventId:

                break;

            case LoadEventIds.LastPresetCalledEventId:

                var dimmer2    = ((ClwDimmingLoad)(args.Load));
                var lastPreset = dimmer2.LastPresetCalled();


                if (lastPreset != null)
                {
                    LoadPresetCalledEvent presetMessage = new LoadPresetCalledEvent(this);
                    presetMessage.PresetNumber = lastPreset.Number;

                    hub.Publish <LoadPresetCalledEvent>(presetMessage);
                }
                else
                {
                }

                break;

            case LoadEventIds.LowerEventId:

                if (currentState == loadState.Lower)
                {
                    CrestronConsole.PrintLine("I was lowering, stopping lower");
                    currentState = loadState.StopLower;
                }
                else
                {
                    CrestronConsole.PrintLine("In default Lower block");
                    currentState         = loadState.Lower;
                    expectedMessageCount = 3;
                }

                LoadLowerEvent lowerMessage = new LoadLowerEvent(this);
                hub.Publish <LoadLowerEvent>(lowerMessage);

                break;

            case LoadEventIds.RaiseEventId:

                if (currentState == loadState.Raise)
                {
                    CrestronConsole.PrintLine("I was raising, stopping raise");
                    currentState = loadState.StopRaise;
                }
                else
                {
                    CrestronConsole.PrintLine("In default Raise block");
                    currentState         = loadState.Raise;
                    expectedMessageCount = 3;
                }

                LoadRaiseEvent raiseMessage = new LoadRaiseEvent(this);
                hub.Publish <LoadRaiseEvent>(raiseMessage);

                break;

            case LoadEventIds.OffReleaseEventId:

                currentState         = loadState.Toggle;
                expectedMessageCount = 2;

                LoadButtonOffReleaseEvent offReleaseMessage = new LoadButtonOffReleaseEvent(this);
                hub.Publish <LoadButtonOffReleaseEvent>(offReleaseMessage);
                break;

            default:
                break;
            }
        }
Exemple #5
0
        void load_LoadEventHandler(LightingBase currentDevice, LoadEventArgs args)
        {
            //Need to review this code/handler to better support multiple loads on device
            var hub = MessageHub.Instance;

            //if (EventIds.ContainsKey(args.EventId))
            //    CrestronConsole.PrintLine("MessgeID: {0} Device {1}: {2}", sequence++, currentDevice.ID, EventIds[args.EventId]);

            // use this structure to react to the different events
            switch (args.EventId)
            {
            case LoadEventIds.IsOnEventId:
            {
                //Shouldn't matter if Switch vs Dimmer
                if (this.IsOn())
                {
                    LoadIsOnEvent message = new LoadIsOnEvent(this);
                    hub.Publish <LoadIsOnEvent>(message);
                }
                else
                {
                    LoadIsOffEvent message = new LoadIsOffEvent(this);
                    hub.Publish <LoadIsOffEvent>(message);
                }
            }
            break;

            case LoadEventIds.LevelChangeEventId:
            {
                //If Level is/was 65535
                //You can expect two level events with no prior warning (This means button was pressed);

                var dimmer = ((ClwDimmingLoad)(args.Load));
                _levelFB = dimmer.LevelFeedback.UShortValue;

                if (currentState == LoadState.Raise || currentState == LoadState.Lower ||
                    currentState == LoadState.StopLower || currentState == LoadState.StopRaise)
                {
                    if (expectedMessageCount == 3)
                    {
                        //Swallow the initial Level Message (for now);
                        _startLevel = _levelFB;
                        expectedMessageCount--;
                        break;
                    }
                    else if (expectedMessageCount == 2)
                    {
                        expectedMessageCount--;
                        break;
                        //Next to last message (pulse)
                    }
                    else if (expectedMessageCount == 1)
                    {
                        //Final state (store in Level);
                        _endLevel = _levelFB;
                        expectedMessageCount--;
                        _level = dimmer.LevelFeedback.UShortValue;
                        SetLevelFB(_level);
                        currentState = LoadState.Steady;
                        break;
                    }
                }
                else if (currentState == LoadState.Toggle)
                {
                    if (expectedMessageCount == 2)
                    {
                        //Swallow first level
                        _startLevel = _levelFB;
                        expectedMessageCount--;
                        break;
                    }
                    else if (expectedMessageCount == 1)
                    {
                        expectedMessageCount--;
                        _endLevel = _levelFB;
                        _level    = _levelFB;
                        SetLevelFB(_level);
                        currentState = LoadState.Steady;
                        break;
                    }
                }
                else
                {
                    if (currentState == LoadState.Steady)
                    {
                        //This only gets called when load is at MAX 65535 and we keep pushing to go max again
                        //This really shouldn't trigger an event (as we already should have this level)
                        //Let's process it anyway
                        _startLevel          = _levelFB;
                        currentState         = LoadState.Toggle;
                        expectedMessageCount = 1;
                        break;
                    }
                }
            }
            break;

            case LoadEventIds.LevelInputChangedEventId:
            {
            }
            break;

            case LoadEventIds.PresetLoadIsAtEventId:
            {
            }
            break;

            case LoadEventIds.FastOffEventId:
            {         //We must handle this
                currentState         = LoadState.Toggle;
                expectedMessageCount = 2;

                LoadOffEvent message = new LoadOffEvent(this);
                message.Time = _fastOnOffTime;

                hub.Publish <LoadOffEvent>(message);
            }
            break;

            case LoadEventIds.FastFullOnEventId:
            {
                //Need to handle this
                var dimmer = ((ClwDimmingLoad)(args.Load));
                // var last1Preset = dimmer12.LastPresetCalled();

                currentState         = LoadState.Toggle;
                expectedMessageCount = 2;

                LoadOnEvent message = new LoadOnEvent(this);
                message.Time = _fastOnOffTime;
                //lpresetMessage.PresetNumber = last1Preset.Number;

                hub.Publish <LoadOnEvent>(message);
            }

            break;

            case LoadEventIds.LastPresetCalledEventId:
            {
                //This is preset to go full on
                //I'm not handling other presets right now
                //Switch somehow has "PressOn" triggered to preset

                var dimmer     = ((ClwDimmingLoad)(args.Load));
                var lastPreset = dimmer.LastPresetCalled();

                currentState         = LoadState.Toggle;
                expectedMessageCount = 2;


                if (lastPreset != null)
                {
                    LoadOnEvent message = new LoadOnEvent(this);
                    message.Time = _presetFadeTime;
                    // presetMessage.PresetNumber = lastPreset.Number;

                    hub.Publish <LoadOnEvent>(message);
                }
                else
                {
                }
            }
            break;

            case LoadEventIds.LowerEventId:
            {
                //Basic lower

                if (currentState == LoadState.Lower)
                {
                    currentState = LoadState.StopLower;
                }
                else
                {
                    currentState         = LoadState.Lower;
                    expectedMessageCount = 3;
                }

                LoadLowerEvent message = new LoadLowerEvent(this);
                hub.Publish <LoadLowerEvent>(message);
            }
            break;

            case LoadEventIds.RaiseEventId:
            {         //Basic Raise
                if (currentState == LoadState.Raise)
                {
                    currentState = LoadState.StopRaise;
                }
                else
                {
                    currentState         = LoadState.Raise;
                    expectedMessageCount = 3;
                }

                LoadRaiseEvent message = new LoadRaiseEvent(this);
                hub.Publish <LoadRaiseEvent>(message);
            }
            break;

            case LoadEventIds.OffReleaseEventId:
            {
                //Off Release
                //We don't do anything with Off Press?
                //Holding Off just triggers a lower

                currentState         = LoadState.Toggle;
                expectedMessageCount = 2;

                LoadOffEvent message = new LoadOffEvent(this);
                message.Time = _offFadeTime;

                hub.Publish <LoadOffEvent>(message);
            }
            break;

            default:
            {
            }
            break;
            }
        }