From ce261c1ecbf6c5eac60136e40357bd83d84014dc Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Wed, 6 Feb 2019 20:01:06 -0600 Subject: [PATCH] Add internal support for panel test modes, and rename "test mode" to "sensor test mode" to make the distinction clearer. --- sdk/SMX.h | 15 ++++++++++++- sdk/Windows/SMX.cpp | 4 +++- sdk/Windows/SMXDevice.cpp | 4 ++-- sdk/Windows/SMXDevice.h | 2 +- sdk/Windows/SMXManager.cpp | 44 ++++++++++++++++++++++++++++++++++++++ sdk/Windows/SMXManager.h | 8 +++++++ 6 files changed, 72 insertions(+), 5 deletions(-) diff --git a/sdk/SMX.h b/sdk/SMX.h index f881013..587d18c 100644 --- a/sdk/SMX.h +++ b/sdk/SMX.h @@ -12,6 +12,7 @@ struct SMXInfo; struct SMXConfig; enum SensorTestMode; +enum PanelTestMode; enum SMXUpdateCallbackReason; struct SMXSensorTestModeData; @@ -101,10 +102,15 @@ SMX_API void SMX_FactoryReset(int pad); // for diagnostics. SMX_API void SMX_ForceRecalibration(int pad); -// Set a panel test mode and request test data. This is used by the configuration tool. +// Set a sensor test mode and request test data. This is used by the configuration tool. SMX_API void SMX_SetTestMode(int pad, SensorTestMode mode); SMX_API bool SMX_GetTestData(int pad, SMXSensorTestModeData *data); +// Set a panel test mode. These only appear as debug lighting on the panel and don't +// return data to us. Lights can't be updated while a panel test mode is active. +// This applies to all connected pads. +SMX_API void SMX_SetPanelTestMode(PanelTestMode mode); + // Return the build version of the DLL, which is based on the git tag at build time. This // is only intended for diagnostic logging, and it's also the version we show in SMXConfig. SMX_API const char *SMX_Version(); @@ -291,4 +297,11 @@ struct SMXSensorTestModeData bool iBadJumper[9][4]; }; +// The values also correspond with the protocol and must not be changed. +// These are panel-side diagnostics modes. +enum PanelTestMode { + PanelTestMode_Off = '0', + PanelTestMode_PressureTest = '1', +}; + #endif diff --git a/sdk/Windows/SMX.cpp b/sdk/Windows/SMX.cpp index 3196136..f42a2cd 100644 --- a/sdk/Windows/SMX.cpp +++ b/sdk/Windows/SMX.cpp @@ -62,8 +62,10 @@ SMX_API void SMX_GetInfo(int pad, SMXInfo *info) { SMXManager::g_pSMX->GetDevice SMX_API uint16_t SMX_GetInputState(int pad) { return SMXManager::g_pSMX->GetDevice(pad)->GetInputState(); } SMX_API void SMX_FactoryReset(int pad) { SMXManager::g_pSMX->GetDevice(pad)->FactoryReset(); } SMX_API void SMX_ForceRecalibration(int pad) { SMXManager::g_pSMX->GetDevice(pad)->ForceRecalibration(); } -SMX_API void SMX_SetTestMode(int pad, SensorTestMode mode) { SMXManager::g_pSMX->GetDevice(pad)->SetSensorTestMode((SensorTestMode) mode); } +SMX_API void SMX_SetTestMode(int pad, SensorTestMode mode) { SMXManager::g_pSMX->GetDevice(pad)->SetSensorTestMode(mode); } SMX_API bool SMX_GetTestData(int pad, SMXSensorTestModeData *data) { return SMXManager::g_pSMX->GetDevice(pad)->GetTestData(*data); } +SMX_API void SMX_SetPanelTestMode(PanelTestMode mode) { SMXManager::g_pSMX->SetPanelTestMode(mode); } + SMX_API void SMX_SetLights(const char lightData[864]) { SMX_SetLights2(lightData, 864); diff --git a/sdk/Windows/SMXDevice.cpp b/sdk/Windows/SMXDevice.cpp index 0e085b7..f1b1931 100644 --- a/sdk/Windows/SMXDevice.cpp +++ b/sdk/Windows/SMXDevice.cpp @@ -359,7 +359,7 @@ void SMX::SMXDevice::Update(wstring &sError) CheckActive(); SendConfig(); - UpdateTestMode(); + UpdateSensorTestMode(); { uint16_t iOldState = m_pConnection->GetInputState(); @@ -396,7 +396,7 @@ void SMX::SMXDevice::CheckActive() } // Check if we need to request test mode data. -void SMX::SMXDevice::UpdateTestMode() +void SMX::SMXDevice::UpdateSensorTestMode() { m_Lock.AssertLockedByCurrentThread(); diff --git a/sdk/Windows/SMXDevice.h b/sdk/Windows/SMXDevice.h index 6802390..ce9ef9c 100644 --- a/sdk/Windows/SMXDevice.h +++ b/sdk/Windows/SMXDevice.h @@ -121,7 +121,7 @@ private: bool IsConnectedLocked() const; // Test/diagnostics mode handling. - void UpdateTestMode(); + void UpdateSensorTestMode(); void HandleSensorTestDataResponse(const string &sReadBuffer); SensorTestMode m_WaitingForSensorTestModeResponse = SensorTestMode_Off; SensorTestMode m_SensorTestMode = SensorTestMode_Off; diff --git a/sdk/Windows/SMXManager.cpp b/sdk/Windows/SMXManager.cpp index cd16c43..f3e79da 100644 --- a/sdk/Windows/SMXManager.cpp +++ b/sdk/Windows/SMXManager.cpp @@ -135,6 +135,9 @@ void SMX::SMXManager::ThreadMain() // since this actually just queues commands, which are actually handled in Update. SendLightUpdates(); + // Send panel test mode commands if needed. + UpdatePanelTestMode(); + // See if there are any new devices. AttemptConnections(); @@ -246,6 +249,10 @@ void SMX::SMXManager::SetLights(const string sPanelLights[2]) g_Lock.AssertNotLockedByCurrentThread(); LockMutex L(g_Lock); + // Don't send lights when a panel test mode is active. + if(m_PanelTestMode != PanelTestMode_Off) + return; + // Separate top and bottom lights commands. // // sPanelLights[iPad] is @@ -491,6 +498,43 @@ void SMX::SMXManager::SendLightUpdates() m_aPendingLightsCommands.erase(m_aPendingLightsCommands.begin(), m_aPendingLightsCommands.begin()+1); } +void SMX::SMXManager::SetPanelTestMode(PanelTestMode mode) +{ + g_Lock.AssertNotLockedByCurrentThread(); + LockMutex Lock(g_Lock); + m_PanelTestMode = mode; +} + +void SMX::SMXManager::UpdatePanelTestMode() +{ + // If the test mode has changed, send the new test mode. + // + // When the test mode is enabled, send the test mode again periodically, or it'll time + // out on the master and be turned off. Don't repeat the PanelTestMode_Off command. + g_Lock.AssertLockedByCurrentThread(); + uint32_t now = GetTickCount(); + if(m_PanelTestMode == m_LastSentPanelTestMode && + (m_PanelTestMode == PanelTestMode_Off || now - m_SentPanelTestModeAtTicks < 1000)) + return; + + // When we first send the test mode command (not for repeats), turn off lights. + if(m_LastSentPanelTestMode == PanelTestMode_Off) + { + // The 'l' command used to set lights, but it's now only used to turn lights off + // for cases like this. + string sData = "l"; + sData.append(108, 0); + sData += "\n"; + for(int iPad = 0; iPad < 2; ++iPad) + m_pDevices[iPad]->SendCommandLocked(sData); + } + + m_SentPanelTestModeAtTicks = now; + m_LastSentPanelTestMode = m_PanelTestMode; + for(int iPad = 0; iPad < 2; ++iPad) + m_pDevices[iPad]->SendCommandLocked(ssprintf("t %c\n", m_PanelTestMode)); +} + void SMX::SMXManager::RunInHelperThread(function func) { m_UserCallbackThread.RunInThread(func); diff --git a/sdk/Windows/SMXManager.h b/sdk/Windows/SMXManager.h index 10afe6e..40cd6dd 100644 --- a/sdk/Windows/SMXManager.h +++ b/sdk/Windows/SMXManager.h @@ -45,6 +45,7 @@ public: shared_ptr GetDevice(int pad); void SetLights(const string sLights[2]); void ReenableAutoLights(); + void SetPanelTestMode(PanelTestMode mode); // Run a function in the user callback thread. void RunInHelperThread(function func); @@ -76,6 +77,13 @@ private: }; vector m_aPendingLightsCommands; double m_fDelayLightCommandsUntil = 0; + + // Panel test mode. This is separate from the sensor test mode (pressure display), + // which is handled in SMXDevice. + void UpdatePanelTestMode(); + uint32_t m_SentPanelTestModeAtTicks = 0; + PanelTestMode m_PanelTestMode = PanelTestMode_Off; + PanelTestMode m_LastSentPanelTestMode = PanelTestMode_Off; }; }