Skip to content

Commit be3b3e2

Browse files
committed
ensure that no command gets lost
1 parent de98ff2 commit be3b3e2

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/ZeDMDComm.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,18 @@ void ZeDMDComm::QueueCommand(char command, uint8_t* data, int size)
132132
return;
133133
}
134134

135-
if (FillDelayed())
135+
// It must be ensured that no command is lost.
136+
// Losing frames is ok.
137+
if (ZEDMD_COMM_COMMAND::ClearScreen != command)
138+
{
139+
uint8_t timeout = 0;
140+
while (!IsQueueEmpty() && timeout < 10)
141+
{
142+
std::this_thread::sleep_for(std::chrono::milliseconds(200));
143+
timeout++;
144+
}
145+
}
146+
else if (FillDelayed())
136147
{
137148
ClearFrames();
138149
}
@@ -278,6 +289,14 @@ bool ZeDMDComm::FillDelayed()
278289
return delayed;
279290
}
280291

292+
bool ZeDMDComm::IsQueueEmpty()
293+
{
294+
m_frameQueueMutex.lock();
295+
bool empty = m_frames.empty();
296+
m_frameQueueMutex.unlock();
297+
return empty;
298+
}
299+
281300
void ZeDMDComm::IgnoreDevice(const char* ignore_device)
282301
{
283302
if (sizeof(ignore_device) < 32 && m_ignoredDevicesCounter < 10)

src/ZeDMDComm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ class ZeDMDComm
237237
virtual void Reset();
238238
void Log(const char* format, ...);
239239
void ClearFrames();
240+
bool IsQueueEmpty();
240241

241242
char m_firmwareVersion[12] = "0.0.0";
242243
uint16_t m_width = 128;

0 commit comments

Comments
 (0)