示例#1
0
        /// <summary>
        /// Create a UIController instance
        /// </summary>
        /// <param name="system">The base system</param>
        /// <param name="device">The UI device used for the UIController</param>
        /// <param name="defaultRoom">The default room for the UI</param>
        protected UIController(SystemBase system, BasicTriList device, RoomBase defaultRoom)
        {
            _idCount++;
            Id      = _idCount;
            _system = system;
            _system.SystemStartupProgressChange += OnSystemStartupProgressChange;

            Device      = device;
            DefaultRoom = defaultRoom;

            CloudLog.Debug("Creating {0} for device: {1} ({2}) with ID 0x{3:X2}", GetType().Name, device.GetType().Name, device.Name, device.ID);

            try
            {
                device.IpInformationChange += DeviceOnIpInformationChange;
                _isEthernetDevice           = true;
            }
            catch
            {
                CloudLog.Debug("{0} is not Ethernet Device", device.ToString());
            }
            device.OnlineStatusChange += DeviceOnOnlineStatusChange;
            device.SigChange          += OnSigChange;

            var tswFt5Button = device as TswFt5Button;

            if (tswFt5Button != null)
            {
                tswFt5Button.ExtenderEthernetReservedSigs.Use();
                tswFt5Button.ExtenderEthernetReservedSigs.DeviceExtenderSigChange +=
                    ExtenderEthernetReservedSigsOnDeviceExtenderSigChange;
            }

            var tswx52ButtonVoiceControl = device as Tswx52ButtonVoiceControl;

            if (tswx52ButtonVoiceControl != null)
            {
                tswx52ButtonVoiceControl.ExtenderSystemReservedSigs.Use();
                tswx52ButtonVoiceControl.ExtenderAutoUpdateReservedSigs.Use();
                tswx52ButtonVoiceControl.ExtenderAutoUpdateReservedSigs.DeviceExtenderSigChange += ExtenderAutoUpdateReservedSigsOnDeviceExtenderSigChange;
            }

            var tswX60BaseClass = device as TswX60BaseClass;

            if (tswX60BaseClass != null)
            {
                tswX60BaseClass.ExtenderHardButtonReservedSigs.Use();
                Debug.WriteInfo("Setting up hard buttons for TswX60BaseClass device");
                _hardButtons = new ButtonCollection();
                for (uint b = 1; b <= 5; b++)
                {
                    var extender  = tswX60BaseClass.ExtenderHardButtonReservedSigs;
                    var t         = extender.GetType().GetCType();
                    var offMethod = t.GetMethod(string.Format("TurnButton{0}BackLightOff", b));
                    var onMethod  = t.GetMethod(string.Format("TurnButton{0}BackLightOn", b));
                    var delType   = typeof(HardKeyBackLightMethod).GetCType();
                    var offDel    = (HardKeyBackLightMethod)CDelegate.CreateDelegate(delType, extender, offMethod);
                    var onDel     = (HardKeyBackLightMethod)CDelegate.CreateDelegate(delType, extender, onMethod);
                    var button    = new UIHardButton(this, b, onDel, offDel);
                    _hardButtons.Add(b, button);
                }
            }
            else if (device is Tswx52ButtonVoiceControl)
            {
                Debug.WriteInfo("Setting up hard buttons for Tswx52ButtonVoiceControl device");
                _hardButtons = new ButtonCollection();
                for (uint b = 1; b <= 5; b++)
                {
                    var button = new UIHardButton(this, b);
                    _hardButtons.Add(b, button);
                }
            }

            _system.UIControllers.Add(this);
        }
        void ui_SigChange(BasicTriList currentDevice, SigEventArgs args)
        {
            Sig sig = args.Sig;

            OnDebug(eDebugEventType.Info, "{0} SigChange in {1} type: {2}, sig: {3}, Name: {4}", currentDevice.ToString(), currentDevice.ID.ToString(), sig.Type.ToString(), sig.Number.ToString(), sig.Name);
            switch (sig.Type)
            {
            case eSigType.Bool:
                if (sig.BoolValue)     // press
                {
                    OnDebug(eDebugEventType.Info, "Press event on sig number: {0}", sig.Number);
                    switch (sig.Number)
                    {
                    case DIG_TOGGLE_POWER:
                        UI.ToggleDigitalJoin(currentDevice, sig.Number);
                        break;

                    case DIG_MACRO:
                        UI.PulseDigitalJoin(currentDevice, DIG_TOGGLE_POWER);
                        var randomNumber = new Random().Next(ushort.MaxValue);
                        UI.SetAnalogJoin(currentDevice, ANA_RANDOM, (ushort)randomNumber);
                        UI.SetSerialJoin(currentDevice, SER_VALUE, randomNumber.ToString());
                        break;
                    }
                }
                else     // release
                {
                }
                break;

            case eSigType.UShort:
                OnDebug(eDebugEventType.Info, "UShortValue: {0}", sig.UShortValue.ToString());
                switch (sig.Number)
                {
                case ANA_BAR_GRAPH:
                    UI.SetAnalogJoin(currentDevice, sig.Number, sig.UShortValue);
                    UI.SetSerialJoin(currentDevice, SER_VALUE, sig.UShortValue.ToString());
                    break;

                case ANA_RANDOM:
                    UI.SetAnalogJoin(currentDevice, ANA_BAR_GRAPH, sig.UShortValue);
                    break;
                }
                break;

            case eSigType.String:
                OnDebug(eDebugEventType.Info, "StringValue: {0}", sig.StringValue);
                switch (sig.Number)
                {
                case SER_INPUT:
                    UI.SetSerialJoin(currentDevice, SER_VALUE, sig.StringValue.ToString());
                    break;
                }
                break;

            default:
                OnDebug(eDebugEventType.Info, "Unhandled sig type: {0}", sig.Type.ToString());
                break;
            }
        }
        public void EICSignalHandler(BasicTriList currentDevice, SigEventArgs args)
        {
            CrestronConsole.PrintLine("[+] Signal Received : {0}", currentDevice.ToString());

            Sig signal = args.Sig;

            switch (signal.Type)
            {
            // Digital
            case (eSigType.Bool):
                CrestronConsole.PrintLine("[+]   Digital: {0}", signal.ToString());

                // Occupancy Detected Signal
                if (signal.Number == (uint)eSignalDigitalID.Occupancy_Detected)
                {
                    CrestronConsole.PrintLine("[+]   Occupancy Detected: {0}", signal.BoolValue);

                    if (signal.BoolValue)
                    {
                        // Start receiving occupancy information. New room object to store info.
                        _room = new Room();
                        _room.setOccupied();
                    }
                    else
                    {
                        // Done receiving occupancy information. Store the room state
                        property.updateRoom(_room);
                        TxPropertyStatus(property);
                    }
                }

                // Vacancy Detected Signal
                if (signal.Number == (uint)eSignalDigitalID.Vacancy_Detected)
                {
                    CrestronConsole.PrintLine("[+]   Vacancy Detected: {0}", signal.BoolValue);

                    if (signal.BoolValue)
                    {
                        // Start receiving vacancy information. New room object to store info.
                        _room = new Room();
                        _room.setVacant();
                    }
                    else
                    {
                        // Done receiving vacancy information. Store the room state
                        property.updateRoom(_room);
                    }
                }

                break;

            // Analog
            case (eSigType.UShort):
                CrestronConsole.PrintLine("[+]   Analog: {0}", signal.ToString());

                break;

            // Serial
            case (eSigType.String):
                CrestronConsole.PrintLine("[+]   Serial: {0}", signal.ToString());

                // Motion_Location$ Signal
                if (signal.Number == (uint)eSignalSerialID.Motion_Location)
                {
                    CrestronConsole.PrintLine("[+]   Motion Location: {0}", signal.StringValue);

                    _room.Name = signal.StringValue;
                }

                break;

            default:
                CrestronConsole.PrintLine("[+]   Unknown: {0}", signal.ToString());

                break;
            }
        }