From 0285b522f10a0a8500117c300f05acffede41499 Mon Sep 17 00:00:00 2001 From: Rune Harlyk Date: Sun, 14 Sep 2025 19:46:42 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Replaces=20delay=20with=20vTaskD?= =?UTF-8?q?elay?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- esp32/include/peripherals/gesture.h | 4 ++-- esp32/include/task_manager.h | 2 +- esp32/src/peripherals/peripherals.cpp | 2 +- esp32/src/system_service.cpp | 12 ++++++------ esp32/src/wifi_service.cpp | 2 +- esp32/test/gait_performance.cpp | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/esp32/include/peripherals/gesture.h b/esp32/include/peripherals/gesture.h index bd91864..fc138ef 100644 --- a/esp32/include/peripherals/gesture.h +++ b/esp32/include/peripherals/gesture.h @@ -49,12 +49,12 @@ class PAJ7620U2 { uint8_t f1 = 0, f0 = 0, t0 = 0; if (readReg(REG_GES_FLAG_1, &f1, 1) != 1) return eGestureNone; if (f1) { - delay(highRate ? QUIT_MS / 5 : QUIT_MS); + vTaskDelay(highRate ? QUIT_MS / 5 : QUIT_MS / portTICK_PERIOD_MS); return eGestureWave; } if (readReg(REG_GES_FLAG_0, &f0, 1) != 1) return eGestureNone; if (!highRate) { - delay(ENTRY_MS); + vTaskDelay(ENTRY_MS / portTICK_PERIOD_MS); if (readReg(REG_GES_FLAG_0, &t0, 1) == 1) f0 |= t0; } if (f0 & 0x01) return eGestureRight; diff --git a/esp32/include/task_manager.h b/esp32/include/task_manager.h index f26c677..c2925cf 100644 --- a/esp32/include/task_manager.h +++ b/esp32/include/task_manager.h @@ -172,7 +172,7 @@ class CPUBurnerTask { esp_task_wdt_reset(); } - delay(idle_time); + vTaskDelay(idle_time / portTICK_PERIOD_MS); } } diff --git a/esp32/src/peripherals/peripherals.cpp b/esp32/src/peripherals/peripherals.cpp index 0c109fd..b9a2bae 100644 --- a/esp32/src/peripherals/peripherals.cpp +++ b/esp32/src/peripherals/peripherals.cpp @@ -120,7 +120,7 @@ bool Peripherals::readGesture() { void Peripherals::readSonar() { #if FT_ENABLED(USE_USS) _left_distance = _left_sonar->ping_cm(); - delay(50); + vTaskDelay(50 / portTICK_PERIOD_MS); _right_distance = _right_sonar->ping_cm(); #endif } diff --git a/esp32/src/system_service.cpp b/esp32/src/system_service.cpp index c34ed63..6f58098 100644 --- a/esp32/src/system_service.cpp +++ b/esp32/src/system_service.cpp @@ -49,11 +49,11 @@ void restart() { xTaskCreate( [](void *pvParameters) { for (;;) { - delay(250); + vTaskDelay(250 / portTICK_PERIOD_MS); MDNS.end(); - delay(100); + vTaskDelay(100 / portTICK_PERIOD_MS); WiFi.disconnect(true); - delay(500); + vTaskDelay(500 / portTICK_PERIOD_MS); ESP.restart(); } }, @@ -64,11 +64,11 @@ void sleep() { xTaskCreate( [](void *pvParameters) { for (;;) { - delay(250); + vTaskDelay(250 / portTICK_PERIOD_MS); MDNS.end(); - delay(100); + vTaskDelay(100 / portTICK_PERIOD_MS); WiFi.disconnect(true); - delay(500); + vTaskDelay(500 / portTICK_PERIOD_MS); uint64_t bitmask = (uint64_t)1 << (WAKEUP_PIN_NUMBER); diff --git a/esp32/src/wifi_service.cpp b/esp32/src/wifi_service.cpp index 0ce1434..8b3f682 100644 --- a/esp32/src/wifi_service.cpp +++ b/esp32/src/wifi_service.cpp @@ -26,7 +26,7 @@ void WiFiService::begin() { if (state().wifiSettings.size() == 1) { configureNetwork(state().wifiSettings[0]); - delay(500); + vTaskDelay(500 / portTICK_PERIOD_MS); } } diff --git a/esp32/test/gait_performance.cpp b/esp32/test/gait_performance.cpp index 839472f..21e892c 100644 --- a/esp32/test/gait_performance.cpp +++ b/esp32/test/gait_performance.cpp @@ -27,7 +27,7 @@ void test_gaitPlanner_calculateStep_time() { } void setup() { - delay(2000); // Allow time for Serial to initialize if running on an ESP32 + vTaskDelay(2000 / portTICK_PERIOD_MS); // Allow time for Serial to initialize if running on an ESP32 UNITY_BEGIN(); RUN_TEST(test_gaitPlanner_calculateStep_time); UNITY_END();