Skip to content

Commit 6393612

Browse files
Perform VialRGB version and flag checks before registering QMK VialRGB controllers
1 parent d7bab0d commit 6393612

3 files changed

Lines changed: 35 additions & 3 deletions

File tree

Controllers/QMKController/QMKVialRGBController/QMKVialRGBController.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ QMKVialRGBController::QMKVialRGBController(hid_device *dev_handle, const char *p
2727
\*-----------------------------------------------------*/
2828
dev = dev_handle;
2929
location = path;
30+
supported = false;
3031

3132
/*-----------------------------------------------------*\
3233
| Read product string |
@@ -80,7 +81,20 @@ QMKVialRGBController::QMKVialRGBController(hid_device *dev_handle, const char *p
8081
| Get VIA, Vial, and VialRGB information |
8182
\*-----------------------------------------------------*/
8283
CmdGetViaProtocolVersion(&via_protocol_version);
84+
85+
if(via_protocol_version < 9)
86+
{
87+
return;
88+
}
89+
8390
CmdGetVialInfo(&vial_protocol_version, &keyboard_uid, &vialrgb_flag);
91+
92+
if((vial_protocol_version < 4) || ((vialrgb_flag & 1) == 0))
93+
{
94+
supported = false;
95+
return;
96+
}
97+
8498
CmdGetVialRGBInfo(&vialrgb_protocol_version, &maximum_brightness);
8599

86100
/*-----------------------------------------------------*\
@@ -101,6 +115,8 @@ QMKVialRGBController::QMKVialRGBController(hid_device *dev_handle, const char *p
101115
led_info.push_back(CmdGetLEDInfo(led_index));
102116
keycodes.push_back(CmdGetKeycode(0, led_info[led_index].row, led_info[led_index].col));
103117
}
118+
119+
supported = true;
104120
}
105121

106122
QMKVialRGBController::~QMKVialRGBController()
@@ -145,6 +161,11 @@ std::string QMKVialRGBController::GetVersion()
145161
+ "UID: " + uid_buf);
146162
}
147163

164+
bool QMKVialRGBController::GetSupported()
165+
{
166+
return(supported);
167+
}
168+
148169
unsigned short QMKVialRGBController::GetEffect(std::size_t effect_idx)
149170
{
150171
return(supported_effects[effect_idx]);

Controllers/QMKController/QMKVialRGBController/QMKVialRGBController.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ class QMKVialRGBController
119119
std::string GetVendor();
120120
std::string GetVersion();
121121

122+
bool GetSupported();
123+
122124
unsigned short GetEffect(std::size_t effect_idx);
123125
std::size_t GetEffectCount();
124126
unsigned short GetKeycode(unsigned short led_index);
@@ -159,6 +161,7 @@ class QMKVialRGBController
159161
std::string name;
160162
unsigned short number_leds;
161163
std::string serial;
164+
bool supported;
162165
std::vector<unsigned short> supported_effects;
163166
std::string vendor;
164167
unsigned short via_protocol_version;

Controllers/QMKController/QMKVialRGBController/QMKVialRGBControllerDetect.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,17 @@ void DetectQMKVialRGBControllers(hid_device_info *info, const std::string&)
3333

3434
if(dev)
3535
{
36-
QMKVialRGBController* controller = new QMKVialRGBController(dev, info->path);
37-
RGBController_QMKVialRGB* rgb_controller = new RGBController_QMKVialRGB(controller);
38-
ResourceManager::get()->RegisterRGBController(rgb_controller);
36+
QMKVialRGBController* controller = new QMKVialRGBController(dev, info->path);
37+
38+
if(controller->GetSupported())
39+
{
40+
RGBController_QMKVialRGB* rgb_controller = new RGBController_QMKVialRGB(controller);
41+
ResourceManager::get()->RegisterRGBController(rgb_controller);
42+
}
43+
else
44+
{
45+
delete controller;
46+
}
3947
}
4048
}
4149

0 commit comments

Comments
 (0)