From 43b97bca75a0fd3058a4d2e04630b02cca0cc7f0 Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Wed, 30 Jul 2025 19:50:53 -0500 Subject: [PATCH] Rework Debug controller and add manual settings entry for it, also remove graying out the settings save button as sometimes it prevents saving changes --- .../DebugController/DebugControllerDetect.cpp | 737 +----------------- .../DebugController/RGBController_Debug.cpp | 574 +++++++++++++- .../DebugController/RGBController_Debug.h | 27 +- .../DebugSettingsEntry/DebugSettingsEntry.cpp | 145 ++++ .../DebugSettingsEntry/DebugSettingsEntry.h | 37 + .../DebugSettingsEntry/DebugSettingsEntry.ui | 114 +++ .../ManualDevicesSettingsPage.cpp | 1 - 7 files changed, 919 insertions(+), 716 deletions(-) create mode 100644 qt/ManualDevicesSettingsPage/DebugSettingsEntry/DebugSettingsEntry.cpp create mode 100644 qt/ManualDevicesSettingsPage/DebugSettingsEntry/DebugSettingsEntry.h create mode 100644 qt/ManualDevicesSettingsPage/DebugSettingsEntry/DebugSettingsEntry.ui diff --git a/Controllers/DebugController/DebugControllerDetect.cpp b/Controllers/DebugController/DebugControllerDetect.cpp index b11e17d5..1007ef5a 100644 --- a/Controllers/DebugController/DebugControllerDetect.cpp +++ b/Controllers/DebugController/DebugControllerDetect.cpp @@ -3,37 +3,22 @@ | | | Detector for debug devices | | | +| Adam Honse 31 Jul 2025 | +| | | This file is part of the OpenRGB project | | SPDX-License-Identifier: GPL-2.0-only | \*---------------------------------------------------------*/ -#include -#include -#include -#include -#include -#include #include "Detector.h" #include "RGBController.h" #include "RGBController_Debug.h" -#include "RGBController_Dummy.h" -#include "RGBControllerKeyNames.h" // Unused? -#include "KeyboardLayoutManager.h" #include "SettingsManager.h" -//0xFFFFFFFF indicates an unused entry in matrix -#define NA 0xFFFFFFFF - -static unsigned int dummy_keyboard_underglow_map[3][10] = - { { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, - { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }, - { 20, 21, 22, 23, 24, 25, 26, 27, 28, 29 } }; - /******************************************************************************************\ * * * DetectDebugControllers * * * -* Add dummy controllers based on the DebugDevices key in the settings json * +* Add debug controllers based on the DebugDevices key in the settings json * * * \******************************************************************************************/ @@ -41,714 +26,50 @@ void DetectDebugControllers() { json debug_settings; - /*-------------------------------------------------*\ - | Get Debug Device settings from settings manager | - \*-------------------------------------------------*/ + /*-----------------------------------------------------*\ + | Get Debug Device settings from settings manager | + \*-----------------------------------------------------*/ debug_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("DebugDevices"); - /*-------------------------------------------------*\ - | If the Debug settings contains devices, process | - \*-------------------------------------------------*/ + /*-----------------------------------------------------*\ + | If the Debug settings contains devices, process | + \*-----------------------------------------------------*/ if(debug_settings.contains("devices")) { for(unsigned int device_idx = 0; device_idx < debug_settings["devices"].size(); device_idx++) { - std::string type = ""; - - if(debug_settings["devices"][device_idx].contains("type")) - { - type = debug_settings["devices"][device_idx]["type"]; - } - - if(type == "motherboard") - { - /*---------------------------------------------------------*\ - | Create a dummy motherboard | - \*---------------------------------------------------------*/ - RGBController_Dummy* dummy_motherboard = new RGBController_Dummy(); - - dummy_motherboard->name = "Debug Motherboard"; - dummy_motherboard->type = DEVICE_TYPE_MOTHERBOARD; - dummy_motherboard->description = "Debug Motherboard Device"; - dummy_motherboard->location = "Debug Motherboard Location"; - dummy_motherboard->version = "Debug Motherboard Version"; - dummy_motherboard->serial = "Debug Motherboard Serial"; - - /*---------------------------------------------------------*\ - | Create a direct mode for the dummy motherboard | - \*---------------------------------------------------------*/ - mode dummy_motherboard_direct_mode; - - dummy_motherboard_direct_mode.name = "Direct"; - dummy_motherboard_direct_mode.value = 0; - dummy_motherboard_direct_mode.flags = MODE_FLAG_HAS_PER_LED_COLOR; - dummy_motherboard_direct_mode.color_mode = MODE_COLORS_PER_LED; - - dummy_motherboard->modes.push_back(dummy_motherboard_direct_mode); - - /*---------------------------------------------------------*\ - | Create a single zone/LED for the dummy motherboard | - \*---------------------------------------------------------*/ - zone dummy_motherboard_single_zone; - - dummy_motherboard_single_zone.name = "Single Zone"; - dummy_motherboard_single_zone.type = ZONE_TYPE_SINGLE; - dummy_motherboard_single_zone.leds_min = 1; - dummy_motherboard_single_zone.leds_max = 1; - dummy_motherboard_single_zone.leds_count = 1; - dummy_motherboard_single_zone.matrix_map = NULL; - - dummy_motherboard->zones.push_back(dummy_motherboard_single_zone); - - led dummy_motherboard_single_led; - - dummy_motherboard_single_led.name = "Single LED"; - - dummy_motherboard->leds.push_back(dummy_motherboard_single_led); - - /*---------------------------------------------------------*\ - | Create a linear zone for the dummy motherboard | - \*---------------------------------------------------------*/ - zone dummy_motherboard_linear_zone; - - dummy_motherboard_linear_zone.name = "Linear Zone"; - dummy_motherboard_linear_zone.type = ZONE_TYPE_LINEAR; - dummy_motherboard_linear_zone.leds_min = 10; - dummy_motherboard_linear_zone.leds_max = 10; - dummy_motherboard_linear_zone.leds_count = 10; - dummy_motherboard_linear_zone.matrix_map = NULL; - - dummy_motherboard->zones.push_back(dummy_motherboard_linear_zone); - - for(std::size_t led_idx = 0; led_idx < 10; led_idx++) - { - led dummy_motherboard_linear_led; - - dummy_motherboard_linear_led.name = "Linear LED " + std::to_string(led_idx); - - dummy_motherboard->leds.push_back(dummy_motherboard_linear_led); - } - - dummy_motherboard->SetupColors(); - - /*---------------------------------------------------------*\ - | Push the dummy motherboard onto the controller list | - \*---------------------------------------------------------*/ - ResourceManager::get()->RegisterRGBController(dummy_motherboard); - } - else if(type == "dram") - { - /*---------------------------------------------------------*\ - | Create a dummy DRAM | - \*---------------------------------------------------------*/ - RGBController_Dummy* dummy_dram = new RGBController_Dummy(); - - dummy_dram->name = "Debug DRAM"; - dummy_dram->type = DEVICE_TYPE_DRAM; - dummy_dram->description = "Debug DRAM Device"; - dummy_dram->location = "Debug DRAM Location"; - dummy_dram->version = "Debug DRAM Version"; - dummy_dram->serial = "Debug DRAM Serial"; - - /*---------------------------------------------------------*\ - | Create a direct mode for the dummy DRAM | - \*---------------------------------------------------------*/ - mode dummy_dram_direct_mode; - - dummy_dram_direct_mode.name = "Direct"; - dummy_dram_direct_mode.value = 0; - dummy_dram_direct_mode.flags = MODE_FLAG_HAS_PER_LED_COLOR; - dummy_dram_direct_mode.color_mode = MODE_COLORS_PER_LED; - - dummy_dram->modes.push_back(dummy_dram_direct_mode); - - /*---------------------------------------------------------*\ - | Create a single zone/LED for the dummy DRAM | - \*---------------------------------------------------------*/ - zone dummy_dram_single_zone; - - dummy_dram_single_zone.name = "Single Zone"; - dummy_dram_single_zone.type = ZONE_TYPE_SINGLE; - dummy_dram_single_zone.leds_min = 1; - dummy_dram_single_zone.leds_max = 1; - dummy_dram_single_zone.leds_count = 1; - dummy_dram_single_zone.matrix_map = NULL; - - dummy_dram->zones.push_back(dummy_dram_single_zone); - - led dummy_dram_single_led; - - dummy_dram_single_led.name = "Single LED"; - - dummy_dram->leds.push_back(dummy_dram_single_led); - - /*---------------------------------------------------------*\ - | Create a linear zone for the dummy DRAM | - \*---------------------------------------------------------*/ - zone dummy_dram_linear_zone; - - dummy_dram_linear_zone.name = "Linear Zone"; - dummy_dram_linear_zone.type = ZONE_TYPE_LINEAR; - dummy_dram_linear_zone.leds_min = 5; - dummy_dram_linear_zone.leds_max = 5; - dummy_dram_linear_zone.leds_count = 5; - dummy_dram_linear_zone.matrix_map = NULL; - - dummy_dram->zones.push_back(dummy_dram_linear_zone); - - for(std::size_t led_idx = 0; led_idx < 5; led_idx++) - { - led dummy_dram_linear_led; - - dummy_dram_linear_led.name = "Linear LED " + std::to_string(led_idx); - - dummy_dram->leds.push_back(dummy_dram_linear_led); - } - - dummy_dram->SetupColors(); - - /*---------------------------------------------------------*\ - | Push the dummy DRAM onto the controller list | - \*---------------------------------------------------------*/ - ResourceManager::get()->RegisterRGBController(dummy_dram); - } - else if(type == "gpu") - { - /*---------------------------------------------------------*\ - | Create a dummy GPU | - \*---------------------------------------------------------*/ - RGBController_Dummy* dummy_gpu = new RGBController_Dummy(); - - dummy_gpu->name = "Debug GPU"; - dummy_gpu->type = DEVICE_TYPE_GPU; - dummy_gpu->description = "Debug GPU Device"; - dummy_gpu->location = "Debug GPU Location"; - dummy_gpu->version = "Debug GPU Version"; - dummy_gpu->serial = "Debug GPU Serial"; - - /*---------------------------------------------------------*\ - | Create a direct mode for the dummy GPU | - \*---------------------------------------------------------*/ - mode dummy_gpu_direct_mode; - - dummy_gpu_direct_mode.name = "Direct"; - dummy_gpu_direct_mode.value = 0; - dummy_gpu_direct_mode.flags = MODE_FLAG_HAS_PER_LED_COLOR; - dummy_gpu_direct_mode.color_mode = MODE_COLORS_PER_LED; - - dummy_gpu->modes.push_back(dummy_gpu_direct_mode); - - /*---------------------------------------------------------*\ - | Create a single zone/LED for the dummy GPU | - \*---------------------------------------------------------*/ - zone dummy_gpu_single_zone; - - dummy_gpu_single_zone.name = "Single Zone"; - dummy_gpu_single_zone.type = ZONE_TYPE_SINGLE; - dummy_gpu_single_zone.leds_min = 1; - dummy_gpu_single_zone.leds_max = 1; - dummy_gpu_single_zone.leds_count = 1; - dummy_gpu_single_zone.matrix_map = NULL; - - dummy_gpu->zones.push_back(dummy_gpu_single_zone); - - led dummy_gpu_single_led; - - dummy_gpu_single_led.name = "Single LED"; - - dummy_gpu->leds.push_back(dummy_gpu_single_led); - - /*---------------------------------------------------------*\ - | Create a linear zone for the dummy GPU | - \*---------------------------------------------------------*/ - zone dummy_gpu_linear_zone; - - dummy_gpu_linear_zone.name = "Linear Zone"; - dummy_gpu_linear_zone.type = ZONE_TYPE_LINEAR; - dummy_gpu_linear_zone.leds_min = 15; - dummy_gpu_linear_zone.leds_max = 15; - dummy_gpu_linear_zone.leds_count = 15; - dummy_gpu_linear_zone.matrix_map = NULL; - - dummy_gpu->zones.push_back(dummy_gpu_linear_zone); - - for(std::size_t led_idx = 0; led_idx < 15; led_idx++) - { - led dummy_gpu_linear_led; - - dummy_gpu_linear_led.name = "Linear LED " + std::to_string(led_idx); - - dummy_gpu->leds.push_back(dummy_gpu_linear_led); - } - - dummy_gpu->SetupColors(); - - /*---------------------------------------------------------*\ - | Push the dummy GPU onto the controller list | - \*---------------------------------------------------------*/ - ResourceManager::get()->RegisterRGBController(dummy_gpu); - } - else if(type == "keyboard") - { - json json_kbd = debug_settings["devices"][device_idx]; - KEYBOARD_LAYOUT layout = KEYBOARD_LAYOUT::KEYBOARD_LAYOUT_ANSI_QWERTY; - KEYBOARD_SIZE size = KEYBOARD_SIZE::KEYBOARD_SIZE_FULL; - - if(json_kbd.contains("layout")) - { - layout = json_kbd["layout"]; - } - - if(json_kbd.contains("size")) - { - size = json_kbd["size"]; - } - - /*---------------------------------------------------------*\ - | Create a dummy Keyboard | - \*---------------------------------------------------------*/ - RGBController_Dummy* dummy_keyboard = new RGBController_Dummy(); - KeyboardLayoutManager new_kb(layout, size); - - /*---------------------------------------------------------*\ - | Check for custom key inserts and swaps | - \*---------------------------------------------------------*/ - std::vector change; - const char* change_keys = "change_keys"; - - const char* ins_row = "ins_row"; - const char* rmv_key = "rmv_key"; - const char* rmv_row = "rmv_row"; - const char* swp_key = "swp_key"; - - const char* dbg_zone = "Zone"; - const char* dbg_row = "Row"; - const char* dbg_col = "Col"; - const char* dbg_val = "Val"; - const char* dbg_name = "Name"; - const char* dbg_opcode = "Opcode"; - - if(json_kbd.contains(change_keys)) - { - for(size_t i = 0; i < json_kbd[change_keys].size(); i++) - { - keyboard_led* key = new keyboard_led; - - key->zone = json_kbd[change_keys][i][dbg_zone]; - key->row = json_kbd[change_keys][i][dbg_row]; - key->col = json_kbd[change_keys][i][dbg_col]; - key->value = json_kbd[change_keys][i][dbg_val]; - key->name = json_kbd[change_keys][i][dbg_name].get_ref().c_str(); - - if(json_kbd[change_keys][i][dbg_opcode] == ins_row) - { - key->opcode = KEYBOARD_OPCODE_INSERT_ROW; - } - else if(json_kbd[change_keys][i][dbg_opcode] == rmv_key) - { - key->opcode = KEYBOARD_OPCODE_REMOVE_SHIFT_LEFT; - } - else if(json_kbd[change_keys][i][dbg_opcode] == rmv_row) - { - key->opcode = KEYBOARD_OPCODE_REMOVE_ROW; - } - else if(json_kbd[change_keys][i][dbg_opcode] == swp_key) - { - key->opcode = KEYBOARD_OPCODE_SWAP_ONLY; - } - else - { - key->opcode = KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT; - } - - change.push_back(*key); - } - } - - new_kb.ChangeKeys(change); - - dummy_keyboard->name = new_kb.GetName(); - dummy_keyboard->type = DEVICE_TYPE_KEYBOARD; - dummy_keyboard->description = dummy_keyboard->name; - dummy_keyboard->description.append(" Debug Keyboard"); - dummy_keyboard->location = "Debug Keyboard Location"; - dummy_keyboard->version = "Debug Keyboard Version"; - dummy_keyboard->serial = "Debug Keyboard Serial"; - - /*---------------------------------------------------------*\ - | Create a direct mode for the dummy keyboard | - \*---------------------------------------------------------*/ - mode dummy_keyboard_direct_mode; - - dummy_keyboard_direct_mode.name = "Direct"; - dummy_keyboard_direct_mode.value = 0; - dummy_keyboard_direct_mode.flags = MODE_FLAG_HAS_PER_LED_COLOR; - dummy_keyboard_direct_mode.color_mode = MODE_COLORS_PER_LED; - - dummy_keyboard->modes.push_back(dummy_keyboard_direct_mode); - - /*---------------------------------------------------------*\ - | Create a matrix zone for the debug Keyboard | - \*---------------------------------------------------------*/ - zone dummy_keyboard_matrix_zone; - - dummy_keyboard_matrix_zone.name = "Keyboard Matrix Zone"; - dummy_keyboard_matrix_zone.type = ZONE_TYPE_MATRIX; - dummy_keyboard_matrix_zone.leds_min = new_kb.GetKeyCount(); - dummy_keyboard_matrix_zone.leds_max = new_kb.GetKeyCount(); - dummy_keyboard_matrix_zone.leds_count = new_kb.GetKeyCount(); - dummy_keyboard_matrix_zone.matrix_map = new matrix_map_type; - dummy_keyboard_matrix_zone.matrix_map->height = new_kb.GetRowCount(); - dummy_keyboard_matrix_zone.matrix_map->width = new_kb.GetColumnCount(); - dummy_keyboard_matrix_zone.matrix_map->map = new unsigned int[dummy_keyboard_matrix_zone.matrix_map->height - * dummy_keyboard_matrix_zone.matrix_map->width]; - new_kb.GetKeyMap(dummy_keyboard_matrix_zone.matrix_map->map, KEYBOARD_MAP_FILL_TYPE_COUNT); - - dummy_keyboard->zones.push_back(dummy_keyboard_matrix_zone); - - for(unsigned int led_idx = 0; led_idx < dummy_keyboard_matrix_zone.leds_count; led_idx++) - { - led dummy_keyboard_led; - dummy_keyboard_led.name = new_kb.GetKeyNameAt(led_idx); - dummy_keyboard->leds.push_back(dummy_keyboard_led); - dummy_keyboard->led_alt_names.push_back(new_kb.GetKeyAltNameAt(led_idx)); - } - - /*-----------------------------------------------------------------*\ - | Add another matrix zone so that is can resemble a huntsman elite | - \*-----------------------------------------------------------------*/ - bool underglow = true; - if(json_kbd.contains("underglow")) - { - underglow = json_kbd["underglow"]; - } - - if(underglow) - { - zone dummy_keyboard_underglow_matrix_zone; - - dummy_keyboard_underglow_matrix_zone.name = "Underglow"; - dummy_keyboard_underglow_matrix_zone.type = ZONE_TYPE_MATRIX; - dummy_keyboard_underglow_matrix_zone.leds_min = 30; - dummy_keyboard_underglow_matrix_zone.leds_max = 30; - dummy_keyboard_underglow_matrix_zone.leds_count = 30; - dummy_keyboard_underglow_matrix_zone.matrix_map = new matrix_map_type; - dummy_keyboard_underglow_matrix_zone.matrix_map->height = 3; - dummy_keyboard_underglow_matrix_zone.matrix_map->width = 10; - dummy_keyboard_underglow_matrix_zone.matrix_map->map = (unsigned int*)&dummy_keyboard_underglow_map; - - dummy_keyboard->zones.push_back(dummy_keyboard_underglow_matrix_zone); - - for(std::size_t led_idx = 0; led_idx < dummy_keyboard_underglow_matrix_zone.leds_count; led_idx++) - { - led dummy_keyboard_led; - dummy_keyboard_led.name = dummy_keyboard_underglow_matrix_zone.name + " LED "; - dummy_keyboard_led.name.append(std::to_string(led_idx)); - dummy_keyboard->leds.push_back(dummy_keyboard_led); - dummy_keyboard->led_alt_names.push_back(""); - } - } - - /*---------------------------------------------------------*\ - | Create a linear zone for the dummy Keyboard | - \*---------------------------------------------------------*/ - bool linear = true; - if(json_kbd.contains("linear")) - { - linear = json_kbd["linear"]; - } - - if(linear) - { - zone dummy_keyboard_linear_zone; - - dummy_keyboard_linear_zone.name = "Linear Zone"; - dummy_keyboard_linear_zone.type = ZONE_TYPE_LINEAR; - dummy_keyboard_linear_zone.leds_min = 18; - dummy_keyboard_linear_zone.leds_max = 18; - dummy_keyboard_linear_zone.leds_count = 18; - dummy_keyboard_linear_zone.matrix_map = NULL; - - dummy_keyboard->zones.push_back(dummy_keyboard_linear_zone); - - for(std::size_t led_idx = 0; led_idx < dummy_keyboard_linear_zone.leds_count; led_idx++) - { - led dummy_keyboard_led; - dummy_keyboard_led.name = "RGB Strip "; - dummy_keyboard_led.name.append(std::to_string(led_idx)); - dummy_keyboard->leds.push_back(dummy_keyboard_led); - dummy_keyboard->led_alt_names.push_back(""); - } - } - - dummy_keyboard->SetupColors(); - - /*---------------------------------------------------------*\ - | Push the dummy Keyboard onto the controller list | - \*---------------------------------------------------------*/ - ResourceManager::get()->RegisterRGBController(dummy_keyboard); - } - else if(type == "argb") - { - /*---------------------------------------------------------*\ - | Create a dummy ARGB | - \*---------------------------------------------------------*/ - RGBController_Debug* dummy_argb = new RGBController_Debug(); - - dummy_argb->name = "Debug ARGB"; - dummy_argb->type = DEVICE_TYPE_LEDSTRIP; - dummy_argb->description = "Debug ARGB Device"; - dummy_argb->location = "Debug ARGB Location"; - dummy_argb->version = "Debug ARGB Version"; - dummy_argb->serial = "Debug ARGB Serial"; - - /*---------------------------------------------------------*\ - | Create a direct mode for the dummy ARGB | - \*---------------------------------------------------------*/ - mode dummy_argb_direct_mode; - - dummy_argb_direct_mode.name = "Direct"; - dummy_argb_direct_mode.value = 0; - dummy_argb_direct_mode.flags = MODE_FLAG_HAS_PER_LED_COLOR; - dummy_argb_direct_mode.color_mode = MODE_COLORS_PER_LED; - - dummy_argb->modes.push_back(dummy_argb_direct_mode); - - /*---------------------------------------------------------*\ - | Create a linear zone for the dummy ARGB | - \*---------------------------------------------------------*/ - zone dummy_argb_linear_zone; - - dummy_argb_linear_zone.name = "Resizable zone"; - dummy_argb_linear_zone.type = ZONE_TYPE_LINEAR; - dummy_argb_linear_zone.leds_min = 1; - dummy_argb_linear_zone.leds_max = 100; - dummy_argb_linear_zone.leds_count = 0; - dummy_argb_linear_zone.matrix_map = NULL; - - dummy_argb->zones.push_back(dummy_argb_linear_zone); - - dummy_argb->SetupColors(); - dummy_argb->ResizeZone(0, 60); - - /*---------------------------------------------------------*\ - | Push the dummy ARGB onto the controller list | - \*---------------------------------------------------------*/ - ResourceManager::get()->RegisterRGBController(dummy_argb); - } + RGBController_Debug * debug_controller = new RGBController_Debug(false, debug_settings["devices"][device_idx]); + ResourceManager::get()->RegisterRGBController(debug_controller); } } if (debug_settings.contains("CustomDevices")) { - for (int CustomDevice = 0; CustomDevice < (int)debug_settings["CustomDevices"].size(); CustomDevice++) + for(unsigned int device_idx = 0; device_idx < debug_settings["CustomDevices"].size(); device_idx++) { - json CustomDev = debug_settings["CustomDevices"][CustomDevice]; - /*---------------------------*\ - | Create a custom controller | - \*---------------------------*/ - RGBController_Debug* dummy_custom = new RGBController_Debug(); + json custom_device_settings = debug_settings["CustomDevices"][device_idx]; - /*----------------------------------------------------------------------*\ - | if ANY of the attributes are missing then go ahead and skip the entry | - \*----------------------------------------------------------------------*/ - if ( - !CustomDev.contains("DeviceName") || - !CustomDev.contains("DeviceType") || - !CustomDev.contains("DeviceDescription") || - !CustomDev.contains("DeviceLocation") || - !CustomDev.contains("DeviceVersion") || - !CustomDev.contains("DeviceSerial") || - !CustomDev.contains("DeviceZones") - ) + /*---------------------------------------------*\ + | If ANY of the attributes are missing then go | + | ahead and skip the entry | + \*---------------------------------------------*/ + if( + !custom_device_settings.contains("DeviceName") || + !custom_device_settings.contains("DeviceType") || + !custom_device_settings.contains("DeviceDescription") || + !custom_device_settings.contains("DeviceLocation") || + !custom_device_settings.contains("DeviceVersion") || + !custom_device_settings.contains("DeviceSerial") || + !custom_device_settings.contains("DeviceZones") + ) { continue; } - - - /*-------------*\ - | Set the name | - \*-------------*/ - dummy_custom->name = CustomDev["DeviceName"]; - - /*---------------------*\ - | Find the device type | - \*---------------------*/ - if (CustomDev["DeviceType"] == "motherboard") dummy_custom->type = DEVICE_TYPE_MOTHERBOARD; - else if (CustomDev["DeviceType"] == "dram") dummy_custom->type = DEVICE_TYPE_DRAM; - else if (CustomDev["DeviceType"] == "gpu") dummy_custom->type = DEVICE_TYPE_GPU; - else if (CustomDev["DeviceType"] == "cooler") dummy_custom->type = DEVICE_TYPE_COOLER; - else if (CustomDev["DeviceType"] == "led_strip") dummy_custom->type = DEVICE_TYPE_LEDSTRIP; - else if (CustomDev["DeviceType"] == "keyboard") dummy_custom->type = DEVICE_TYPE_KEYBOARD; - else if (CustomDev["DeviceType"] == "mouse") dummy_custom->type = DEVICE_TYPE_MOUSE; - else if (CustomDev["DeviceType"] == "mousemat") dummy_custom->type = DEVICE_TYPE_MOUSEMAT; - else if (CustomDev["DeviceType"] == "headset") dummy_custom->type = DEVICE_TYPE_HEADSET; - else if (CustomDev["DeviceType"] == "headset_stand") dummy_custom->type = DEVICE_TYPE_HEADSET_STAND; - else if (CustomDev["DeviceType"] == "gamepad") dummy_custom->type = DEVICE_TYPE_GAMEPAD; - else if (CustomDev["DeviceType"] == "light") dummy_custom->type = DEVICE_TYPE_LIGHT; - else if (CustomDev["DeviceType"] == "speaker") dummy_custom->type = DEVICE_TYPE_SPEAKER; - else if (CustomDev["DeviceType"] == "unknown") dummy_custom->type = DEVICE_TYPE_UNKNOWN; - - /*-----------------------------------------------*\ - | Set description, location, version, and serial | - \*-----------------------------------------------*/ - dummy_custom->description = CustomDev["DeviceDescription"]; - dummy_custom->location = CustomDev["DeviceLocation"]; - dummy_custom->version = CustomDev["DeviceVersion"]; - dummy_custom->serial = CustomDev["DeviceSerial"]; - - /*----------------*\ - | Create the mode | - \*----------------*/ - mode dummy_custom_direct; - dummy_custom_direct.name = "Direct"; - dummy_custom_direct.value = 0; - dummy_custom_direct.flags = MODE_FLAG_HAS_PER_LED_COLOR; - dummy_custom_direct.color_mode = MODE_COLORS_PER_LED; - dummy_custom->modes.push_back(dummy_custom_direct); - - /*--------------*\ - | Fill in zones | - \*--------------*/ - for (int ZoneID = 0; ZoneID < (int)CustomDev["DeviceZones"].size(); ZoneID++) + else { - json ZoneJson = CustomDev["DeviceZones"][ZoneID]; - if - ( - !ZoneJson.contains("name") || - !ZoneJson.contains("type") || - !ZoneJson.contains("leds_min") || - !ZoneJson.contains("leds_max") || - !ZoneJson.contains("leds_count") - ) - { - continue; - } - zone custom_zone; - - custom_zone.name = ZoneJson["name"]; - - if (ZoneJson["type"] == "linear") custom_zone.type = ZONE_TYPE_LINEAR; - else if (ZoneJson["type"] == "matrix") custom_zone.type = ZONE_TYPE_MATRIX; - else if (ZoneJson["type"] == "single") custom_zone.type = ZONE_TYPE_SINGLE; - else - { - continue; - } - - custom_zone.leds_min = ZoneJson["leds_min"]; - custom_zone.leds_max = ZoneJson["leds_max"]; - custom_zone.leds_count = ZoneJson["leds_count"]; - - /*-----------------------*\ - | Fill in the matrix map | - \*-----------------------*/ - bool BadVal = false; - if (custom_zone.type == ZONE_TYPE_MATRIX) - { - if - ( - !ZoneJson.contains("matrix_height") || - !ZoneJson.contains("matrix_width") || - !ZoneJson.contains("matrix_map") - ) - { - /*--------------------------------------------------------------*\ - | If there is no map then the zone can't be valid. Don't add it | - \*--------------------------------------------------------------*/ - continue; - } - - custom_zone.matrix_map = new matrix_map_type; - - custom_zone.matrix_map->width = ZoneJson["matrix_width"]; - custom_zone.matrix_map->height = ZoneJson["matrix_height"]; - - int H = custom_zone.matrix_map->height; - int W = custom_zone.matrix_map->width; - - BadVal = (ZoneJson["matrix_map"].size() != custom_zone.matrix_map->height); - - unsigned int* MatrixARR = new unsigned int[H * W]; - for (int MatrixMapRow = 0; MatrixMapRow < H; MatrixMapRow++) - { - /*-----------------------------------------------------------------------------------------------------*\ - | If something went wrong then make no attempt to recover and just move on in a way that doesn't crash | - | Even 1 bad row can corrupt the map so skip the zone entirely | - \*-----------------------------------------------------------------------------------------------------*/ - if ((custom_zone.matrix_map->width != ZoneJson["matrix_map"][MatrixMapRow].size()) || BadVal) - { - BadVal = true; - break; - } - - for (int MatrixMapCol = 0; MatrixMapCol < W; MatrixMapCol++) - { - int Val = ZoneJson["matrix_map"][MatrixMapRow][MatrixMapCol]; - - if ((signed)Val == -1) - { - MatrixARR[MatrixMapRow * W + MatrixMapCol] = NA; - } - else - { - MatrixARR[MatrixMapRow * W + MatrixMapCol] = (unsigned)Val; - } - } - } - - custom_zone.matrix_map->map = MatrixARR; - } - - /*------------------------------------*\ - | Don't add the zone if it is invalid | - \*------------------------------------*/ - if (BadVal) - { - continue; - } - - bool UseCustomLabels = false; - if (ZoneJson.contains("custom_labels")) - { - /*-------------------------------------------------------*\ - | If the count is correct and the zone is non-resizeable | - \*-------------------------------------------------------*/ - if ((ZoneJson["custom_labels"].size() == custom_zone.leds_count) && (custom_zone.leds_min == custom_zone.leds_max)) - { - UseCustomLabels = true; - } - } - - /*------------------*\ - | Set the LED names | - \*------------------*/ - for (int LED_ID = 0; LED_ID < (int)custom_zone.leds_count; LED_ID++) - { - led custom_led; - if (UseCustomLabels) - { - /*----------------------------------------*\ - | Set the label to the user defined label | - \*----------------------------------------*/ - custom_led.name = ZoneJson["custom_labels"][LED_ID]; - } - else - { - /*------------------------------------------------*\ - | Set default labels because something went wrong | - \*------------------------------------------------*/ - custom_led.name = ("Custom LED. Zone " + std::to_string(ZoneID) + ", LED " + std::to_string(LED_ID)); - } - dummy_custom->leds.push_back(custom_led); - } - - dummy_custom->zones.push_back(custom_zone); + RGBController_Debug * debug_controller = new RGBController_Debug(true, custom_device_settings); + ResourceManager::get()->RegisterRGBController(debug_controller); } - - dummy_custom->SetupColors(); - - ResourceManager::get()->RegisterRGBController(dummy_custom); } } diff --git a/Controllers/DebugController/RGBController_Debug.cpp b/Controllers/DebugController/RGBController_Debug.cpp index 0eaffb41..42cfe107 100644 --- a/Controllers/DebugController/RGBController_Debug.cpp +++ b/Controllers/DebugController/RGBController_Debug.cpp @@ -1,7 +1,10 @@ /*---------------------------------------------------------*\ | RGBController_Debug.cpp | | | -| RGBController for debug devices | +| Debug RGBController that can mimic various devices for | +| development and test purposes | +| | +| Adam Honse (CalcProgrammer1) 31 Jul 2025 | | | | This file is part of the OpenRGB project | | SPDX-License-Identifier: GPL-2.0-only | @@ -9,6 +12,7 @@ #include #include +#include "KeyboardLayoutManager.h" #include "RGBController_Debug.h" /**------------------------------------------------------------------*\ @@ -22,7 +26,548 @@ @comment \*-------------------------------------------------------------------*/ -RGBController_Debug::RGBController_Debug() +//0xFFFFFFFF indicates an unused entry in matrix +#define NA 0xFFFFFFFF + +#define NUM_LAYOUTS 6 + +static const std::string layout_names[] = +{ + "Default", + "ANSI QWERTY", + "ISO QWERTY", + "ISO QWERTZ", + "ISO AZERTY", + "JIS" +}; + +static unsigned int debug_keyboard_underglow_map[3][10] = + { { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, + { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }, + { 20, 21, 22, 23, 24, 25, 26, 27, 28, 29 } }; + +RGBController_Debug::RGBController_Debug(bool custom_controller, json debug_settings) +{ + if(custom_controller) + { + /*-------------------------------------------------*\ + | Set the name | + \*-------------------------------------------------*/ + name = debug_settings["DeviceName"]; + + /*-------------------------------------------------*\ + | Find the device type | + \*-------------------------------------------------*/ + if (debug_settings["DeviceType"] == "motherboard") type = DEVICE_TYPE_MOTHERBOARD; + else if (debug_settings["DeviceType"] == "dram") type = DEVICE_TYPE_DRAM; + else if (debug_settings["DeviceType"] == "gpu") type = DEVICE_TYPE_GPU; + else if (debug_settings["DeviceType"] == "cooler") type = DEVICE_TYPE_COOLER; + else if (debug_settings["DeviceType"] == "led_strip") type = DEVICE_TYPE_LEDSTRIP; + else if (debug_settings["DeviceType"] == "keyboard") type = DEVICE_TYPE_KEYBOARD; + else if (debug_settings["DeviceType"] == "mouse") type = DEVICE_TYPE_MOUSE; + else if (debug_settings["DeviceType"] == "mousemat") type = DEVICE_TYPE_MOUSEMAT; + else if (debug_settings["DeviceType"] == "headset") type = DEVICE_TYPE_HEADSET; + else if (debug_settings["DeviceType"] == "headset_stand") type = DEVICE_TYPE_HEADSET_STAND; + else if (debug_settings["DeviceType"] == "gamepad") type = DEVICE_TYPE_GAMEPAD; + else if (debug_settings["DeviceType"] == "light") type = DEVICE_TYPE_LIGHT; + else if (debug_settings["DeviceType"] == "speaker") type = DEVICE_TYPE_SPEAKER; + else if (debug_settings["DeviceType"] == "unknown") type = DEVICE_TYPE_UNKNOWN; + + /*-------------------------------------------------*\ + | Set description, location, version, and serial | + \*-------------------------------------------------*/ + description = debug_settings["DeviceDescription"]; + location = debug_settings["DeviceLocation"]; + version = debug_settings["DeviceVersion"]; + serial = debug_settings["DeviceSerial"]; + + /*-------------------------------------------------*\ + | Create the mode | + \*-------------------------------------------------*/ + mode Direct; + + Direct.name = "Direct"; + Direct.value = 0; + Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR; + Direct.color_mode = MODE_COLORS_PER_LED; + + modes.push_back(Direct); + + /*-------------------------------------------------*\ + | Fill in zones | + \*-------------------------------------------------*/ + for(int ZoneID = 0; ZoneID < (int)debug_settings["DeviceZones"].size(); ZoneID++) + { + json ZoneJson = debug_settings["DeviceZones"][ZoneID]; + + if + ( + !ZoneJson.contains("name") || + !ZoneJson.contains("type") || + !ZoneJson.contains("leds_min") || + !ZoneJson.contains("leds_max") || + !ZoneJson.contains("leds_count") + ) + { + continue; + } + zone custom_zone; + + custom_zone.name = ZoneJson["name"]; + + if (ZoneJson["type"] == "linear") custom_zone.type = ZONE_TYPE_LINEAR; + else if (ZoneJson["type"] == "matrix") custom_zone.type = ZONE_TYPE_MATRIX; + else if (ZoneJson["type"] == "single") custom_zone.type = ZONE_TYPE_SINGLE; + else + { + continue; + } + + custom_zone.leds_min = ZoneJson["leds_min"]; + custom_zone.leds_max = ZoneJson["leds_max"]; + custom_zone.leds_count = ZoneJson["leds_count"]; + + /*---------------------------------------------*\ + | Fill in the matrix map | + \*---------------------------------------------*/ + bool BadVal = false; + + if(custom_zone.type == ZONE_TYPE_MATRIX) + { + if + ( + !ZoneJson.contains("matrix_height") || + !ZoneJson.contains("matrix_width") || + !ZoneJson.contains("matrix_map") + ) + { + /*-------------------------------------*\ + | If there is no map then the zone | + | can't be valid. Don't add it | + \*-------------------------------------*/ + continue; + } + + custom_zone.matrix_map = new matrix_map_type; + + custom_zone.matrix_map->width = ZoneJson["matrix_width"]; + custom_zone.matrix_map->height = ZoneJson["matrix_height"]; + + int H = custom_zone.matrix_map->height; + int W = custom_zone.matrix_map->width; + + BadVal = (ZoneJson["matrix_map"].size() != custom_zone.matrix_map->height); + + unsigned int* MatrixARR = new unsigned int[H * W]; + + for(int MatrixMapRow = 0; MatrixMapRow < H; MatrixMapRow++) + { + /*-------------------------------------*\ + | If something went wrong then make no | + | attempt to recover and just move on | + | in a way that doesn't crash. Even 1 | + | bad row can corrupt the map so skip | + | the zone entirely | + \*-------------------------------------*/ + if((custom_zone.matrix_map->width != ZoneJson["matrix_map"][MatrixMapRow].size()) || BadVal) + { + BadVal = true; + break; + } + + for(int MatrixMapCol = 0; MatrixMapCol < W; MatrixMapCol++) + { + int Val = ZoneJson["matrix_map"][MatrixMapRow][MatrixMapCol]; + + if((signed)Val == -1) + { + MatrixARR[MatrixMapRow * W + MatrixMapCol] = NA; + } + else + { + MatrixARR[MatrixMapRow * W + MatrixMapCol] = (unsigned)Val; + } + } + } + + custom_zone.matrix_map->map = MatrixARR; + } + + /*---------------------------------------------*\ + | Don't add the zone if it is invalid | + \*---------------------------------------------*/ + if(BadVal) + { + continue; + } + + bool UseCustomLabels = false; + if(ZoneJson.contains("custom_labels")) + { + /*-----------------------------------------*\ + | If the count is correct and the zone is | + | non-resizeable | + \*-----------------------------------------*/ + if((ZoneJson["custom_labels"].size() == custom_zone.leds_count) && (custom_zone.leds_min == custom_zone.leds_max)) + { + UseCustomLabels = true; + } + } + + /*---------------------------------------------*\ + | Set the LED names | + \*---------------------------------------------*/ + for(int LED_ID = 0; LED_ID < (int)custom_zone.leds_count; LED_ID++) + { + led custom_led; + if(UseCustomLabels) + { + /*-------------------------------------*\ + | Set the label to the user defined | + | label | + \*-------------------------------------*/ + custom_led.name = ZoneJson["custom_labels"][LED_ID]; + } + else + { + /*-------------------------------------*\ + | Set default labels because something | + | went wrong | + \*-------------------------------------*/ + custom_led.name = ("Custom LED. Zone " + std::to_string(ZoneID) + ", LED " + std::to_string(LED_ID)); + } + + leds.push_back(custom_led); + } + + zones.push_back(custom_zone); + } + + SetupColors(); + } + else + { + bool zone_single = true; + bool zone_linear = true; + bool zone_resizable = false; + bool zone_keyboard = false; + bool zone_underglow = false; + std::string name_setting = ""; + std::string type_setting = "keyboard"; + + if(debug_settings.contains("name")) + { + name_setting = debug_settings["name"]; + } + + if(debug_settings.contains("type")) + { + type_setting = debug_settings["type"]; + } + + if(debug_settings.contains("single")) + { + zone_single = debug_settings["single"]; + } + + if(debug_settings.contains("linear")) + { + zone_linear = debug_settings["linear"]; + } + + if(debug_settings.contains("resizable")) + { + zone_resizable = debug_settings["resizable"]; + } + + if(debug_settings.contains("keyboard")) + { + zone_keyboard = debug_settings["keyboard"]; + } + + if(debug_settings.contains("underglow")) + { + zone_underglow = debug_settings["underglow"]; + } + + if(type_setting == "motherboard") + { + name = "Debug Motherboard"; + type = DEVICE_TYPE_MOTHERBOARD; + } + else if(type_setting == "dram") + { + name = "Debug DRAM"; + type = DEVICE_TYPE_DRAM; + } + else if(type_setting == "gpu") + { + name = "Debug GPU"; + type = DEVICE_TYPE_GPU; + } + else if(type_setting == "keyboard") + { + name = "Debug Keyboard"; + type = DEVICE_TYPE_KEYBOARD; + } + else if(type_setting == "mouse") + { + name = "Debug Mouse"; + type = DEVICE_TYPE_MOUSE; + } + else if(type_setting == "argb") + { + name = "Debug ARGB Controller"; + type = DEVICE_TYPE_LEDSTRIP; + } + + /*---------------------------------------------------------*\ + | Fill in debug controller information | + \*---------------------------------------------------------*/ + description = name + " Device"; + vendor = name + " Vendor String"; + location = name + " Location String"; + version = name + " Version String"; + serial = name + " Serial String"; + + if(name_setting != "") + { + name = name_setting; + } + + /*---------------------------------------------------------*\ + | Create a direct mode | + \*---------------------------------------------------------*/ + mode Direct; + + Direct.name = "Direct"; + Direct.value = 0; + Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR; + Direct.color_mode = MODE_COLORS_PER_LED; + + modes.push_back(Direct); + + /*---------------------------------------------------------*\ + | Create a single zone/LED | + \*---------------------------------------------------------*/ + if(zone_single) + { + zone single_zone; + + single_zone.name = "Single Zone"; + single_zone.type = ZONE_TYPE_SINGLE; + single_zone.leds_min = 1; + single_zone.leds_max = 1; + single_zone.leds_count = 1; + single_zone.matrix_map = NULL; + + zones.push_back(single_zone); + + led single_led; + + single_led.name = "Single LED"; + + leds.push_back(single_led); + + led_alt_names.push_back(""); + } + + /*---------------------------------------------------------*\ + | Create a linear zone | + \*---------------------------------------------------------*/ + if(zone_linear) + { + zone linear_zone; + + linear_zone.name = "Linear Zone"; + linear_zone.type = ZONE_TYPE_LINEAR; + linear_zone.leds_min = 10; + linear_zone.leds_max = 10; + linear_zone.leds_count = 10; + linear_zone.matrix_map = NULL; + + zones.push_back(linear_zone); + + for(std::size_t led_idx = 0; led_idx < 10; led_idx++) + { + led linear_led; + + linear_led.name = "Linear LED " + std::to_string(led_idx); + + leds.push_back(linear_led); + + led_alt_names.push_back(""); + } + } + /*---------------------------------------------------------*\ + | Create a keyboard matrix zone | + \*---------------------------------------------------------*/ + if(zone_keyboard) + { + KEYBOARD_LAYOUT layout = KEYBOARD_LAYOUT::KEYBOARD_LAYOUT_ANSI_QWERTY; + KEYBOARD_SIZE size = KEYBOARD_SIZE::KEYBOARD_SIZE_FULL; + + if(debug_settings.contains("layout")) + { + KEYBOARD_LAYOUT temp_layout = debug_settings["layout"]; + + if(temp_layout < NUM_LAYOUTS) + { + layout = temp_layout; + } + } + + if(debug_settings.contains("size")) + { + size = debug_settings["size"]; + } + + KeyboardLayoutManager new_kb(layout, size); + + description += ", Layout: " + layout_names[layout] + ", Size: " + new_kb.GetName(); + + /*-----------------------------------------------------*\ + | Check for custom key inserts and swaps | + \*-----------------------------------------------------*/ + const char* change_keys = "change_keys"; + + if(debug_settings.contains(change_keys)) + { + std::vector change; + + const char* ins_row = "ins_row"; + const char* rmv_key = "rmv_key"; + const char* rmv_row = "rmv_row"; + const char* swp_key = "swp_key"; + + const char* dbg_zone = "Zone"; + const char* dbg_row = "Row"; + const char* dbg_col = "Col"; + const char* dbg_val = "Val"; + const char* dbg_name = "Name"; + const char* dbg_opcode = "Opcode"; + + for(size_t i = 0; i < debug_settings[change_keys].size(); i++) + { + keyboard_led* key = new keyboard_led; + + key->zone = debug_settings[change_keys][i][dbg_zone]; + key->row = debug_settings[change_keys][i][dbg_row]; + key->col = debug_settings[change_keys][i][dbg_col]; + key->value = debug_settings[change_keys][i][dbg_val]; + key->name = debug_settings[change_keys][i][dbg_name].get_ref().c_str(); + + if(debug_settings[change_keys][i][dbg_opcode] == ins_row) + { + key->opcode = KEYBOARD_OPCODE_INSERT_ROW; + } + else if(debug_settings[change_keys][i][dbg_opcode] == rmv_key) + { + key->opcode = KEYBOARD_OPCODE_REMOVE_SHIFT_LEFT; + } + else if(debug_settings[change_keys][i][dbg_opcode] == rmv_row) + { + key->opcode = KEYBOARD_OPCODE_REMOVE_ROW; + } + else if(debug_settings[change_keys][i][dbg_opcode] == swp_key) + { + key->opcode = KEYBOARD_OPCODE_SWAP_ONLY; + } + else + { + key->opcode = KEYBOARD_OPCODE_INSERT_SHIFT_RIGHT; + } + + change.push_back(*key); + } + + new_kb.ChangeKeys(change); + } + + zone keyboard_zone; + + keyboard_zone.name = "Keyboard Zone"; + keyboard_zone.type = ZONE_TYPE_MATRIX; + keyboard_zone.leds_min = new_kb.GetKeyCount(); + keyboard_zone.leds_max = new_kb.GetKeyCount(); + keyboard_zone.leds_count = new_kb.GetKeyCount(); + keyboard_zone.matrix_map = new matrix_map_type; + keyboard_zone.matrix_map->height = new_kb.GetRowCount(); + keyboard_zone.matrix_map->width = new_kb.GetColumnCount(); + keyboard_zone.matrix_map->map = new unsigned int[keyboard_zone.matrix_map->height * keyboard_zone.matrix_map->width]; + + new_kb.GetKeyMap(keyboard_zone.matrix_map->map, KEYBOARD_MAP_FILL_TYPE_COUNT); + + zones.push_back(keyboard_zone); + + for(unsigned int led_idx = 0; led_idx < keyboard_zone.leds_count; led_idx++) + { + led keyboard_led; + + keyboard_led.name = new_kb.GetKeyNameAt(led_idx); + + leds.push_back(keyboard_led); + + led_alt_names.push_back(new_kb.GetKeyAltNameAt(led_idx)); + } + } + /*---------------------------------------------------------*\ + | Create an underglow matrix zone | + \*---------------------------------------------------------*/ + if(zone_underglow) + { + zone underglow_zone; + + underglow_zone.name = "Underglow Zone"; + underglow_zone.type = ZONE_TYPE_MATRIX; + underglow_zone.leds_min = 30; + underglow_zone.leds_max = 30; + underglow_zone.leds_count = 30; + underglow_zone.matrix_map = new matrix_map_type; + underglow_zone.matrix_map->height = 3; + underglow_zone.matrix_map->width = 10; + underglow_zone.matrix_map->map = (unsigned int*)&debug_keyboard_underglow_map; + + zones.push_back(underglow_zone); + + for(std::size_t led_idx = 0; led_idx < underglow_zone.leds_count; led_idx++) + { + led underglow_led; + + underglow_led.name = "Underglow LED " + std::to_string(led_idx);; + + leds.push_back(underglow_led); + + led_alt_names.push_back(""); + } + } + /*---------------------------------------------------------*\ + | Create a resizable linear zone | + \*---------------------------------------------------------*/ + if(zone_resizable) + { + zone resizable_zone; + + resizable_zone.name = "Resizable Zone"; + resizable_zone.type = ZONE_TYPE_LINEAR; + resizable_zone.leds_min = 0; + resizable_zone.leds_max = 100; + resizable_zone.leds_count = 0; + resizable_zone.matrix_map = NULL; + + zones.push_back(resizable_zone); + } + } + + SetupColors(); +} + +RGBController_Debug::~RGBController_Debug() +{ + +} + +void RGBController_Debug::SetupZones() { } @@ -66,3 +611,28 @@ void RGBController_Debug::ResizeZone(int index, int new_size) SetupColors(); } + +void RGBController_Debug::DeviceUpdateLEDs() +{ + +} + +void RGBController_Debug::UpdateZoneLEDs(int /*zone*/) +{ + +} + +void RGBController_Debug::UpdateSingleLED(int /*led*/) +{ + +} + +void RGBController_Debug::SetCustomMode() +{ + +} + +void RGBController_Debug::DeviceUpdateMode() +{ + +} diff --git a/Controllers/DebugController/RGBController_Debug.h b/Controllers/DebugController/RGBController_Debug.h index 459a9133..816b47d6 100644 --- a/Controllers/DebugController/RGBController_Debug.h +++ b/Controllers/DebugController/RGBController_Debug.h @@ -1,7 +1,10 @@ /*---------------------------------------------------------*\ | RGBController_Debug.h | | | -| RGBController for debug devices | +| Debug RGBController that can mimic various devices for | +| development and test purposes | +| | +| Adam Honse (CalcProgrammer1) 31 Jul 2025 | | | | This file is part of the OpenRGB project | | SPDX-License-Identifier: GPL-2.0-only | @@ -9,11 +12,25 @@ #pragma once -#include "RGBController_Dummy.h" +#include +#include "RGBController.h" -class RGBController_Debug : public RGBController_Dummy +using json = nlohmann::json; + +class RGBController_Debug : public RGBController { public: - RGBController_Debug(); - void ResizeZone(int zone, int newSize) override; + RGBController_Debug(bool custom_controller, json debug_settings); + ~RGBController_Debug(); + + void SetupZones(); + + void ResizeZone(int zone, int new_size); + + void DeviceUpdateLEDs(); + void UpdateZoneLEDs(int zone); + void UpdateSingleLED(int led); + + void SetCustomMode(); + void DeviceUpdateMode(); }; diff --git a/qt/ManualDevicesSettingsPage/DebugSettingsEntry/DebugSettingsEntry.cpp b/qt/ManualDevicesSettingsPage/DebugSettingsEntry/DebugSettingsEntry.cpp new file mode 100644 index 00000000..149a6008 --- /dev/null +++ b/qt/ManualDevicesSettingsPage/DebugSettingsEntry/DebugSettingsEntry.cpp @@ -0,0 +1,145 @@ +/*---------------------------------------------------------*\ +| DebugSettingsEntry.cpp | +| | +| User interface for OpenRGB Debug settings entry | +| | +| Adam Honse 30 Jul 2025 | +| | +| This file is part of the OpenRGB project | +| SPDX-License-Identifier: GPL-2.0-only | +\*---------------------------------------------------------*/ + +#include "DebugSettingsEntry.h" +#include "ui_DebugSettingsEntry.h" +#include "ManualDevicesTypeManager.h" +#include "nlohmann/json.hpp" + +using json = nlohmann::json; + +#define NUM_TYPES 6 + +const std::string types[] = +{ + "motherboard", + "dram", + "gpu", + "keyboard", + "mouse", + "argb" +}; + +DebugSettingsEntry::DebugSettingsEntry(QWidget *parent) : + BaseManualDeviceEntry(parent), + ui(new Ui::DebugSettingsEntry) +{ + ui->setupUi(this); + + ui->TypeComboBox->addItem("motherboard"); + ui->TypeComboBox->addItem("dram"); + ui->TypeComboBox->addItem("gpu"); + ui->TypeComboBox->addItem("keyboard"); + ui->TypeComboBox->addItem("mouse"); + ui->TypeComboBox->addItem("argb"); + + ui->LayoutComboBox->addItem("Default"); + ui->LayoutComboBox->addItem("ANSI QWERTY"); + ui->LayoutComboBox->addItem("ISO QWERTY"); + ui->LayoutComboBox->addItem("ISO QWERTZ"); + ui->LayoutComboBox->addItem("ISO AZERTY"); + ui->LayoutComboBox->addItem("JIS"); +} + +DebugSettingsEntry::~DebugSettingsEntry() +{ + delete ui; +} + +void DebugSettingsEntry::changeEvent(QEvent *event) +{ + if(event->type() == QEvent::LanguageChange) + { + ui->retranslateUi(this); + } +} + +void DebugSettingsEntry::loadFromSettings(const json& data) +{ + if(data.contains("name")) + { + ui->NameEdit->setText(QString::fromStdString(data["name"])); + } + + if(data.contains("type")) + { + for(unsigned int type_idx = 0; type_idx < NUM_TYPES; type_idx++) + { + if(data["type"] == types[type_idx]) + { + ui->TypeComboBox->setCurrentIndex(type_idx); + break; + } + } + } + + if(data.contains("layout")) + { + ui->LayoutComboBox->setCurrentIndex(data["layout"]); + } + + if(data.contains("single")) + { + ui->SingleCheckBox->setChecked(data["single"]); + } + + if(data.contains("linear")) + { + ui->LinearCheckBox->setChecked(data["linear"]); + } + + if(data.contains("resizable")) + { + ui->ResizableCheckBox->setChecked(data["resizable"]); + } + + if(data.contains("keyboard")) + { + ui->KeyboardCheckBox->setChecked(data["keyboard"]); + } + + if(data.contains("underglow")) + { + ui->UnderglowCheckBox->setChecked(data["underglow"]); + } +} + +json DebugSettingsEntry::saveSettings() +{ + json result; + + result["name"] = ui->NameEdit->text().toStdString(); + result["type"] = types[ui->TypeComboBox->currentIndex()]; + result["layout"] = ui->LayoutComboBox->currentIndex(); + result["single"] = ui->SingleCheckBox->isChecked(); + result["linear"] = ui->LinearCheckBox->isChecked(); + result["resizable"] = ui->ResizableCheckBox->isChecked(); + result["keyboard"] = ui->KeyboardCheckBox->isChecked(); + result["underglow"] = ui->UnderglowCheckBox->isChecked(); + + return result; +} + +bool DebugSettingsEntry::isDataValid() +{ + return true; +} + +static BaseManualDeviceEntry* SpawnDebugEntry(const json& data) +{ + DebugSettingsEntry* entry = new DebugSettingsEntry; + entry->loadFromSettings(data); + return entry; +} + +static const char* DebugDeviceName = QT_TRANSLATE_NOOP("ManualDevice", "Debug Device"); + +REGISTER_MANUAL_DEVICE_TYPE(DebugDeviceName, "DebugDevices", SpawnDebugEntry); diff --git a/qt/ManualDevicesSettingsPage/DebugSettingsEntry/DebugSettingsEntry.h b/qt/ManualDevicesSettingsPage/DebugSettingsEntry/DebugSettingsEntry.h new file mode 100644 index 00000000..300d88aa --- /dev/null +++ b/qt/ManualDevicesSettingsPage/DebugSettingsEntry/DebugSettingsEntry.h @@ -0,0 +1,37 @@ +/*---------------------------------------------------------*\ +| DebugSettingsEntry.h | +| | +| User interface for OpenRGB Debug settings entry | +| | +| Adam Honse 30 Jul 2025 | +| | +| This file is part of the OpenRGB project | +| SPDX-License-Identifier: GPL-2.0-only | +\*---------------------------------------------------------*/ + +#pragma once + +#include "BaseManualDeviceEntry.h" + +namespace Ui +{ + class DebugSettingsEntry; +} + +class DebugSettingsEntry : public BaseManualDeviceEntry +{ + Q_OBJECT + +public: + explicit DebugSettingsEntry(QWidget *parent = nullptr); + ~DebugSettingsEntry(); + void loadFromSettings(const json& data); + json saveSettings() override; + bool isDataValid() override; + +private: + Ui::DebugSettingsEntry *ui; + +private slots: + void changeEvent(QEvent *event) override; +}; diff --git a/qt/ManualDevicesSettingsPage/DebugSettingsEntry/DebugSettingsEntry.ui b/qt/ManualDevicesSettingsPage/DebugSettingsEntry/DebugSettingsEntry.ui new file mode 100644 index 00000000..471929cd --- /dev/null +++ b/qt/ManualDevicesSettingsPage/DebugSettingsEntry/DebugSettingsEntry.ui @@ -0,0 +1,114 @@ + + + DebugSettingsEntry + + + + 0 + 0 + 400 + 293 + + + + + 0 + 0 + + + + Debug Settings Entry + + + + + + Debug Device + + + + + + Type: + + + + + + + Device Name + + + + + + + + + + Zones + + + + + + Keyboard + + + + + + + Linear + + + + + + + Single + + + + + + + Resizable + + + + + + + Underglow + + + + + + + + + + Name: + + + + + + + Layout: + + + + + + + + + + + + + + diff --git a/qt/ManualDevicesSettingsPage/ManualDevicesSettingsPage.cpp b/qt/ManualDevicesSettingsPage/ManualDevicesSettingsPage.cpp index 5b6c9b14..e1649a16 100644 --- a/qt/ManualDevicesSettingsPage/ManualDevicesSettingsPage.cpp +++ b/qt/ManualDevicesSettingsPage/ManualDevicesSettingsPage.cpp @@ -184,7 +184,6 @@ void ManualDevicesSettingsPage::clearList() void ManualDevicesSettingsPage::setUnsavedChanges(bool v) { unsavedChanges = v; - ui->saveConfigurationButton->setEnabled(v && checkValidToSave()); if(v) {