Пример #1
0
        private void UpdateLampStates()
        {
            lock (this.UpdatingDataLocker)
            {
                CurrentLampStates = new List <LuxxusSmartLight>();

                //f3:d4:21:f9:ee:07:00:00:1d:05:00:00:00:43:00
                MemoryStream ms = new MemoryStream();

                ms.WriteByte(0xf3);
                ms.WriteByte((byte)PacketType.QueryState);

                byte[] bGatewayId = BitConverter.GetBytes(this.GatewayId);
                if (!BitConverter.IsLittleEndian)
                {
                    Array.Reverse(bGatewayId);
                }

                ms.Write(bGatewayId, 0, bGatewayId.Length);

                ms.WriteByte(0x00);
                ms.WriteByte(0x00);
                ms.WriteByte(0x1d);
                ms.WriteByte(0x05);
                ms.WriteByte(0x00);
                ms.WriteByte(0x00);
                ms.WriteByte(0x00);
                ms.WriteByte(0x43);
                ms.WriteByte(0x00);

                if (WritePacket(ms.ToArray()))
                {
                    byte[] response = GetResponse();

                    if (response != null && response.Length > 10)
                    {
                        byte[] bLampStates = new byte[response[9]];
                        Buffer.BlockCopy(response, 10, bLampStates, 0, response.Length - 10);

                        int numberOfStates = bLampStates.Length / 8;

                        for (int i = 0; i < numberOfStates; i++)
                        {
                            int startIndex = i * 8;

                            uint deviceId  = BitConverter.ToUInt32(bLampStates, startIndex);
                            byte intensity = bLampStates[startIndex + 7];

                            byte            R     = bLampStates[startIndex + 4];
                            byte            G     = bLampStates[startIndex + 5];
                            byte            B     = bLampStates[startIndex + 6];
                            SmartLightColor color = new SmartLightColor(R, G, B);

                            CurrentLampStates.Add(new LuxxusSmartLight(deviceId, intensity, color));
                        }
                    }
                }
            }
        }
Пример #2
0
        /**
        * description  It sets RGB values of the bulb
        * param        address1   : high address of bulb [0..255]
        * param        address2   : low address of bulb [0..255]
        * param        ui8RedValue   : PWM value of red coulor [0..255]
        * param        uiGreenValue  : PWM value of red coulor [0..255]
        * param        uiBlueValue   : PWM value of red coulor [0..255]
        * param        castType   : transmission mode
        *                              This parameter can be one of following values:
        *                                Constants.C_UNICAST  : command sent to a single bulb and check of answer (default)
        *                                Constants.C_MULTICAST: command sent to a multiple bulbs and no check of answer
        * param        dimmerSteps: number of dimmer steps. One step every 10 ms.
        *                              This parameter can be one of following values:
        *                                0    : no dimmer effect (default)
        *                                value: dimmer effect in value*10 ms [1..100]
        * retval       none
        * note         In Constants.C_UNICAST mode, the bulb sends an answer for reporting command results
        */
        public bool SetRGB(SmartLightColor color)
        {
            byte dimmerSteps = 0;
            Command commandToSend = new Command();

            commandToSend.commandType = (CommandType)((byte)transmissionMode | (byte)CommandType.SetRGB);
            commandToSend.destinationAddress1 = upperAddressByte;
            commandToSend.destinationAddress2 = lowerAddressByte;

            commandToSend.param1 = color.red;
            commandToSend.param2 = color.green;
            commandToSend.param3 = color.blue;

            if (transmissionMode == TransmissionMode.Unicast)
            {
                commandToSend.param4 = (byte)((dimmerSteps <= Constants.PROTOCOL_DIMMER_STEPS) ? dimmerSteps : Constants.PROTOCOL_DIMMER_STEPS);
                commandToSend.frameNumber = frameCounter++;
            }
            else
                commandToSend.param4 = 0;

            commandToSend.CalculateCRC();

            if (OnCommandReady != null)
            {
                OnCommandReady(this, new CommandReadyEventArgs(commandToSend));
            }

            return true;
        }
Пример #3
0
 public bool SetRGBW(SmartLightColor color)
 {
     throw new NotImplementedException();
 }
Пример #4
0
 public LuxxusSmartLight(uint id, ushort intensity, SmartLightColor color)
     : base(id, intensity, color)
 {
 }
Пример #5
0
 public SmartLight(uint id, ushort intensity, SmartLightColor color)
 {
     this.Id    = id;
     this.State = new SmartLightState(intensity, color);
 }