diff --git a/src/main.cpp b/src/main.cpp index 0491219..65a967b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -57,7 +57,7 @@ void pm_init() { } extern "C" void app_main() { - // pm_init(); + pm_init(); mainApp(); // servo_test(); } \ No newline at end of file diff --git a/src/mainEventLoop.cpp b/src/mainEventLoop.cpp index 73b4589..74ccdb0 100644 --- a/src/mainEventLoop.cpp +++ b/src/mainEventLoop.cpp @@ -9,6 +9,7 @@ #include "socketIO.hpp" #include "max17048.h" #include "esp_sleep.h" +#include "defines.h" // Give C linkage so max17048.c (a C translation unit) can link against these extern "C" { @@ -68,6 +69,8 @@ bool postServoPos(uint8_t currentAppPos) { cJSON_Delete(response); if (awaitCalib) { + gpio_set_level(debugLED, 1); // Start with LED off + gpio_hold_en(debugLED); Calibration::clearCalibrated(); if (!calibrate()) { if (!WiFi::attemptDHCPrenewal()) @@ -77,6 +80,8 @@ bool postServoPos(uint8_t currentAppPos) { setupAndCalibrate(); } } + gpio_hold_dis(debugLED); + gpio_set_level(debugLED, 0); } } return success; @@ -201,7 +206,7 @@ void mainEventLoop() { postBatteryAlert(alertType, established_soc); printf("CRITICAL BATTERY EVENT (%s, SOC=%d%%). Entering deep sleep.\n", battAlertTypeStr(alertType), established_soc); - // esp_deep_sleep_start(); + esp_deep_sleep_start(); } else if (received_event_type == EVENT_BATTERY_WARNING) { postBatteryAlert((batt_alert_type_t)bms_pending_alert, established_soc); diff --git a/src/max17048.c b/src/max17048.c index da4e826..90ce08e 100644 --- a/src/max17048.c +++ b/src/max17048.c @@ -91,7 +91,7 @@ void bms_checker_task(void *pvParameters) { main_event_type_t evt; - if ((status & VHbit) || (status & HDbit) || ((status & VLbit) && soc < SOC_CRITICAL_VL)) { + if ((status & HDbit) || ((status & VLbit) && soc < SOC_CRITICAL_VL)) { // Critical: overvoltage (hardware fault) or battery truly empty bms_pending_alert = (status & VHbit) ? BATT_ALERT_OVERVOLTAGE : BATT_ALERT_CRITICAL_LOW; evt = EVENT_BATTERY_CRITICAL; diff --git a/src/setup.cpp b/src/setup.cpp index 6eb8d38..8030cc9 100644 --- a/src/setup.cpp +++ b/src/setup.cpp @@ -23,6 +23,7 @@ void setupAndCalibrate() { gpio_reset_pin(debugLED); gpio_set_direction(debugLED, GPIO_MODE_OUTPUT); gpio_set_level(debugLED, 1); // Start with LED off + gpio_hold_en(debugLED); while (1) { setupLoop(); if (awaitCalibration) { @@ -30,6 +31,7 @@ void setupAndCalibrate() { } else break; } + gpio_hold_dis(debugLED); gpio_set_level(debugLED, 0); // Start with LED off }