internal mutex
This commit is contained in:
parent
fdf32d8503
commit
0b1ca17351
4 changed files with 125 additions and 69 deletions
|
@ -8,15 +8,17 @@
|
|||
bool ESPMegaDisplay::recieveSerialCommand(bool process)
|
||||
{
|
||||
bool dataRecieved = false;
|
||||
// Read the serial buffer if available
|
||||
if (xSemaphoreTake(this->serialMutex, DISPLAY_MUTEX_TAKE_TIMEOUT) == pdFALSE)
|
||||
{
|
||||
ESP_LOGI("ESPMegaDisplay", "Failed to take serial mutex");
|
||||
return false;
|
||||
}
|
||||
|
||||
while (displayAdapter->available())
|
||||
{
|
||||
// Read the serial buffer if available
|
||||
if (xSemaphoreTake(this->serialMutex, DISPLAY_MUTEX_TAKE_TIMEOUT) == pdFALSE)
|
||||
{
|
||||
ESP_LOGI("ESPMegaDisplay", "Failed to take serial mutex");
|
||||
return false;
|
||||
}
|
||||
rx_buffer[rx_buffer_index] = displayAdapter->read();
|
||||
xSemaphoreGive(this->serialMutex);
|
||||
rx_buffer_index++;
|
||||
// Check for overflow
|
||||
if (rx_buffer_index >= 256)
|
||||
|
@ -27,7 +29,6 @@ bool ESPMegaDisplay::recieveSerialCommand(bool process)
|
|||
this->processSerialCommand();
|
||||
dataRecieved = true;
|
||||
}
|
||||
xSemaphoreGive(this->serialMutex);
|
||||
return dataRecieved;
|
||||
}
|
||||
|
||||
|
@ -605,10 +606,17 @@ void ESPMegaDisplay::unregisterPayloadCallback(uint16_t handle)
|
|||
|
||||
/**
|
||||
* @brief Takes the serial mutex.
|
||||
*
|
||||
* @note only neccessary if you are using the display adapter directly, otherwise the mutex is taken by the helper functions.
|
||||
*/
|
||||
void ESPMegaDisplay::takeSerialMutex()
|
||||
bool ESPMegaDisplay::takeSerialMutex()
|
||||
{
|
||||
xSemaphoreTake(this->serialMutex, DISPLAY_MUTEX_TAKE_TIMEOUT);
|
||||
if (xSemaphoreTake(this->serialMutex, DISPLAY_MUTEX_TAKE_TIMEOUT) == pdFALSE)
|
||||
{
|
||||
ESP_LOGI("ESPMegaDisplay", "Failed to take serial mutex");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -616,6 +624,7 @@ void ESPMegaDisplay::takeSerialMutex()
|
|||
*/
|
||||
void ESPMegaDisplay::giveSerialMutex()
|
||||
{
|
||||
ESP_LOGD("ESPMegaDisplay", "Giving serial mutex");
|
||||
xSemaphoreGive(this->serialMutex);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue