Ejemplo n.º 1
0
 /// <summary>
 /// Sets the light controller to be used
 /// </summary>
 public void SetController(LightControllerType type, int ledCount = 0, bool reverseOrder = false)
 {
     ((IDisposable)lightController).Dispose();
     if (type == LightControllerType.LED_Strip)
     {
         lightController    = SACNController.Create();
         this.preferredMode = LightingMode.Line;
     }
     else if (type == LightControllerType.RazerChroma)
     {
         lightController    = RazerChromaController.Create();
         this.preferredMode = LightingMode.Keyboard;
     }
     RestartManager(this.preferredMode, ledCount, reverseOrder);
 }
 /// <summary>
 /// Sends LED data to a wireless LED strip using the E1.31 sACN protocol.
 /// </summary>
 public async void SendData()
 {
     await SACNController.Send(this.ToByteArray(reverseOrder));
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Update the virtual LED strip with the given LED color data.
        /// </summary>
        public void UpdateUI(Led[] leds, LightingMode mode)
        {
            if (updatingUI)
            {
                return;
            }
            updatingUI = true;
            Task.Run(() => // HACK This is done asynchronously but it's still very slow. 10ms to draw stuff...
            {
                if (currentLightingMode == LightingMode.Keyboard)
                {
                    if (mode == LightingMode.Keyboard)
                    {
                        if (lastDrawnMode != LightingMode.Keyboard)
                        {
                            canvas.Clear(Color.White);
                        }
                        int i = 0;
                        foreach (var led in leds)
                        {
                            byte[] col          = led.color.ToRGB();
                            SolidBrush colBrush = new SolidBrush(Color.FromArgb(col[0], col[1], col[2]));
                            KeyboardKey key     = keyboardLayout[i];
                            canvas.FillRectangle(colBrush, new Rectangle(key.X, key.Y, (key.Width ?? 20) - 2, (key.Height ?? 20) - 2));
                            i++;
                        }
                        lastDrawnMode = LightingMode.Keyboard;
                    }
                    else
                    {
                        SolidBrush blackBrush = new SolidBrush(Color.Black);
                        if (lastDrawnMode != LightingMode.Line)
                        {
                            for (int i = 0; i < 88; i++)
                            {
                                KeyboardKey key = keyboardLayout[i];
                                canvas.FillRectangle(blackBrush, new Rectangle(key.X, key.Y, (key.Width ?? 20) - 2, (key.Height ?? 20) - 2));
                                i++;
                            }
                        }
                        for (int i = 0; i < leds.Length; i++)
                        {
                            byte[] col = leds[i].color.ToRGB();
                            // SolidBrush colBrush = new SolidBrush(Color.FromArgb((int)(leds[i].color.v*255), col[0], col[1], col[2]));
                            SolidBrush colBrush = new SolidBrush(Color.FromArgb(col[0], col[1], col[2]));
                            int x = (int)Utils.Scale(i, 0, leds.Length, 0, 22);
                            for (int j = 0; j < 6; j++)
                            {
                                canvas.FillRectangle(colBrush, new Rectangle(x * 20, j * 20, 18, 18));
                            }
                        }
                        lastDrawnMode = LightingMode.Line;
                    }
                }
                else if (currentLightingMode == LightingMode.Line)
                {
                    Led[] ledsToDraw = null;
                    if (mode == LightingMode.Line)
                    {
                        ledsToDraw = leds;
                    }
                    else if (mode == LightingMode.Keyboard)
                    {
                        ledsToDraw = SACNController.GetKeyboardToLedStripArray(leds.ToByteArray());
                    }
                    else if (mode == LightingMode.Point)
                    {
                        throw new NotImplementedException();
                    }
                    int i = 0;
                    foreach (var led in ledsToDraw)
                    {
                        byte[] col          = led.color.ToRGB();
                        SolidBrush colBrush = new SolidBrush(Color.FromArgb(col[0], col[1], col[2]));
                        canvas.FillRectangle(colBrush, new Rectangle(0 + i * 10, 0, 10, 10));
                        i++;
                    }
                    lastDrawnMode = LightingMode.Line;
                }

                updatingUI = false;
            });
        }
Ejemplo n.º 4
0
 /// <param name="ledCount">Number of lights in the LED strip</param>
 /// <param name="reverseOrder">Set to true if you want the lights to be reverse in order (i.e. Color for LED 0 will be applied to the last LED in the strip)</param>
 private void InitLeds(bool reverseOrder = false)
 {
     lightControllers.Add(RazerChromaController.Create());
     lightControllers.Add(SACNController.Create(reverseOrder));
 }