static async Task Error(IChroma chroma) // Flashes entire keyboard red. { for (int i = 0; i < 4; i++) { await chroma.Keyboard.SetAllAsync(ColoreColor.Red); await Task.Delay(250); await chroma.Keyboard.SetAllAsync(ColoreColor.Black); await Task.Delay(250); } await chroma.SetAllAsync(ColoreColor.Red); await Task.Delay(1500); return; }
public void UpdateColor(byte red, byte green, byte blue) { // Traverse all devices foreach (IAuraSyncDevice dev in devices) { // Traverse all LED's foreach (IAuraRgbLight light in dev.Lights) { // Set all LED's to blue light.Red = red; light.Green = green; light.Blue = blue; } // Apply colors that we have just set dev.Apply(); } if (chroma != null) { chroma.SetAllAsync(Colore.Data.Color.FromRgb((uint)(red << 16 | green << 8 | blue))); } }
private bool MqttC_PublishArrived(object sender, PublishArrivedArgs e) { log.Debug("Mqtt Rx : " + e.Topic + " : " + e.Payload); string[] topic = e.Topic.Substring(mqttPreTopic.Length).Split('/'); string payload = e.Payload; ColoreColor c; try { c = HexToColore(payload); } catch { log.Error(payload + " is no valid color"); return(false); } if (topic.Length >= 1) { switch (topic[0].ToLower()) { case "set": if (topic.Length >= 2) { switch (topic[1].ToLower()) { case "all": chroma.SetAllAsync(c); break; case "keyboard": if (topic.Length >= 3) { switch (topic[2].ToLower()) { case "all": chroma.Keyboard.SetAllAsync(c); break; case "key": if (topic.Length < 4) { log.Error("Key is not specified "); return(false); } Key key; if (Enum.TryParse(topic[3], out key)) { chroma.Keyboard[key] = c; } else { log.Error($"\"{topic[3]}\" is no valid key"); return(false); } break; case "grid": if (topic.Length < 5) { log.Error("Position is not specified "); return(false); } int row, column; if (!int.TryParse(topic[3], out row)) { log.Error($"\"{topic[3]}\" NaN"); return(false); } if (!int.TryParse(topic[4], out column)) { log.Error($"\"{topic[4]}\" NaN"); return(false); } if (row < 0 || row >= KeyboardConstants.MaxRows) { log.Error($"\"{row}\" out of range. Max:" + (KeyboardConstants.MaxRows - 1)); return(false); } if (column < 0 || column >= KeyboardConstants.MaxColumns) { log.Error($"\"{column}\" out of range. Max:" + (KeyboardConstants.MaxColumns - 1)); return(false); } chroma.Keyboard[row, column] = c; break; case "zone": if (topic.Length < 4) { log.Error("Zone is not specified "); return(false); } int zone; if (!int.TryParse(topic[3], out zone)) { log.Error($"\"{topic[3]}\" NaN"); return(false); } if (zone < 0 || zone >= KeyboardConstants.MaxDeathstalkerZones) { log.Error($"\"{zone}\" out of range. Max:" + (KeyboardConstants.MaxDeathstalkerZones - 1)); return(false); } chroma.Keyboard[zone] = c; break; default: log.Error($"\"{topic[2]}\" unknown"); return(false); } } else { log.Error("no specification (\"all\", \"key\", \"grid\", \"zone\")"); return(false); } break; case "keypad": if (topic.Length >= 3) { switch (topic[2].ToLower()) { case "all": chroma.Keypad.SetAllAsync(c); break; case "grid": if (topic.Length < 5) { log.Error("Position is not specified "); return(false); } int row, column; if (!int.TryParse(topic[3], out row)) { log.Error($"\"{topic[3]}\" NaN"); return(false); } if (!int.TryParse(topic[4], out column)) { log.Error($"\"{topic[4]}\" NaN"); return(false); } if (row < 0 || row >= Colore.Effects.Keypad.KeypadConstants.MaxRows) { log.Error($"\"{row}\" out of range. Max:" + (Colore.Effects.Keypad.KeypadConstants.MaxRows - 1)); return(false); } if (column < 0 || column >= Colore.Effects.Keypad.KeypadConstants.MaxColumns) { log.Error($"\"{column}\" out of range. Max:" + (Colore.Effects.Keypad.KeypadConstants.MaxColumns - 1)); return(false); } chroma.Keypad[row, column] = c; break; default: log.Error($"\"{topic[2]}\" unknown"); return(false); } } else { log.Error("no specification (\"all\", \"grid\")"); return(false); } break; case "mouse": if (topic.Length >= 3) { switch (topic[2].ToLower()) { case "all": chroma.Mouse.SetAllAsync(c); break; case "gridled": if (topic.Length < 4) { log.Error("Key is not specified "); return(false); } Colore.Effects.Mouse.GridLed gridLed; if (Enum.TryParse(topic[3], out gridLed)) { chroma.Mouse[gridLed] = c; } else { log.Error($"\"{topic[3]}\" is no valid GridLed"); return(false); } break; case "grid": if (topic.Length < 5) { log.Error("Position is not specified "); return(false); } int row, column; if (!int.TryParse(topic[3], out row)) { log.Error($"\"{topic[3]}\" NaN"); return(false); } if (!int.TryParse(topic[4], out column)) { log.Error($"\"{topic[4]}\" NaN"); return(false); } if (row < 0 || row >= Colore.Effects.Mouse.MouseConstants.MaxRows) { log.Error($"\"{row}\" out of range. Max:" + (Colore.Effects.Mouse.MouseConstants.MaxRows - 1)); return(false); } if (column < 0 || column >= Colore.Effects.Mouse.MouseConstants.MaxColumns) { log.Error($"\"{column}\" out of range. Max:" + (Colore.Effects.Mouse.MouseConstants.MaxColumns - 1)); return(false); } chroma.Mouse[row, column] = c; break; default: log.Error($"\"{topic[2]}\" unknown"); return(false); } } else { log.Error("no specification (\"all\", \"gridled\", \"grid\")"); return(false); } break; case "mousepad": if (topic.Length >= 3) { switch (topic[2].ToLower()) { case "all": chroma.Mousepad.SetAllAsync(c); break; case "index": if (topic.Length < 4) { log.Error("Index is not specified "); return(false); } int index; if (!int.TryParse(topic[3], out index)) { log.Error($"\"{topic[3]}\" NaN"); return(false); } if (index < 0 || index >= Colore.Effects.Mousepad.MousepadConstants.MaxLeds) { log.Error($"\"{index}\" out of range. Max:" + (Colore.Effects.Mousepad.MousepadConstants.MaxLeds - 1)); return(false); } chroma.Mousepad[index] = c; break; default: log.Error($"\"{topic[2]}\" unknown"); return(false); } } else { log.Error("no specification (\"all\", \"index\")"); return(false); } break; case "headset": if (topic.Length >= 3) { switch (topic[2].ToLower()) { case "all": chroma.Headset.SetAllAsync(c); break; case "index": if (topic.Length < 4) { log.Error("Index is not specified "); return(false); } int index; if (!int.TryParse(topic[3], out index)) { log.Error($"\"{topic[3]}\" NaN"); return(false); } if (index < 0 || index >= Colore.Effects.Headset.HeadsetConstants.MaxLeds) { log.Error($"\"{index}\" out of range. Max:" + (Colore.Effects.Headset.HeadsetConstants.MaxLeds - 1)); return(false); } chroma.Headset[index] = c; break; default: log.Error($"\"{topic[2]}\" unknown"); return(false); } } else { log.Error("no specification (\"all\", \"index\")"); return(false); } break; case "link": if (topic.Length >= 3) { switch (topic[2]) { case "all": chroma.ChromaLink.SetAllAsync(c); break; case "index": if (topic.Length < 4) { log.Error("Index is not specified "); return(false); } int index; if (!int.TryParse(topic[3], out index)) { log.Error($"\"{topic[3]}\" NaN"); return(false); } if (index < 0 || index >= Colore.Effects.ChromaLink.ChromaLinkConstants.MaxLeds) { log.Error($"\"{index}\" out of range. Max:" + (Colore.Effects.ChromaLink.ChromaLinkConstants.MaxLeds - 1)); return(false); } chroma.ChromaLink[index] = c; break; default: log.Error($"\"{topic[2]}\" unknown"); return(false); } } else { log.Error("no specification (\"all\", \"index\")"); return(false); } break; default: log.Error($"\"{topic[1]}\" unknown"); return(false); } string retTopic = "state"; for (int i = 1; i < topic.Length; i++) { retTopic += "/" + topic[i]; } mqttClient.Publish(mqttPreTopic + retTopic, new MqttPayload(ColoreToHex(c)), QoS.BestEfforts, false); } break; default: log.Error($"\"{topic[0]}\" unknown"); return(false); } } return(true); }
public Module Setup() { IChroma chroma = ColoreProvider.CreateNativeAsync().Result; chroma.SetAllAsync(Colore.Data.Color.Red); chroma.Keyboard[Key.A] = Colore.Data.Color.Red; Module module = new Module() { Name = "Razer" }; module.Devices.Add(new Device() { Id = "RAZER_BLACKWIDOW_V1", Title = "BlackWidow", Map = new DeviceMap() { BackgroundImage = ImageToByteArray(Resource.keyboard), Size = new Size(100, 30), Leds = new Point[1, 2] { { new Point(10, 10), new Point(10, 40) } } } /*Map = new int[7, 23] * { * {0,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0}, * {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, * {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, * {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,0}, * {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,1,1,1}, * {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, * {0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0} * }*/ }); module.Devices.Add(new Device() { Id = "LED_STRIP", Title = "LedStrip", Map = new DeviceMap() { BackgroundImage = null, Size = new Size(300, 5), Leds = new Point[1, 21] { { new Point(0, 0), new Point(15, 0), new Point(30, 0), new Point(45, 0), new Point(60, 0), new Point(75, 0), new Point(90, 0), new Point(105, 0), new Point(120, 0), new Point(135, 0), new Point(150, 0), new Point(165, 0), new Point(180, 0), new Point(195, 0), new Point(210, 0), new Point(225, 0), new Point(240, 0), new Point(255, 0), new Point(270, 0), new Point(285, 0), new Point(300, 0) } } } }); module.Devices.Add(new Device() { Id = "RAZER_DEATHADDER_V2", Title = "Death Adder", Map = new DeviceMap() { BackgroundImage = ImageToByteArray(Resource.mouse), Size = new Size(50, 50), Leds = new Point[1, 2] { { new Point(25, 15), new Point(25, 40) } } } }); module.Devices.Add(new Device() { Id = "RAZER_CHROMA_7.1", Title = "Chroma 7.1", Map = new DeviceMap() { BackgroundImage = ImageToByteArray(Resource.headphones), Size = new Size(50, 50), Leds = new Point[2, 1] { { new Point(5, 36) }, { new Point(45, 36) } } } }); return(module); }