pre-eth-dbg
This commit is contained in:
parent
e8804864b8
commit
443a02c319
7 changed files with 240 additions and 79 deletions
|
@ -89,6 +89,10 @@ void ESPMegaDisplay::processPageReportPayload()
|
|||
if (rx_buffer_index != 5)
|
||||
return;
|
||||
// The second byte of the payload is the page number
|
||||
// Check if the page number is different from the current page
|
||||
// If it is different, we call the page change callbacks
|
||||
if (rx_buffer[1] == this->currentPage)
|
||||
return;
|
||||
this->currentPage = rx_buffer[1];
|
||||
ESP_LOGV("ESPMegaDisplay", "Page change event: page=%d", this->currentPage);
|
||||
for (auto const &callback : page_change_callbacks)
|
||||
|
@ -186,12 +190,15 @@ uint32_t ESPMegaDisplay::getNumber(const char *component)
|
|||
// The rx buffer is invalid, reset the rx buffer index
|
||||
rx_buffer_index = 0;
|
||||
continue;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
validPayload = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!validPayload) {
|
||||
if (!validPayload)
|
||||
{
|
||||
ESP_LOGE("ESPMegaDisplay", "Invalid payload type: %d, max retry excceded.", rx_buffer[0]);
|
||||
return 0;
|
||||
}
|
||||
|
@ -235,7 +242,7 @@ const char *ESPMegaDisplay::getString(const char *component)
|
|||
if (!waitForValidPayload(DISPLAY_FETCH_TIMEOUT))
|
||||
{
|
||||
ESP_LOGE("ESPMegaDisplay", "Timeout while waiting for display response");
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
if (rx_buffer[0] != 0x70)
|
||||
{
|
||||
|
@ -243,14 +250,17 @@ const char *ESPMegaDisplay::getString(const char *component)
|
|||
// The rx buffer is invalid, reset the rx buffer index
|
||||
rx_buffer_index = 0;
|
||||
continue;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
validPayload = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!validPayload) {
|
||||
if (!validPayload)
|
||||
{
|
||||
ESP_LOGE("ESPMegaDisplay", "Invalid payload type: %d, max retry excceded.", rx_buffer[0]);
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
// The 2nd bytes onwards before the stop bytes is the string
|
||||
// The length of the string is the length of the payload minus 4
|
||||
|
@ -267,29 +277,62 @@ const char *ESPMegaDisplay::getString(const char *component)
|
|||
|
||||
bool ESPMegaDisplay::getStringToBuffer(const char *component, char *buffer, uint8_t buffer_size)
|
||||
{
|
||||
// We might be in the middle of a serial command
|
||||
// We reset the rx buffer index to 0 to ensure that we don't read the wrong data
|
||||
this->rx_buffer_index = 0;
|
||||
uint32_t start = millis();
|
||||
// Send the get command
|
||||
this->displayAdapter->print("get ");
|
||||
this->displayAdapter->print(component);
|
||||
sendStopBytes();
|
||||
// Wait for the response
|
||||
if (!waitForValidPayload(DISPLAY_FETCH_TIMEOUT))
|
||||
return false;
|
||||
// The rx buffer is valid
|
||||
// The expected payload is type 0x70
|
||||
if (rx_buffer[0] != 0x70)
|
||||
return false;
|
||||
// Try to get a valid payload DISPLAY_FETCH_RETRY_COUNT times
|
||||
// Wait for the response
|
||||
bool validPayload = false;
|
||||
for (int i = 0; i < DISPLAY_FETCH_RETRY_COUNT; i++)
|
||||
{
|
||||
if (!waitForValidPayload(DISPLAY_FETCH_TIMEOUT))
|
||||
{
|
||||
ESP_LOGE("ESPMegaDisplay", "Timeout while waiting for display response");
|
||||
this->sendStopBytes();
|
||||
return 0;
|
||||
}
|
||||
if (rx_buffer[0] != 0x70)
|
||||
{
|
||||
ESP_LOGI("ESPMegaDisplay", "Invalid payload type: %d, retrying.", rx_buffer[0]);
|
||||
this->sendStopBytes();
|
||||
// The rx buffer is invalid, reset the rx buffer index
|
||||
rx_buffer_index = 0;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
validPayload = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!validPayload)
|
||||
{
|
||||
ESP_LOGE("ESPMegaDisplay", "Invalid payload type: %d, max retry excceded.", rx_buffer[0]);
|
||||
this->sendStopBytes();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// The 2nd bytes onwards before the stop bytes is the string
|
||||
// The length of the string is the length of the payload minus 4
|
||||
uint8_t length = rx_buffer_index - 4;
|
||||
// Check if the buffer is large enough to hold the string
|
||||
if (length > buffer_size)
|
||||
{
|
||||
ESP_LOGE("ESPMegaDisplay", "Buffer size too small");
|
||||
this->sendStopBytes();
|
||||
return false;
|
||||
}
|
||||
// Copy the string from the rx buffer to the char array
|
||||
memcpy(buffer, rx_buffer + 1, length);
|
||||
// Add the null terminator
|
||||
buffer[length] = '\0';
|
||||
return true;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue