Skip to content

Commit

Permalink
added guru log, fine tuned keep alive
Browse files Browse the repository at this point in the history
  • Loading branch information
mkalkbrenner committed Jan 26, 2025
1 parent 8d98882 commit 07eecb2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
13 changes: 13 additions & 0 deletions src/ZeDMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,23 @@ void ZeDMD::LedTest()
if (m_usb)
{
m_pZeDMDComm->QueueCommand(ZEDMD_COMM_COMMAND::LEDTest);
m_pZeDMDComm->DisableKeepAlive();
}
else if (m_wifi)
{
m_pZeDMDWiFi->QueueCommand(ZEDMD_COMM_COMMAND::LEDTest);
m_pZeDMDWiFi->DisableKeepAlive();
}

std::this_thread::sleep_for(std::chrono::milliseconds(8000));

if (m_usb)
{
m_pZeDMDComm->EnableKeepAlive();
}
else if (m_wifi)
{
m_pZeDMDWiFi->EnableKeepAlive();
}
}

Expand Down
28 changes: 26 additions & 2 deletions src/ZeDMDComm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,9 +593,11 @@ void ZeDMDComm::Reset()

void ZeDMDComm::SoftReset()
{
DisableKeepAlive();
QueueCommand(ZEDMD_COMM_COMMAND::Reset);
// Wait a bit to let the reset command be transmitted.
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
std::this_thread::sleep_for(std::chrono::milliseconds(3000));
EnableKeepAlive();
}

bool ZeDMDComm::StreamBytes(ZeDMDFrame* pFrame)
Expand Down Expand Up @@ -681,6 +683,7 @@ bool ZeDMDComm::SendChunks(uint8_t* pData, uint16_t size)
(defined(__APPLE__) && ((defined(TARGET_OS_IOS) && TARGET_OS_IOS) || (defined(TARGET_OS_TV) && TARGET_OS_TV))) || \
defined(__ANDROID__))

static uint8_t guru[4] = {'G', 'u', 'r', 'u'};
uint8_t ack[CTRL_CHARS_HEADER_SIZE + 1] = {0};
int status = 0;
uint16_t sent = 0;
Expand Down Expand Up @@ -721,8 +724,23 @@ bool ZeDMDComm::SendChunks(uint8_t* pData, uint16_t size)
if (status < CTRL_CHARS_HEADER_SIZE + 1 || memcmp(ack, CTRL_CHARS_HEADER, CTRL_CHARS_HEADER_SIZE) != 0 ||
ack[CTRL_CHARS_HEADER_SIZE] == 'F')
{
if (memcmp(ack, guru, 4) == 0 || memcmp(&ack[1], guru, 4) == 0 || memcmp(&ack[2], guru, 4) == 0)
{
Log("ZeDMD %s", ack);
uint8_t message[64];
while (sp_input_waiting(m_pSerialPort) > 0)
{
memset(message, ' ', 64);
sp_nonblocking_read(m_pSerialPort, message, 64);
Log("%s", message);
}
}
else
{
Log("Full frame forced, error %d", status);
}

m_fullFrameFlag.store(true, std::memory_order_release);
Log("Full frame forced, error %d", status);
return false;
}

Expand All @@ -743,6 +761,12 @@ bool ZeDMDComm::SendChunks(uint8_t* pData, uint16_t size)
void ZeDMDComm::KeepAlive()
{
auto now = std::chrono::steady_clock::now();

if (!m_keepAlive) {
m_lastKeepAlive = now;
return;
}

if (now - m_lastKeepAlive > m_keepAliveInterval)
{
m_lastKeepAlive = now;
Expand Down
3 changes: 3 additions & 0 deletions src/ZeDMDComm.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ class ZeDMDComm
void QueueCommand(char command, uint8_t value);
bool FillDelayed();
void SoftReset();
void EnableKeepAlive() { m_keepAlive = true; }
void DisableKeepAlive() { m_keepAlive = false; }

uint16_t const GetWidth();
uint16_t const GetHeight();
Expand Down Expand Up @@ -252,5 +254,6 @@ class ZeDMDComm
std::mutex m_delayedFrameMutex;
bool m_delayedFrameReady = false;
uint16_t m_writeAtOnce = ZEDMD_COMM_MAX_SERIAL_WRITE_AT_ONCE;
bool m_keepAlive = true;
std::chrono::steady_clock::time_point m_lastKeepAlive;
};
2 changes: 0 additions & 2 deletions src/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,6 @@ int main(int argc, const char* argv[])

pZeDMD->LedTest();

std::this_thread::sleep_for(std::chrono::milliseconds(5000));

pZeDMD->Close();
}
}

0 comments on commit 07eecb2

Please sign in to comment.