From ebb13e9d735797d6b5772983275fe5d99d09fd30 Mon Sep 17 00:00:00 2001 From: paxo-rch Date: Sun, 15 Sep 2024 16:47:43 +0200 Subject: [PATCH] stack size fixed --- lib/gsm/src/gsm.cpp | 16 ++++++++- lib/tasks/src/threads.cpp | 4 +-- src/main.cpp | 71 +++------------------------------------ 3 files changed, 21 insertions(+), 70 deletions(-) diff --git a/lib/gsm/src/gsm.cpp b/lib/gsm/src/gsm.cpp index dff35508..056de620 100644 --- a/lib/gsm/src/gsm.cpp +++ b/lib/gsm/src/gsm.cpp @@ -42,6 +42,7 @@ namespace GSM std::vector messages; State state; uint16_t seconds, minutes, hours, days, months, years = 0; + std::vector battery_voltage_history; float voltage = -1; int networkQuality = 0; bool flightMode = false; @@ -994,6 +995,19 @@ namespace GSM try { voltage = std::stof(voltage_str); + + battery_voltage_history.push_back(voltage); + if (battery_voltage_history.size() > 24) + battery_voltage_history.erase(battery_voltage_history.begin()); + + if (battery_voltage_history.size() > 0) { + double sum = 0; + for (auto v : battery_voltage_history) + sum += v; + voltage = sum / battery_voltage_history.size(); + + std::cout << "Battery voltage average: " << voltage << std::endl; + } } catch (std::exception) { @@ -1010,7 +1024,7 @@ namespace GSM // Thanks NumWorks for the regression app const double batteryLevel = 3.083368 * std::pow(voltage, 3) - 37.21203 * std::pow(voltage, 2) + 150.5735 * voltage - 203.3347; - std::cout << "Battery level: " << batteryLevel << std::endl; + //std::cout << "Battery level: " << batteryLevel << std::endl; return std::clamp(batteryLevel, 0.0, 1.0); diff --git a/lib/tasks/src/threads.cpp b/lib/tasks/src/threads.cpp index 8c0f9281..6f194be2 100644 --- a/lib/tasks/src/threads.cpp +++ b/lib/tasks/src/threads.cpp @@ -24,8 +24,8 @@ void ThreadManager::init() { - new_thread(CORE_BACK, &ThreadManager::simcom_thread, 32*1024); - new_thread(CORE_BACK, &ThreadManager::background_thread, 16*1024); + new_thread(CORE_BACK, &ThreadManager::simcom_thread, 8*1024); + new_thread(CORE_BACK, &ThreadManager::background_thread, 8*1024); } void ThreadManager::new_thread(bool core, void(*func)(void*), int stackSize) diff --git a/src/main.cpp b/src/main.cpp index 10368c34..2748c4f4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,6 +8,10 @@ #include #include +#include + +SET_LOOP_TASK_STACK_SIZE(8 * 1024); + #endif #include @@ -141,67 +145,6 @@ void mainLoop(void* data) { StandbyMode::wait(); } -/* - // Main loop - while (true) { - // Update inputs - hardware::input::update(); - std::cout << "Update inputs" << std::endl; - - // Update running apps - AppManager::update(); - - // Don't show anything - if (libsystem::getDeviceMode() == libsystem::SLEEP) { - if (getButtonDown(hardware::input::HOME)) { - setDeviceMode(libsystem::NORMAL); - } - - continue; - } - - if (AppManager::isAnyVisibleApp()) { - if (getButtonDown(hardware::input::HOME)) { - AppManager::quitApp(); - } - } else { - // If home button pressed on the launcher - // Put the device in sleep - if (getButtonDown(hardware::input::HOME)) { - // Free the launcher resources - applications::launcher::free(); - - setDeviceMode(libsystem::SLEEP); - continue; - } - - std::cout << "Update launcher" << std::endl; - - // Update, show and allocate launcher - applications::launcher::update(); - - // Icons interactions - if (applications::launcher::iconTouched()) { - const std::shared_ptr app = applications::launcher::getApp(); - - // Free the launcher resources - applications::launcher::free(); - - // Launch the app - try { - app->run(false); - } catch (std::runtime_error& e) { - std::cerr << "Erreur: " << e.what() << std::endl; - // Affichage du msg d'erreur - guiManager.showErrorMessage(e.what()); - // on kill l'application ?!? - //AppManager::appList[i].kill(); - } - } - } - - AppManager::loop(); - }*/ } void setup() @@ -330,13 +273,7 @@ void setup() */ AppManager::init(); - #ifdef ESP_PLATFORM - // // stack size: >32k = crash due to image decoder in stack - xTaskCreateUniversal(mainLoop,"newloop", 16*1024, NULL, 1, NULL, ARDUINO_RUNNING_CORE); - vTaskDelete(NULL); - #else mainLoop(NULL); - #endif } void loop(){}