public static unsafe Frame GetFrameFromLeds(LedState state) { var frame = new Frame(); var index = 0; foreach (var led in state.Leds) { frame.Red[index] = led.Red; frame.Green[index] = led.Green; frame.Blue[index] = led.Blue; ++index; } return frame; }
public Device() { _isRunning = false; _currentFrame = new LedState(); _whiteFrame = new LedState(); _darkFrame = new LedState(); var white = new Color("#ffffff"); var dark = new Color("#000000"); for (var i = 0; i < 8; i++) { _whiteFrame.Leds[i] = white; _darkFrame.Leds[i] = dark; } }
static void Main(string[] args) { var handle = GlowProxy.Open(); try { var state = new LedState(); var white = new Color(0xff, 0xff, 0xff); var blue = new Color(0x00, 0x00, 0xff); var green = new Color(0x00, 0xff, 0x00); state.Leds[0] = blue; state.Leds[1] = blue; state.Leds[2] = blue; state.Leds[3] = blue; state.Leds[4] = green; state.Leds[5] = green; state.Leds[6] = green; state.Leds[7] = green; GlowProxy.SetColor(handle, state); var report = new InputReport(); while (true) { var lastReport = report; var r = GlowProxy.ReadInput(handle, ref report); if (!lastReport.Equals(report)) { Console.WriteLine(report.ButtonMask + ":" + report.CurrentCount); if (report.ButtonMask > 0) { var lastState = state; for (var i = 0; i < 8; i++) { state.Leds[i] = white; } //GlowProxy.SetColor(handle, state); state = lastState; GlowProxy.SetColor(handle, lastState); } else { var red = report.CurrentCount * 2; var color1 = new Color((byte)red, 0x00, 0xff); var color2 = new Color((byte)red, 0xff, 0x00); state.Leds[0] = color1; state.Leds[1] = color1; state.Leds[2] = color1; state.Leds[3] = color1; state.Leds[4] = color2; state.Leds[5] = color2; state.Leds[6] = color2; state.Leds[7] = color2; GlowProxy.SetColor(handle, state); } } } } catch (Exception) { { } throw; } finally { GlowProxy.Close(handle); } }
public static void SetColor(IntPtr handle, LedState state) { var frame = GetFrameFromLeds(state); _setColor(handle, frame); }