From 2927135cdd9a0d7e14fbc4fd3fb554aaaa73db01 Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Fri, 8 Aug 2025 11:26:55 -0500 Subject: [PATCH] Store name in GaiZhongGaiControllers to avoid setting it in detector --- .../GaiZhongGaiController.cpp | 8 +- .../GaiZhongGaiController.h | 4 +- .../GaiZhongGaiControllerDetect.cpp | 7 +- .../RGBController_GaiZhongGai.cpp | 126 ++++++++---------- 4 files changed, 68 insertions(+), 77 deletions(-) diff --git a/Controllers/GaiZongGaiKeyboardController/GaiZhongGaiController.cpp b/Controllers/GaiZongGaiKeyboardController/GaiZhongGaiController.cpp index 2148d405..3028a1b3 100644 --- a/Controllers/GaiZongGaiKeyboardController/GaiZhongGaiController.cpp +++ b/Controllers/GaiZongGaiKeyboardController/GaiZhongGaiController.cpp @@ -22,10 +22,11 @@ | https://oshwhub.com/morempty/CH552gyin-liang-xuan-niu | \*---------------------------------------------------------------*/ -GaiZhongGaiKeyboardController::GaiZhongGaiKeyboardController(hid_device* dev_handle, hid_device_info* info) +GaiZhongGaiKeyboardController::GaiZhongGaiKeyboardController(hid_device* dev_handle, hid_device_info* info, std::string dev_name) { dev = dev_handle; location = info->path; + name = dev_name; usb_pid = info->product_id; /*-----------------------------------------------------*\ | Obtaining the Firmware Version | @@ -163,6 +164,11 @@ std::string GaiZhongGaiKeyboardController::GetDeviceLocation() return("HID: " + location); } +std::string GaiZhongGaiKeyboardController::GetNameString() +{ + return(name); +} + std::string GaiZhongGaiKeyboardController::GetSerialString() { wchar_t serial_string[128]; diff --git a/Controllers/GaiZongGaiKeyboardController/GaiZhongGaiController.h b/Controllers/GaiZongGaiKeyboardController/GaiZhongGaiController.h index c72c7a15..0dcb01a9 100644 --- a/Controllers/GaiZongGaiKeyboardController/GaiZhongGaiController.h +++ b/Controllers/GaiZongGaiKeyboardController/GaiZhongGaiController.h @@ -40,10 +40,11 @@ class GaiZhongGaiKeyboardController { public: - GaiZhongGaiKeyboardController(hid_device* dev_handle, hid_device_info* info); + GaiZhongGaiKeyboardController(hid_device* dev_handle, hid_device_info* info, std::string dev_name); ~GaiZhongGaiKeyboardController(); std::string GetDeviceLocation(); + std::string GetNameString(); std::string GetSerialString(); std::string GetVersion(); unsigned short GetUSBPID(); @@ -60,6 +61,7 @@ public: private: hid_device* dev; std::string location; + std::string name; std::string version; unsigned short usb_pid; uint8_t data_flash[128]; diff --git a/Controllers/GaiZongGaiKeyboardController/GaiZhongGaiControllerDetect.cpp b/Controllers/GaiZongGaiKeyboardController/GaiZhongGaiControllerDetect.cpp index 3c746f26..4dc7e225 100644 --- a/Controllers/GaiZongGaiKeyboardController/GaiZhongGaiControllerDetect.cpp +++ b/Controllers/GaiZongGaiKeyboardController/GaiZhongGaiControllerDetect.cpp @@ -25,11 +25,12 @@ void DetectGaiZhongGaiKeyboardControllers(hid_device_info* info, const std::string& name) { hid_device* dev = hid_open_path(info->path); - if( dev ) + + if(dev) { - GaiZhongGaiKeyboardController* controller = new GaiZhongGaiKeyboardController(dev, info); + GaiZhongGaiKeyboardController* controller = new GaiZhongGaiKeyboardController(dev, info, name); RGBController_GaiZhongGaiKeyboard* rgb_controller = new RGBController_GaiZhongGaiKeyboard(controller); - rgb_controller->name = name; + ResourceManager::get()->RegisterRGBController(rgb_controller); } } /* DetectGaiZhongGaiKeyboardControllers() */ diff --git a/Controllers/GaiZongGaiKeyboardController/RGBController_GaiZhongGai.cpp b/Controllers/GaiZongGaiKeyboardController/RGBController_GaiZhongGai.cpp index 83bd1515..7865a885 100644 --- a/Controllers/GaiZongGaiKeyboardController/RGBController_GaiZhongGai.cpp +++ b/Controllers/GaiZongGaiKeyboardController/RGBController_GaiZhongGai.cpp @@ -383,85 +383,67 @@ uint16_t LightBoard_init(uint8_t* p_in) RGBController_GaiZhongGaiKeyboard::RGBController_GaiZhongGaiKeyboard(GaiZhongGaiKeyboardController* controller_ptr) { - controller = controller_ptr; + controller = controller_ptr; + name = controller->GetNameString(); switch(controller->GetUSBPID()) { - case GAIZHONGGAI_68_PRO_PID: - { - name = "GaiZhongGai Keyboard Device"; - type = DEVICE_TYPE_KEYBOARD; - description = "https://oshwhub.com/yangzen/zui-gai68-/"; - } - break; - case GAIZHONGGAI_42_PRO_PID: - { - name = "GaiZhongGai Keyboard Device"; - type = DEVICE_TYPE_KEYBOARD; - description = "https://oshwhub.com/myng/42-jian-pan/"; - } - break; - case GAIZHONGGAI_17_TOUCH_PRO_PID: - { - name = "GaiZhongGai Keyboard Device"; - type = DEVICE_TYPE_KEYPAD; - description = "https://oshwhub.com/yangzen/xing-huo-ji-hua-zui-gai-17-4-chu-mo-ji-xie-jian-pan-pro/"; - } - break; - case GAIZHONGGAI_17_PRO_PID: - { - name = "GaiZhongGai Keyboard Device"; - type = DEVICE_TYPE_KEYPAD; - description = "https://oshwhub.com/hivisme/17jian-shuo-zi-xiao-jian-pan/"; - } - break; - case GAIZHONGGAI_20_PRO_PID: - { - name = "GaiZhongGai Keyboard Device"; - type = DEVICE_TYPE_KEYPAD; - description = "https://oshwhub.com/runkuny/19keys_pad_normal/"; - } - break; - case GAIZHONGGAI_LIGHT_BOARD_PID: - { - name = "GaiZhongGai Controller Device"; - type = DEVICE_TYPE_ACCESSORY; - description = "https://oshwhub.com/yangzen/xing-huo-2-qi-guang-ban-qu-dong-/"; - } - break; - case GAIZHONGGAI_RGB_HUB_GREEN_PID: - { - name = "GaiZhongGai Controller Device"; - type = DEVICE_TYPE_LEDSTRIP; - description = "https://oshwhub.com/yangzen/album/gai-zhong-gai-jian-pan-ge-ji/"; - } - break; - case GAIZHONGGAI_RGB_HUB_BLUE_PID: - { - name = "GaiZhongGai Controller Device"; - type = DEVICE_TYPE_LEDSTRIP; - description = "https://oshwhub.com/yangzen/album/gai-zhong-gai-jian-pan-ge-ji/"; - } - break; - case GAIZHONGGAI_DIAL_PID: - { - name = "GaiZhongGai DIAL Device"; - type = DEVICE_TYPE_UNKNOWN; - description = "https://oshwhub.com/morempty/CH552gyin-liang-xuan-niu/"; - } - break; + case GAIZHONGGAI_68_PRO_PID: + type = DEVICE_TYPE_KEYBOARD; + description = "https://oshwhub.com/yangzen/zui-gai68-/"; + break; + + case GAIZHONGGAI_42_PRO_PID: + type = DEVICE_TYPE_KEYBOARD; + description = "https://oshwhub.com/myng/42-jian-pan/"; + break; + + case GAIZHONGGAI_17_TOUCH_PRO_PID: + type = DEVICE_TYPE_KEYPAD; + description = "https://oshwhub.com/yangzen/xing-huo-ji-hua-zui-gai-17-4-chu-mo-ji-xie-jian-pan-pro/"; + break; + + case GAIZHONGGAI_17_PRO_PID: + type = DEVICE_TYPE_KEYPAD; + description = "https://oshwhub.com/hivisme/17jian-shuo-zi-xiao-jian-pan/"; + break; + + case GAIZHONGGAI_20_PRO_PID: + type = DEVICE_TYPE_KEYPAD; + description = "https://oshwhub.com/runkuny/19keys_pad_normal/"; + break; + + case GAIZHONGGAI_LIGHT_BOARD_PID: + type = DEVICE_TYPE_ACCESSORY; + description = "https://oshwhub.com/yangzen/xing-huo-2-qi-guang-ban-qu-dong-/"; + break; + + case GAIZHONGGAI_RGB_HUB_GREEN_PID: + type = DEVICE_TYPE_LEDSTRIP; + description = "https://oshwhub.com/yangzen/album/gai-zhong-gai-jian-pan-ge-ji/"; + break; + + case GAIZHONGGAI_RGB_HUB_BLUE_PID: + type = DEVICE_TYPE_LEDSTRIP; + description = "https://oshwhub.com/yangzen/album/gai-zhong-gai-jian-pan-ge-ji/"; + break; + + case GAIZHONGGAI_DIAL_PID: + type = DEVICE_TYPE_UNKNOWN; + description = "https://oshwhub.com/morempty/CH552gyin-liang-xuan-niu/"; + break; } - vendor = "Yang"; - version = controller->GetVersion(); - location = controller->GetDeviceLocation(); - serial = controller->GetSerialString(); + vendor = "Yang"; + version = controller->GetVersion(); + location = controller->GetDeviceLocation(); + serial = controller->GetSerialString(); mode Direct; - Direct.name = "Direct"; - Direct.value = 0xFFFF; - Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR; - Direct.color_mode = MODE_COLORS_PER_LED; + Direct.name = "Direct"; + Direct.value = 0xFFFF; + Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR; + Direct.color_mode = MODE_COLORS_PER_LED; modes.push_back(Direct); SetupZones();