Skip to content

Commit

Permalink
stack size fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
paxo-rch committed Sep 15, 2024
1 parent 2b1a2e3 commit ebb13e9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 70 deletions.
16 changes: 15 additions & 1 deletion lib/gsm/src/gsm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ namespace GSM
std::vector<Message> messages;
State state;
uint16_t seconds, minutes, hours, days, months, years = 0;
std::vector<float> battery_voltage_history;
float voltage = -1;
int networkQuality = 0;
bool flightMode = false;
Expand Down Expand Up @@ -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)
{
Expand All @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions lib/tasks/src/threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
71 changes: 4 additions & 67 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#include <backtrace_saver.hpp>
#include <backtrace.hpp>

#include <Arduino.h>

SET_LOOP_TASK_STACK_SIZE(8 * 1024);

#endif

#include <unistd.h>
Expand Down Expand Up @@ -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<AppManager::App> 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()
Expand Down Expand Up @@ -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(){}
Expand Down

0 comments on commit ebb13e9

Please sign in to comment.