Use mutexes to guard the MCP

This commit is contained in:
Djuri 2023-11-13 20:02:58 +01:00
parent a3783ceffa
commit 59f9b29df3
5 changed files with 164 additions and 77 deletions

View file

@ -9,6 +9,8 @@ void buttonTask(void *parameter)
while (1)
{
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
std::lock_guard<std::mutex> lock(mcpMutex);
TickType_t currentTime = xTaskGetTickCount();
if ((currentTime - lastDebounceTime) >= debounceDelay)
{
@ -35,11 +37,14 @@ void buttonTask(void *parameter)
}
}
mcp.clearInterrupts();
// Very ugly, but for some reason this is necessary
while (!digitalRead(MCP_INT_PIN))
{
mcp.clearInterrupts();
}
}
else
{
}
// Very ugly, but for some reason this is necessary
while (!digitalRead(MCP_INT_PIN))
{
mcp.clearInterrupts();
}
}
}