diff --git a/sdk/Windows/SMXDevice.cpp b/sdk/Windows/SMXDevice.cpp index 400c1e3..c4ebf6a 100644 --- a/sdk/Windows/SMXDevice.cpp +++ b/sdk/Windows/SMXDevice.cpp @@ -103,13 +103,13 @@ bool SMX::SMXDevice::IsConnectedLocked() const return m_pConnection->IsConnectedWithDeviceInfo() && m_bHaveConfig; } -void SMX::SMXDevice::SendCommand(string cmd, function pComplete) +void SMX::SMXDevice::SendCommand(string cmd, function pComplete) { LockMutex Lock(m_Lock); SendCommandLocked(cmd, pComplete); } -void SMX::SMXDevice::SendCommandLocked(string cmd, function pComplete) +void SMX::SMXDevice::SendCommandLocked(string cmd, function pComplete) { m_Lock.AssertLockedByCurrentThread(); @@ -117,7 +117,7 @@ void SMX::SMXDevice::SendCommandLocked(string cmd, function pComplete) { // If we're not connected, just call pComplete. if(pComplete) - pComplete(); + pComplete(""); return; } @@ -200,7 +200,7 @@ void SMX::SMXDevice::FactoryReset() // Send a factory reset command, and then read the new configuration. LockMutex Lock(m_Lock); SendCommandLocked("f\n"); - SendCommandLocked("g\n", [&] { + SendCommandLocked("g\n", [&](string response) { // We now have the new configuration. m_Lock.AssertLockedByCurrentThread(); CallUpdateCallback(SMXUpdateCallback_FactoryResetCommandComplete); @@ -319,7 +319,7 @@ void SMX::SMXDevice::SendConfig() // Don't send another config packet until this one finishes, so if we get a bunch of // SetConfig calls quickly we won't spam the device, which can get slow. m_bSendingConfig = true; - SendCommandLocked(sData, [&] { + SendCommandLocked(sData, [&](string response) { m_bSendingConfig = false; }); m_bSendConfig = false; @@ -336,7 +336,7 @@ void SMX::SMXDevice::SendConfig() // After we write the configuration, read back the updated configuration to // verify it. - SendCommandLocked("g\n", [this]() { + SendCommandLocked("g\n", [this](string response) { m_bWaitingForConfigResponse = false; }); } diff --git a/sdk/Windows/SMXDevice.h b/sdk/Windows/SMXDevice.h index 374c667..6802390 100644 --- a/sdk/Windows/SMXDevice.h +++ b/sdk/Windows/SMXDevice.h @@ -41,8 +41,8 @@ public: bool IsConnected() const; // Send a raw command. - void SendCommand(string sCmd, function pComplete=nullptr); - void SendCommandLocked(string sCmd, function pComplete=nullptr); + void SendCommand(string sCmd, function pComplete=nullptr); + void SendCommandLocked(string sCmd, function pComplete=nullptr); // Get basic info about the device. void GetInfo(SMXInfo &info); diff --git a/sdk/Windows/SMXDeviceConnection.cpp b/sdk/Windows/SMXDeviceConnection.cpp index 5f47b1a..1c1f228 100644 --- a/sdk/Windows/SMXDeviceConnection.cpp +++ b/sdk/Windows/SMXDeviceConnection.cpp @@ -41,7 +41,7 @@ bool SMX::SMXDeviceConnection::Open(shared_ptr DeviceHandle, ws BeginAsyncRead(sError); // Request device info. - RequestDeviceInfo([&] { + RequestDeviceInfo([&](string response) { Log(ssprintf("Received device info. Master version: %i, P%i", m_DeviceInfo.m_iFirmwareVersion, m_DeviceInfo.m_bP2+1)); m_bGotInfo = true; }); @@ -59,14 +59,14 @@ void SMX::SMXDeviceConnection::Close() // If we're being closed while a command was in progress, call its completion // callback, so it's guaranteed to always be called. if(m_pCurrentCommand && m_pCurrentCommand->m_pComplete) - m_pCurrentCommand->m_pComplete(); + m_pCurrentCommand->m_pComplete(""); // If any commands were queued with completion callbacks, call their completion // callbacks. for(auto &pendingCommand: m_aPendingCommands) { if(pendingCommand->m_pComplete) - pendingCommand->m_pComplete(); + pendingCommand->m_pComplete(""); } m_hDevice.reset(); @@ -205,7 +205,7 @@ void SMX::SMXDeviceConnection::HandleUsbPacket(const string &buf) memcpy(m_DeviceInfo.m_Serial, sHexSerial.c_str(), 33); if(m_pCurrentCommand->m_pComplete) - m_pCurrentCommand->m_pComplete(); + m_pCurrentCommand->m_pComplete(sPacket); m_pCurrentCommand = nullptr; break; @@ -230,22 +230,24 @@ void SMX::SMXDeviceConnection::HandleUsbPacket(const string &buf) m_sCurrentReadBuffer.append(sPacket); - if(cmd & PACKET_FLAG_END_OF_COMMAND) - { - if(!m_sCurrentReadBuffer.empty()) - m_sReadBuffers.push_back(m_sCurrentReadBuffer); - m_sCurrentReadBuffer.clear(); - } - + // Note that if PACKET_FLAG_HOST_CMD_FINISHED is set, PACKET_FLAG_END_OF_COMMAND + // will always also be set. if(cmd & PACKET_FLAG_HOST_CMD_FINISHED) { // This tells us that a command we wrote to the device has finished executing, and // it's safe to start writing another. if(m_pCurrentCommand && m_pCurrentCommand->m_pComplete) - m_pCurrentCommand->m_pComplete(); + m_pCurrentCommand->m_pComplete(m_sCurrentReadBuffer); m_pCurrentCommand = nullptr; } + if(cmd & PACKET_FLAG_END_OF_COMMAND) + { + if(!m_sCurrentReadBuffer.empty()) + m_sReadBuffers.push_back(m_sCurrentReadBuffer); + m_sCurrentReadBuffer.clear(); + } + break; } @@ -341,7 +343,7 @@ void SMX::SMXDeviceConnection::CheckWrites(wstring &error) // Request device info. This is the same as sending an 'i' command, but we can send it safely // at any time, even if another application is talking to the device, so we can do this during // enumeration. -void SMX::SMXDeviceConnection::RequestDeviceInfo(function pComplete) +void SMX::SMXDeviceConnection::RequestDeviceInfo(function pComplete) { shared_ptr pPendingCommand = make_shared(); pPendingCommand->m_pComplete = pComplete; @@ -362,7 +364,7 @@ void SMX::SMXDeviceConnection::RequestDeviceInfo(function pComplete) m_aPendingCommands.push_back(pPendingCommand); } -void SMX::SMXDeviceConnection::SendCommand(const string &cmd, function pComplete) +void SMX::SMXDeviceConnection::SendCommand(const string &cmd, function pComplete) { shared_ptr pPendingCommand = make_shared(); pPendingCommand->m_pComplete = pComplete; diff --git a/sdk/Windows/SMXDeviceConnection.h b/sdk/Windows/SMXDeviceConnection.h index 003b3a5..c096863 100644 --- a/sdk/Windows/SMXDeviceConnection.h +++ b/sdk/Windows/SMXDeviceConnection.h @@ -60,12 +60,12 @@ public: // Send a command. This must be a single complete command: partial writes and multiple // commands in a call aren't allowed. - void SendCommand(const string &cmd, function pComplete=nullptr); + void SendCommand(const string &cmd, function pComplete=nullptr); uint16_t GetInputState() const { return m_iInputState; } private: - void RequestDeviceInfo(function pComplete = nullptr); + void RequestDeviceInfo(function pComplete = nullptr); void CheckReads(wstring &error); void BeginAsyncRead(wstring &error); @@ -95,8 +95,8 @@ private: list> m_Packets; // This is only called if m_bWaitForResponse if true. Otherwise, we send the command - // and forget about it. - function m_pComplete; + // and forget about it. If the command has a response, it'll be in buf. + function m_pComplete; // If true, once we send this command we won't send any other commands until we get // a response. diff --git a/sdk/Windows/SMXPanelAnimationUpload.cpp b/sdk/Windows/SMXPanelAnimationUpload.cpp index 8178e52..1e41c2a 100644 --- a/sdk/Windows/SMXPanelAnimationUpload.cpp +++ b/sdk/Windows/SMXPanelAnimationUpload.cpp @@ -409,7 +409,7 @@ void SMX_LightsUpload_BeginUpload(int pad, SMX_LightsUploadCallback pCallback, v for(int i = 0; i < asCommands.size(); ++i) { const string &sCommand = asCommands[i]; - pDevice->SendCommand(sCommand, [i, iTotalCommands, pCallback, pUser]() { + pDevice->SendCommand(sCommand, [i, iTotalCommands, pCallback, pUser](string response) { // Command #i has finished being sent. // // If this isn't the last command, make sure progress isn't 100.