mirror of
https://github.com/CalcProgrammer1/OpenRGB.git
synced 2026-06-24 13:48:45 -04:00
Create a common type for storing QMK LED info and use it in both VialRGB and Keychron controllers
This commit is contained in:
22
Controllers/QMKController/QMKCommon.h
Normal file
22
Controllers/QMKController/QMKCommon.h
Normal file
@@ -0,0 +1,22 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| QMKCommon.h |
|
||||
| |
|
||||
| Common QMK definitions |
|
||||
| |
|
||||
| Adam Honse <calcprogrammer1@gmail.com) 24 Jun 2026 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned char x; /* X position in RGB matrix (0-224) */
|
||||
unsigned char y; /* Y position in RGB matrix (0-64) */
|
||||
unsigned char flags; /* LED flags */
|
||||
unsigned char row; /* Row in key matrix */
|
||||
unsigned char col; /* Column in key matrix */
|
||||
bool valid; /* Is this LED valid? */
|
||||
} qmk_rgb_matrix_led_info;
|
||||
@@ -190,7 +190,7 @@ unsigned short QMKKeychronController::GetLEDCount()
|
||||
return(number_leds);
|
||||
}
|
||||
|
||||
kc_led_info QMKKeychronController::GetLEDInfo(unsigned short led_index)
|
||||
qmk_rgb_matrix_led_info QMKKeychronController::GetLEDInfo(unsigned short led_index)
|
||||
{
|
||||
return(led_info[led_index]);
|
||||
}
|
||||
|
||||
@@ -12,9 +12,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RGBController.h"
|
||||
#include <string>
|
||||
#include <hidapi.h>
|
||||
#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<unsigned short> keycodes;
|
||||
std::vector<kc_led_info> 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<unsigned short> keycodes;
|
||||
std::vector<qmk_rgb_matrix_led_info> 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<unsigned char> 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<unsigned char> 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
|
||||
(
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
#include <hidapi.h>
|
||||
#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<unsigned short> keycodes;
|
||||
std::vector<vialrgb_led_info> led_info;
|
||||
std::string location;
|
||||
unsigned char maximum_brightness;
|
||||
std::string name;
|
||||
unsigned short number_leds;
|
||||
std::string serial;
|
||||
bool supported;
|
||||
std::vector<unsigned short> 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<unsigned short> keycodes;
|
||||
std::vector<qmk_rgb_matrix_led_info> led_info;
|
||||
std::string location;
|
||||
unsigned char maximum_brightness;
|
||||
std::string name;
|
||||
unsigned short number_leds;
|
||||
std::string serial;
|
||||
bool supported;
|
||||
std::vector<unsigned short> 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
|
||||
);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user