Skip to content

Commit

Permalink
more verbose messages, fixed close() behaviour in case of transport c…
Browse files Browse the repository at this point in the history
…hange
  • Loading branch information
mkalkbrenner committed Feb 25, 2025
1 parent 7c0536c commit f48d5d7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/ZeDMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,15 @@ void ZeDMD::DisableDebug()
void ZeDMD::EnableVerbose()
{
m_verbose = true;
m_pZeDMDComm->SetVerbose(true);
m_pZeDMDWiFi->SetVerbose(true);
}

void ZeDMD::DisableVerbose()
{
m_verbose = false;
m_pZeDMDComm->SetVerbose(false);
m_pZeDMDWiFi->SetVerbose(false);
}

void ZeDMD::SetRGBOrder(uint8_t rgbOrder)
Expand Down
7 changes: 7 additions & 0 deletions src/ZeDMDComm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,8 @@ bool ZeDMDComm::StreamBytes(ZeDMDFrame* pFrame)
uint16_t pos = FRAME_HEADER_SIZE;

m_lastKeepAlive = std::chrono::steady_clock::now();
m_currentCommand = pFrame->command;
if (m_verbose) Log("StreamBytes, command %02X", m_currentCommand);

for (auto it = pFrame->data.rbegin(); it != pFrame->data.rend(); ++it)
{
Expand Down Expand Up @@ -988,6 +990,11 @@ bool ZeDMDComm::SendChunks(uint8_t* pData, uint16_t size)
memset(ack, 0, CTRL_CHARS_HEADER_SIZE + 2);
status = sp_blocking_read(m_pSerialPort, ack, CTRL_CHARS_HEADER_SIZE + 1, ZEDMD_COMM_SERIAL_READ_TIMEOUT);

if (0 == status && ZEDMD_COMM_COMMAND::Reset == m_currentCommand) {
// Sometimes ZeDMD doesn't acknowledge the reset command because the reset of the serial port happens too early on the client side.
continue;
}

if (status < (CTRL_CHARS_HEADER_SIZE + 1) || memcmp(ack, CTRL_CHARS_HEADER, CTRL_CHARS_HEADER_SIZE) != 0 ||
ack[CTRL_CHARS_HEADER_SIZE] == 'F')
{
Expand Down
4 changes: 4 additions & 0 deletions src/ZeDMDComm.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ class ZeDMDComm
void SoftReset(bool reenableKeepAive = true);
void EnableKeepAlive() { m_keepAlive = true; }
void DisableKeepAlive() { m_keepAlive = false; }
void SetVerbose(bool verbose) { m_verbose = verbose; };

uint16_t const GetWidth();
uint16_t const GetHeight();
Expand Down Expand Up @@ -245,6 +246,7 @@ class ZeDMDComm
void ClearFrames();
bool IsQueueEmpty();

bool m_verbose = false;
char m_firmwareVersion[12] = "0.0.0";
uint16_t m_id = 0;
uint16_t m_width = 128;
Expand All @@ -269,6 +271,8 @@ class ZeDMDComm
uint8_t m_udpDelay = 5;
uint16_t m_writeAtOnce = ZEDMD_COMM_DEFAULT_SERIAL_WRITE_AT_ONCE;

uint8_t m_currentCommand = 0;

private:
bool Connect(char* pName);
bool Handshake(char* pDevice);
Expand Down
30 changes: 21 additions & 9 deletions src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ int main(int argc, char* argv[])
{
char identifier;
cag_option_context cag_context;
bool wifi = false;

const char* opt_port = NULL;
const char* opt_ip_address = NULL;
Expand Down Expand Up @@ -420,6 +421,7 @@ int main(int argc, char* argv[])
pZeDMD = nullptr;
return -1;
}
wifi = true;
}
else if (opt_port)
{
Expand All @@ -435,12 +437,16 @@ int main(int argc, char* argv[])
}
else
{
if (!pZeDMD->Open() && !pZeDMD->OpenDefaultWiFi())
if (!pZeDMD->Open())
{
printf("Unable to open connection to ZeDMD via USB or WiFi.\n");
delete pZeDMD;
pZeDMD = nullptr;
return -1;
if (!pZeDMD->OpenDefaultWiFi())
{
printf("Unable to open connection to ZeDMD via USB or WiFi.\n");
delete pZeDMD;
pZeDMD = nullptr;
return -1;
}
wifi = true;
}
}

Expand Down Expand Up @@ -565,15 +571,21 @@ int main(int argc, char* argv[])
if (save)
{
pZeDMD->SaveSettings();
pZeDMD->Reset();
if (wifi) {
pZeDMD->Reset();
}
else {
pZeDMD->Close();
}
}

if (opt_led_test)
else if (opt_led_test)
{
pZeDMD->LedTest();
}
else {
pZeDMD->Close();
}

pZeDMD->Close();
delete pZeDMD;
pZeDMD = nullptr;
return 0;
Expand Down

0 comments on commit f48d5d7

Please sign in to comment.