diff --git a/Platformio/HAL/Targets/ESP32/HardwareRevX.cpp b/Platformio/HAL/Targets/ESP32/HardwareRevX.cpp index 040d339..b8d6fc5 100644 --- a/Platformio/HAL/Targets/ESP32/HardwareRevX.cpp +++ b/Platformio/HAL/Targets/ESP32/HardwareRevX.cpp @@ -428,10 +428,19 @@ void HardwareRevX::setupWifi() { } void HardwareRevX::startTasks() { - // if (xTaskCreate(&HardwareRevX::updateBatteryTask, "Battery Percent Update", - // 1024, nullptr, 5, &batteryUpdateTskHndl) != pdPASS) { - // debugPrint("ERROR Could not Create Battery Update Task!"); - // } + if (xTaskCreate(&HardwareRevX::updateBatteryTask, "Battery Percent Update", + 1024, nullptr, 5, &batteryUpdateTskHndl) != pdPASS) { + debugPrint("ERROR Could not Create Battery Update Task!"); + } +} + +void HardwareRevX::updateBatteryTask(void*){ + while(true){ + if(auto status = mInstance->getBatteryStatus(); status.has_value()){ + mInstance->mBatteryNotification.notify(status.value()); + } + vTaskDelay(5000 / portTICK_PERIOD_MS); + } } void HardwareRevX::loopHandler() { diff --git a/Platformio/HAL/Targets/ESP32/HardwareRevX.hpp b/Platformio/HAL/Targets/ESP32/HardwareRevX.hpp index cb53766..3321db2 100644 --- a/Platformio/HAL/Targets/ESP32/HardwareRevX.hpp +++ b/Platformio/HAL/Targets/ESP32/HardwareRevX.hpp @@ -60,6 +60,8 @@ protected: // Tasks void startTasks(); + /// @brief Send Battery Notification every 5 Seconds + static void updateBatteryTask(void *); TaskHandle_t batteryUpdateTskHndl = nullptr;