From 4081cda8dfba7741c18a4429dafcc2bc0395b1ef Mon Sep 17 00:00:00 2001 From: Ksaper Date: Tue, 29 Jun 2021 07:31:11 +0300 Subject: [PATCH] Add QMK OpenRGB Protocol Revision B Controller * Updates for direct mode initialization to work with the new QMK Update * Merge each 8 GetLEDInfo HID calls into one single call * Merge all IsEnabledMode HID calls into one single call * Update protocol version Commits squashed and amended by Adam Honse --- .../QMKOpenRGBController.h | 61 +------ .../QMKOpenRGBControllerDetect.cpp | 12 ++ .../QMKOpenRGBRev9Controller.h | 116 +------------ ...oller.cpp => QMKOpenRGBRevBController.cpp} | 161 +++++++++-------- .../QMKOpenRGBRevBController.h | 68 ++++++++ ...B.cpp => RGBController_QMKOpenRGBRevB.cpp} | 164 ++++++++++-------- ...enRGB.h => RGBController_QMKOpenRGBRevB.h} | 14 +- OpenRGB.pro | 5 + 8 files changed, 281 insertions(+), 320 deletions(-) rename Controllers/QMKOpenRGBController/{QMKOpenRGBController.cpp => QMKOpenRGBRevBController.cpp} (77%) create mode 100644 Controllers/QMKOpenRGBController/QMKOpenRGBRevBController.h rename Controllers/QMKOpenRGBController/{RGBController_QMKOpenRGB.cpp => RGBController_QMKOpenRGBRevB.cpp} (74%) rename Controllers/QMKOpenRGBController/{RGBController_QMKOpenRGB.h => RGBController_QMKOpenRGBRevB.h} (91%) diff --git a/Controllers/QMKOpenRGBController/QMKOpenRGBController.h b/Controllers/QMKOpenRGBController/QMKOpenRGBController.h index 0de6ee386..f54a8ec98 100644 --- a/Controllers/QMKOpenRGBController/QMKOpenRGBController.h +++ b/Controllers/QMKOpenRGBController/QMKOpenRGBController.h @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------*\ | QMKOpenRGBController.h | | | -| Driver for QMK keyboards using OpenRGB Protocol | +| Common definitions for QMK OpenRGB Controller | | | | Kasper 10th Octobber 2020 | | Jath03 28th May 2021 | @@ -27,6 +27,7 @@ enum CommandsId QMK_OPENRGB_GET_MODE_INFO, QMK_OPENRGB_GET_LED_INFO, QMK_OPENRGB_GET_IS_MODE_ENABLED, + QMK_OPENRGB_GET_ENABLED_MODES = QMK_OPENRGB_GET_IS_MODE_ENABLED, QMK_OPENRGB_SET_MODE, QMK_OPENRGB_DIRECT_MODE_SET_SINGLE_LED, @@ -123,60 +124,4 @@ typedef struct { uint8_t x; uint8_t y; -} point_t; - -class QMKOpenRGBController -{ -public: - QMKOpenRGBController(hid_device *dev_handle, const char *path); - ~QMKOpenRGBController(); - - 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 GetLEDPoints(); - std::vector GetLEDFlags(); - std::vector GetLEDNames(); - std::vector GetLEDColors(); - - unsigned int GetProtocolVersion(); - std::string GetQMKVersion(); - void GetDeviceInfo(); - void GetModeInfo(); - 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 colors, unsigned int num_colors); - -protected: - hid_device *dev; - -private: - unsigned int leds_per_update; - - std::string location; - - std::string device_name; - std::string device_vendor; - - 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 led_points; - std::vector led_flags; - std::vector led_names; - std::vector led_colors; -}; +} point_t; \ No newline at end of file diff --git a/Controllers/QMKOpenRGBController/QMKOpenRGBControllerDetect.cpp b/Controllers/QMKOpenRGBController/QMKOpenRGBControllerDetect.cpp index 058d83e25..23d526c43 100644 --- a/Controllers/QMKOpenRGBController/QMKOpenRGBControllerDetect.cpp +++ b/Controllers/QMKOpenRGBController/QMKOpenRGBControllerDetect.cpp @@ -12,14 +12,17 @@ #include "Detector.h" #include "QMKOpenRGBRev9Controller.h" +#include "QMKOpenRGBRevBController.h" #include "RGBController.h" #include "RGBController_QMKOpenRGBRev9.h" +#include "RGBController_QMKOpenRGBRevB.h" #include /*-----------------------------------------------------*\ | Protocol version | \*-----------------------------------------------------*/ #define QMK_OPENRGB_PROTOCOL_VERSION_9 0x09 +#define QMK_OPENRGB_PROTOCOL_VERSION_B 0x0B /*-----------------------------------------------------*\ | Usage and Usage Page | @@ -73,6 +76,15 @@ void DetectQMKOpenRGBControllers(hid_device_info *info, const std::string&) RGBController_QMKOpenRGBRev9* rgb_controller = new RGBController_QMKOpenRGBRev9(controller); ResourceManager::get()->RegisterRGBController(rgb_controller); } + break; + + case QMK_OPENRGB_PROTOCOL_VERSION_B: + { + QMKOpenRGBRevBController* controller = new QMKOpenRGBRevBController(dev, info->path); + RGBController_QMKOpenRGBRevB* rgb_controller = new RGBController_QMKOpenRGBRevB(controller); + ResourceManager::get()->RegisterRGBController(rgb_controller); + } + break; } } } diff --git a/Controllers/QMKOpenRGBController/QMKOpenRGBRev9Controller.h b/Controllers/QMKOpenRGBController/QMKOpenRGBRev9Controller.h index 52ce717eb..d1b8a17c9 100644 --- a/Controllers/QMKOpenRGBController/QMKOpenRGBRev9Controller.h +++ b/Controllers/QMKOpenRGBController/QMKOpenRGBRev9Controller.h @@ -11,121 +11,7 @@ #pragma once -#include "ResourceManager.h" -#include "RGBController.h" -#include "hsv.h" -#include -#include -#include - -#define QMK_OPENRGB_PACKET_SIZE 65 -#define QMK_OPENRGB_HID_READ_TIMEOUT 50 - -enum CommandsId -{ - QMK_OPENRGB_GET_PROTOCOL_VERSION = 1, - QMK_OPENRGB_GET_QMK_VERSION, - QMK_OPENRGB_GET_DEVICE_INFO, - QMK_OPENRGB_GET_MODE_INFO, - QMK_OPENRGB_GET_LED_INFO, - QMK_OPENRGB_GET_IS_MODE_ENABLED, - - QMK_OPENRGB_SET_MODE, - QMK_OPENRGB_DIRECT_MODE_SET_SINGLE_LED, - QMK_OPENRGB_DIRECT_MODE_SET_LEDS, -}; - -enum Modes -{ - QMK_OPENRGB_MODE_OPENRGB_DIRECT = 1, - QMK_OPENRGB_MODE_SOLID_COLOR, - QMK_OPENRGB_MODE_ALPHA_MOD, - QMK_OPENRGB_MODE_GRADIENT_UP_DOWN, - QMK_OPENRGB_MODE_GRADIENT_LEFT_RIGHT, - QMK_OPENRGB_MODE_BREATHING, - QMK_OPENRGB_MODE_BAND_SAT, - QMK_OPENRGB_MODE_BAND_VAL, - QMK_OPENRGB_MODE_BAND_PINWHEEL_SAT, - QMK_OPENRGB_MODE_BAND_PINWHEEL_VAL, - QMK_OPENRGB_MODE_BAND_SPIRAL_SAT, - QMK_OPENRGB_MODE_BAND_SPIRAL_VAL, - QMK_OPENRGB_MODE_CYCLE_ALL, - QMK_OPENRGB_MODE_CYCLE_LEFT_RIGHT, - QMK_OPENRGB_MODE_CYCLE_UP_DOWN, - QMK_OPENRGB_MODE_CYCLE_OUT_IN, - QMK_OPENRGB_MODE_CYCLE_OUT_IN_DUAL, - QMK_OPENRGB_MODE_RAINBOW_MOVING_CHEVRON, - QMK_OPENRGB_MODE_CYCLE_PINWHEEL, - QMK_OPENRGB_MODE_CYCLE_SPIRAL, - QMK_OPENRGB_MODE_DUAL_BEACON, - QMK_OPENRGB_MODE_RAINBOW_BEACON, - QMK_OPENRGB_MODE_RAINBOW_PINWHEELS, - QMK_OPENRGB_MODE_RAINDROPS, - QMK_OPENRGB_MODE_JELLYBEAN_RAINDROPS, - QMK_OPENRGB_MODE_HUE_BREATHING, - QMK_OPENRGB_MODE_HUE_PENDULUM, - QMK_OPENRGB_MODE_HUE_WAVE, - QMK_OPENRGB_MODE_TYPING_HEATMAP, - QMK_OPENRGB_MODE_DIGITAL_RAIN, - QMK_OPENRGB_MODE_SOLID_REACTIVE_SIMPLE, - QMK_OPENRGB_MODE_SOLID_REACTIVE, - QMK_OPENRGB_MODE_SOLID_REACTIVE_WIDE, - QMK_OPENRGB_MODE_SOLID_REACTIVE_MULTIWIDE, - QMK_OPENRGB_MODE_SOLID_REACTIVE_CROSS, - QMK_OPENRGB_MODE_SOLID_REACTIVE_MULTICROSS, - QMK_OPENRGB_MODE_SOLID_REACTIVE_NEXUS, - QMK_OPENRGB_MODE_SOLID_REACTIVE_MULTINEXUS, - QMK_OPENRGB_MODE_SPLASH, - QMK_OPENRGB_MODE_MULTISPLASH, - QMK_OPENRGB_MODE_SOLID_SPLASH, - QMK_OPENRGB_MODE_SOLID_MULTISPLASH, -}; - -enum SpeedCommands -{ - QMK_OPENRGB_SPEED_SLOWEST = 0x00, /* Slowest speed */ - QMK_OPENRGB_SPEED_NORMAL = 0x7F, /* Normal speed */ - QMK_OPENRGB_SPEED_FASTEST = 0xFF, /* Fastest speed */ -}; - -enum -{ - QMK_OPENRGB_FAILURE = 25, /* Failure status code */ - QMK_OPENRGB_SUCCESS = 50, /* Success status code */ - QMK_OPENRGB_END_OF_MESSAGE = 100, /* End of Message status code */ -}; - -enum -{ - QMK_OPENRGB_TOTAL_NUMBER_OF_LEDS_BYTE = 1, - QMK_OPENRGB_TOTAL_NUMBER_OF_LEDS_WITH_EMPTY_SPACE_BYTE = 2 -}; - -enum -{ - QMK_OPENRGB_MODE_BYTE = 1, - QMK_OPENRGB_SPEED_BYTE = 2, - QMK_OPENRGB_HUE_BYTE = 3, - QMK_OPENRGB_SATURATION_BYTE = 4, - QMK_OPENRGB_VALUE_BYTE = 5, -}; - -enum -{ - QMK_OPENRGB_POINT_X_BYTE = 1, - QMK_OPENRGB_POINT_Y_BYTE = 2, - QMK_OPENRGB_FLAG_BYTE = 3, - QMK_OPENRGB_R_COLOR_BYTE = 4, - QMK_OPENRGB_G_COLOR_BYTE = 5, - QMK_OPENRGB_B_COLOR_BYTE = 6, - QMK_OPENRGB_KEYCODE_BYTE = 7 -}; - -typedef struct -{ - uint8_t x; - uint8_t y; -} point_t; +#include "QMKOpenRGBController.h" class QMKOpenRGBRev9Controller { diff --git a/Controllers/QMKOpenRGBController/QMKOpenRGBController.cpp b/Controllers/QMKOpenRGBController/QMKOpenRGBRevBController.cpp similarity index 77% rename from Controllers/QMKOpenRGBController/QMKOpenRGBController.cpp rename to Controllers/QMKOpenRGBController/QMKOpenRGBRevBController.cpp index 879629af9..efb5fcfe6 100644 --- a/Controllers/QMKOpenRGBController/QMKOpenRGBController.cpp +++ b/Controllers/QMKOpenRGBController/QMKOpenRGBRevBController.cpp @@ -1,13 +1,13 @@ /*-------------------------------------------------------------------*\ -| QMKOpenRGBController.cpp | +| QMKOpenRGBRevBController.cpp | | | -| Driver for QMK keyboards using OpenRGB Protocol | +| Driver for QMK keyboards using OpenRGB Protocol (Revision B) | | | | Kasper 10th Octobber 2020 | | Jath03 28th May 2021 | \*-------------------------------------------------------------------*/ -#include "QMKOpenRGBController.h" +#include "QMKOpenRGBRevBController.h" static std::map QMKKeycodeToKeynameMap { @@ -57,7 +57,7 @@ static std::map QMKKeycodeToKeynameMap { 228, "Right Control" }, { 229, "Right Shift" }, { 230, "Right Alt" }, { 231, "Right Windows" }, }; -QMKOpenRGBController::QMKOpenRGBController(hid_device *dev_handle, const char *path) +QMKOpenRGBRevBController::QMKOpenRGBRevBController(hid_device *dev_handle, const char *path) { /*-------------------------------------------------*\ | Get QMKOpenRGB settings | @@ -90,72 +90,72 @@ QMKOpenRGBController::QMKOpenRGBController(hid_device *dev_handle, const char *p GetModeInfo(); } -QMKOpenRGBController::~QMKOpenRGBController() +QMKOpenRGBRevBController::~QMKOpenRGBRevBController() { hid_close(dev); } -std::string QMKOpenRGBController::GetLocation() +std::string QMKOpenRGBRevBController::GetLocation() { return location; } -std::string QMKOpenRGBController::GetDeviceName() +std::string QMKOpenRGBRevBController::GetDeviceName() { return device_name; } -std::string QMKOpenRGBController::GetDeviceVendor() +std::string QMKOpenRGBRevBController::GetDeviceVendor() { return device_vendor; } -unsigned int QMKOpenRGBController::GetTotalNumberOfLEDs() +unsigned int QMKOpenRGBRevBController::GetTotalNumberOfLEDs() { return total_number_of_leds; } -unsigned int QMKOpenRGBController::GetTotalNumberOfLEDsWithEmptySpace() +unsigned int QMKOpenRGBRevBController::GetTotalNumberOfLEDsWithEmptySpace() { return total_number_of_leds_with_empty_space; } -unsigned int QMKOpenRGBController::GetMode() +unsigned int QMKOpenRGBRevBController::GetMode() { return mode; } -unsigned int QMKOpenRGBController::GetModeSpeed() +unsigned int QMKOpenRGBRevBController::GetModeSpeed() { return mode_speed; } -unsigned int QMKOpenRGBController::GetModeColor() +unsigned int QMKOpenRGBRevBController::GetModeColor() { return mode_color; } -std::vector QMKOpenRGBController::GetLEDPoints() +std::vector QMKOpenRGBRevBController::GetLEDPoints() { return led_points; } -std::vector QMKOpenRGBController::GetLEDFlags() +std::vector QMKOpenRGBRevBController::GetLEDFlags() { return led_flags; } -std::vector QMKOpenRGBController::GetLEDNames() +std::vector QMKOpenRGBRevBController::GetLEDNames() { return led_names; } -std::vector QMKOpenRGBController::GetLEDColors() +std::vector QMKOpenRGBRevBController::GetLEDColors() { return led_colors; } -unsigned int QMKOpenRGBController::GetProtocolVersion() +unsigned int QMKOpenRGBRevBController::GetProtocolVersion() { unsigned char usb_buf[QMK_OPENRGB_PACKET_SIZE]; @@ -180,7 +180,7 @@ unsigned int QMKOpenRGBController::GetProtocolVersion() return usb_buf[1]; } -std::string QMKOpenRGBController::GetQMKVersion() +std::string QMKOpenRGBRevBController::GetQMKVersion() { unsigned char usb_buf[QMK_OPENRGB_PACKET_SIZE]; @@ -209,7 +209,7 @@ std::string QMKOpenRGBController::GetQMKVersion() return qmk_version; } -void QMKOpenRGBController::GetDeviceInfo() +void QMKOpenRGBRevBController::GetDeviceInfo() { unsigned char usb_buf[QMK_OPENRGB_PACKET_SIZE]; @@ -249,7 +249,7 @@ void QMKOpenRGBController::GetDeviceInfo() } } -void QMKOpenRGBController::GetModeInfo() +void QMKOpenRGBRevBController::GetModeInfo() { unsigned char usb_buf[QMK_OPENRGB_PACKET_SIZE]; @@ -290,7 +290,67 @@ void QMKOpenRGBController::GetModeInfo() mode_color = hsv2rgb(&hsv); } -void QMKOpenRGBController::GetLEDInfo(unsigned int led) +void QMKOpenRGBRevBController::GetLEDInfo(unsigned int leds_count) +{ + unsigned int leds_sent = 0; + unsigned int leds_per_update_info = 8; + + while (leds_sent < leds_count) + { + if ((leds_count - leds_sent) < leds_per_update_info) + { + leds_per_update_info = leds_count - leds_sent; + } + + 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_LED_INFO; + usb_buf[0x02] = leds_sent; + usb_buf[0x03] = leds_per_update_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); + + 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) + { + 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])); + } + + if(usb_buf[(led_idx * 7) + QMK_OPENRGB_KEYCODE_BYTE] != 0) + { + if (QMKKeycodeToKeynameMap.count(usb_buf[(led_idx * 7) + QMK_OPENRGB_KEYCODE_BYTE]) > 0) + { + led_names.push_back("Key: " + QMKKeycodeToKeynameMap[usb_buf[(led_idx * 7) + QMK_OPENRGB_KEYCODE_BYTE]]); + } + else + { + led_names.push_back("Key: "); + } + } + } + + leds_sent += leds_per_update_info; + } +} + +std::vector QMKOpenRGBRevBController::GetEnabledModes() { unsigned char usb_buf[QMK_OPENRGB_PACKET_SIZE]; @@ -303,8 +363,7 @@ void QMKOpenRGBController::GetLEDInfo(unsigned int led) | Set up config table request packet | \*-----------------------------------------------------*/ usb_buf[0x00] = 0x00; - usb_buf[0x01] = QMK_OPENRGB_GET_LED_INFO; - usb_buf[0x02] = led; + usb_buf[0x01] = QMK_OPENRGB_GET_ENABLED_MODES; int bytes_read = 0; do @@ -313,53 +372,17 @@ void QMKOpenRGBController::GetLEDInfo(unsigned int led) bytes_read = hid_read_timeout(dev, usb_buf, QMK_OPENRGB_PACKET_SIZE, QMK_OPENRGB_HID_READ_TIMEOUT); } while(bytes_read <= 0); - if(usb_buf[62] != QMK_OPENRGB_FAILURE) + std::vector enabled_modes; + int i = 1; + while (usb_buf[i] != 0) { - led_points.push_back(point_t{usb_buf[QMK_OPENRGB_POINT_X_BYTE], usb_buf[QMK_OPENRGB_POINT_Y_BYTE]}); - led_flags.push_back(usb_buf[QMK_OPENRGB_FLAG_BYTE]); - led_colors.push_back(ToRGBColor(usb_buf[QMK_OPENRGB_R_COLOR_BYTE], usb_buf[QMK_OPENRGB_G_COLOR_BYTE], usb_buf[QMK_OPENRGB_B_COLOR_BYTE])); - } - - if(usb_buf[QMK_OPENRGB_KEYCODE_BYTE] != 0) - { - if (QMKKeycodeToKeynameMap.count(usb_buf[QMK_OPENRGB_KEYCODE_BYTE]) > 0) - { - led_names.push_back("Key: " + QMKKeycodeToKeynameMap[usb_buf[QMK_OPENRGB_KEYCODE_BYTE]]); - } - else - { - led_names.push_back("Key: "); - } + enabled_modes.push_back(usb_buf[i]); + i++; } + return enabled_modes; } -bool QMKOpenRGBController::GetIsModeEnabled(unsigned int mode) -{ - 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_IS_MODE_ENABLED; - usb_buf[0x02] = mode; - - 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] == QMK_OPENRGB_SUCCESS ? true : false; -} - -void QMKOpenRGBController::SetMode(hsv_t hsv_color, unsigned char mode, unsigned char speed) +void QMKOpenRGBRevBController::SetMode(hsv_t hsv_color, unsigned char mode, unsigned char speed) { unsigned char usb_buf[QMK_OPENRGB_PACKET_SIZE]; @@ -386,7 +409,7 @@ void QMKOpenRGBController::SetMode(hsv_t hsv_color, unsigned char mode, unsigned hid_read_timeout(dev, usb_buf, 65, QMK_OPENRGB_HID_READ_TIMEOUT); } -void QMKOpenRGBController::DirectModeSetSingleLED(unsigned int led, unsigned char red, unsigned char green, unsigned char blue) +void QMKOpenRGBRevBController::DirectModeSetSingleLED(unsigned int led, unsigned char red, unsigned char green, unsigned char blue) { unsigned char usb_buf[QMK_OPENRGB_PACKET_SIZE]; @@ -413,7 +436,7 @@ void QMKOpenRGBController::DirectModeSetSingleLED(unsigned int led, unsigned cha hid_read_timeout(dev, usb_buf, 65, QMK_OPENRGB_HID_READ_TIMEOUT); } -void QMKOpenRGBController::DirectModeSetLEDs(std::vector colors, unsigned int leds_count) +void QMKOpenRGBRevBController::DirectModeSetLEDs(std::vector colors, unsigned int leds_count) { unsigned int leds_sent = 0; unsigned int tmp_leds_per_update = leds_per_update; diff --git a/Controllers/QMKOpenRGBController/QMKOpenRGBRevBController.h b/Controllers/QMKOpenRGBController/QMKOpenRGBRevBController.h new file mode 100644 index 000000000..5325ebd5d --- /dev/null +++ b/Controllers/QMKOpenRGBController/QMKOpenRGBRevBController.h @@ -0,0 +1,68 @@ +/*-------------------------------------------------------------------*\ +| QMKOpenRGBRevBController.h | +| | +| Driver for QMK keyboards using OpenRGB Protocol (Revision B) | +| | +| Kasper 10th Octobber 2020 | +| Jath03 28th May 2021 | +\*-------------------------------------------------------------------*/ + +#pragma once + +#include "QMKOpenRGBController.h" + +class QMKOpenRGBRevBController +{ +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 GetLEDPoints(); + std::vector GetLEDFlags(); + std::vector GetLEDNames(); + std::vector GetLEDColors(); + + unsigned int GetProtocolVersion(); + std::string GetQMKVersion(); + void GetDeviceInfo(); + void GetModeInfo(); + void GetLEDInfo(unsigned int leds_count); + std::vector GetEnabledModes(); + + 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 colors, unsigned int num_colors); + +protected: + hid_device *dev; + +private: + unsigned int leds_per_update; + + std::string location; + + std::string device_name; + std::string device_vendor; + + 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 led_points; + std::vector led_flags; + std::vector led_names; + std::vector led_colors; +}; diff --git a/Controllers/QMKOpenRGBController/RGBController_QMKOpenRGB.cpp b/Controllers/QMKOpenRGBController/RGBController_QMKOpenRGBRevB.cpp similarity index 74% rename from Controllers/QMKOpenRGBController/RGBController_QMKOpenRGB.cpp rename to Controllers/QMKOpenRGBController/RGBController_QMKOpenRGBRevB.cpp index 444e5f039..e979a9192 100644 --- a/Controllers/QMKOpenRGBController/RGBController_QMKOpenRGB.cpp +++ b/Controllers/QMKOpenRGBController/RGBController_QMKOpenRGBRevB.cpp @@ -1,16 +1,16 @@ /*-------------------------------------------------------------------*\ -| RGBController_QMKOpenRGB.cpp | +| RGBController_QMKOpenRGBRevB.cpp | | | -| Driver for QMK keyboards using OpenRGB Protocol | +| Driver for QMK keyboards using OpenRGB Protocol (Revision B) | | | | Kasper 10th Octobber 2020 | | Jath03 28th May 2021 | \*-------------------------------------------------------------------*/ #include "hsv.h" -#include "RGBController_QMKOpenRGB.h" +#include "RGBController_QMKOpenRGBRevB.h" -RGBController_QMKOpenRGB::RGBController_QMKOpenRGB(QMKOpenRGBController* controller_ptr) +RGBController_QMKOpenRGBRevB::RGBController_QMKOpenRGBRevB(QMKOpenRGBRevBController* controller_ptr) { controller = controller_ptr; @@ -22,223 +22,237 @@ RGBController_QMKOpenRGB::RGBController_QMKOpenRGB(QMKOpenRGBController* control version = controller->GetQMKVersion(); unsigned int current_mode = 1; + std::vector enabled_modes = controller->GetEnabledModes(); - if(controller->GetIsModeEnabled(QMK_OPENRGB_MODE_OPENRGB_DIRECT)) - { - InitializeMode("Direct", current_mode, MODE_FLAG_HAS_PER_LED_COLOR, MODE_COLORS_PER_LED); - } - - if(controller->GetIsModeEnabled(QMK_OPENRGB_MODE_SOLID_COLOR)) + if(std::find(enabled_modes.begin(), enabled_modes.end(), QMK_OPENRGB_MODE_SOLID_COLOR) != enabled_modes.end()) { InitializeMode("Static", current_mode, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR, MODE_COLORS_MODE_SPECIFIC); } - if(controller->GetIsModeEnabled(QMK_OPENRGB_MODE_ALPHA_MOD)) + if(std::find(enabled_modes.begin(), enabled_modes.end(), QMK_OPENRGB_MODE_ALPHA_MOD) != enabled_modes.end()) { InitializeMode("Alpha Mod", current_mode, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED, MODE_COLORS_MODE_SPECIFIC); } - if(controller->GetIsModeEnabled(QMK_OPENRGB_MODE_GRADIENT_UP_DOWN)) + if(std::find(enabled_modes.begin(), enabled_modes.end(), QMK_OPENRGB_MODE_GRADIENT_UP_DOWN) != enabled_modes.end()) { InitializeMode("Gradient Up Down", current_mode, MODE_FLAG_HAS_SPEED, MODE_COLORS_NONE); } - if(controller->GetIsModeEnabled(QMK_OPENRGB_MODE_GRADIENT_LEFT_RIGHT)) + if(std::find(enabled_modes.begin(), enabled_modes.end(), QMK_OPENRGB_MODE_GRADIENT_LEFT_RIGHT) != enabled_modes.end()) { InitializeMode("Gradient Left Right", current_mode, MODE_FLAG_HAS_SPEED, MODE_COLORS_NONE); } - if(controller->GetIsModeEnabled(QMK_OPENRGB_MODE_BREATHING)) + if(std::find(enabled_modes.begin(), enabled_modes.end(), QMK_OPENRGB_MODE_BREATHING) != enabled_modes.end()) { InitializeMode("Breathing", current_mode, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED, MODE_COLORS_MODE_SPECIFIC); } - if(controller->GetIsModeEnabled(QMK_OPENRGB_MODE_BAND_SAT)) + if(std::find(enabled_modes.begin(), enabled_modes.end(), QMK_OPENRGB_MODE_BAND_SAT) != enabled_modes.end()) { InitializeMode("Band Saturation", current_mode, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED, MODE_COLORS_MODE_SPECIFIC); } - if(controller->GetIsModeEnabled(QMK_OPENRGB_MODE_BAND_VAL)) + if(std::find(enabled_modes.begin(), enabled_modes.end(), QMK_OPENRGB_MODE_BAND_VAL) != enabled_modes.end()) { InitializeMode("Band Value", current_mode, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED, MODE_COLORS_MODE_SPECIFIC); } - if(controller->GetIsModeEnabled(QMK_OPENRGB_MODE_BAND_PINWHEEL_SAT)) + if(std::find(enabled_modes.begin(), enabled_modes.end(), QMK_OPENRGB_MODE_BAND_PINWHEEL_SAT) != enabled_modes.end()) { InitializeMode("Band Pinwheel Saturation", current_mode, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED, MODE_COLORS_MODE_SPECIFIC); } - if(controller->GetIsModeEnabled(QMK_OPENRGB_MODE_BAND_PINWHEEL_VAL)) + if(std::find(enabled_modes.begin(), enabled_modes.end(), QMK_OPENRGB_MODE_BAND_PINWHEEL_VAL) != enabled_modes.end()) { InitializeMode("Band Pinwheel Value", current_mode, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED, MODE_COLORS_MODE_SPECIFIC); } - if(controller->GetIsModeEnabled(QMK_OPENRGB_MODE_BAND_SPIRAL_SAT)) + if(std::find(enabled_modes.begin(), enabled_modes.end(), QMK_OPENRGB_MODE_BAND_SPIRAL_SAT) != enabled_modes.end()) { InitializeMode("Band Spiral Saturation", current_mode, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED, MODE_COLORS_MODE_SPECIFIC); } - if(controller->GetIsModeEnabled(QMK_OPENRGB_MODE_BAND_SPIRAL_VAL)) + if(std::find(enabled_modes.begin(), enabled_modes.end(), QMK_OPENRGB_MODE_BAND_SPIRAL_VAL) != enabled_modes.end()) { InitializeMode("Band Spiral Value", current_mode, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED, MODE_COLORS_MODE_SPECIFIC); } - if(controller->GetIsModeEnabled(QMK_OPENRGB_MODE_CYCLE_ALL)) + if(std::find(enabled_modes.begin(), enabled_modes.end(), QMK_OPENRGB_MODE_CYCLE_ALL) != enabled_modes.end()) { InitializeMode("Cycle All", current_mode, MODE_FLAG_HAS_SPEED, MODE_COLORS_NONE); } - if(controller->GetIsModeEnabled(QMK_OPENRGB_MODE_CYCLE_LEFT_RIGHT)) + if(std::find(enabled_modes.begin(), enabled_modes.end(), QMK_OPENRGB_MODE_CYCLE_LEFT_RIGHT) != enabled_modes.end()) { InitializeMode("Cycle Left Right", current_mode, MODE_FLAG_HAS_SPEED, MODE_COLORS_NONE); } - if(controller->GetIsModeEnabled(QMK_OPENRGB_MODE_CYCLE_UP_DOWN)) + if(std::find(enabled_modes.begin(), enabled_modes.end(), QMK_OPENRGB_MODE_CYCLE_UP_DOWN) != enabled_modes.end()) { InitializeMode("Cycle Up Down", current_mode, MODE_FLAG_HAS_SPEED, MODE_COLORS_NONE); } - if(controller->GetIsModeEnabled(QMK_OPENRGB_MODE_CYCLE_OUT_IN)) + if(std::find(enabled_modes.begin(), enabled_modes.end(), QMK_OPENRGB_MODE_CYCLE_OUT_IN) != enabled_modes.end()) { InitializeMode("Cycle Out In", current_mode, MODE_FLAG_HAS_SPEED, MODE_COLORS_NONE); } - if(controller->GetIsModeEnabled(QMK_OPENRGB_MODE_CYCLE_OUT_IN_DUAL)) + if(std::find(enabled_modes.begin(), enabled_modes.end(), QMK_OPENRGB_MODE_CYCLE_OUT_IN_DUAL) != enabled_modes.end()) { InitializeMode("Cycle Out In Dual", current_mode, MODE_FLAG_HAS_SPEED, MODE_COLORS_NONE); } - if(controller->GetIsModeEnabled(QMK_OPENRGB_MODE_RAINBOW_MOVING_CHEVRON)) + if(std::find(enabled_modes.begin(), enabled_modes.end(), QMK_OPENRGB_MODE_RAINBOW_MOVING_CHEVRON) != enabled_modes.end()) { InitializeMode("Rainbow Moving Chevron", current_mode, MODE_FLAG_HAS_SPEED, MODE_COLORS_NONE); } - if(controller->GetIsModeEnabled(QMK_OPENRGB_MODE_CYCLE_PINWHEEL)) + if(std::find(enabled_modes.begin(), enabled_modes.end(), QMK_OPENRGB_MODE_CYCLE_PINWHEEL) != enabled_modes.end()) { InitializeMode("Cycle Pinwheel", current_mode, MODE_FLAG_HAS_SPEED, MODE_COLORS_NONE); } - if(controller->GetIsModeEnabled(QMK_OPENRGB_MODE_CYCLE_SPIRAL)) + if(std::find(enabled_modes.begin(), enabled_modes.end(), QMK_OPENRGB_MODE_CYCLE_SPIRAL) != enabled_modes.end()) { InitializeMode("Cycle Spiral", current_mode, MODE_FLAG_HAS_SPEED, MODE_COLORS_NONE); } - if(controller->GetIsModeEnabled(QMK_OPENRGB_MODE_DUAL_BEACON)) + if(std::find(enabled_modes.begin(), enabled_modes.end(), QMK_OPENRGB_MODE_DUAL_BEACON) != enabled_modes.end()) { InitializeMode("Dual Beacon", current_mode, MODE_FLAG_HAS_SPEED, MODE_COLORS_NONE); } - if(controller->GetIsModeEnabled(QMK_OPENRGB_MODE_RAINBOW_BEACON)) + if(std::find(enabled_modes.begin(), enabled_modes.end(), QMK_OPENRGB_MODE_RAINBOW_BEACON) != enabled_modes.end()) { InitializeMode("Rainbow Beacon", current_mode, MODE_FLAG_HAS_SPEED, MODE_COLORS_NONE); } - if(controller->GetIsModeEnabled(QMK_OPENRGB_MODE_RAINBOW_PINWHEELS)) + if(std::find(enabled_modes.begin(), enabled_modes.end(), QMK_OPENRGB_MODE_RAINBOW_PINWHEELS) != enabled_modes.end()) { InitializeMode("Rainbow Pinwheels", current_mode, MODE_FLAG_HAS_SPEED, MODE_COLORS_NONE); } - if(controller->GetIsModeEnabled(QMK_OPENRGB_MODE_RAINDROPS)) + if(std::find(enabled_modes.begin(), enabled_modes.end(), QMK_OPENRGB_MODE_RAINDROPS) != enabled_modes.end()) { InitializeMode("Raindrops", current_mode, 0, MODE_COLORS_NONE); } - if(controller->GetIsModeEnabled(QMK_OPENRGB_MODE_JELLYBEAN_RAINDROPS)) + if(std::find(enabled_modes.begin(), enabled_modes.end(), QMK_OPENRGB_MODE_JELLYBEAN_RAINDROPS) != enabled_modes.end()) { InitializeMode("Jellybean Raindrops", current_mode, 0, MODE_COLORS_NONE); } - if(controller->GetIsModeEnabled(QMK_OPENRGB_MODE_HUE_BREATHING)) + if(std::find(enabled_modes.begin(), enabled_modes.end(), QMK_OPENRGB_MODE_HUE_BREATHING) != enabled_modes.end()) { InitializeMode("Hue Breathing", current_mode, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED, MODE_COLORS_MODE_SPECIFIC); } - if(controller->GetIsModeEnabled(QMK_OPENRGB_MODE_HUE_PENDULUM)) + if(std::find(enabled_modes.begin(), enabled_modes.end(), QMK_OPENRGB_MODE_HUE_PENDULUM) != enabled_modes.end()) { InitializeMode("Hue Pendulum", current_mode, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED, MODE_COLORS_MODE_SPECIFIC); } - if(controller->GetIsModeEnabled(QMK_OPENRGB_MODE_HUE_WAVE)) + if(std::find(enabled_modes.begin(), enabled_modes.end(), QMK_OPENRGB_MODE_HUE_WAVE) != enabled_modes.end()) { InitializeMode("Hue Wave", current_mode, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED, MODE_COLORS_MODE_SPECIFIC); } - if(controller->GetIsModeEnabled(QMK_OPENRGB_MODE_TYPING_HEATMAP)) + if(std::find(enabled_modes.begin(), enabled_modes.end(), QMK_OPENRGB_MODE_TYPING_HEATMAP) != enabled_modes.end()) { InitializeMode("Typing Heatmap", current_mode, 0, MODE_COLORS_NONE); } - if(controller->GetIsModeEnabled(QMK_OPENRGB_MODE_DIGITAL_RAIN)) + if(std::find(enabled_modes.begin(), enabled_modes.end(), QMK_OPENRGB_MODE_DIGITAL_RAIN) != enabled_modes.end()) { InitializeMode("Digital Rain", current_mode, 0, MODE_COLORS_NONE); } - if(controller->GetIsModeEnabled(QMK_OPENRGB_MODE_SOLID_REACTIVE_SIMPLE)) + if(std::find(enabled_modes.begin(), enabled_modes.end(), QMK_OPENRGB_MODE_SOLID_REACTIVE_SIMPLE) != enabled_modes.end()) { InitializeMode("Solid Reactive Simple", current_mode, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED, MODE_COLORS_MODE_SPECIFIC); } - if(controller->GetIsModeEnabled(QMK_OPENRGB_MODE_SOLID_REACTIVE)) + if(std::find(enabled_modes.begin(), enabled_modes.end(), QMK_OPENRGB_MODE_SOLID_REACTIVE) != enabled_modes.end()) { InitializeMode("Solid Reactive", current_mode, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED, MODE_COLORS_MODE_SPECIFIC); } - if(controller->GetIsModeEnabled(QMK_OPENRGB_MODE_SOLID_REACTIVE_WIDE)) + if(std::find(enabled_modes.begin(), enabled_modes.end(), QMK_OPENRGB_MODE_SOLID_REACTIVE_WIDE) != enabled_modes.end()) { InitializeMode("Solid Reactive Wide", current_mode, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED, MODE_COLORS_MODE_SPECIFIC); } - if(controller->GetIsModeEnabled(QMK_OPENRGB_MODE_SOLID_REACTIVE_MULTIWIDE)) + if(std::find(enabled_modes.begin(), enabled_modes.end(), QMK_OPENRGB_MODE_SOLID_REACTIVE_MULTIWIDE) != enabled_modes.end()) { InitializeMode("Solid Reactive Multi Wide", current_mode, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED, MODE_COLORS_MODE_SPECIFIC); } - if(controller->GetIsModeEnabled(QMK_OPENRGB_MODE_SOLID_REACTIVE_CROSS)) + if(std::find(enabled_modes.begin(), enabled_modes.end(), QMK_OPENRGB_MODE_SOLID_REACTIVE_CROSS) != enabled_modes.end()) { InitializeMode("Solid Reactive Cross", current_mode, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED, MODE_COLORS_MODE_SPECIFIC); } - if(controller->GetIsModeEnabled(QMK_OPENRGB_MODE_SOLID_REACTIVE_MULTICROSS)) + if(std::find(enabled_modes.begin(), enabled_modes.end(), QMK_OPENRGB_MODE_SOLID_REACTIVE_MULTICROSS) != enabled_modes.end()) { InitializeMode("Solid Reactive Multi Cross", current_mode, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED, MODE_COLORS_MODE_SPECIFIC); } - if(controller->GetIsModeEnabled(QMK_OPENRGB_MODE_SOLID_REACTIVE_NEXUS)) + if(std::find(enabled_modes.begin(), enabled_modes.end(), QMK_OPENRGB_MODE_SOLID_REACTIVE_NEXUS) != enabled_modes.end()) { InitializeMode("Solid Reactive Nexus", current_mode, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED, MODE_COLORS_MODE_SPECIFIC); } - if(controller->GetIsModeEnabled(QMK_OPENRGB_MODE_SOLID_REACTIVE_MULTINEXUS)) + if(std::find(enabled_modes.begin(), enabled_modes.end(), QMK_OPENRGB_MODE_SOLID_REACTIVE_MULTINEXUS) != enabled_modes.end()) { InitializeMode("Solid Reactive Multi Nexus", current_mode, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED, MODE_COLORS_MODE_SPECIFIC); } - if(controller->GetIsModeEnabled(QMK_OPENRGB_MODE_SPLASH)) + if(std::find(enabled_modes.begin(), enabled_modes.end(), QMK_OPENRGB_MODE_SPLASH) != enabled_modes.end()) { InitializeMode("Rainbow Reactive Splash", current_mode, MODE_FLAG_HAS_SPEED, MODE_COLORS_NONE); } - if(controller->GetIsModeEnabled(QMK_OPENRGB_MODE_MULTISPLASH)) + if(std::find(enabled_modes.begin(), enabled_modes.end(), QMK_OPENRGB_MODE_MULTISPLASH) != enabled_modes.end()) { InitializeMode("Rainbow Reactive Multi Splash", current_mode, MODE_FLAG_HAS_SPEED, MODE_COLORS_NONE); } - if(controller->GetIsModeEnabled(QMK_OPENRGB_MODE_SOLID_SPLASH)) + if(std::find(enabled_modes.begin(), enabled_modes.end(), QMK_OPENRGB_MODE_SOLID_SPLASH) != enabled_modes.end()) { InitializeMode("Solid Reactive Splash", current_mode, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED, MODE_COLORS_MODE_SPECIFIC); } - if(controller->GetIsModeEnabled(QMK_OPENRGB_MODE_SOLID_MULTISPLASH)) + if(std::find(enabled_modes.begin(), enabled_modes.end(), QMK_OPENRGB_MODE_SOLID_MULTISPLASH) != enabled_modes.end()) { InitializeMode("Solid Reactive Multi Splash", current_mode, MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_SPEED, MODE_COLORS_MODE_SPECIFIC); } - active_mode = controller->GetMode() - 1; + if(std::find(enabled_modes.begin(), enabled_modes.end(), QMK_OPENRGB_MODE_OPENRGB_DIRECT) != enabled_modes.end()) + { + InitializeMode("Direct", current_mode, MODE_FLAG_HAS_PER_LED_COLOR, MODE_COLORS_PER_LED); + } + + /*-----------------------------------------------------*\ + | As we are insertting direct mode at index 0 | + | for it to be the first mode in the UI there will | + | be a mismatch between the values. QMK has direct | + | mode last in order, while in OpenRGB it's first. | + \*-----------------------------------------------------*/ + if(controller->GetMode() == (current_mode - 1)) + { + active_mode = 0; + } + else + { + active_mode = controller->GetMode(); + } SetupZones(); } -RGBController_QMKOpenRGB::~RGBController_QMKOpenRGB() +RGBController_QMKOpenRGBRevB::~RGBController_QMKOpenRGBRevB() { for(unsigned int zone_index = 0; zone_index < zones.size(); zone_index++) { @@ -249,7 +263,7 @@ RGBController_QMKOpenRGB::~RGBController_QMKOpenRGB() } } -void RGBController_QMKOpenRGB::SetupZones() +void RGBController_QMKOpenRGBRevB::SetupZones() { /*---------------------------------------------------------*\ | Get the number of LEDs from the device | @@ -260,10 +274,7 @@ void RGBController_QMKOpenRGB::SetupZones() /*---------------------------------------------------------*\ | Get information for each LED | \*---------------------------------------------------------*/ - for(unsigned int i = 0; i < std::max(total_number_of_leds, total_number_of_leds_with_empty_space); i++) - { - controller->GetLEDInfo(i); - } + controller->GetLEDInfo(std::max(total_number_of_leds, total_number_of_leds_with_empty_space)); /*---------------------------------------------------------*\ | Get LED vectors from controller | @@ -383,24 +394,24 @@ void RGBController_QMKOpenRGB::SetupZones() } } -void RGBController_QMKOpenRGB::ResizeZone(int /*zone*/, int /*new_size*/) +void RGBController_QMKOpenRGBRevB::ResizeZone(int /*zone*/, int /*new_size*/) { /*---------------------------------------------------------*\ | This device does not support resizing zones | \*---------------------------------------------------------*/ } -void RGBController_QMKOpenRGB::DeviceUpdateLEDs() +void RGBController_QMKOpenRGBRevB::DeviceUpdateLEDs() { controller->DirectModeSetLEDs(colors, controller->GetTotalNumberOfLEDs()); } -void RGBController_QMKOpenRGB::UpdateZoneLEDs(int /*zone*/) +void RGBController_QMKOpenRGBRevB::UpdateZoneLEDs(int /*zone*/) { DeviceUpdateLEDs(); } -void RGBController_QMKOpenRGB::UpdateSingleLED(int led) +void RGBController_QMKOpenRGBRevB::UpdateSingleLED(int led) { RGBColor color = colors[led]; unsigned char red = RGBGetRValue(color); @@ -410,12 +421,12 @@ void RGBController_QMKOpenRGB::UpdateSingleLED(int led) controller->DirectModeSetSingleLED(led, red, grn, blu); } -void RGBController_QMKOpenRGB::SetCustomMode() +void RGBController_QMKOpenRGBRevB::SetCustomMode() { active_mode = 0; } -void RGBController_QMKOpenRGB::DeviceUpdateMode() +void RGBController_QMKOpenRGBRevB::DeviceUpdateMode() { if(modes[active_mode].color_mode == MODE_COLORS_PER_LED) { @@ -442,7 +453,7 @@ void RGBController_QMKOpenRGB::DeviceUpdateMode() } } -void RGBController_QMKOpenRGB::InitializeMode +void RGBController_QMKOpenRGBRevB::InitializeMode ( std::string name, unsigned int ¤t_mode, @@ -470,10 +481,21 @@ void RGBController_QMKOpenRGB::InitializeMode qmk_mode.colors[0] = controller->GetModeColor(); } - modes.push_back(qmk_mode); + /*-----------------------------------------------------*\ + | Direct mode it the last mode on the QMK firmware | + | but we still want it to appear first on the UI | + \*-----------------------------------------------------*/ + if(flags & MODE_FLAG_HAS_PER_LED_COLOR) + { + modes.insert(modes.begin(), qmk_mode); + } + else + { + modes.push_back(qmk_mode); + } } -unsigned int RGBController_QMKOpenRGB::CalculateDivisor +unsigned int RGBController_QMKOpenRGBRevB::CalculateDivisor ( std::vector led_points, std::set rows, @@ -520,7 +542,7 @@ unsigned int RGBController_QMKOpenRGB::CalculateDivisor return divisor; } -void RGBController_QMKOpenRGB::CountKeyTypes +void RGBController_QMKOpenRGBRevB::CountKeyTypes ( std::vector led_flags, unsigned int total_led_count, @@ -544,7 +566,7 @@ void RGBController_QMKOpenRGB::CountKeyTypes } } -void RGBController_QMKOpenRGB::PlaceLEDsInMaps +void RGBController_QMKOpenRGBRevB::PlaceLEDsInMaps ( std::set unique_rows, std::set unique_cols, @@ -593,7 +615,7 @@ void RGBController_QMKOpenRGB::PlaceLEDsInMaps } } -VectorMatrix RGBController_QMKOpenRGB::MakeEmptyMatrixMap +VectorMatrix RGBController_QMKOpenRGBRevB::MakeEmptyMatrixMap ( unsigned int height, unsigned int width @@ -610,7 +632,7 @@ VectorMatrix RGBController_QMKOpenRGB::MakeEmptyMatrixMap return matrix_map; } -void RGBController_QMKOpenRGB::CleanMatrixMaps +void RGBController_QMKOpenRGBRevB::CleanMatrixMaps ( VectorMatrix& matrix_map, VectorMatrix& underglow_map, @@ -709,7 +731,7 @@ void RGBController_QMKOpenRGB::CleanMatrixMaps } } -std::vector RGBController_QMKOpenRGB::FlattenMatrixMap +std::vector RGBController_QMKOpenRGBRevB::FlattenMatrixMap ( VectorMatrix matrix_map ) diff --git a/Controllers/QMKOpenRGBController/RGBController_QMKOpenRGB.h b/Controllers/QMKOpenRGBController/RGBController_QMKOpenRGBRevB.h similarity index 91% rename from Controllers/QMKOpenRGBController/RGBController_QMKOpenRGB.h rename to Controllers/QMKOpenRGBController/RGBController_QMKOpenRGBRevB.h index 3aed25e84..98b95b0e4 100644 --- a/Controllers/QMKOpenRGBController/RGBController_QMKOpenRGB.h +++ b/Controllers/QMKOpenRGBController/RGBController_QMKOpenRGBRevB.h @@ -1,7 +1,7 @@ /*-------------------------------------------------------------------*\ -| RGBController_QMKOpenRGB.h | +| RGBController_QMKOpenRGBRevB.h | | | -| Driver for QMK keyboards using OpenRGB Protocol | +| Driver for QMK keyboards using OpenRGB Protocol (Revision B) | | | | Kasper 10th Octobber 2020 | | Jath03 28th May 2021 | @@ -10,7 +10,7 @@ #pragma once #include "RGBController.h" -#include "QMKOpenRGBController.h" +#include "QMKOpenRGBRevBController.h" #include #include #include @@ -20,11 +20,11 @@ typedef std::vector> VectorMatrix; -class RGBController_QMKOpenRGB : public RGBController +class RGBController_QMKOpenRGBRevB : public RGBController { public: - RGBController_QMKOpenRGB(QMKOpenRGBController* controller_ptr); - ~RGBController_QMKOpenRGB(); + RGBController_QMKOpenRGBRevB(QMKOpenRGBRevBController* controller_ptr); + ~RGBController_QMKOpenRGBRevB(); void SetupZones(); void ResizeZone(int zone, int new_size); @@ -37,7 +37,7 @@ public: void DeviceUpdateMode(); private: - QMKOpenRGBController* controller; + QMKOpenRGBRevBController* controller; std::vector flat_matrix_map; std::vector flat_underglow_map; diff --git a/OpenRGB.pro b/OpenRGB.pro index 6b142502a..3ed8fa2aa 100644 --- a/OpenRGB.pro +++ b/OpenRGB.pro @@ -356,8 +356,11 @@ HEADERS += Controllers/PhilipsHueController/RGBController_PhilipsHue.h \ Controllers/PhilipsWizController/PhilipsWizController.h \ Controllers/PhilipsWizController/RGBController_PhilipsWiz.h \ + Controllers/QMKOpenRGBController/QMKOpenRGBController.h \ Controllers/QMKOpenRGBController/QMKOpenRGBRev9Controller.h \ + Controllers/QMKOpenRGBController/QMKOpenRGBRevBController.h \ Controllers/QMKOpenRGBController/RGBController_QMKOpenRGBRev9.h \ + Controllers/QMKOpenRGBController/RGBController_QMKOpenRGBRevB.h \ Controllers/RazerController/RazerController.h \ Controllers/RazerController/RazerKrakenController.h \ Controllers/RazerController/RazerDevices.h \ @@ -720,7 +723,9 @@ SOURCES += Controllers/PhilipsWizController/RGBController_PhilipsWiz.cpp \ Controllers/QMKOpenRGBController/QMKOpenRGBControllerDetect.cpp \ Controllers/QMKOpenRGBController/QMKOpenRGBRev9Controller.cpp \ + Controllers/QMKOpenRGBController/QMKOpenRGBRevBController.cpp \ Controllers/QMKOpenRGBController/RGBController_QMKOpenRGBRev9.cpp \ + Controllers/QMKOpenRGBController/RGBController_QMKOpenRGBRevB.cpp \ Controllers/RazerController/RazerController.cpp \ Controllers/RazerController/RazerKrakenController.cpp \ Controllers/RazerController/RazerControllerDetect.cpp \