Browse Source

Make detectors for QMK OpenRGB controller configurable

merge-requests/525/merge
Adam Honse 8 months ago
parent
commit
68b0287cdd
  1. 55
      Controllers/QMKOpenRGBController/QMKOpenRGBControllerDetect.cpp
  2. 29
      Detector.h

55
Controllers/QMKOpenRGBController/QMKOpenRGBControllerDetect.cpp

@ -7,6 +7,9 @@
| Jath03 28th May 2021 |
\*-------------------------------------------------------------------*/
#include <iostream>
#include <string>
#include "Detector.h"
#include "QMKOpenRGBController.h"
#include "RGBController.h"
@ -24,26 +27,6 @@
#define QMK_USAGE_PAGE 0xFF60
#define QMK_USAGE 0x61
/*-----------------------------------------------------*\
| Massdrop |
\*-----------------------------------------------------*/
#define MASSDROP_VID 0x04D8
#define MASSDROP_ALT_PID 0xEED3
#define MASSDROP_CTRL_PID 0xEED2
/*-----------------------------------------------------*\
| SonixQMK |
\*-----------------------------------------------------*/
#define SONIXQMK_VID 0x0C45
#define SONIXQMK_5004_PID 0x5004
#define SONIXQMK_5104_PID 0x5104
/*-----------------------------------------------------*\
| KBDFans |
\*-----------------------------------------------------*/
#define KBDFANS_VID 0x4B42
#define KBDFANS_K67_MKII_RGB_PID 0x1225
void DetectQMKOpenRGBControllers(hid_device_info *info, const std::string&)
{
hid_device *dev = hid_open_path(info->path);
@ -67,11 +50,33 @@ void DetectQMKOpenRGBControllers(hid_device_info *info, const std::string&)
void RegisterQMKDetectors()
{
REGISTER_HID_DETECTOR_IPU("Massdrop Alt", DetectQMKOpenRGBControllers, MASSDROP_VID, MASSDROP_ALT_PID, 1, QMK_USAGE_PAGE, QMK_USAGE);
REGISTER_HID_DETECTOR_IPU("Massdrop Ctrl", DetectQMKOpenRGBControllers, MASSDROP_VID, MASSDROP_CTRL_PID, 1, QMK_USAGE_PAGE, QMK_USAGE);
REGISTER_HID_DETECTOR_IPU("SonixQMK 0C45:5004", DetectQMKOpenRGBControllers, SONIXQMK_VID, SONIXQMK_5004_PID, 1, QMK_USAGE_PAGE, QMK_USAGE);
REGISTER_HID_DETECTOR_IPU("SonixQMK 0C45:5104", DetectQMKOpenRGBControllers, SONIXQMK_VID, SONIXQMK_5104_PID, 1, QMK_USAGE_PAGE, QMK_USAGE);
REGISTER_HID_DETECTOR_IPU("KBDFans KBD67 MKII RGB", DetectQMKOpenRGBControllers, KBDFANS_VID, KBDFANS_K67_MKII_RGB_PID, 1, QMK_USAGE_PAGE, QMK_USAGE);
/*-------------------------------------------------*\
| Get QMKOpenRGB settings |
\*-------------------------------------------------*/
json qmk_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("QMKOpenRGBDevices");
if(qmk_settings.contains("devices"))
{
for(unsigned int device_idx = 0; device_idx < qmk_settings["devices"].size(); device_idx++)
{
if( qmk_settings["devices"][device_idx].contains("usb_pid")
&& qmk_settings["devices"][device_idx].contains("usb_vid")
&& qmk_settings["devices"][device_idx].contains("name"))
{
std::string usb_pid_str = qmk_settings["devices"][device_idx]["usb_pid"];
std::string usb_vid_str = qmk_settings["devices"][device_idx]["usb_vid"];
std::string name = qmk_settings["devices"][device_idx]["name"];
/*-------------------------------------*\
| Parse hex string to integer |
\*-------------------------------------*/
unsigned short usb_pid = std::stoi(usb_pid_str, 0, 16);
unsigned short usb_vid = std::stoi(usb_vid_str, 0, 16);
REGISTER_DYNAMIC_HID_DETECTOR_IPU(name, DetectQMKOpenRGBControllers, usb_vid, usb_pid, 1, QMK_USAGE_PAGE, QMK_USAGE);
}
}
}
}
REGISTER_DYNAMIC_DETECTOR("QMK OpenRGB Devices", RegisterQMKDetectors);

29
Detector.h

@ -2,13 +2,22 @@
#include "DeviceDetector.h"
#define REGISTER_DETECTOR(name, func) static DeviceDetector device_detector_obj_##func(name, func)
#define REGISTER_I2C_DETECTOR(name, func) static I2CDeviceDetector device_detector_obj_##func(name, func)
#define REGISTER_I2C_BUS_DETECTOR(func) static I2CBusDetector device_detector_obj_##func(func)
#define REGISTER_HID_DETECTOR(name, func, vid, pid) static HIDDeviceDetector device_detector_obj_##vid##pid(name, func, vid, pid, HID_INTERFACE_ANY, HID_USAGE_PAGE_ANY, HID_USAGE_ANY)
#define REGISTER_HID_DETECTOR_I(name, func, vid, pid, interface) static HIDDeviceDetector device_detector_obj_##vid##pid##_##interface(name, func, vid, pid, interface, HID_USAGE_PAGE_ANY, HID_USAGE_ANY)
#define REGISTER_HID_DETECTOR_IP(name, func, vid, pid, interface, page) static HIDDeviceDetector device_detector_obj_##vid##pid##_##interface##_##page(name, func, vid, pid, interface, page, HID_USAGE_ANY)
#define REGISTER_HID_DETECTOR_IPU(name, func, vid, pid, interface, page, usage) static HIDDeviceDetector device_detector_obj_##vid##pid##_##interface##_##page##_##usage(name, func, vid, pid, interface, page, usage)
#define REGISTER_HID_DETECTOR_P(name, func, vid, pid, page) static HIDDeviceDetector device_detector_obj_##vid##pid##__##page(name, func, vid, pid, HID_INTERFACE_ANY, page, HID_USAGE_ANY)
#define REGISTER_HID_DETECTOR_PU(name, func, vid, pid, page, usage) static HIDDeviceDetector device_detector_obj_##vid##pid##__##page##_##usage(name, func, vid, pid, HID_INTERFACE_ANY, page, usage)
#define REGISTER_DYNAMIC_DETECTOR(name, func) static DynamicDetector device_detector_obj_##func(name, func)
#define REGISTER_DETECTOR(name, func) static DeviceDetector device_detector_obj_##func(name, func)
#define REGISTER_I2C_DETECTOR(name, func) static I2CDeviceDetector device_detector_obj_##func(name, func)
#define REGISTER_I2C_BUS_DETECTOR(func) static I2CBusDetector device_detector_obj_##func(func)
#define REGISTER_HID_DETECTOR(name, func, vid, pid) static HIDDeviceDetector device_detector_obj_##vid##pid(name, func, vid, pid, HID_INTERFACE_ANY, HID_USAGE_PAGE_ANY, HID_USAGE_ANY)
#define REGISTER_HID_DETECTOR_I(name, func, vid, pid, interface) static HIDDeviceDetector device_detector_obj_##vid##pid##_##interface(name, func, vid, pid, interface, HID_USAGE_PAGE_ANY, HID_USAGE_ANY)
#define REGISTER_HID_DETECTOR_IP(name, func, vid, pid, interface, page) static HIDDeviceDetector device_detector_obj_##vid##pid##_##interface##_##page(name, func, vid, pid, interface, page, HID_USAGE_ANY)
#define REGISTER_HID_DETECTOR_IPU(name, func, vid, pid, interface, page, usage) static HIDDeviceDetector device_detector_obj_##vid##pid##_##interface##_##page##_##usage(name, func, vid, pid, interface, page, usage)
#define REGISTER_HID_DETECTOR_P(name, func, vid, pid, page) static HIDDeviceDetector device_detector_obj_##vid##pid##__##page(name, func, vid, pid, HID_INTERFACE_ANY, page, HID_USAGE_ANY)
#define REGISTER_HID_DETECTOR_PU(name, func, vid, pid, page, usage) static HIDDeviceDetector device_detector_obj_##vid##pid##__##page##_##usage(name, func, vid, pid, HID_INTERFACE_ANY, page, usage)
#define REGISTER_DYNAMIC_DETECTOR(name, func) static DynamicDetector device_detector_obj_##func(name, func)
#define REGISTER_DYNAMIC_I2C_DETECTOR(name, func) I2CDeviceDetector device_detector_obj_##func(name, func)
#define REGISTER_DYNAMIC_I2C_BUS_DETECTOR(func) I2CBusDetector device_detector_obj_##func(func)
#define REGISTER_DYNAMIC_HID_DETECTOR(name, func, vid, pid) HIDDeviceDetector device_detector_obj_##vid##pid(name, func, vid, pid, HID_INTERFACE_ANY, HID_USAGE_PAGE_ANY, HID_USAGE_ANY)
#define REGISTER_DYNAMIC_HID_DETECTOR_I(name, func, vid, pid, interface) HIDDeviceDetector device_detector_obj_##vid##pid##_##interface(name, func, vid, pid, interface, HID_USAGE_PAGE_ANY, HID_USAGE_ANY)
#define REGISTER_DYNAMIC_HID_DETECTOR_IP(name, func, vid, pid, interface, page) HIDDeviceDetector device_detector_obj_##vid##pid##_##interface##_##page(name, func, vid, pid, interface, page, HID_USAGE_ANY)
#define REGISTER_DYNAMIC_HID_DETECTOR_IPU(name, func, vid, pid, interface, page, usage) HIDDeviceDetector device_detector_obj_##vid##pid##_##interface##_##page##_##usage(name, func, vid, pid, interface, page, usage)
#define REGISTER_DYNAMIC_HID_DETECTOR_P(name, func, vid, pid, page) HIDDeviceDetector device_detector_obj_##vid##pid##__##page(name, func, vid, pid, HID_INTERFACE_ANY, page, HID_USAGE_ANY)
#define REGISTER_DYNAMIC_HID_DETECTOR_PU(name, func, vid, pid, page, usage) HIDDeviceDetector device_detector_obj_##vid##pid##__##page##_##usage(name, func, vid, pid, HID_INTERFACE_ANY, page, usage)
Loading…
Cancel
Save