From 2c630a5218ca7c221bcbd27f6d4bffdd1397529f Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Thu, 14 Aug 2025 19:06:29 -0500 Subject: [PATCH] Store name in OKSKeyboardController to avoid setting it in detector --- .../OKSController/OKSKeyboardController.cpp | 8 ++- .../OKSController/OKSKeyboardController.h | 28 +++++---- .../OKSKeyboardControllerDetect.cpp | 4 +- .../RGBController_OKSKeyboard.cpp | 61 +++++++++---------- 4 files changed, 54 insertions(+), 47 deletions(-) diff --git a/Controllers/OKSController/OKSKeyboardController.cpp b/Controllers/OKSController/OKSKeyboardController.cpp index 0af54e3c..b6c9d541 100644 --- a/Controllers/OKSController/OKSKeyboardController.cpp +++ b/Controllers/OKSController/OKSKeyboardController.cpp @@ -13,10 +13,11 @@ #include "OKSKeyboardController.h" #include "StringUtils.h" -OKSKeyboardController::OKSKeyboardController(hid_device* dev_handle, const char* path, const unsigned short pid) +OKSKeyboardController::OKSKeyboardController(hid_device* dev_handle, const char* path, const unsigned short pid, std::string dev_name) { dev = dev_handle; location = path; + name = dev_name; usb_pid = pid; SendInitialize(); @@ -32,6 +33,11 @@ std::string OKSKeyboardController::GetDeviceLocation() return("HID: " + location); } +std::string OKSKeyboardController::GetNameString() +{ + return(name); +} + std::string OKSKeyboardController::GetSerialString() { wchar_t serial_string[128]; diff --git a/Controllers/OKSController/OKSKeyboardController.h b/Controllers/OKSController/OKSKeyboardController.h index 1166f334..5a24ba7f 100644 --- a/Controllers/OKSController/OKSKeyboardController.h +++ b/Controllers/OKSController/OKSKeyboardController.h @@ -67,26 +67,28 @@ union uint32_kb2 class OKSKeyboardController { public: - OKSKeyboardController(hid_device* dev_handle, const char* path, const unsigned short pid); + OKSKeyboardController(hid_device* dev_handle, const char* path, const unsigned short pid, std::string dev_name); ~OKSKeyboardController(); std::string GetDeviceLocation(); + std::string GetNameString(); std::string GetSerialString(); unsigned short GetUSBPID(); - void SendColors(unsigned char* color_data, unsigned int color_data_size); - void SendKeyboardModeEx(const mode &m, unsigned char red, unsigned char green, unsigned char blue); + void SendColors(unsigned char* color_data, unsigned int color_data_size); + void SendKeyboardModeEx(const mode &m, unsigned char red, unsigned char green, unsigned char blue); private: - hid_device* dev; - std::string location; - unsigned short usb_pid; + hid_device* dev; + std::string location; + std::string name; + unsigned short usb_pid; - void Send(const uint8_t bin[64], const uint16_t len); - void SendInitialize(); - uint8_t kb2_ComputeChecksum(const union kb2_port_t* const Pack); - int kb2_add_32b(union kb2_port_t* const Pack, const uint32_t value); - void kb2M_init(union kb2_port_t* const Pack, const enum kb2_cmd cmd); - void kb2M_wrgb(union kb2_port_t* const Pack, const uint8_t bright, const uint8_t mode, const uint8_t speed, const uint8_t dir); - void kb2M_wled(union kb2_port_t* const Pack, const uint32_t irgb[14]); + void Send(const uint8_t bin[64], const uint16_t len); + void SendInitialize(); + uint8_t kb2_ComputeChecksum(const union kb2_port_t* const Pack); + int kb2_add_32b(union kb2_port_t* const Pack, const uint32_t value); + void kb2M_init(union kb2_port_t* const Pack, const enum kb2_cmd cmd); + void kb2M_wrgb(union kb2_port_t* const Pack, const uint8_t bright, const uint8_t mode, const uint8_t speed, const uint8_t dir); + void kb2M_wled(union kb2_port_t* const Pack, const uint32_t irgb[14]); }; diff --git a/Controllers/OKSController/OKSKeyboardControllerDetect.cpp b/Controllers/OKSController/OKSKeyboardControllerDetect.cpp index bd4c35d3..9a77f0ee 100644 --- a/Controllers/OKSController/OKSKeyboardControllerDetect.cpp +++ b/Controllers/OKSController/OKSKeyboardControllerDetect.cpp @@ -27,9 +27,9 @@ void DetectOKSKeyboardControllers(hid_device_info* info, const std::string& name if(dev) { - OKSKeyboardController* controller = new OKSKeyboardController(dev, info->path, info->product_id); + OKSKeyboardController* controller = new OKSKeyboardController(dev, info->path, info->product_id, name); RGBController_OKSKeyboard* rgb_controller = new RGBController_OKSKeyboard(controller); - rgb_controller->name = name; + ResourceManager::get()->RegisterRGBController(rgb_controller); } } /* DetectOKSKeyboardControllers() */ diff --git a/Controllers/OKSController/RGBController_OKSKeyboard.cpp b/Controllers/OKSController/RGBController_OKSKeyboard.cpp index 50c8ea3c..f9c7c4be 100644 --- a/Controllers/OKSController/RGBController_OKSKeyboard.cpp +++ b/Controllers/OKSController/RGBController_OKSKeyboard.cpp @@ -109,47 +109,46 @@ enum RGBController_OKSKeyboard::RGBController_OKSKeyboard(OKSKeyboardController* controller_ptr) { - controller = controller_ptr; + controller = controller_ptr; - - name = "OKS Keyboard Device"; - vendor = "OKS"; - type = DEVICE_TYPE_KEYBOARD; - description = "OKS Keyboard Device"; - location = controller->GetDeviceLocation(); - serial = controller->GetSerialString(); + name = controller->GetNameString(); + vendor = "OKS"; + type = DEVICE_TYPE_KEYBOARD; + description = "OKS Keyboard Device"; + location = controller->GetDeviceLocation(); + serial = controller->GetSerialString(); mode Direct; - Direct.name = "Direct"; - Direct.value = UP_RGB_MODES_DIRECT; - Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_HAS_BRIGHTNESS ; - Direct.brightness_min = 0; - Direct.brightness_max = 5; - Direct.brightness = 2; - Direct.color_mode = MODE_COLORS_PER_LED; - Direct.speed_min = OKS_SPEED_FASTEST; - Direct.speed_max = OKS_SPEED_SLOWEST; - Direct.speed = OKS_SPEED_NORMAL; - Direct.direction = MODE_DIRECTION_RIGHT; + Direct.name = "Direct"; + Direct.value = UP_RGB_MODES_DIRECT; + Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_HAS_BRIGHTNESS ; + Direct.brightness_min = 0; + Direct.brightness_max = 5; + Direct.brightness = 2; + Direct.color_mode = MODE_COLORS_PER_LED; + Direct.speed_min = OKS_SPEED_FASTEST; + Direct.speed_max = OKS_SPEED_SLOWEST; + Direct.speed = OKS_SPEED_NORMAL; + Direct.direction = MODE_DIRECTION_RIGHT; modes.push_back(Direct); mode udef = Direct; - udef.name = "User mode1"; - udef.value = UP_RGB_MODES_UDEF1; - udef.direction = MODE_DIRECTION_LEFT; - udef.speed = 0; + udef.name = "User mode1"; + udef.value = UP_RGB_MODES_UDEF1; + udef.direction = MODE_DIRECTION_LEFT; + udef.speed = 0; modes.push_back(udef); - udef.name = "User mode2"; - udef.value = UP_RGB_MODES_UDEF2; + udef.name = "User mode2"; + udef.value = UP_RGB_MODES_UDEF2; modes.push_back(udef); - udef.name = "User mode3"; - udef.value = UP_RGB_MODES_UDEF3; + udef.name = "User mode3"; + udef.value = UP_RGB_MODES_UDEF3; modes.push_back(udef); - udef.name = "User mode4"; - udef.value = UP_RGB_MODES_UDEF4; + udef.name = "User mode4"; + udef.value = UP_RGB_MODES_UDEF4; modes.push_back(udef); - udef.name = "User mode5"; - udef.value = UP_RGB_MODES_UDEF5; + udef.name = "User mode5"; + udef.value = UP_RGB_MODES_UDEF5; modes.push_back(udef); /*---------------------------------------------------------*\ | Delete the "Horse race lamp","Breathing"... mode |