From 6ea3cdb8b7153796830fdbcf8c875d026f596d59 Mon Sep 17 00:00:00 2001 From: Kasper Date: Fri, 25 Jun 2021 23:49:02 +0000 Subject: [PATCH] QMK Improvements - make LEDs per update configurable * Fix Windows include error that breaks std::min/max if a Windows header is included (tracked down to net_port.h) Commit amended by Adam Honse --- .../QMKOpenRGBController.cpp | 39 +++++++++++++++---- .../QMKOpenRGBController.h | 7 +++- .../RGBController_QMKOpenRGB.cpp | 2 +- net_port/net_port.h | 4 ++ 4 files changed, 41 insertions(+), 11 deletions(-) diff --git a/Controllers/QMKOpenRGBController/QMKOpenRGBController.cpp b/Controllers/QMKOpenRGBController/QMKOpenRGBController.cpp index 9e80e030..00d76452 100644 --- a/Controllers/QMKOpenRGBController/QMKOpenRGBController.cpp +++ b/Controllers/QMKOpenRGBController/QMKOpenRGBController.cpp @@ -59,6 +59,30 @@ static std::map QMKKeycodeToKeynameMap QMKOpenRGBController::QMKOpenRGBController(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; + } + dev = dev_handle; location = path; @@ -150,7 +174,7 @@ unsigned int QMKOpenRGBController::GetProtocolVersion() do { hid_write(dev, usb_buf, QMK_OPENRGB_PACKET_SIZE); - bytes_read = hid_read_timeout(dev, usb_buf, QMK_OPENRGB_PACKET_SIZE, QMK_HID_READ_TIMEOUT); + 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]; @@ -204,7 +228,7 @@ void QMKOpenRGBController::GetDeviceInfo() do { hid_write(dev, usb_buf, QMK_OPENRGB_PACKET_SIZE); - bytes_read = hid_read_timeout(dev, usb_buf, QMK_OPENRGB_PACKET_SIZE, QMK_HID_READ_TIMEOUT); + 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]; @@ -244,7 +268,7 @@ void QMKOpenRGBController::GetModeInfo() do { hid_write(dev, usb_buf, 65); - bytes_read = hid_read_timeout(dev, usb_buf, 65, QMK_HID_READ_TIMEOUT); + 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]; @@ -286,7 +310,7 @@ void QMKOpenRGBController::GetLEDInfo(unsigned int led) do { hid_write(dev, usb_buf, QMK_OPENRGB_PACKET_SIZE); - bytes_read = hid_read_timeout(dev, usb_buf, QMK_OPENRGB_PACKET_SIZE, QMK_HID_READ_TIMEOUT); + 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) @@ -329,7 +353,7 @@ bool QMKOpenRGBController::GetIsModeEnabled(unsigned int mode) do { hid_write(dev, usb_buf, QMK_OPENRGB_PACKET_SIZE); - bytes_read = hid_read_timeout(dev, usb_buf, QMK_OPENRGB_PACKET_SIZE, QMK_HID_READ_TIMEOUT); + 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; @@ -359,7 +383,7 @@ void QMKOpenRGBController::SetMode(hsv_t hsv_color, unsigned char mode, unsigned | Send packet | \*-----------------------------------------------------*/ hid_write(dev, usb_buf, 65); - hid_read_timeout(dev, usb_buf, 65, QMK_HID_READ_TIMEOUT); + 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) @@ -386,13 +410,12 @@ void QMKOpenRGBController::DirectModeSetSingleLED(unsigned int led, unsigned cha | Send packet | \*-----------------------------------------------------*/ hid_write(dev, usb_buf, 65); - hid_read_timeout(dev, usb_buf, 65, QMK_HID_READ_TIMEOUT); + hid_read_timeout(dev, usb_buf, 65, QMK_OPENRGB_HID_READ_TIMEOUT); } void QMKOpenRGBController::DirectModeSetLEDs(std::vector colors, unsigned int leds_count) { unsigned int leds_sent = 0; - unsigned int leds_per_update = 20; while (leds_sent < leds_count) { diff --git a/Controllers/QMKOpenRGBController/QMKOpenRGBController.h b/Controllers/QMKOpenRGBController/QMKOpenRGBController.h index c2cd01cd..0de6ee38 100644 --- a/Controllers/QMKOpenRGBController/QMKOpenRGBController.h +++ b/Controllers/QMKOpenRGBController/QMKOpenRGBController.h @@ -9,14 +9,15 @@ #pragma once +#include "ResourceManager.h" #include "RGBController.h" #include "hsv.h" #include #include #include -#define QMK_OPENRGB_PACKET_SIZE 65 -#define QMK_HID_READ_TIMEOUT 50 +#define QMK_OPENRGB_PACKET_SIZE 65 +#define QMK_OPENRGB_HID_READ_TIMEOUT 50 enum CommandsId { @@ -160,6 +161,8 @@ protected: hid_device *dev; private: + unsigned int leds_per_update; + std::string location; std::string device_name; diff --git a/Controllers/QMKOpenRGBController/RGBController_QMKOpenRGB.cpp b/Controllers/QMKOpenRGBController/RGBController_QMKOpenRGB.cpp index 163da18c..444e5f03 100644 --- a/Controllers/QMKOpenRGBController/RGBController_QMKOpenRGB.cpp +++ b/Controllers/QMKOpenRGBController/RGBController_QMKOpenRGB.cpp @@ -554,7 +554,7 @@ void RGBController_QMKOpenRGB::PlaceLEDsInMaps VectorMatrix& matrix_map_xl, VectorMatrix& underglow_map_xl ) -{ +{ matrix_map_xl = MakeEmptyMatrixMap(unique_rows.size(), std::round(255/divisor) + 10); underglow_map_xl = MakeEmptyMatrixMap(unique_rows.size(), std::round(255/divisor) + 10); diff --git a/net_port/net_port.h b/net_port/net_port.h index 790d8d19..2ffc0dff 100644 --- a/net_port/net_port.h +++ b/net_port/net_port.h @@ -13,6 +13,10 @@ #include #ifdef WIN32 +/*---------------------------------------------------------*\ +| Windows interferes with std::max unless NOMINMAX defined | +\*---------------------------------------------------------*/ +#define NOMINMAX #include #include #else