Example #1
0
        public void SetColor(ColorMode mode, ControlBlock block, LEDConfiguration ledConfig,
                             params int[] colorPattern)
        {
            var message = GenerateLightMessage(mode, block, ledConfig, colorPattern);

            usbDevice.Write(message, 1050);
        }
Example #2
0
 public void SetColorPattern(ColorMode mode, ControlBlock block, LEDConfiguration ledConfig,
                             int[][] colorPattern)
 {
     for (byte i = 0; i < colorPattern.Length && i < 8; i++)
     {
         var correctConfig = new LEDConfiguration(i, ledConfig.ledGroupSize, ledConfig.animationSpeed);
         var message       = GenerateLightMessage(mode, block, correctConfig, colorPattern[i]);
         usbDevice.Write(message, 1050);
     }
 }
Example #3
0
        public static byte[] GenerateLightMessage(ColorMode mode, ControlBlock block, LEDConfiguration ledConfig,
                                                  int[] colorPattern)
        {
            // a message is constructed as following:
            // 0x02  ; control command
            // 0x4c  ; light control, which begs to wonder what 0x4a is
            // 0x13  ; 0b0001_0_0_00 is directional parameter
            //       ; 0b0000_1_0_00 is a binary option solely for "alternating" light option
            //       ; 0b0000_0_0_11 is 'iChannelMode'; controls logo or rim settings:
            //       ;                   - 0 - apply this set for rim and logo
            //       ;                   - 1 - apply this set for logo only
            //       ;                   - 2 - apply this set for rim only
            // 0x06  ; pulse mode, see light mode table
            // 0x25  ; 0b111_00_000 is the light index number (for multiple colored light)
            //       ; 0b000_11_000 is the LED group size, which exists only for marquee width
            //       ; 0b000_00_111 is the speed of animation between 0-4
            // 0xFF  ; Green Color for Text
            // 0xFF  ; Red Color for Text
            // 0xFF  ; Blue Color for Text
            // 0xFF  ; Red Color for 1st LED
            // 0xFF  ; Green Color for 1st LED
            // 0xFF  ; Blue Color for 1st LED
            if (colorPattern.Length < 1)
            {
                throw new ArgumentException("Color Pattern needs to have at least 1 color!");
            }

            byte[] message = new byte[32];
            message[0] = 0x02; // control message
            message[1] = 0x4c; // lightning control message
            message[2] = block;
            message[3] = (byte)mode;
            message[4] = ledConfig;
            message[5] = (byte)((colorPattern[0] & 0x00_FF_00) >> 8);
            message[6] = (byte)((colorPattern[0] & 0xFF_00_00) >> 16);
            message[7] = (byte)((colorPattern[0] & 0x00_00_FF) >> 0);
            for (byte i = 1; i < 9 && i < colorPattern.Length; i++)
            {
                message[i * 3 + 5] = (byte)((colorPattern[i] & 0xFF_00_00) >> 16);
                message[i * 3 + 6] = (byte)((colorPattern[i] & 0x00_FF_00) >> 8);
                message[i * 3 + 7] = (byte)((colorPattern[i] & 0x00_00_FF) >> 0);
            }


            return(message);
        }