Updates for QMK key code mapping

* Added QMKOpenRGBBaseController
* Refactored Rev9, RevB and RevD controllers to remove redundant code
* Updated "qmk_keycode_keyname_map" to add missing keycodes
* Resolves #3781
This commit is contained in:
Chris M
2023-12-20 18:30:34 +11:00
committed by Adam Honse
parent 6b4442ce39
commit b05f954d35
9 changed files with 563 additions and 1103 deletions

View File

@@ -0,0 +1,424 @@
/*---------------------------------------------------------*\
| QMKOpenRGBBaseController.cpp |
| |
| Base class for QMK keyboards using OpenRGB Protocol |
| |
| ChrisM 20th December 2023 |
\*---------------------------------------------------------*/
#include "LogManager.h"
#include "RGBControllerKeyNames.h"
#include "SettingsManager.h"
#include "QMKOpenRGBBaseController.h"
using namespace std::chrono_literals;
qmk_keycodes qmk_keycode_keyname_map =
{
{ 0, KEY_EN_UNUSED },
{ 1, KEY_EN_RIGHT_FUNCTION },
{ 2, KEY_EN_UNUSED },
{ 3, KEY_EN_UNUSED },
{ 4, KEY_EN_A },
{ 5, KEY_EN_B },
{ 6, KEY_EN_C },
{ 7, KEY_EN_D },
{ 8, KEY_EN_E },
{ 9, KEY_EN_F },
{ 10, KEY_EN_G },
{ 11, KEY_EN_H },
{ 12, KEY_EN_I },
{ 13, KEY_EN_J },
{ 14, KEY_EN_K },
{ 15, KEY_EN_L },
{ 16, KEY_EN_M },
{ 17, KEY_EN_N },
{ 18, KEY_EN_O },
{ 19, KEY_EN_P },
{ 20, KEY_EN_Q },
{ 21, KEY_EN_R },
{ 22, KEY_EN_S },
{ 23, KEY_EN_T },
{ 24, KEY_EN_U },
{ 25, KEY_EN_V },
{ 26, KEY_EN_W },
{ 27, KEY_EN_X },
{ 28, KEY_EN_Y },
{ 29, KEY_EN_Z },
{ 30, KEY_EN_1 },
{ 31, KEY_EN_2 },
{ 32, KEY_EN_3 },
{ 33, KEY_EN_4 },
{ 34, KEY_EN_5 },
{ 35, KEY_EN_6 },
{ 36, KEY_EN_7 },
{ 37, KEY_EN_8 },
{ 38, KEY_EN_9 },
{ 39, KEY_EN_0 },
{ 40, KEY_EN_ANSI_ENTER },
{ 41, KEY_EN_ESCAPE },
{ 42, KEY_EN_BACKSPACE },
{ 43, KEY_EN_TAB },
{ 44, KEY_EN_SPACE },
{ 45, KEY_EN_MINUS },
{ 46, KEY_EN_EQUALS },
{ 47, KEY_EN_LEFT_BRACKET },
{ 48, KEY_EN_RIGHT_BRACKET },
{ 49, KEY_EN_ANSI_BACK_SLASH },
{ 50, KEY_EN_POUND },
{ 51, KEY_EN_SEMICOLON },
{ 52, KEY_EN_QUOTE },
{ 53, KEY_EN_BACK_TICK },
{ 54, KEY_EN_COMMA },
{ 55, KEY_EN_PERIOD },
{ 56, KEY_EN_FORWARD_SLASH },
{ 57, KEY_EN_CAPS_LOCK },
{ 58, KEY_EN_F1 },
{ 59, KEY_EN_F2 },
{ 60, KEY_EN_F3 },
{ 61, KEY_EN_F4 },
{ 62, KEY_EN_F5 },
{ 63, KEY_EN_F6 },
{ 64, KEY_EN_F7 },
{ 65, KEY_EN_F8 },
{ 66, KEY_EN_F9 },
{ 67, KEY_EN_F10 },
{ 68, KEY_EN_F11 },
{ 69, KEY_EN_F12 },
{ 70, KEY_EN_PRINT_SCREEN },
{ 71, KEY_EN_SCROLL_LOCK },
{ 72, KEY_EN_PAUSE_BREAK },
{ 73, KEY_EN_INSERT },
{ 74, KEY_EN_HOME },
{ 75, KEY_EN_PAGE_UP },
{ 76, KEY_EN_DELETE },
{ 77, KEY_EN_END },
{ 78, KEY_EN_PAGE_DOWN },
{ 79, KEY_EN_RIGHT_ARROW },
{ 80, KEY_EN_LEFT_ARROW },
{ 81, KEY_EN_DOWN_ARROW },
{ 82, KEY_EN_UP_ARROW },
{ 83, KEY_EN_NUMPAD_LOCK },
{ 84, KEY_EN_NUMPAD_DIVIDE },
{ 85, KEY_EN_NUMPAD_TIMES },
{ 86, KEY_EN_NUMPAD_MINUS },
{ 87, KEY_EN_NUMPAD_PLUS },
{ 88, KEY_EN_NUMPAD_ENTER },
{ 89, KEY_EN_NUMPAD_1 },
{ 90, KEY_EN_NUMPAD_2 },
{ 91, KEY_EN_NUMPAD_3 },
{ 92, KEY_EN_NUMPAD_4 },
{ 93, KEY_EN_NUMPAD_5 },
{ 94, KEY_EN_NUMPAD_6 },
{ 95, KEY_EN_NUMPAD_7 },
{ 96, KEY_EN_NUMPAD_8 },
{ 97, KEY_EN_NUMPAD_9 },
{ 98, KEY_EN_NUMPAD_0 },
{ 99, KEY_EN_NUMPAD_PERIOD },
{ 100, KEY_EN_ISO_BACK_SLASH },
{ 101, KEY_EN_MENU },
{ 104, "Key: F13" },
{ 105, "Key: F14" },
{ 106, "Key: F15" },
{ 107, "Key: F16" },
{ 168, KEY_EN_MEDIA_MUTE },
{ 169, KEY_EN_MEDIA_VOLUME_UP },
{ 170, KEY_EN_MEDIA_VOLUME_DOWN },
{ 171, KEY_EN_MEDIA_NEXT },
{ 172, KEY_EN_MEDIA_PREVIOUS },
{ 173, KEY_EN_MEDIA_STOP },
{ 174, KEY_EN_MEDIA_PLAY_PAUSE },
{ 175, "Key: Media Select" },
{ 176, "Key: Media Eject" },
{ 189, "Key: Brightness Up" },
{ 190, "Key: Brightness Down" },
{ 196, "Key: Task Manager" },
{ 202, "Key: RGB Brightness Up" },
{ 203, "Key: RGB Brightness Down" },
{ 216, KEY_EN_LEFT_SHIFT }, /* Space Cadet Left Shift */
{ 217, KEY_EN_RIGHT_SHIFT }, /* Space Cadet Right Shift */
{ 224, KEY_EN_LEFT_CONTROL },
{ 225, KEY_EN_LEFT_SHIFT },
{ 226, KEY_EN_LEFT_ALT },
{ 227, KEY_EN_LEFT_WINDOWS },
{ 228, KEY_EN_RIGHT_CONTROL },
{ 229, KEY_EN_RIGHT_SHIFT },
{ 230, KEY_EN_RIGHT_ALT },
{ 231, KEY_EN_RIGHT_WINDOWS },
};
QMKOpenRGBBaseController::QMKOpenRGBBaseController(hid_device *dev_handle, const char *path, unsigned char max_led_count)
{
/*-------------------------------------------------*\
| Get QMKOpenRGB settings |
\*-------------------------------------------------*/
json qmk_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("QMKOpenRGBDevices");
if(qmk_settings.contains("leds_per_update"))
{
if(qmk_settings["leds_per_update"] > max_led_count)
{
qmk_settings["leds_per_update"] = max_led_count;
}
else if(qmk_settings["leds_per_update"] < 1)
{
qmk_settings["leds_per_update"] = 1;
}
SettingsManager* settings_manager = ResourceManager::get()->GetSettingsManager();
settings_manager->SetSettings("QMKOpenRGBDevices", qmk_settings);
settings_manager->SaveSettings();
leds_per_update = qmk_settings["leds_per_update"];
}
else
{
leds_per_update = max_led_count;
}
if(qmk_settings.contains("delay"))
{
delay = (unsigned int)qmk_settings["delay"] * 1ms;
}
else
{
delay = 0ms;
}
dev = dev_handle;
location = path;
GetDeviceInfo();
GetModeInfo();
}
QMKOpenRGBBaseController::~QMKOpenRGBBaseController()
{
hid_close(dev);
}
std::string QMKOpenRGBBaseController::GetLocation()
{
return location;
}
std::string QMKOpenRGBBaseController::GetDeviceName()
{
return device_name;
}
std::string QMKOpenRGBBaseController::GetDeviceVendor()
{
return device_vendor;
}
unsigned int QMKOpenRGBBaseController::GetTotalNumberOfLEDs()
{
return total_number_of_leds;
}
unsigned int QMKOpenRGBBaseController::GetTotalNumberOfLEDsWithEmptySpace()
{
return total_number_of_leds_with_empty_space;
}
unsigned int QMKOpenRGBBaseController::GetMode()
{
return mode;
}
unsigned int QMKOpenRGBBaseController::GetModeSpeed()
{
return mode_speed;
}
unsigned int QMKOpenRGBBaseController::GetModeColor()
{
return mode_color;
}
std::vector<point_t> QMKOpenRGBBaseController::GetLEDPoints()
{
return led_points;
}
std::vector<unsigned int> QMKOpenRGBBaseController::GetLEDFlags()
{
return led_flags;
}
std::vector<std::string> QMKOpenRGBBaseController::GetLEDNames()
{
return led_names;
}
std::vector<RGBColor> QMKOpenRGBBaseController::GetLEDColors()
{
return led_colors;
}
unsigned int QMKOpenRGBBaseController::GetProtocolVersion()
{
unsigned char usb_buf[QMK_OPENRGB_PACKET_SIZE];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, QMK_OPENRGB_PACKET_SIZE);
/*-----------------------------------------------------*\
| Set up config table request packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = QMK_OPENRGB_GET_PROTOCOL_VERSION;
int bytes_read = 0;
do
{
hid_write(dev, usb_buf, QMK_OPENRGB_PACKET_SIZE);
bytes_read = hid_read_timeout(dev, usb_buf, QMK_OPENRGB_PACKET_SIZE, QMK_OPENRGB_HID_READ_TIMEOUT);
} while(bytes_read <= 0);
return usb_buf[1];
}
std::string QMKOpenRGBBaseController::GetQMKVersion()
{
unsigned char usb_buf[QMK_OPENRGB_PACKET_SIZE];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, QMK_OPENRGB_PACKET_SIZE);
/*-----------------------------------------------------*\
| Set up config table request packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = QMK_OPENRGB_GET_QMK_VERSION;
hid_write(dev, usb_buf, QMK_OPENRGB_PACKET_SIZE);
hid_read(dev, usb_buf, QMK_OPENRGB_PACKET_SIZE);
std::string qmk_version;
int i = 1;
while (usb_buf[i] != 0)
{
qmk_version.push_back(usb_buf[i]);
i++;
}
return qmk_version;
}
void QMKOpenRGBBaseController::GetDeviceInfo()
{
unsigned char usb_buf[QMK_OPENRGB_PACKET_SIZE];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, QMK_OPENRGB_PACKET_SIZE);
/*-----------------------------------------------------*\
| Set up config table request packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = QMK_OPENRGB_GET_DEVICE_INFO;
int bytes_read = 0;
do
{
hid_write(dev, usb_buf, QMK_OPENRGB_PACKET_SIZE);
bytes_read = hid_read_timeout(dev, usb_buf, QMK_OPENRGB_PACKET_SIZE, QMK_OPENRGB_HID_READ_TIMEOUT);
} while(bytes_read <= 0);
total_number_of_leds = usb_buf[QMK_OPENRGB_TOTAL_NUMBER_OF_LEDS_BYTE];
total_number_of_leds_with_empty_space = usb_buf[QMK_OPENRGB_TOTAL_NUMBER_OF_LEDS_WITH_EMPTY_SPACE_BYTE];
int i = QMK_OPENRGB_TOTAL_NUMBER_OF_LEDS_WITH_EMPTY_SPACE_BYTE + 1;
while (usb_buf[i] != 0)
{
device_name.push_back(usb_buf[i]);
i++;
}
i++;
while (usb_buf[i] != 0)
{
device_vendor.push_back(usb_buf[i]);
i++;
}
}
void QMKOpenRGBBaseController::GetModeInfo()
{
unsigned char usb_buf[QMK_OPENRGB_PACKET_SIZE];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, QMK_OPENRGB_PACKET_SIZE);
/*-----------------------------------------------------*\
| Set up config table request packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = QMK_OPENRGB_GET_MODE_INFO;
int bytes_read = 0;
do
{
hid_write(dev, usb_buf, 65);
bytes_read = hid_read_timeout(dev, usb_buf, 65, QMK_OPENRGB_HID_READ_TIMEOUT);
} while(bytes_read <= 0);
mode = usb_buf[QMK_OPENRGB_MODE_BYTE];
mode_speed = usb_buf[QMK_OPENRGB_SPEED_BYTE];
/*-----------------------------------------------------*\
| QMK hue range is between 0-255 so hue needs to be |
| converted |
\*-----------------------------------------------------*/
unsigned int oldRange = 255;
unsigned int newRange = 359;
unsigned int convertedHue = (usb_buf[QMK_OPENRGB_HUE_BYTE] * newRange / oldRange);
hsv_t hsv;
hsv.hue = convertedHue;
hsv.saturation = usb_buf[QMK_OPENRGB_SATURATION_BYTE];
hsv.value = usb_buf[QMK_OPENRGB_VALUE_BYTE];
mode_color = hsv2rgb(&hsv);
}
void QMKOpenRGBBaseController::SetMode(hsv_t hsv_color, unsigned char mode, unsigned char speed)
{
SetMode(hsv_color, mode, speed, false);
}
void QMKOpenRGBBaseController::SetMode(hsv_t hsv_color, unsigned char mode, unsigned char speed, bool save)
{
unsigned char usb_buf[QMK_OPENRGB_PACKET_SIZE];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, QMK_OPENRGB_PACKET_SIZE);
/*-----------------------------------------------------*\
| Set up config table request packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = QMK_OPENRGB_SET_MODE;
usb_buf[0x02] = hsv_color.hue * 255 / 359;
usb_buf[0x03] = hsv_color.saturation;
usb_buf[0x04] = hsv_color.value;
usb_buf[0x05] = mode;
usb_buf[0x06] = speed;
usb_buf[0x07] = save;
/*-----------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------*/
hid_write(dev, usb_buf, 65);
hid_read_timeout(dev, usb_buf, 65, QMK_OPENRGB_HID_READ_TIMEOUT);
}

View File

@@ -0,0 +1,79 @@
/*---------------------------------------------------------*\
| QMKOpenRGBBaseController.cpp |
| |
| Base class for QMK keyboards using OpenRGB Protocol |
| |
| ChrisM 20th December 2023 |
\*---------------------------------------------------------*/
#pragma once
#include "LogManager.h"
#include "RGBController.h"
#include "RGBControllerKeyNames.h"
#include "SettingsManager.h"
#include "QMKOpenRGBController.h"
typedef std::map<uint8_t, std::string> qmk_keycodes;
extern qmk_keycodes qmk_keycode_keyname_map;
class QMKOpenRGBBaseController
{
public:
QMKOpenRGBBaseController(hid_device *dev_handle, const char *path, unsigned char max_led_count);
virtual ~QMKOpenRGBBaseController();
std::string GetLocation();
std::string GetDeviceName();
std::string GetDeviceVendor();
unsigned int GetTotalNumberOfLEDs();
unsigned int GetTotalNumberOfLEDsWithEmptySpace();
unsigned int GetMode();
unsigned int GetModeSpeed();
unsigned int GetModeColor();
std::vector<point_t> GetLEDPoints();
std::vector<unsigned int> GetLEDFlags();
std::vector<std::string> GetLEDNames();
std::vector<RGBColor> GetLEDColors();
unsigned int GetProtocolVersion();
std::string GetQMKVersion();
void GetDeviceInfo();
void GetModeInfo();
void SetMode(hsv_t hsv_color, unsigned char mode, unsigned char speed);
void SetMode(hsv_t hsv_color, unsigned char mode, unsigned char speed, bool save);
virtual void GetLEDInfo(unsigned int leds_count) = 0;
virtual void DirectModeSetSingleLED(unsigned int led, unsigned char red, unsigned char green, unsigned char blue) = 0;
virtual void DirectModeSetLEDs(std::vector<RGBColor> colors, unsigned int leds_count) = 0;
protected:
hid_device *dev;
unsigned int leds_per_update;
std::string location;
std::string device_name;
std::string device_vendor;
std::chrono::milliseconds delay;
unsigned int total_number_of_leds;
unsigned int total_number_of_leds_with_empty_space;
unsigned int mode;
unsigned int mode_speed;
RGBColor mode_color;
std::vector<point_t> led_points;
std::vector<unsigned int> led_flags;
std::vector<std::string> led_names;
std::vector<RGBColor> led_colors;
private:
};

View File

@@ -9,301 +9,17 @@
| Jath03 28th May 2021 |
\*-------------------------------------------------------------------*/
#include "RGBControllerKeyNames.h"
#include "QMKOpenRGBRev9Controller.h"
#include "SettingsManager.h"
using namespace std::chrono_literals;
static std::map<uint8_t, std::string> QMKKeycodeToKeynameMap
QMKOpenRGBRev9Controller::QMKOpenRGBRev9Controller(hid_device *dev_handle, const char *path) :
QMKOpenRGBBaseController(dev_handle, path, 20)
{
{ 0, KEY_EN_UNUSED }, { 1, KEY_EN_RIGHT_FUNCTION }, { 2, KEY_EN_UNUSED }, { 3, KEY_EN_UNUSED },
{ 4, KEY_EN_A }, { 5, KEY_EN_B }, { 6, KEY_EN_C }, { 7, KEY_EN_D },
{ 8, KEY_EN_E }, { 9, KEY_EN_F }, { 10, KEY_EN_G }, { 11, KEY_EN_H },
{ 12, KEY_EN_I }, { 13, KEY_EN_J }, { 14, KEY_EN_K }, { 15, KEY_EN_L },
{ 16, KEY_EN_M }, { 17, KEY_EN_N }, { 18, KEY_EN_O }, { 19, KEY_EN_P },
{ 20, KEY_EN_Q }, { 21, KEY_EN_R }, { 22, KEY_EN_S }, { 23, KEY_EN_T },
{ 24, KEY_EN_U }, { 25, KEY_EN_V }, { 26, KEY_EN_W }, { 27, KEY_EN_X },
{ 28, KEY_EN_Y }, { 29, KEY_EN_Z }, { 30, KEY_EN_1 }, { 31, KEY_EN_2 },
{ 32, KEY_EN_3 }, { 33, KEY_EN_4 }, { 34, KEY_EN_5 }, { 35, KEY_EN_6 },
{ 36, KEY_EN_7 }, { 37, KEY_EN_8 }, { 38, KEY_EN_9 }, { 39, KEY_EN_0 },
{ 40, KEY_EN_ANSI_ENTER }, { 41, KEY_EN_ESCAPE }, { 42, KEY_EN_BACKSPACE }, { 43, KEY_EN_TAB },
{ 44, KEY_EN_SPACE }, { 45, KEY_EN_MINUS }, { 46, KEY_EN_EQUALS }, { 47, KEY_EN_LEFT_BRACKET },
{ 48, KEY_EN_RIGHT_BRACKET }, { 49, KEY_EN_ANSI_BACK_SLASH }, { 50, KEY_EN_POUND }, { 51, KEY_EN_SEMICOLON },
{ 52, KEY_EN_QUOTE }, { 53, KEY_EN_BACK_TICK }, { 54, KEY_EN_COMMA }, { 55, KEY_EN_PERIOD },
{ 56, KEY_EN_FORWARD_SLASH }, { 57, KEY_EN_CAPS_LOCK }, { 58, KEY_EN_F1 }, { 59, KEY_EN_F2 },
{ 60, KEY_EN_F3 }, { 61, KEY_EN_F4 }, { 62, KEY_EN_F5 }, { 63, KEY_EN_F6 },
{ 64, KEY_EN_F7 }, { 65, KEY_EN_F8 }, { 66, KEY_EN_F9 }, { 67, KEY_EN_F10 },
{ 68, KEY_EN_F11 }, { 69, KEY_EN_F12 }, { 70, KEY_EN_PRINT_SCREEN }, { 71, KEY_EN_SCROLL_LOCK },
{ 72, KEY_EN_PAUSE_BREAK }, { 73, KEY_EN_INSERT }, { 74, KEY_EN_HOME }, { 75, KEY_EN_PAGE_UP },
{ 76, KEY_EN_DELETE }, { 77, KEY_EN_END }, { 78, KEY_EN_PAGE_DOWN }, { 79, KEY_EN_RIGHT_ARROW },
{ 80, KEY_EN_LEFT_ARROW }, { 81, KEY_EN_DOWN_ARROW }, { 82, KEY_EN_UP_ARROW }, { 83, KEY_EN_NUMPAD_LOCK },
{ 84, KEY_EN_NUMPAD_DIVIDE }, { 85, KEY_EN_NUMPAD_TIMES }, { 86, KEY_EN_NUMPAD_MINUS }, { 87, KEY_EN_NUMPAD_PLUS },
{ 88, KEY_EN_NUMPAD_ENTER }, { 89, KEY_EN_NUMPAD_1 }, { 90, KEY_EN_NUMPAD_2 }, { 91, KEY_EN_NUMPAD_3 },
{ 92, KEY_EN_NUMPAD_4 }, { 93, KEY_EN_NUMPAD_5 }, { 94, KEY_EN_NUMPAD_6 }, { 95, KEY_EN_NUMPAD_7 },
{ 96, KEY_EN_NUMPAD_8 }, { 97, KEY_EN_NUMPAD_9 }, { 98, KEY_EN_NUMPAD_0 }, { 99, KEY_EN_NUMPAD_PERIOD },
{ 100, KEY_EN_ISO_BACK_SLASH}, { 101, KEY_EN_MENU }, { 102, KEY_EN_UNUSED }, { 103, KEY_EN_UNUSED },
{ 104, KEY_EN_UNUSED }, { 105, KEY_EN_UNUSED }, { 106, KEY_EN_UNUSED }, { 107, KEY_EN_UNUSED },
{ 108, KEY_EN_UNUSED }, { 109, KEY_EN_UNUSED }, { 110, KEY_EN_UNUSED }, { 111, KEY_EN_UNUSED },
{ 112, KEY_EN_UNUSED }, { 113, KEY_EN_UNUSED }, { 114, KEY_EN_UNUSED }, { 115, KEY_EN_UNUSED },
{ 116, KEY_EN_UNUSED }, { 117, KEY_EN_UNUSED }, { 118, KEY_EN_UNUSED }, { 119, KEY_EN_UNUSED },
{ 120, KEY_EN_UNUSED }, { 121, KEY_EN_UNUSED }, { 122, KEY_EN_UNUSED }, { 123, KEY_EN_UNUSED },
{ 124, KEY_EN_UNUSED }, { 125, KEY_EN_UNUSED }, { 126, KEY_EN_UNUSED }, { 127, KEY_EN_UNUSED },
{ 128, KEY_EN_UNUSED }, { 129, KEY_EN_UNUSED }, { 130, KEY_EN_UNUSED }, { 131, KEY_EN_UNUSED },
{ 132, KEY_EN_UNUSED }, { 133, KEY_EN_UNUSED }, { 134, KEY_EN_UNUSED }, { 135, KEY_EN_UNUSED },
{ 136, KEY_EN_UNUSED }, { 137, KEY_EN_UNUSED }, { 138, KEY_EN_UNUSED }, { 139, KEY_EN_UNUSED },
{ 140, KEY_EN_UNUSED }, { 141, KEY_EN_UNUSED }, { 142, KEY_EN_UNUSED }, { 143, KEY_EN_UNUSED },
{ 144, KEY_EN_UNUSED }, { 145, KEY_EN_UNUSED }, { 146, KEY_EN_UNUSED }, { 147, KEY_EN_UNUSED },
{ 148, KEY_EN_UNUSED }, { 149, KEY_EN_UNUSED }, { 150, KEY_EN_UNUSED }, { 151, KEY_EN_UNUSED },
{ 152, KEY_EN_UNUSED }, { 153, KEY_EN_UNUSED }, { 154, KEY_EN_UNUSED }, { 155, KEY_EN_UNUSED },
{ 156, KEY_EN_UNUSED }, { 157, KEY_EN_UNUSED }, { 158, KEY_EN_UNUSED }, { 159, KEY_EN_UNUSED },
{ 160, KEY_EN_UNUSED }, { 161, KEY_EN_UNUSED }, { 162, KEY_EN_UNUSED }, { 163, KEY_EN_UNUSED },
{ 164, KEY_EN_UNUSED },
/*Space Cadet Left Shift*/ { 216, KEY_EN_LEFT_SHIFT }, /*Space Cadet Right Shift*/ { 217, KEY_EN_RIGHT_SHIFT },
{ 224, KEY_EN_LEFT_CONTROL }, { 225, KEY_EN_LEFT_SHIFT }, { 226, KEY_EN_LEFT_ALT }, { 227, KEY_EN_LEFT_WINDOWS },
{ 228, KEY_EN_RIGHT_CONTROL }, { 229, KEY_EN_RIGHT_SHIFT }, { 230, KEY_EN_RIGHT_ALT }, { 231, KEY_EN_RIGHT_WINDOWS },
};
QMKOpenRGBRev9Controller::QMKOpenRGBRev9Controller(hid_device *dev_handle, const char *path)
{
/*-------------------------------------------------*\
| Get QMKOpenRGB settings |
\*-------------------------------------------------*/
json qmk_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("QMKOpenRGBDevices");
if(qmk_settings.contains("leds_per_update"))
{
if(qmk_settings["leds_per_update"] > 20)
{
qmk_settings["leds_per_update"] = 20;
}
else if(qmk_settings["leds_per_update"] < 1)
{
qmk_settings["leds_per_update"] = 1;
}
SettingsManager* settings_manager = ResourceManager::get()->GetSettingsManager();
settings_manager->SetSettings("QMKOpenRGBDevices", qmk_settings);
settings_manager->SaveSettings();
leds_per_update = qmk_settings["leds_per_update"];
}
else
{
leds_per_update = 20;
}
if(qmk_settings.contains("delay"))
{
delay = (unsigned int)qmk_settings["delay"] * 1ms;
}
else
{
delay = 0ms;
}
dev = dev_handle;
location = path;
GetDeviceInfo();
GetModeInfo();
}
QMKOpenRGBRev9Controller::~QMKOpenRGBRev9Controller()
{
hid_close(dev);
}
std::string QMKOpenRGBRev9Controller::GetLocation()
{
return location;
}
std::string QMKOpenRGBRev9Controller::GetDeviceName()
{
return device_name;
}
std::string QMKOpenRGBRev9Controller::GetDeviceVendor()
{
return device_vendor;
}
unsigned int QMKOpenRGBRev9Controller::GetTotalNumberOfLEDs()
{
return total_number_of_leds;
}
unsigned int QMKOpenRGBRev9Controller::GetTotalNumberOfLEDsWithEmptySpace()
{
return total_number_of_leds_with_empty_space;
}
unsigned int QMKOpenRGBRev9Controller::GetMode()
{
return mode;
}
unsigned int QMKOpenRGBRev9Controller::GetModeSpeed()
{
return mode_speed;
}
unsigned int QMKOpenRGBRev9Controller::GetModeColor()
{
return mode_color;
}
std::vector<point_t> QMKOpenRGBRev9Controller::GetLEDPoints()
{
return led_points;
}
std::vector<unsigned int> QMKOpenRGBRev9Controller::GetLEDFlags()
{
return led_flags;
}
std::vector<std::string> QMKOpenRGBRev9Controller::GetLEDNames()
{
return led_names;
}
std::vector<RGBColor> QMKOpenRGBRev9Controller::GetLEDColors()
{
return led_colors;
}
unsigned int QMKOpenRGBRev9Controller::GetProtocolVersion()
{
unsigned char usb_buf[QMK_OPENRGB_PACKET_SIZE];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, QMK_OPENRGB_PACKET_SIZE);
/*-----------------------------------------------------*\
| Set up config table request packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = QMK_OPENRGB_GET_PROTOCOL_VERSION;
int bytes_read = 0;
do
{
hid_write(dev, usb_buf, QMK_OPENRGB_PACKET_SIZE);
bytes_read = hid_read_timeout(dev, usb_buf, QMK_OPENRGB_PACKET_SIZE, QMK_OPENRGB_HID_READ_TIMEOUT);
} while(bytes_read <= 0);
return usb_buf[1];
}
std::string QMKOpenRGBRev9Controller::GetQMKVersion()
{
unsigned char usb_buf[QMK_OPENRGB_PACKET_SIZE];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, QMK_OPENRGB_PACKET_SIZE);
/*-----------------------------------------------------*\
| Set up config table request packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = QMK_OPENRGB_GET_QMK_VERSION;
hid_write(dev, usb_buf, QMK_OPENRGB_PACKET_SIZE);
hid_read(dev, usb_buf, QMK_OPENRGB_PACKET_SIZE);
std::string qmk_version;
int i = 1;
while (usb_buf[i] != 0)
{
qmk_version.push_back(usb_buf[i]);
i++;
}
return qmk_version;
}
void QMKOpenRGBRev9Controller::GetDeviceInfo()
{
unsigned char usb_buf[QMK_OPENRGB_PACKET_SIZE];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, QMK_OPENRGB_PACKET_SIZE);
/*-----------------------------------------------------*\
| Set up config table request packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = QMK_OPENRGB_GET_DEVICE_INFO;
int bytes_read = 0;
do
{
hid_write(dev, usb_buf, QMK_OPENRGB_PACKET_SIZE);
bytes_read = hid_read_timeout(dev, usb_buf, QMK_OPENRGB_PACKET_SIZE, QMK_OPENRGB_HID_READ_TIMEOUT);
} while(bytes_read <= 0);
total_number_of_leds = usb_buf[QMK_OPENRGB_TOTAL_NUMBER_OF_LEDS_BYTE];
total_number_of_leds_with_empty_space = usb_buf[QMK_OPENRGB_TOTAL_NUMBER_OF_LEDS_WITH_EMPTY_SPACE_BYTE];
int i = QMK_OPENRGB_TOTAL_NUMBER_OF_LEDS_WITH_EMPTY_SPACE_BYTE + 1;
while (usb_buf[i] != 0)
{
device_name.push_back(usb_buf[i]);
i++;
}
i++;
while (usb_buf[i] != 0)
{
device_vendor.push_back(usb_buf[i]);
i++;
}
}
void QMKOpenRGBRev9Controller::GetModeInfo()
{
unsigned char usb_buf[QMK_OPENRGB_PACKET_SIZE];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, QMK_OPENRGB_PACKET_SIZE);
/*-----------------------------------------------------*\
| Set up config table request packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = QMK_OPENRGB_GET_MODE_INFO;
int bytes_read = 0;
do
{
hid_write(dev, usb_buf, 65);
bytes_read = hid_read_timeout(dev, usb_buf, 65, QMK_OPENRGB_HID_READ_TIMEOUT);
} while(bytes_read <= 0);
mode = usb_buf[QMK_OPENRGB_MODE_BYTE];
mode_speed = usb_buf[QMK_OPENRGB_SPEED_BYTE];
/*-----------------------------------------------------*\
| QMK hue range is between 0-255 so hue needs to be |
| converted |
\*-----------------------------------------------------*/
unsigned int oldRange = 255;
unsigned int newRange = 359;
unsigned int convertedHue = (usb_buf[QMK_OPENRGB_HUE_BYTE] * newRange / oldRange);
hsv_t hsv;
hsv.hue = convertedHue;
hsv.saturation = usb_buf[QMK_OPENRGB_SATURATION_BYTE];
hsv.value = usb_buf[QMK_OPENRGB_VALUE_BYTE];
mode_color = hsv2rgb(&hsv);
}
void QMKOpenRGBRev9Controller::GetLEDInfo(unsigned int led)
@@ -338,12 +54,15 @@ void QMKOpenRGBRev9Controller::GetLEDInfo(unsigned int led)
if(usb_buf[QMK_OPENRGB_KEYCODE_BYTE] != 0)
{
if (QMKKeycodeToKeynameMap.count(usb_buf[QMK_OPENRGB_KEYCODE_BYTE]) > 0)
if (qmk_keycode_keyname_map.count(usb_buf[QMK_OPENRGB_KEYCODE_BYTE]) > 0)
{
led_names.push_back(QMKKeycodeToKeynameMap[usb_buf[QMK_OPENRGB_KEYCODE_BYTE]]);
led_names.push_back(qmk_keycode_keyname_map[usb_buf[QMK_OPENRGB_KEYCODE_BYTE]]);
}
else
{
LOG_DEBUG("[%s] Key code: %d (%02X) @ offset %d was not found in the QMK keyname map",
device_name.c_str(), usb_buf[QMK_OPENRGB_KEYCODE_BYTE],
usb_buf[QMK_OPENRGB_KEYCODE_BYTE], led);
led_names.push_back(KEY_EN_UNUSED);
}
}
@@ -375,33 +94,6 @@ bool QMKOpenRGBRev9Controller::GetIsModeEnabled(unsigned int mode)
return usb_buf[1] == QMK_OPENRGB_SUCCESS ? true : false;
}
void QMKOpenRGBRev9Controller::SetMode(hsv_t hsv_color, unsigned char mode, unsigned char speed)
{
unsigned char usb_buf[QMK_OPENRGB_PACKET_SIZE];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, QMK_OPENRGB_PACKET_SIZE);
/*-----------------------------------------------------*\
| Set up config table request packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = QMK_OPENRGB_SET_MODE;
usb_buf[0x02] = hsv_color.hue * 255 / 359;
usb_buf[0x03] = hsv_color.saturation;
usb_buf[0x04] = hsv_color.value;
usb_buf[0x05] = mode;
usb_buf[0x06] = speed;
/*-----------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------*/
hid_write(dev, usb_buf, 65);
hid_read_timeout(dev, usb_buf, 65, QMK_OPENRGB_HID_READ_TIMEOUT);
}
void QMKOpenRGBRev9Controller::DirectModeSetSingleLED(unsigned int led, unsigned char red, unsigned char green, unsigned char blue)
{
unsigned char usb_buf[QMK_OPENRGB_PACKET_SIZE];

View File

@@ -11,62 +11,21 @@
#pragma once
#include "QMKOpenRGBController.h"
#include "QMKOpenRGBBaseController.h"
class QMKOpenRGBRev9Controller
class QMKOpenRGBRev9Controller : public QMKOpenRGBBaseController
{
public:
QMKOpenRGBRev9Controller(hid_device *dev_handle, const char *path);
~QMKOpenRGBRev9Controller();
std::string GetLocation();
std::string GetDeviceName();
std::string GetDeviceVendor();
unsigned int GetTotalNumberOfLEDs();
unsigned int GetTotalNumberOfLEDsWithEmptySpace();
unsigned int GetMode();
unsigned int GetModeSpeed();
unsigned int GetModeColor();
std::vector<point_t> GetLEDPoints();
std::vector<unsigned int> GetLEDFlags();
std::vector<std::string> GetLEDNames();
std::vector<RGBColor> GetLEDColors();
unsigned int GetProtocolVersion();
std::string GetQMKVersion();
void GetDeviceInfo();
void GetModeInfo();
//Virtual function implementations
void GetLEDInfo(unsigned int led);
bool GetIsModeEnabled(unsigned int mode);
void SetMode(hsv_t hsv_color, unsigned char mode, unsigned char speed);
void DirectModeSetSingleLED(unsigned int led, unsigned char red, unsigned char green, unsigned char blue);
void DirectModeSetLEDs(std::vector<RGBColor> colors, unsigned int num_colors);
protected:
hid_device *dev;
//Protocol Specific functions
bool GetIsModeEnabled(unsigned int mode);
private:
unsigned int leds_per_update;
std::string location;
std::string device_name;
std::string device_vendor;
std::chrono::milliseconds delay;
unsigned int total_number_of_leds;
unsigned int total_number_of_leds_with_empty_space;
unsigned int mode;
unsigned int mode_speed;
RGBColor mode_color;
std::vector<point_t> led_points;
std::vector<unsigned int> led_flags;
std::vector<std::string> led_names;
std::vector<RGBColor> led_colors;
};

View File

@@ -7,301 +7,17 @@
| Jath03 28th May 2021 |
\*-------------------------------------------------------------------*/
#include "RGBControllerKeyNames.h"
#include "QMKOpenRGBRevBController.h"
#include "SettingsManager.h"
using namespace std::chrono_literals;
static std::map<uint8_t, std::string> QMKKeycodeToKeynameMap
QMKOpenRGBRevBController::QMKOpenRGBRevBController(hid_device *dev_handle, const char *path) :
QMKOpenRGBBaseController(dev_handle, path, 20)
{
{ 0, KEY_EN_UNUSED }, { 1, KEY_EN_RIGHT_FUNCTION }, { 2, KEY_EN_UNUSED }, { 3, KEY_EN_UNUSED },
{ 4, KEY_EN_A }, { 5, KEY_EN_B }, { 6, KEY_EN_C }, { 7, KEY_EN_D },
{ 8, KEY_EN_E }, { 9, KEY_EN_F }, { 10, KEY_EN_G }, { 11, KEY_EN_H },
{ 12, KEY_EN_I }, { 13, KEY_EN_J }, { 14, KEY_EN_K }, { 15, KEY_EN_L },
{ 16, KEY_EN_M }, { 17, KEY_EN_N }, { 18, KEY_EN_O }, { 19, KEY_EN_P },
{ 20, KEY_EN_Q }, { 21, KEY_EN_R }, { 22, KEY_EN_S }, { 23, KEY_EN_T },
{ 24, KEY_EN_U }, { 25, KEY_EN_V }, { 26, KEY_EN_W }, { 27, KEY_EN_X },
{ 28, KEY_EN_Y }, { 29, KEY_EN_Z }, { 30, KEY_EN_1 }, { 31, KEY_EN_2 },
{ 32, KEY_EN_3 }, { 33, KEY_EN_4 }, { 34, KEY_EN_5 }, { 35, KEY_EN_6 },
{ 36, KEY_EN_7 }, { 37, KEY_EN_8 }, { 38, KEY_EN_9 }, { 39, KEY_EN_0 },
{ 40, KEY_EN_ANSI_ENTER }, { 41, KEY_EN_ESCAPE }, { 42, KEY_EN_BACKSPACE }, { 43, KEY_EN_TAB },
{ 44, KEY_EN_SPACE }, { 45, KEY_EN_MINUS }, { 46, KEY_EN_EQUALS }, { 47, KEY_EN_LEFT_BRACKET },
{ 48, KEY_EN_RIGHT_BRACKET }, { 49, KEY_EN_ANSI_BACK_SLASH }, { 50, KEY_EN_POUND }, { 51, KEY_EN_SEMICOLON },
{ 52, KEY_EN_QUOTE }, { 53, KEY_EN_BACK_TICK }, { 54, KEY_EN_COMMA }, { 55, KEY_EN_PERIOD },
{ 56, KEY_EN_FORWARD_SLASH }, { 57, KEY_EN_CAPS_LOCK }, { 58, KEY_EN_F1 }, { 59, KEY_EN_F2 },
{ 60, KEY_EN_F3 }, { 61, KEY_EN_F4 }, { 62, KEY_EN_F5 }, { 63, KEY_EN_F6 },
{ 64, KEY_EN_F7 }, { 65, KEY_EN_F8 }, { 66, KEY_EN_F9 }, { 67, KEY_EN_F10 },
{ 68, KEY_EN_F11 }, { 69, KEY_EN_F12 }, { 70, KEY_EN_PRINT_SCREEN }, { 71, KEY_EN_SCROLL_LOCK },
{ 72, KEY_EN_PAUSE_BREAK }, { 73, KEY_EN_INSERT }, { 74, KEY_EN_HOME }, { 75, KEY_EN_PAGE_UP },
{ 76, KEY_EN_DELETE }, { 77, KEY_EN_END }, { 78, KEY_EN_PAGE_DOWN }, { 79, KEY_EN_RIGHT_ARROW },
{ 80, KEY_EN_LEFT_ARROW }, { 81, KEY_EN_DOWN_ARROW }, { 82, KEY_EN_UP_ARROW }, { 83, KEY_EN_NUMPAD_LOCK },
{ 84, KEY_EN_NUMPAD_DIVIDE }, { 85, KEY_EN_NUMPAD_TIMES }, { 86, KEY_EN_NUMPAD_MINUS }, { 87, KEY_EN_NUMPAD_PLUS },
{ 88, KEY_EN_NUMPAD_ENTER }, { 89, KEY_EN_NUMPAD_1 }, { 90, KEY_EN_NUMPAD_2 }, { 91, KEY_EN_NUMPAD_3 },
{ 92, KEY_EN_NUMPAD_4 }, { 93, KEY_EN_NUMPAD_5 }, { 94, KEY_EN_NUMPAD_6 }, { 95, KEY_EN_NUMPAD_7 },
{ 96, KEY_EN_NUMPAD_8 }, { 97, KEY_EN_NUMPAD_9 }, { 98, KEY_EN_NUMPAD_0 }, { 99, KEY_EN_NUMPAD_PERIOD },
{ 100, KEY_EN_ISO_BACK_SLASH}, { 101, KEY_EN_MENU }, { 102, KEY_EN_UNUSED }, { 103, KEY_EN_UNUSED },
{ 104, KEY_EN_UNUSED }, { 105, KEY_EN_UNUSED }, { 106, KEY_EN_UNUSED }, { 107, KEY_EN_UNUSED },
{ 108, KEY_EN_UNUSED }, { 109, KEY_EN_UNUSED }, { 110, KEY_EN_UNUSED }, { 111, KEY_EN_UNUSED },
{ 112, KEY_EN_UNUSED }, { 113, KEY_EN_UNUSED }, { 114, KEY_EN_UNUSED }, { 115, KEY_EN_UNUSED },
{ 116, KEY_EN_UNUSED }, { 117, KEY_EN_UNUSED }, { 118, KEY_EN_UNUSED }, { 119, KEY_EN_UNUSED },
{ 120, KEY_EN_UNUSED }, { 121, KEY_EN_UNUSED }, { 122, KEY_EN_UNUSED }, { 123, KEY_EN_UNUSED },
{ 124, KEY_EN_UNUSED }, { 125, KEY_EN_UNUSED }, { 126, KEY_EN_UNUSED }, { 127, KEY_EN_UNUSED },
{ 128, KEY_EN_UNUSED }, { 129, KEY_EN_UNUSED }, { 130, KEY_EN_UNUSED }, { 131, KEY_EN_UNUSED },
{ 132, KEY_EN_UNUSED }, { 133, KEY_EN_UNUSED }, { 134, KEY_EN_UNUSED }, { 135, KEY_EN_UNUSED },
{ 136, KEY_EN_UNUSED }, { 137, KEY_EN_UNUSED }, { 138, KEY_EN_UNUSED }, { 139, KEY_EN_UNUSED },
{ 140, KEY_EN_UNUSED }, { 141, KEY_EN_UNUSED }, { 142, KEY_EN_UNUSED }, { 143, KEY_EN_UNUSED },
{ 144, KEY_EN_UNUSED }, { 145, KEY_EN_UNUSED }, { 146, KEY_EN_UNUSED }, { 147, KEY_EN_UNUSED },
{ 148, KEY_EN_UNUSED }, { 149, KEY_EN_UNUSED }, { 150, KEY_EN_UNUSED }, { 151, KEY_EN_UNUSED },
{ 152, KEY_EN_UNUSED }, { 153, KEY_EN_UNUSED }, { 154, KEY_EN_UNUSED }, { 155, KEY_EN_UNUSED },
{ 156, KEY_EN_UNUSED }, { 157, KEY_EN_UNUSED }, { 158, KEY_EN_UNUSED }, { 159, KEY_EN_UNUSED },
{ 160, KEY_EN_UNUSED }, { 161, KEY_EN_UNUSED }, { 162, KEY_EN_UNUSED }, { 163, KEY_EN_UNUSED },
{ 164, KEY_EN_UNUSED },
/*Space Cadet Left Shift*/ { 216, KEY_EN_LEFT_SHIFT }, /*Space Cadet Right Shift*/ { 217, KEY_EN_RIGHT_SHIFT },
{ 224, KEY_EN_LEFT_CONTROL }, { 225, KEY_EN_LEFT_SHIFT }, { 226, KEY_EN_LEFT_ALT }, { 227, KEY_EN_LEFT_WINDOWS },
{ 228, KEY_EN_RIGHT_CONTROL }, { 229, KEY_EN_RIGHT_SHIFT }, { 230, KEY_EN_RIGHT_ALT }, { 231, KEY_EN_RIGHT_WINDOWS },
};
QMKOpenRGBRevBController::QMKOpenRGBRevBController(hid_device *dev_handle, const char *path)
{
/*-------------------------------------------------*\
| Get QMKOpenRGB settings |
\*-------------------------------------------------*/
json qmk_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("QMKOpenRGBDevices");
if(qmk_settings.contains("leds_per_update"))
{
if(qmk_settings["leds_per_update"] > 20)
{
qmk_settings["leds_per_update"] = 20;
}
else if(qmk_settings["leds_per_update"] < 1)
{
qmk_settings["leds_per_update"] = 1;
}
SettingsManager* settings_manager = ResourceManager::get()->GetSettingsManager();
settings_manager->SetSettings("QMKOpenRGBDevices", qmk_settings);
settings_manager->SaveSettings();
leds_per_update = qmk_settings["leds_per_update"];
}
else
{
leds_per_update = 20;
}
if(qmk_settings.contains("delay"))
{
delay = (unsigned int)qmk_settings["delay"] * 1ms;
}
else
{
delay = 0ms;
}
dev = dev_handle;
location = path;
GetDeviceInfo();
GetModeInfo();
}
QMKOpenRGBRevBController::~QMKOpenRGBRevBController()
{
hid_close(dev);
}
std::string QMKOpenRGBRevBController::GetLocation()
{
return location;
}
std::string QMKOpenRGBRevBController::GetDeviceName()
{
return device_name;
}
std::string QMKOpenRGBRevBController::GetDeviceVendor()
{
return device_vendor;
}
unsigned int QMKOpenRGBRevBController::GetTotalNumberOfLEDs()
{
return total_number_of_leds;
}
unsigned int QMKOpenRGBRevBController::GetTotalNumberOfLEDsWithEmptySpace()
{
return total_number_of_leds_with_empty_space;
}
unsigned int QMKOpenRGBRevBController::GetMode()
{
return mode;
}
unsigned int QMKOpenRGBRevBController::GetModeSpeed()
{
return mode_speed;
}
unsigned int QMKOpenRGBRevBController::GetModeColor()
{
return mode_color;
}
std::vector<point_t> QMKOpenRGBRevBController::GetLEDPoints()
{
return led_points;
}
std::vector<unsigned int> QMKOpenRGBRevBController::GetLEDFlags()
{
return led_flags;
}
std::vector<std::string> QMKOpenRGBRevBController::GetLEDNames()
{
return led_names;
}
std::vector<RGBColor> QMKOpenRGBRevBController::GetLEDColors()
{
return led_colors;
}
unsigned int QMKOpenRGBRevBController::GetProtocolVersion()
{
unsigned char usb_buf[QMK_OPENRGB_PACKET_SIZE];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, QMK_OPENRGB_PACKET_SIZE);
/*-----------------------------------------------------*\
| Set up config table request packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = QMK_OPENRGB_GET_PROTOCOL_VERSION;
int bytes_read = 0;
do
{
hid_write(dev, usb_buf, QMK_OPENRGB_PACKET_SIZE);
bytes_read = hid_read_timeout(dev, usb_buf, QMK_OPENRGB_PACKET_SIZE, QMK_OPENRGB_HID_READ_TIMEOUT);
} while(bytes_read <= 0);
return usb_buf[1];
}
std::string QMKOpenRGBRevBController::GetQMKVersion()
{
unsigned char usb_buf[QMK_OPENRGB_PACKET_SIZE];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, QMK_OPENRGB_PACKET_SIZE);
/*-----------------------------------------------------*\
| Set up config table request packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = QMK_OPENRGB_GET_QMK_VERSION;
hid_write(dev, usb_buf, QMK_OPENRGB_PACKET_SIZE);
hid_read(dev, usb_buf, QMK_OPENRGB_PACKET_SIZE);
std::string qmk_version;
int i = 1;
while (usb_buf[i] != 0)
{
qmk_version.push_back(usb_buf[i]);
i++;
}
return qmk_version;
}
void QMKOpenRGBRevBController::GetDeviceInfo()
{
unsigned char usb_buf[QMK_OPENRGB_PACKET_SIZE];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, QMK_OPENRGB_PACKET_SIZE);
/*-----------------------------------------------------*\
| Set up config table request packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = QMK_OPENRGB_GET_DEVICE_INFO;
int bytes_read = 0;
do
{
hid_write(dev, usb_buf, QMK_OPENRGB_PACKET_SIZE);
bytes_read = hid_read_timeout(dev, usb_buf, QMK_OPENRGB_PACKET_SIZE, QMK_OPENRGB_HID_READ_TIMEOUT);
} while(bytes_read <= 0);
total_number_of_leds = usb_buf[QMK_OPENRGB_TOTAL_NUMBER_OF_LEDS_BYTE];
total_number_of_leds_with_empty_space = usb_buf[QMK_OPENRGB_TOTAL_NUMBER_OF_LEDS_WITH_EMPTY_SPACE_BYTE];
int i = QMK_OPENRGB_TOTAL_NUMBER_OF_LEDS_WITH_EMPTY_SPACE_BYTE + 1;
while (usb_buf[i] != 0)
{
device_name.push_back(usb_buf[i]);
i++;
}
i++;
while (usb_buf[i] != 0)
{
device_vendor.push_back(usb_buf[i]);
i++;
}
}
void QMKOpenRGBRevBController::GetModeInfo()
{
unsigned char usb_buf[QMK_OPENRGB_PACKET_SIZE];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, QMK_OPENRGB_PACKET_SIZE);
/*-----------------------------------------------------*\
| Set up config table request packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = QMK_OPENRGB_GET_MODE_INFO;
int bytes_read = 0;
do
{
hid_write(dev, usb_buf, 65);
bytes_read = hid_read_timeout(dev, usb_buf, 65, QMK_OPENRGB_HID_READ_TIMEOUT);
} while(bytes_read <= 0);
mode = usb_buf[QMK_OPENRGB_MODE_BYTE];
mode_speed = usb_buf[QMK_OPENRGB_SPEED_BYTE];
/*-----------------------------------------------------*\
| QMK hue range is between 0-255 so hue needs to be |
| converted |
\*-----------------------------------------------------*/
unsigned int oldRange = 255;
unsigned int newRange = 359;
unsigned int convertedHue = (usb_buf[QMK_OPENRGB_HUE_BYTE] * newRange / oldRange);
hsv_t hsv;
hsv.hue = convertedHue;
hsv.saturation = usb_buf[QMK_OPENRGB_SATURATION_BYTE];
hsv.value = usb_buf[QMK_OPENRGB_VALUE_BYTE];
mode_color = hsv2rgb(&hsv);
}
void QMKOpenRGBRevBController::GetLEDInfo(unsigned int leds_count)
@@ -340,21 +56,26 @@ void QMKOpenRGBRevBController::GetLEDInfo(unsigned int leds_count)
for (unsigned int led_idx = 0; led_idx < leds_per_update_info; led_idx++)
{
if(usb_buf[(led_idx * 7) + QMK_OPENRGB_FLAG_BYTE] != QMK_OPENRGB_FAILURE)
unsigned int offset = offset;
if(usb_buf[(offset) + QMK_OPENRGB_FLAG_BYTE] != QMK_OPENRGB_FAILURE)
{
led_points.push_back(point_t{usb_buf[(led_idx * 7) + QMK_OPENRGB_POINT_X_BYTE], usb_buf[(led_idx * 7) + QMK_OPENRGB_POINT_Y_BYTE]});
led_flags.push_back(usb_buf[(led_idx * 7) + QMK_OPENRGB_FLAG_BYTE]);
led_colors.push_back(ToRGBColor(usb_buf[(led_idx * 7) + QMK_OPENRGB_R_COLOR_BYTE], usb_buf[(led_idx * 7) + QMK_OPENRGB_G_COLOR_BYTE], usb_buf[(led_idx * 7) + QMK_OPENRGB_B_COLOR_BYTE]));
led_points.push_back(point_t{usb_buf[(offset) + QMK_OPENRGB_POINT_X_BYTE], usb_buf[(offset) + QMK_OPENRGB_POINT_Y_BYTE]});
led_flags.push_back(usb_buf[(offset) + QMK_OPENRGB_FLAG_BYTE]);
led_colors.push_back(ToRGBColor(usb_buf[(offset) + QMK_OPENRGB_R_COLOR_BYTE], usb_buf[(offset) + QMK_OPENRGB_G_COLOR_BYTE], usb_buf[(offset) + QMK_OPENRGB_B_COLOR_BYTE]));
}
if(usb_buf[(led_idx * 7) + QMK_OPENRGB_KEYCODE_BYTE] != 0)
if(usb_buf[(offset) + QMK_OPENRGB_KEYCODE_BYTE] != 0)
{
if (QMKKeycodeToKeynameMap.count(usb_buf[(led_idx * 7) + QMK_OPENRGB_KEYCODE_BYTE]) > 0)
if (qmk_keycode_keyname_map.count(usb_buf[(offset) + QMK_OPENRGB_KEYCODE_BYTE]) > 0)
{
led_names.push_back(QMKKeycodeToKeynameMap[usb_buf[(led_idx * 7) + QMK_OPENRGB_KEYCODE_BYTE]]);
led_names.push_back(qmk_keycode_keyname_map[usb_buf[(offset) + QMK_OPENRGB_KEYCODE_BYTE]]);
}
else
{
LOG_DEBUG("[%s] Key code: %d (%02X) @ offset %d was not found in the QMK keyname map",
device_name.c_str(), usb_buf[offset + QMK_OPENRGB_KEYCODE_BYTE],
usb_buf[offset + QMK_OPENRGB_KEYCODE_BYTE], leds_sent + led_idx);
led_names.push_back(KEY_EN_UNUSED);
}
}
@@ -396,34 +117,6 @@ std::vector<unsigned int> QMKOpenRGBRevBController::GetEnabledModes()
return enabled_modes;
}
void QMKOpenRGBRevBController::SetMode(hsv_t hsv_color, unsigned char mode, unsigned char speed, bool save)
{
unsigned char usb_buf[QMK_OPENRGB_PACKET_SIZE];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, QMK_OPENRGB_PACKET_SIZE);
/*-----------------------------------------------------*\
| Set up config table request packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = QMK_OPENRGB_SET_MODE;
usb_buf[0x02] = hsv_color.hue * 255 / 359;
usb_buf[0x03] = hsv_color.saturation;
usb_buf[0x04] = hsv_color.value;
usb_buf[0x05] = mode;
usb_buf[0x06] = speed;
usb_buf[0x07] = save;
/*-----------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------*/
hid_write(dev, usb_buf, 65);
hid_read_timeout(dev, usb_buf, 65, QMK_OPENRGB_HID_READ_TIMEOUT);
}
void QMKOpenRGBRevBController::DirectModeSetSingleLED(unsigned int led, unsigned char red, unsigned char green, unsigned char blue)
{
unsigned char usb_buf[QMK_OPENRGB_PACKET_SIZE];

View File

@@ -9,62 +9,21 @@
#pragma once
#include "QMKOpenRGBController.h"
#include "QMKOpenRGBBaseController.h"
class QMKOpenRGBRevBController
class QMKOpenRGBRevBController : public QMKOpenRGBBaseController
{
public:
QMKOpenRGBRevBController(hid_device *dev_handle, const char *path);
~QMKOpenRGBRevBController();
std::string GetLocation();
std::string GetDeviceName();
std::string GetDeviceVendor();
unsigned int GetTotalNumberOfLEDs();
unsigned int GetTotalNumberOfLEDsWithEmptySpace();
unsigned int GetMode();
unsigned int GetModeSpeed();
unsigned int GetModeColor();
std::vector<point_t> GetLEDPoints();
std::vector<unsigned int> GetLEDFlags();
std::vector<std::string> GetLEDNames();
std::vector<RGBColor> GetLEDColors();
unsigned int GetProtocolVersion();
std::string GetQMKVersion();
void GetDeviceInfo();
void GetModeInfo();
void GetLEDInfo(unsigned int leds_count);
std::vector<unsigned int> GetEnabledModes();
void SetMode(hsv_t hsv_color, unsigned char mode, unsigned char speed, bool save);
//Virtual function implementations
void GetLEDInfo(unsigned int leds_count);
void DirectModeSetSingleLED(unsigned int led, unsigned char red, unsigned char green, unsigned char blue);
void DirectModeSetLEDs(std::vector<RGBColor> colors, unsigned int num_colors);
protected:
hid_device *dev;
//Protocol Specific functions
std::vector<unsigned int> GetEnabledModes();
private:
unsigned int leds_per_update;
std::string location;
std::string device_name;
std::string device_vendor;
std::chrono::milliseconds delay;
unsigned int total_number_of_leds;
unsigned int total_number_of_leds_with_empty_space;
unsigned int mode;
unsigned int mode_speed;
RGBColor mode_color;
std::vector<point_t> led_points;
std::vector<unsigned int> led_flags;
std::vector<std::string> led_names;
std::vector<RGBColor> led_colors;
};

View File

@@ -7,166 +7,17 @@
| Jath03 28th May 2021 |
\*-------------------------------------------------------------------*/
#include "RGBControllerKeyNames.h"
#include "QMKOpenRGBRevDController.h"
#include "SettingsManager.h"
using namespace std::chrono_literals;
static std::map<uint8_t, std::string> QMKKeycodeToKeynameMap
QMKOpenRGBRevDController::QMKOpenRGBRevDController(hid_device *dev_handle, const char *path) :
QMKOpenRGBBaseController(dev_handle, path, 15)
{
{ 0, KEY_EN_UNUSED }, { 1, KEY_EN_RIGHT_FUNCTION }, { 2, KEY_EN_UNUSED }, { 3, KEY_EN_UNUSED },
{ 4, KEY_EN_A }, { 5, KEY_EN_B }, { 6, KEY_EN_C }, { 7, KEY_EN_D },
{ 8, KEY_EN_E }, { 9, KEY_EN_F }, { 10, KEY_EN_G }, { 11, KEY_EN_H },
{ 12, KEY_EN_I }, { 13, KEY_EN_J }, { 14, KEY_EN_K }, { 15, KEY_EN_L },
{ 16, KEY_EN_M }, { 17, KEY_EN_N }, { 18, KEY_EN_O }, { 19, KEY_EN_P },
{ 20, KEY_EN_Q }, { 21, KEY_EN_R }, { 22, KEY_EN_S }, { 23, KEY_EN_T },
{ 24, KEY_EN_U }, { 25, KEY_EN_V }, { 26, KEY_EN_W }, { 27, KEY_EN_X },
{ 28, KEY_EN_Y }, { 29, KEY_EN_Z }, { 30, KEY_EN_1 }, { 31, KEY_EN_2 },
{ 32, KEY_EN_3 }, { 33, KEY_EN_4 }, { 34, KEY_EN_5 }, { 35, KEY_EN_6 },
{ 36, KEY_EN_7 }, { 37, KEY_EN_8 }, { 38, KEY_EN_9 }, { 39, KEY_EN_0 },
{ 40, KEY_EN_ANSI_ENTER }, { 41, KEY_EN_ESCAPE }, { 42, KEY_EN_BACKSPACE }, { 43, KEY_EN_TAB },
{ 44, KEY_EN_SPACE }, { 45, KEY_EN_MINUS }, { 46, KEY_EN_EQUALS }, { 47, KEY_EN_LEFT_BRACKET },
{ 48, KEY_EN_RIGHT_BRACKET }, { 49, KEY_EN_ANSI_BACK_SLASH }, { 50, KEY_EN_POUND }, { 51, KEY_EN_SEMICOLON },
{ 52, KEY_EN_QUOTE }, { 53, KEY_EN_BACK_TICK }, { 54, KEY_EN_COMMA }, { 55, KEY_EN_PERIOD },
{ 56, KEY_EN_FORWARD_SLASH }, { 57, KEY_EN_CAPS_LOCK }, { 58, KEY_EN_F1 }, { 59, KEY_EN_F2 },
{ 60, KEY_EN_F3 }, { 61, KEY_EN_F4 }, { 62, KEY_EN_F5 }, { 63, KEY_EN_F6 },
{ 64, KEY_EN_F7 }, { 65, KEY_EN_F8 }, { 66, KEY_EN_F9 }, { 67, KEY_EN_F10 },
{ 68, KEY_EN_F11 }, { 69, KEY_EN_F12 }, { 70, KEY_EN_PRINT_SCREEN }, { 71, KEY_EN_SCROLL_LOCK },
{ 72, KEY_EN_PAUSE_BREAK }, { 73, KEY_EN_INSERT }, { 74, KEY_EN_HOME }, { 75, KEY_EN_PAGE_UP },
{ 76, KEY_EN_DELETE }, { 77, KEY_EN_END }, { 78, KEY_EN_PAGE_DOWN }, { 79, KEY_EN_RIGHT_ARROW },
{ 80, KEY_EN_LEFT_ARROW }, { 81, KEY_EN_DOWN_ARROW }, { 82, KEY_EN_UP_ARROW }, { 83, KEY_EN_NUMPAD_LOCK },
{ 84, KEY_EN_NUMPAD_DIVIDE }, { 85, KEY_EN_NUMPAD_TIMES }, { 86, KEY_EN_NUMPAD_MINUS }, { 87, KEY_EN_NUMPAD_PLUS },
{ 88, KEY_EN_NUMPAD_ENTER }, { 89, KEY_EN_NUMPAD_1 }, { 90, KEY_EN_NUMPAD_2 }, { 91, KEY_EN_NUMPAD_3 },
{ 92, KEY_EN_NUMPAD_4 }, { 93, KEY_EN_NUMPAD_5 }, { 94, KEY_EN_NUMPAD_6 }, { 95, KEY_EN_NUMPAD_7 },
{ 96, KEY_EN_NUMPAD_8 }, { 97, KEY_EN_NUMPAD_9 }, { 98, KEY_EN_NUMPAD_0 }, { 99, KEY_EN_NUMPAD_PERIOD },
{ 100, KEY_EN_ISO_BACK_SLASH}, { 101, KEY_EN_MENU }, { 102, KEY_EN_UNUSED }, { 103, KEY_EN_UNUSED },
{ 104, KEY_EN_UNUSED }, { 105, KEY_EN_UNUSED }, { 106, KEY_EN_UNUSED }, { 107, KEY_EN_UNUSED },
{ 108, KEY_EN_UNUSED }, { 109, KEY_EN_UNUSED }, { 110, KEY_EN_UNUSED }, { 111, KEY_EN_UNUSED },
{ 112, KEY_EN_UNUSED }, { 113, KEY_EN_UNUSED }, { 114, KEY_EN_UNUSED }, { 115, KEY_EN_UNUSED },
{ 116, KEY_EN_UNUSED }, { 117, KEY_EN_UNUSED }, { 118, KEY_EN_UNUSED }, { 119, KEY_EN_UNUSED },
{ 120, KEY_EN_UNUSED }, { 121, KEY_EN_UNUSED }, { 122, KEY_EN_UNUSED }, { 123, KEY_EN_UNUSED },
{ 124, KEY_EN_UNUSED }, { 125, KEY_EN_UNUSED }, { 126, KEY_EN_UNUSED }, { 127, KEY_EN_UNUSED },
{ 128, KEY_EN_UNUSED }, { 129, KEY_EN_UNUSED }, { 130, KEY_EN_UNUSED }, { 131, KEY_EN_UNUSED },
{ 132, KEY_EN_UNUSED }, { 133, KEY_EN_UNUSED }, { 134, KEY_EN_UNUSED }, { 135, KEY_EN_UNUSED },
{ 136, KEY_EN_UNUSED }, { 137, KEY_EN_UNUSED }, { 138, KEY_EN_UNUSED }, { 139, KEY_EN_UNUSED },
{ 140, KEY_EN_UNUSED }, { 141, KEY_EN_UNUSED }, { 142, KEY_EN_UNUSED }, { 143, KEY_EN_UNUSED },
{ 144, KEY_EN_UNUSED }, { 145, KEY_EN_UNUSED }, { 146, KEY_EN_UNUSED }, { 147, KEY_EN_UNUSED },
{ 148, KEY_EN_UNUSED }, { 149, KEY_EN_UNUSED }, { 150, KEY_EN_UNUSED }, { 151, KEY_EN_UNUSED },
{ 152, KEY_EN_UNUSED }, { 153, KEY_EN_UNUSED }, { 154, KEY_EN_UNUSED }, { 155, KEY_EN_UNUSED },
{ 156, KEY_EN_UNUSED }, { 157, KEY_EN_UNUSED }, { 158, KEY_EN_UNUSED }, { 159, KEY_EN_UNUSED },
{ 160, KEY_EN_UNUSED }, { 161, KEY_EN_UNUSED }, { 162, KEY_EN_UNUSED }, { 163, KEY_EN_UNUSED },
{ 164, KEY_EN_UNUSED },
/*Space Cadet Left Shift*/ { 216, KEY_EN_LEFT_SHIFT }, /*Space Cadet Right Shift*/ { 217, KEY_EN_RIGHT_SHIFT },
{ 224, KEY_EN_LEFT_CONTROL }, { 225, KEY_EN_LEFT_SHIFT }, { 226, KEY_EN_LEFT_ALT }, { 227, KEY_EN_LEFT_WINDOWS },
{ 228, KEY_EN_RIGHT_CONTROL }, { 229, KEY_EN_RIGHT_SHIFT }, { 230, KEY_EN_RIGHT_ALT }, { 231, KEY_EN_RIGHT_WINDOWS },
};
QMKOpenRGBRevDController::QMKOpenRGBRevDController(hid_device *dev_handle, const char *path)
{
/*-------------------------------------------------*\
| Get QMKOpenRGB settings |
\*-------------------------------------------------*/
json qmk_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("QMKOpenRGBDevices");
if(qmk_settings.contains("leds_per_update"))
{
if(qmk_settings["leds_per_update"] > 15)
{
qmk_settings["leds_per_update"] = 15;
}
else if(qmk_settings["leds_per_update"] < 1)
{
qmk_settings["leds_per_update"] = 1;
}
SettingsManager* settings_manager = ResourceManager::get()->GetSettingsManager();
settings_manager->SetSettings("QMKOpenRGBDevices", qmk_settings);
settings_manager->SaveSettings();
leds_per_update = qmk_settings["leds_per_update"];
}
else
{
leds_per_update = 15;
}
if(qmk_settings.contains("delay"))
{
delay = (unsigned int)qmk_settings["delay"] * 1ms;
}
else
{
delay = 0ms;
}
dev = dev_handle;
location = path;
GetDeviceInfo();
GetModeInfo();
}
QMKOpenRGBRevDController::~QMKOpenRGBRevDController()
{
hid_close(dev);
}
std::string QMKOpenRGBRevDController::GetLocation()
{
return location;
}
std::string QMKOpenRGBRevDController::GetDeviceName()
{
return device_name;
}
std::string QMKOpenRGBRevDController::GetDeviceVendor()
{
return device_vendor;
}
unsigned int QMKOpenRGBRevDController::GetTotalNumberOfLEDs()
{
return total_number_of_leds;
}
unsigned int QMKOpenRGBRevDController::GetTotalNumberOfLEDsWithEmptySpace()
{
return total_number_of_leds_with_empty_space;
}
unsigned int QMKOpenRGBRevDController::GetMode()
{
return mode;
}
unsigned int QMKOpenRGBRevDController::GetModeSpeed()
{
return mode_speed;
}
unsigned int QMKOpenRGBRevDController::GetModeColor()
{
return mode_color;
}
std::vector<point_t> QMKOpenRGBRevDController::GetLEDPoints()
{
return led_points;
}
std::vector<unsigned int> QMKOpenRGBRevDController::GetLEDFlags()
{
return led_flags;
}
std::vector<std::string> QMKOpenRGBRevDController::GetLEDNames()
{
return led_names;
}
std::vector<RGBColor> QMKOpenRGBRevDController::GetLEDColors()
{
return led_colors;
}
std::vector<unsigned int> QMKOpenRGBRevDController::GetLEDValues()
@@ -174,141 +25,6 @@ std::vector<unsigned int> QMKOpenRGBRevDController::GetLEDValues()
return led_values;
}
unsigned int QMKOpenRGBRevDController::GetProtocolVersion()
{
unsigned char usb_buf[QMK_OPENRGB_PACKET_SIZE];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, QMK_OPENRGB_PACKET_SIZE);
/*-----------------------------------------------------*\
| Set up config table request packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = QMK_OPENRGB_GET_PROTOCOL_VERSION;
int bytes_read = 0;
do
{
hid_write(dev, usb_buf, QMK_OPENRGB_PACKET_SIZE);
bytes_read = hid_read_timeout(dev, usb_buf, QMK_OPENRGB_PACKET_SIZE, QMK_OPENRGB_HID_READ_TIMEOUT);
} while(bytes_read <= 0);
return usb_buf[1];
}
std::string QMKOpenRGBRevDController::GetQMKVersion()
{
unsigned char usb_buf[QMK_OPENRGB_PACKET_SIZE];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, QMK_OPENRGB_PACKET_SIZE);
/*-----------------------------------------------------*\
| Set up config table request packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = QMK_OPENRGB_GET_QMK_VERSION;
hid_write(dev, usb_buf, QMK_OPENRGB_PACKET_SIZE);
hid_read(dev, usb_buf, QMK_OPENRGB_PACKET_SIZE);
std::string qmk_version;
int i = 1;
while (usb_buf[i] != 0)
{
qmk_version.push_back(usb_buf[i]);
i++;
}
return qmk_version;
}
void QMKOpenRGBRevDController::GetDeviceInfo()
{
unsigned char usb_buf[QMK_OPENRGB_PACKET_SIZE];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, QMK_OPENRGB_PACKET_SIZE);
/*-----------------------------------------------------*\
| Set up config table request packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = QMK_OPENRGB_GET_DEVICE_INFO;
int bytes_read = 0;
do
{
hid_write(dev, usb_buf, QMK_OPENRGB_PACKET_SIZE);
bytes_read = hid_read_timeout(dev, usb_buf, QMK_OPENRGB_PACKET_SIZE, QMK_OPENRGB_HID_READ_TIMEOUT);
} while(bytes_read <= 0);
total_number_of_leds = usb_buf[QMK_OPENRGB_TOTAL_NUMBER_OF_LEDS_BYTE];
total_number_of_leds_with_empty_space = usb_buf[QMK_OPENRGB_TOTAL_NUMBER_OF_LEDS_WITH_EMPTY_SPACE_BYTE];
int i = QMK_OPENRGB_TOTAL_NUMBER_OF_LEDS_WITH_EMPTY_SPACE_BYTE + 1;
while (usb_buf[i] != 0)
{
device_name.push_back(usb_buf[i]);
i++;
}
i++;
while (usb_buf[i] != 0)
{
device_vendor.push_back(usb_buf[i]);
i++;
}
}
void QMKOpenRGBRevDController::GetModeInfo()
{
unsigned char usb_buf[QMK_OPENRGB_PACKET_SIZE];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, QMK_OPENRGB_PACKET_SIZE);
/*-----------------------------------------------------*\
| Set up config table request packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = QMK_OPENRGB_GET_MODE_INFO;
int bytes_read = 0;
do
{
hid_write(dev, usb_buf, 65);
bytes_read = hid_read_timeout(dev, usb_buf, 65, QMK_OPENRGB_HID_READ_TIMEOUT);
} while(bytes_read <= 0);
mode = usb_buf[QMK_OPENRGB_MODE_BYTE];
mode_speed = usb_buf[QMK_OPENRGB_SPEED_BYTE];
/*-----------------------------------------------------*\
| QMK hue range is between 0-255 so hue needs to be |
| converted |
\*-----------------------------------------------------*/
unsigned int oldRange = 255;
unsigned int newRange = 359;
unsigned int convertedHue = (usb_buf[QMK_OPENRGB_HUE_BYTE] * newRange / oldRange);
hsv_t hsv;
hsv.hue = convertedHue;
hsv.saturation = usb_buf[QMK_OPENRGB_SATURATION_BYTE];
hsv.value = usb_buf[QMK_OPENRGB_VALUE_BYTE];
mode_color = hsv2rgb(&hsv);
}
void QMKOpenRGBRevDController::GetLEDInfo(unsigned int leds_count)
{
unsigned int leds_sent = 0;
@@ -351,36 +67,41 @@ void QMKOpenRGBRevDController::GetLEDInfo(unsigned int leds_count)
for (unsigned int led_idx = 0; led_idx < leds_per_update_info; led_idx++)
{
if(usb_buf[(led_idx * 7) + QMK_OPENRGB_FLAG_BYTE] != QMK_OPENRGB_FAILURE)
unsigned int offset = led_idx * 7;
if(usb_buf[offset + QMK_OPENRGB_FLAG_BYTE] != QMK_OPENRGB_FAILURE)
{
if(usb_buf[(led_idx * 7) + QMK_OPENRGB_FLAG_BYTE] & 2)
if(usb_buf[offset + QMK_OPENRGB_FLAG_BYTE] & 2)
{
underglow_points.push_back(point_t{usb_buf[(led_idx * 7) + QMK_OPENRGB_POINT_X_BYTE], usb_buf[(led_idx * 7) + QMK_OPENRGB_POINT_Y_BYTE]});
underglow_flags.push_back(usb_buf[(led_idx * 7) + QMK_OPENRGB_FLAG_BYTE]);
underglow_colors.push_back(ToRGBColor(usb_buf[(led_idx * 7) + QMK_OPENRGB_R_COLOR_BYTE], usb_buf[(led_idx * 7) + QMK_OPENRGB_G_COLOR_BYTE], usb_buf[(led_idx * 7) + QMK_OPENRGB_B_COLOR_BYTE]));
underglow_points.push_back(point_t{usb_buf[offset + QMK_OPENRGB_POINT_X_BYTE], usb_buf[offset + QMK_OPENRGB_POINT_Y_BYTE]});
underglow_flags.push_back(usb_buf[offset + QMK_OPENRGB_FLAG_BYTE]);
underglow_colors.push_back(ToRGBColor(usb_buf[offset + QMK_OPENRGB_R_COLOR_BYTE], usb_buf[offset + QMK_OPENRGB_G_COLOR_BYTE], usb_buf[offset + QMK_OPENRGB_B_COLOR_BYTE]));
underglow_values.push_back(underglow_values.size() + led_values.size());
}
else
{
led_points.push_back(point_t{usb_buf[(led_idx * 7) + QMK_OPENRGB_POINT_X_BYTE], usb_buf[(led_idx * 7) + QMK_OPENRGB_POINT_Y_BYTE]});
led_flags.push_back(usb_buf[(led_idx * 7) + QMK_OPENRGB_FLAG_BYTE]);
led_colors.push_back(ToRGBColor(usb_buf[(led_idx * 7) + QMK_OPENRGB_R_COLOR_BYTE], usb_buf[(led_idx * 7) + QMK_OPENRGB_G_COLOR_BYTE], usb_buf[(led_idx * 7) + QMK_OPENRGB_B_COLOR_BYTE]));
led_points.push_back(point_t{usb_buf[offset + QMK_OPENRGB_POINT_X_BYTE], usb_buf[offset + QMK_OPENRGB_POINT_Y_BYTE]});
led_flags.push_back(usb_buf[offset + QMK_OPENRGB_FLAG_BYTE]);
led_colors.push_back(ToRGBColor(usb_buf[offset + QMK_OPENRGB_R_COLOR_BYTE], usb_buf[offset + QMK_OPENRGB_G_COLOR_BYTE], usb_buf[offset + QMK_OPENRGB_B_COLOR_BYTE]));
led_values.push_back(underglow_values.size() + led_values.size());
}
}
if(usb_buf[(led_idx * 7) + QMK_OPENRGB_KEYCODE_BYTE] != 0)
if(usb_buf[offset + QMK_OPENRGB_KEYCODE_BYTE] != 0)
{
if (QMKKeycodeToKeynameMap.count(usb_buf[(led_idx * 7) + QMK_OPENRGB_KEYCODE_BYTE]) > 0)
if (qmk_keycode_keyname_map.count(usb_buf[offset + QMK_OPENRGB_KEYCODE_BYTE]) > 0)
{
led_names.push_back(QMKKeycodeToKeynameMap[usb_buf[(led_idx * 7) + QMK_OPENRGB_KEYCODE_BYTE]]);
led_names.push_back(qmk_keycode_keyname_map[usb_buf[offset + QMK_OPENRGB_KEYCODE_BYTE]]);
}
else
{
LOG_DEBUG("[%s] Key code: %d (%02X) @ offset %d was not found in the QMK keyname map",
device_name.c_str(), usb_buf[offset + QMK_OPENRGB_KEYCODE_BYTE],
usb_buf[offset + QMK_OPENRGB_KEYCODE_BYTE], leds_sent + led_idx);
led_names.push_back(KEY_EN_UNUSED);
}
}
else if(usb_buf[(led_idx * 7) + QMK_OPENRGB_FLAG_BYTE] & 2){
else if(usb_buf[offset + QMK_OPENRGB_FLAG_BYTE] & 2){
underglow_names.push_back("Underglow: " + std::to_string(underglow_names.size() + led_names.size()));
}
}
@@ -427,34 +148,6 @@ std::vector<unsigned int> QMKOpenRGBRevDController::GetEnabledModes()
return enabled_modes;
}
void QMKOpenRGBRevDController::SetMode(hsv_t hsv_color, unsigned char mode, unsigned char speed, bool save)
{
unsigned char usb_buf[QMK_OPENRGB_PACKET_SIZE];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, QMK_OPENRGB_PACKET_SIZE);
/*-----------------------------------------------------*\
| Set up config table request packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x00;
usb_buf[0x01] = QMK_OPENRGB_SET_MODE;
usb_buf[0x02] = hsv_color.hue * 255 / 359;
usb_buf[0x03] = hsv_color.saturation;
usb_buf[0x04] = hsv_color.value;
usb_buf[0x05] = mode;
usb_buf[0x06] = speed;
usb_buf[0x07] = save;
/*-----------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------*/
hid_write(dev, usb_buf, 65);
hid_read_timeout(dev, usb_buf, 65, QMK_OPENRGB_HID_READ_TIMEOUT);
}
void QMKOpenRGBRevDController::DirectModeSetSingleLED(unsigned int led, unsigned char red, unsigned char green, unsigned char blue)
{
unsigned char usb_buf[QMK_OPENRGB_PACKET_SIZE];

View File

@@ -9,64 +9,23 @@
#pragma once
#include "QMKOpenRGBController.h"
#include "QMKOpenRGBBaseController.h"
class QMKOpenRGBRevDController
class QMKOpenRGBRevDController : public QMKOpenRGBBaseController
{
public:
QMKOpenRGBRevDController(hid_device *dev_handle, const char *path);
~QMKOpenRGBRevDController();
std::string GetLocation();
std::string GetDeviceName();
std::string GetDeviceVendor();
unsigned int GetTotalNumberOfLEDs();
unsigned int GetTotalNumberOfLEDsWithEmptySpace();
unsigned int GetMode();
unsigned int GetModeSpeed();
unsigned int GetModeColor();
std::vector<point_t> GetLEDPoints();
std::vector<unsigned int> GetLEDFlags();
std::vector<std::string> GetLEDNames();
std::vector<RGBColor> GetLEDColors();
std::vector<unsigned int> GetLEDValues();
unsigned int GetProtocolVersion();
std::string GetQMKVersion();
void GetDeviceInfo();
void GetModeInfo();
void GetLEDInfo(unsigned int leds_count);
std::vector<unsigned int> GetEnabledModes();
void SetMode(hsv_t hsv_color, unsigned char mode, unsigned char speed, bool save);
//Virtual function implementations
void GetLEDInfo(unsigned int leds_count);
void DirectModeSetSingleLED(unsigned int led, unsigned char red, unsigned char green, unsigned char blue);
void DirectModeSetLEDs(std::vector<RGBColor> colors, unsigned int num_colors);
protected:
hid_device *dev;
//Protocol Specific functions
std::vector<unsigned int> GetLEDValues();
std::vector<unsigned int> GetEnabledModes();
private:
unsigned int leds_per_update;
std::string location;
std::string device_name;
std::string device_vendor;
std::chrono::milliseconds delay;
unsigned int total_number_of_leds;
unsigned int total_number_of_leds_with_empty_space;
unsigned int mode;
unsigned int mode_speed;
RGBColor mode_color;
std::vector<point_t> led_points;
std::vector<unsigned int> led_flags;
std::vector<std::string> led_names;
std::vector<RGBColor> led_colors;
std::vector<unsigned int> led_values;
};

View File

@@ -691,6 +691,7 @@ HEADERS +=
Controllers/PNYLovelaceGPUController/PNYLovelaceGPUController.h \
Controllers/PNYLovelaceGPUController/RGBController_PNYLovelaceGPU.h \
Controllers/QMKOpenRGBController/QMKOpenRGBController.h \
Controllers/QMKOpenRGBController/QMKOpenRGBBaseController.h \
Controllers/QMKOpenRGBController/QMKOpenRGBRev9Controller.h \
Controllers/QMKOpenRGBController/QMKOpenRGBRevBController.h \
Controllers/QMKOpenRGBController/QMKOpenRGBRevDController.h \
@@ -1419,6 +1420,7 @@ SOURCES +=
Controllers/PNYLovelaceGPUController/PNYLovelaceGPUControllerDetect.cpp \
Controllers/PNYLovelaceGPUController/RGBController_PNYLovelaceGPU.cpp \
Controllers/QMKOpenRGBController/QMKOpenRGBControllerDetect.cpp \
Controllers/QMKOpenRGBController/QMKOpenRGBBaseController.cpp \
Controllers/QMKOpenRGBController/QMKOpenRGBRev9Controller.cpp \
Controllers/QMKOpenRGBController/QMKOpenRGBRevBController.cpp \
Controllers/QMKOpenRGBController/QMKOpenRGBRevDController.cpp \