Describe the Issue
This block of code is Blocking. It creates a timeout mechanism tied to wait_time that doesn't allow the function to move past for 10,000 ticks.
// Wait for user input or timeout
bool input_received = false;
TickType_t current_time = xTaskGetTickCount();
TickType_t wait_time = pdMS_TO_TICKS(10000) - (current_time - last_update_time);
if (wait_time > 0) {
if (xQueueReceive(user_input_queue, &input_event, wait_time) == pdTRUE) {
input_received = true;
if (strcmp(input_event, "SHORT") == 0) {
ESP_LOGI(TAG, "Short button press detected, switching to next screen");
current_screen = (current_screen + 1) % 2;
} else if (strcmp(input_event, "LONG") == 0) {
ESP_LOGI(TAG, "Long button press detected, toggling WiFi SoftAP");
toggle_wifi_softap();
}
}
}
// If no input received and 10 seconds have passed, switch to the next screen
if (!input_received && (xTaskGetTickCount() - last_update_time) >= pdMS_TO_TICKS(10000)) {
current_screen = (current_screen + 1) % 2;
}
last_update_time = xTaskGetTickCount();
}
Describe the Issue This block of code is Blocking. It creates a timeout mechanism tied to wait_time that doesn't allow the function to move past for 10,000 ticks.
Based on the xQueueReceive document,
xTickstoWait acts as a delay. Setting this to zero allows for non-blocking functionality, it also seems to still keep the original functionality
Example: