From d6e9ee39780e5f3cc60a47156404fd6d48b071aa Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Sat, 11 Sep 2021 20:10:37 -0500 Subject: [PATCH] Add option for introducing a delay (in milliseconds) between direct mode LED packets for the QMK OpenRGB protocol --- .../QMKOpenRGBRev9Controller.cpp | 16 ++++++++++++++++ .../QMKOpenRGBRev9Controller.h | 2 ++ .../QMKOpenRGBRevBController.cpp | 16 ++++++++++++++++ .../QMKOpenRGBRevBController.h | 2 ++ 4 files changed, 36 insertions(+) diff --git a/Controllers/QMKOpenRGBController/QMKOpenRGBRev9Controller.cpp b/Controllers/QMKOpenRGBController/QMKOpenRGBRev9Controller.cpp index c3510333..80801d4b 100644 --- a/Controllers/QMKOpenRGBController/QMKOpenRGBRev9Controller.cpp +++ b/Controllers/QMKOpenRGBController/QMKOpenRGBRev9Controller.cpp @@ -11,6 +11,8 @@ #include "QMKOpenRGBRev9Controller.h" +using namespace std::chrono_literals; + static std::map QMKKeycodeToKeynameMap { { 0, "" }, { 1, "Right Fn" }, { 2, "" }, { 3, "" }, @@ -85,6 +87,15 @@ QMKOpenRGBRev9Controller::QMKOpenRGBRev9Controller(hid_device *dev_handle, const leds_per_update = 20; } + if(qmk_settings.contains("delay")) + { + delay = (unsigned int)qmk_settings["delay"] * 1ms; + } + else + { + delay = 0ms; + } + dev = dev_handle; location = path; @@ -451,6 +462,11 @@ void QMKOpenRGBRev9Controller::DirectModeSetLEDs(std::vector colors, u hid_write(dev, usb_buf, 65); + if(delay > 0ms) + { + std::this_thread::sleep_for(delay); + } + leds_sent += tmp_leds_per_update; } } diff --git a/Controllers/QMKOpenRGBController/QMKOpenRGBRev9Controller.h b/Controllers/QMKOpenRGBController/QMKOpenRGBRev9Controller.h index d1b8a17c..ea2ebee8 100644 --- a/Controllers/QMKOpenRGBController/QMKOpenRGBRev9Controller.h +++ b/Controllers/QMKOpenRGBController/QMKOpenRGBRev9Controller.h @@ -56,6 +56,8 @@ private: 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; diff --git a/Controllers/QMKOpenRGBController/QMKOpenRGBRevBController.cpp b/Controllers/QMKOpenRGBController/QMKOpenRGBRevBController.cpp index 2da43d52..9e07e171 100644 --- a/Controllers/QMKOpenRGBController/QMKOpenRGBRevBController.cpp +++ b/Controllers/QMKOpenRGBController/QMKOpenRGBRevBController.cpp @@ -9,6 +9,8 @@ #include "QMKOpenRGBRevBController.h" +using namespace std::chrono_literals; + static std::map QMKKeycodeToKeynameMap { { 0, "" }, { 1, "Right Fn" }, { 2, "" }, { 3, "" }, @@ -83,6 +85,15 @@ QMKOpenRGBRevBController::QMKOpenRGBRevBController(hid_device *dev_handle, const leds_per_update = 20; } + if(qmk_settings.contains("delay")) + { + delay = (unsigned int)qmk_settings["delay"] * 1ms; + } + else + { + delay = 0ms; + } + dev = dev_handle; location = path; @@ -473,6 +484,11 @@ void QMKOpenRGBRevBController::DirectModeSetLEDs(std::vector colors, u hid_write(dev, usb_buf, 65); + if(delay > 0ms) + { + std::this_thread::sleep_for(delay); + } + leds_sent += tmp_leds_per_update; } } \ No newline at end of file diff --git a/Controllers/QMKOpenRGBController/QMKOpenRGBRevBController.h b/Controllers/QMKOpenRGBController/QMKOpenRGBRevBController.h index 4544ef61..8590373d 100644 --- a/Controllers/QMKOpenRGBController/QMKOpenRGBRevBController.h +++ b/Controllers/QMKOpenRGBController/QMKOpenRGBRevBController.h @@ -54,6 +54,8 @@ private: 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;