Skip to content

Commit

Permalink
use blocking write
Browse files Browse the repository at this point in the history
  • Loading branch information
mkalkbrenner committed Jan 26, 2025
1 parent 3fe3051 commit 1f35411
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions src/ZeDMDComm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -692,31 +692,23 @@ bool ZeDMDComm::SendChunks(uint8_t* pData, uint16_t size)
{
// std::this_thread::sleep_for(std::chrono::milliseconds(8));
int toSend = ((size - sent) < m_writeAtOnce) ? size - sent : m_writeAtOnce;
if (m_cdc)
{
status = sp_blocking_write(m_pSerialPort, &pData[sent], toSend, ZEDMD_COMM_SERIAL_WRITE_TIMEOUT);
if (toSend < m_writeAtOnce) {
uint8_t* padded = (uint8_t*) malloc(m_writeAtOnce);
memset(padded, 0, m_writeAtOnce);
memcpy(padded, &pData[sent], toSend);
status = sp_blocking_write(m_pSerialPort, padded, m_writeAtOnce, ZEDMD_COMM_SERIAL_WRITE_TIMEOUT);
free(padded);
}
else
{
status = sp_nonblocking_write(m_pSerialPort, &pData[sent], toSend);
else {
status = sp_blocking_write(m_pSerialPort, &pData[sent], toSend, ZEDMD_COMM_SERIAL_WRITE_TIMEOUT);
}

if (status < toSend)
{
m_fullFrameFlag.store(true, std::memory_order_release);
Log("Full frame forced, error %d", status);
return false;
}
else if (status < m_writeAtOnce)
{
if (m_cdc)
{
sp_blocking_write(m_pSerialPort, m_allBlack, m_writeAtOnce - status, ZEDMD_COMM_SERIAL_WRITE_TIMEOUT);
}
else
{
sp_nonblocking_write(m_pSerialPort, m_allBlack, m_writeAtOnce - status);
}
}
sent += status;

status = sp_blocking_read(m_pSerialPort, ack, CTRL_CHARS_HEADER_SIZE + 1, ZEDMD_COMM_SERIAL_READ_TIMEOUT);
Expand Down

0 comments on commit 1f35411

Please sign in to comment.