From 5e1068d565771316c67295d6908f6cb6689bb7b1 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sat, 8 Dec 2018 18:21:51 -0600 Subject: [PATCH] Fix config updates when updating quickly. This fixes the pad flickering when dragging the color slider, because it could briefly use an out-of-date configuration (only really visible when going between red and white on the left). --- sdk/Windows/SMXDevice.cpp | 14 +++++++++++++- sdk/Windows/SMXDevice.h | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/sdk/Windows/SMXDevice.cpp b/sdk/Windows/SMXDevice.cpp index 8245eee..40ece1b 100644 --- a/sdk/Windows/SMXDevice.cpp +++ b/sdk/Windows/SMXDevice.cpp @@ -297,6 +297,11 @@ void SMX::SMXDevice::SendConfig() if(!m_bHaveConfig) return; + // If we're still waiting for a previous configuration to read back, don't send + // another yet. + if(m_bWaitingForConfigResponse) + return; + // Write configuration command: string sData = ssprintf("w"); int8_t iSize = sizeof(SMXConfig); @@ -316,9 +321,16 @@ void SMX::SMXDevice::SendConfig() // command below completes. config = wanted_config; + // Don't send another configuration packet until we receive the response to the above + // command. If we're sending updates quickly (eg. dragging the color slider), we can + // send multiple updates before we get a response. + m_bWaitingForConfigResponse = true; + // After we write the configuration, read back the updated configuration to // verify it. - SendCommandLocked("g\n"); + SendCommandLocked("g\n", [this]() { + m_bWaitingForConfigResponse = false; + }); } void SMX::SMXDevice::Update(wstring &sError) diff --git a/sdk/Windows/SMXDevice.h b/sdk/Windows/SMXDevice.h index bdb6e8c..ddff899 100644 --- a/sdk/Windows/SMXDevice.h +++ b/sdk/Windows/SMXDevice.h @@ -110,6 +110,7 @@ private: SMXConfig wanted_config; bool m_bSendConfig = false; bool m_bSendingConfig = false; + bool m_bWaitingForConfigResponse = false; void CallUpdateCallback(SMXUpdateCallbackReason reason); void HandlePackets();