Perform VialRGB version and flag checks before registering QMK VialRGB controllers

master
Adam Honse 7 months ago
parent d7bab0dc7b
commit 63936126f3

@ -27,6 +27,7 @@ QMKVialRGBController::QMKVialRGBController(hid_device *dev_handle, const char *p
\*-----------------------------------------------------*/
dev = dev_handle;
location = path;
supported = false;
/*-----------------------------------------------------*\
| Read product string |
@ -80,7 +81,20 @@ QMKVialRGBController::QMKVialRGBController(hid_device *dev_handle, const char *p
| Get VIA, Vial, and VialRGB information |
\*-----------------------------------------------------*/
CmdGetViaProtocolVersion(&via_protocol_version);
if(via_protocol_version < 9)
{
return;
}
CmdGetVialInfo(&vial_protocol_version, &keyboard_uid, &vialrgb_flag);
if((vial_protocol_version < 4) || ((vialrgb_flag & 1) == 0))
{
supported = false;
return;
}
CmdGetVialRGBInfo(&vialrgb_protocol_version, &maximum_brightness);
/*-----------------------------------------------------*\
@ -101,6 +115,8 @@ QMKVialRGBController::QMKVialRGBController(hid_device *dev_handle, const char *p
led_info.push_back(CmdGetLEDInfo(led_index));
keycodes.push_back(CmdGetKeycode(0, led_info[led_index].row, led_info[led_index].col));
}
supported = true;
}
QMKVialRGBController::~QMKVialRGBController()
@ -145,6 +161,11 @@ std::string QMKVialRGBController::GetVersion()
+ "UID: " + uid_buf);
}
bool QMKVialRGBController::GetSupported()
{
return(supported);
}
unsigned short QMKVialRGBController::GetEffect(std::size_t effect_idx)
{
return(supported_effects[effect_idx]);

@ -119,6 +119,8 @@ public:
std::string GetVendor();
std::string GetVersion();
bool GetSupported();
unsigned short GetEffect(std::size_t effect_idx);
std::size_t GetEffectCount();
unsigned short GetKeycode(unsigned short led_index);
@ -159,6 +161,7 @@ private:
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;

@ -33,9 +33,17 @@ void DetectQMKVialRGBControllers(hid_device_info *info, const std::string&)
if(dev)
{
QMKVialRGBController* controller = new QMKVialRGBController(dev, info->path);
RGBController_QMKVialRGB* rgb_controller = new RGBController_QMKVialRGB(controller);
ResourceManager::get()->RegisterRGBController(rgb_controller);
QMKVialRGBController* controller = new QMKVialRGBController(dev, info->path);
if(controller->GetSupported())
{
RGBController_QMKVialRGB* rgb_controller = new RGBController_QMKVialRGB(controller);
ResourceManager::get()->RegisterRGBController(rgb_controller);
}
else
{
delete controller;
}
}
}

Loading…
Cancel
Save