From c5abe47859e84e20bdf352297b4a767bdb964e01 Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Wed, 24 Jun 2026 11:45:05 -0500 Subject: [PATCH] Create a common type for storing QMK LED info and use it in both VialRGB and Keychron controllers --- Controllers/QMKController/QMKCommon.h | 22 +++++ .../QMKKeychronController.cpp | 2 +- .../QMKKeychronController.h | 86 +++++++++---------- .../RGBController_QMKKeychron.cpp | 4 +- .../QMKVialRGBController.cpp | 6 +- .../QMKVialRGBController.h | 66 +++++++------- .../RGBController_QMKVialRGB.cpp | 4 +- 7 files changed, 99 insertions(+), 91 deletions(-) create mode 100644 Controllers/QMKController/QMKCommon.h diff --git a/Controllers/QMKController/QMKCommon.h b/Controllers/QMKController/QMKCommon.h new file mode 100644 index 000000000..7ef932cd7 --- /dev/null +++ b/Controllers/QMKController/QMKCommon.h @@ -0,0 +1,22 @@ +/*---------------------------------------------------------*\ +| QMKCommon.h | +| | +| Common QMK definitions | +| | +| Adam Honse #include +#include "QMKCommon.h" +#include "RGBController.h" /*---------------------------------------------------------*\ | Keychron vendor ID | @@ -131,64 +132,57 @@ enum KeychronVIABacklightValueID #define KEYCHRON_QHE_MIN_SPEED 0x00 #define KEYCHRON_QHE_MAX_SPEED 0xFF -typedef struct -{ - bool valid; - unsigned char row; - unsigned char col; -} kc_led_info; - class QMKKeychronController { public: QMKKeychronController(hid_device* dev_handle, const char *path); ~QMKKeychronController(); - std::string GetLocation(); - std::string GetName(); - std::string GetSerial(); - std::string GetVendor(); - std::string GetVersion(); + std::string GetLocation(); + std::string GetName(); + std::string GetSerial(); + std::string GetVendor(); + std::string GetVersion(); - bool GetSupported(); + bool GetSupported(); - unsigned short GetKeycode(unsigned short led_index); - unsigned short GetLEDCount(); - kc_led_info GetLEDInfo(unsigned short led_index); + unsigned short GetKeycode(unsigned short led_index); + unsigned short GetLEDCount(); + qmk_rgb_matrix_led_info GetLEDInfo(unsigned short led_index); - void SendLEDs(unsigned short number_leds, RGBColor* color_data); - void SetMode(unsigned short mode, unsigned char speed, unsigned char hue, unsigned char sat, unsigned char val); + void SendLEDs(unsigned short number_leds, RGBColor* color_data); + void SetMode(unsigned short mode, unsigned char speed, unsigned char hue, unsigned char sat, unsigned char val); - void SaveMode(); + void SaveMode(); private: - hid_device* dev; - unsigned char kc_protocol_version; - unsigned short kc_rgb_protocol_version; - std::vector keycodes; - std::vector led_info; - std::string location; - std::string name; - unsigned short number_leds; - std::string serial; - unsigned short supported_features; - std::string vendor; - unsigned short via_protocol_version; + hid_device* dev; + unsigned char kc_protocol_version; + unsigned short kc_rgb_protocol_version; + std::vector keycodes; + std::vector led_info; + std::string location; + std::string name; + unsigned short number_leds; + std::string serial; + unsigned short supported_features; + std::string vendor; + unsigned short via_protocol_version; - unsigned short CmdGetKeycode(unsigned char layer, unsigned char row, unsigned char col); - void CmdGetKeychronProtocolVersion(unsigned char* kc_protocol_version); - void CmdGetKeychronRGBProtocolVersion(unsigned short* kc_rgb_protocol_version); - std::vector CmdGetLEDIndexByRow(unsigned char row); - void CmdGetNumberLEDs(unsigned short* number_leds); - void CmdGetSupportFeature(unsigned short* supported_features); - void CmdGetViaProtocolVersion(unsigned short* via_protocol_version); - void CmdSaveMode(); - void CmdSendLEDs(unsigned char start_index, unsigned char number_leds, RGBColor* color_data); - void CmdSetBrightness(unsigned char brightness); - void CmdSetColorHS(unsigned char h, unsigned char s); - void CmdSetPerKeyRGBType(unsigned char type); - void CmdSetRGBMatrixMode(unsigned char mode); - void CmdSetSpeed(unsigned char speed); + unsigned short CmdGetKeycode(unsigned char layer, unsigned char row, unsigned char col); + void CmdGetKeychronProtocolVersion(unsigned char* kc_protocol_version); + void CmdGetKeychronRGBProtocolVersion(unsigned short* kc_rgb_protocol_version); + std::vector CmdGetLEDIndexByRow(unsigned char row); + void CmdGetNumberLEDs(unsigned short* number_leds); + void CmdGetSupportFeature(unsigned short* supported_features); + void CmdGetViaProtocolVersion(unsigned short* via_protocol_version); + void CmdSaveMode(); + void CmdSendLEDs(unsigned char start_index, unsigned char number_leds, RGBColor* color_data); + void CmdSetBrightness(unsigned char brightness); + void CmdSetColorHS(unsigned char h, unsigned char s); + void CmdSetPerKeyRGBType(unsigned char type); + void CmdSetRGBMatrixMode(unsigned char mode); + void CmdSetSpeed(unsigned char speed); int ViaSendCommand ( diff --git a/Controllers/QMKController/QMKKeychronController/RGBController_QMKKeychron.cpp b/Controllers/QMKController/QMKKeychronController/RGBController_QMKKeychron.cpp index 8db7e4e39..a68882374 100644 --- a/Controllers/QMKController/QMKKeychronController/RGBController_QMKKeychron.cpp +++ b/Controllers/QMKController/QMKKeychronController/RGBController_QMKKeychron.cpp @@ -137,7 +137,7 @@ void RGBController_QMKKeychron::SetupZones() for(unsigned short led_index = 0; led_index < controller->GetLEDCount(); led_index++) { - kc_led_info info = controller->GetLEDInfo(led_index); + qmk_rgb_matrix_led_info info = controller->GetLEDInfo(led_index); if(info.col > max_col) { @@ -159,7 +159,7 @@ void RGBController_QMKKeychron::SetupZones() for(unsigned short led_index = 0; led_index < controller->GetLEDCount(); led_index++) { - kc_led_info info = controller->GetLEDInfo(led_index); + qmk_rgb_matrix_led_info info = controller->GetLEDInfo(led_index); matrix_map[(width * info.row) + info.col] = (unsigned int)led_index; } diff --git a/Controllers/QMKController/QMKVialRGBController/QMKVialRGBController.cpp b/Controllers/QMKController/QMKVialRGBController/QMKVialRGBController.cpp index 195f64f9b..1713ed64b 100644 --- a/Controllers/QMKController/QMKVialRGBController/QMKVialRGBController.cpp +++ b/Controllers/QMKController/QMKVialRGBController/QMKVialRGBController.cpp @@ -186,7 +186,7 @@ unsigned short QMKVialRGBController::GetLEDCount() return(number_leds); } -vialrgb_led_info QMKVialRGBController::GetLEDInfo(unsigned short led_index) +qmk_rgb_matrix_led_info QMKVialRGBController::GetLEDInfo(unsigned short led_index) { return(led_info[led_index]); } @@ -257,12 +257,12 @@ unsigned short QMKVialRGBController::CmdGetKeycode return(keycode); } -vialrgb_led_info QMKVialRGBController::CmdGetLEDInfo +qmk_rgb_matrix_led_info QMKVialRGBController::CmdGetLEDInfo ( unsigned short led_index ) { - vialrgb_led_info data; + qmk_rgb_matrix_led_info data; SendCheckCommand(CMD_LIGHTING_GET_VALUE, VIALRGB_GET_LED_INFO, (unsigned char*)&led_index, sizeof(led_index), (unsigned char*)&data, sizeof(data)); diff --git a/Controllers/QMKController/QMKVialRGBController/QMKVialRGBController.h b/Controllers/QMKController/QMKVialRGBController/QMKVialRGBController.h index 86d882853..ec2cbc36e 100644 --- a/Controllers/QMKController/QMKVialRGBController/QMKVialRGBController.h +++ b/Controllers/QMKController/QMKVialRGBController/QMKVialRGBController.h @@ -13,6 +13,7 @@ #include #include "ResourceManager.h" +#include "QMKCommon.h" #include "RGBController.h" #define MSG_LEN 32 @@ -98,34 +99,25 @@ enum VIALRGB_EFFECT_SKIP = 0xFFFF }; -typedef struct -{ - unsigned char x; - unsigned char y; - unsigned char flags; - unsigned char row; - unsigned char col; -} vialrgb_led_info; - class QMKVialRGBController { public: QMKVialRGBController(hid_device *dev_handle, const char *path); ~QMKVialRGBController(); - std::string GetLocation(); - std::string GetName(); - std::string GetSerial(); - std::string GetVendor(); - std::string GetVersion(); + std::string GetLocation(); + std::string GetName(); + std::string GetSerial(); + std::string GetVendor(); + std::string GetVersion(); - bool GetSupported(); + bool GetSupported(); - unsigned short GetEffect(std::size_t effect_idx); - std::size_t GetEffectCount(); - unsigned short GetKeycode(unsigned short led_index); - unsigned short GetLEDCount(); - vialrgb_led_info GetLEDInfo(unsigned short led_index); + unsigned short GetEffect(std::size_t effect_idx); + std::size_t GetEffectCount(); + unsigned short GetKeycode(unsigned short led_index); + unsigned short GetLEDCount(); + qmk_rgb_matrix_led_info GetLEDInfo(unsigned short led_index); void GetMode ( @@ -152,22 +144,22 @@ public: ); private: - hid_device* dev; - unsigned long long keyboard_uid; - std::vector keycodes; - std::vector led_info; - std::string location; - unsigned char maximum_brightness; - std::string name; - unsigned short number_leds; - std::string serial; - bool supported; - std::vector supported_effects; - std::string vendor; - unsigned short via_protocol_version; - unsigned int vial_protocol_version; - unsigned short vialrgb_protocol_version; - unsigned char vialrgb_flag; + hid_device* dev; + unsigned long long keyboard_uid; + std::vector keycodes; + std::vector led_info; + std::string location; + unsigned char maximum_brightness; + std::string name; + unsigned short number_leds; + std::string serial; + bool supported; + std::vector supported_effects; + std::string vendor; + unsigned short via_protocol_version; + unsigned int vial_protocol_version; + unsigned short vialrgb_protocol_version; + unsigned char vialrgb_flag; unsigned short CmdGetKeycode ( @@ -176,7 +168,7 @@ private: unsigned char col ); - vialrgb_led_info CmdGetLEDInfo + qmk_rgb_matrix_led_info CmdGetLEDInfo ( unsigned short led_index ); diff --git a/Controllers/QMKController/QMKVialRGBController/RGBController_QMKVialRGB.cpp b/Controllers/QMKController/QMKVialRGBController/RGBController_QMKVialRGB.cpp index df74e8149..0313d78a1 100644 --- a/Controllers/QMKController/QMKVialRGBController/RGBController_QMKVialRGB.cpp +++ b/Controllers/QMKController/QMKVialRGBController/RGBController_QMKVialRGB.cpp @@ -171,7 +171,7 @@ void RGBController_QMKVialRGB::SetupZones() for(unsigned short led_index = 0; led_index < controller->GetLEDCount(); led_index++) { - vialrgb_led_info info = controller->GetLEDInfo(led_index); + qmk_rgb_matrix_led_info info = controller->GetLEDInfo(led_index); if(info.col > max_col) { @@ -193,7 +193,7 @@ void RGBController_QMKVialRGB::SetupZones() for(unsigned short led_index = 0; led_index < controller->GetLEDCount(); led_index++) { - vialrgb_led_info info = controller->GetLEDInfo(led_index); + qmk_rgb_matrix_led_info info = controller->GetLEDInfo(led_index); matrix_map[(width * info.row) + info.col] = (unsigned int)led_index; }