From 19d81d79c378ddbb2e75326876f76b366f134f5b Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Sun, 19 Apr 2020 23:00:31 +0200 Subject: [PATCH 1/2] CoolerMaster - Throw more detailed error when missing LED mappings --- .../Keyboard/CoolerMasterKeyboardRGBDevice.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDevice.cs b/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDevice.cs index ab02892..9b9ed0b 100644 --- a/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDevice.cs +++ b/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDevice.cs @@ -27,8 +27,14 @@ namespace RGB.NET.Devices.CoolerMaster /// protected override void InitializeLayout() { - Dictionary mapping = CoolerMasterKeyboardLedMappings.Mapping[DeviceInfo.DeviceIndex][DeviceInfo.PhysicalLayout]; - + Dictionary> deviceMappings; + Dictionary mapping; + + if (!CoolerMasterKeyboardLedMappings.Mapping.TryGetValue(DeviceInfo.DeviceIndex, out deviceMappings)) + throw new RGBDeviceException($"Failed to find a CoolerMasterKeyboardLedMapping for device index {DeviceInfo.DeviceIndex}"); + if (!deviceMappings.TryGetValue(DeviceInfo.PhysicalLayout, out mapping)) + throw new RGBDeviceException($"Failed to find a CoolerMasterKeyboardLedMapping for device index {DeviceInfo.DeviceIndex} with physical layout {DeviceInfo.PhysicalLayout}"); + foreach (KeyValuePair led in mapping) InitializeLed(led.Key, new Rectangle(led.Value.column * 19, led.Value.row * 19, 19, 19)); From a7dcf3d867eec15600decdf617bc1de95a80f051 Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Mon, 20 Apr 2020 19:26:26 +0200 Subject: [PATCH 2/2] Inlined variables --- .../Keyboard/CoolerMasterKeyboardRGBDevice.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDevice.cs b/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDevice.cs index 9b9ed0b..8a8c17a 100644 --- a/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDevice.cs +++ b/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDevice.cs @@ -27,12 +27,9 @@ namespace RGB.NET.Devices.CoolerMaster /// protected override void InitializeLayout() { - Dictionary> deviceMappings; - Dictionary mapping; - - if (!CoolerMasterKeyboardLedMappings.Mapping.TryGetValue(DeviceInfo.DeviceIndex, out deviceMappings)) + if (!CoolerMasterKeyboardLedMappings.Mapping.TryGetValue(DeviceInfo.DeviceIndex, out Dictionary> deviceMappings)) throw new RGBDeviceException($"Failed to find a CoolerMasterKeyboardLedMapping for device index {DeviceInfo.DeviceIndex}"); - if (!deviceMappings.TryGetValue(DeviceInfo.PhysicalLayout, out mapping)) + if (!deviceMappings.TryGetValue(DeviceInfo.PhysicalLayout, out Dictionary mapping)) throw new RGBDeviceException($"Failed to find a CoolerMasterKeyboardLedMapping for device index {DeviceInfo.DeviceIndex} with physical layout {DeviceInfo.PhysicalLayout}"); foreach (KeyValuePair led in mapping)