From 2967ccb1cb29f20a43ad5593be357e78d6a36a75 Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Tue, 12 Aug 2025 13:10:36 -0500 Subject: [PATCH] Add a mutex and remove a timeout to reduce flicker on HYTE Q60 logo LEDs --- .../HYTENexusController/HYTENexusController.cpp | 13 ++++++++----- .../HYTENexusController/HYTENexusController.h | 2 ++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Controllers/HYTENexusController/HYTENexusController.cpp b/Controllers/HYTENexusController/HYTENexusController.cpp index f4c856a9..b19b598d 100644 --- a/Controllers/HYTENexusController/HYTENexusController.cpp +++ b/Controllers/HYTENexusController/HYTENexusController.cpp @@ -228,14 +228,11 @@ void HYTENexusController::LEDStreaming(unsigned char channel, unsigned short led bytes_to_send = 750; } + port_mutex.lock(); serialport->serial_write((char *)command_buf, bytes_to_send); serialport->serial_flush_tx(); serialport->serial_flush_rx(); - - /*-----------------------------------------------------*\ - | Wait 10ms for device process command | - \*-----------------------------------------------------*/ - std::this_thread::sleep_for(5ms); + port_mutex.unlock(); } void HYTENexusController::ReadChannelInfo(unsigned char channel) @@ -254,6 +251,7 @@ void HYTENexusController::ReadChannelInfo(unsigned char channel) command_buf[2] = 0x01; command_buf[3] = (channel + 1); + port_mutex.lock(); serialport->serial_write((char *)command_buf, sizeof(command_buf)); serialport->serial_flush_tx(); @@ -286,6 +284,7 @@ void HYTENexusController::ReadChannelInfo(unsigned char channel) serialport->serial_read((char *)receive_buf, sizeof(receive_buf)); serialport->serial_flush_rx(); + port_mutex.unlock(); channels[channel].num_devices = 0; memset(&channels[channel].devices, 0, sizeof(channels[channel].devices)); @@ -321,6 +320,7 @@ void HYTENexusController::ReadDeviceInfo() command_buf[2] = 0x01; command_buf[3] = 0x00; + port_mutex.lock(); serialport->serial_write((char *)command_buf, sizeof(command_buf)); serialport->serial_flush_tx(); @@ -351,6 +351,7 @@ void HYTENexusController::ReadDeviceInfo() serialport->serial_read((char *)receive_buf, sizeof(receive_buf)); serialport->serial_flush_rx(); + port_mutex.unlock(); /*-----------------------------------------------------*\ | Update last update time | @@ -374,6 +375,7 @@ void HYTENexusController::ReadFirmwareVersion() command_buf[2] = 0x02; command_buf[3] = 0x00; + port_mutex.lock(); serialport->serial_write((char *)command_buf, sizeof(command_buf)); serialport->serial_flush_tx(); @@ -396,6 +398,7 @@ void HYTENexusController::ReadFirmwareVersion() serialport->serial_read((char *)receive_buf, sizeof(receive_buf)); serialport->serial_flush_rx(); + port_mutex.unlock(); /*-----------------------------------------------------*\ | Format Firmware Version string | diff --git a/Controllers/HYTENexusController/HYTENexusController.h b/Controllers/HYTENexusController/HYTENexusController.h index d44844e4..f590068d 100644 --- a/Controllers/HYTENexusController/HYTENexusController.h +++ b/Controllers/HYTENexusController/HYTENexusController.h @@ -13,6 +13,7 @@ #include #include +#include #include #include #include "RGBController.h" @@ -70,6 +71,7 @@ private: std::string firmware_version; std::string name; std::string port_name; + std::mutex port_mutex; serial_port * serialport = nullptr; std::chrono::time_point last_update_time; std::atomic keepalive_thread_run;