2025-11-28 18:26:32 -06:00
|
|
|
#include <driver/gptimer.h>
|
2025-12-31 15:44:48 -06:00
|
|
|
#include "servo.hpp"
|
2025-11-28 18:26:32 -06:00
|
|
|
#include "defines.h"
|
|
|
|
|
#include "nvs_flash.h"
|
|
|
|
|
#include "NimBLEDevice.h"
|
|
|
|
|
#include "WiFi.hpp"
|
2025-11-29 16:24:56 -06:00
|
|
|
#include "setup.hpp"
|
2025-12-23 17:21:44 -06:00
|
|
|
#include "socketIO.hpp"
|
2025-12-28 12:46:09 -06:00
|
|
|
#include "encoder.hpp"
|
2025-12-28 20:52:11 -06:00
|
|
|
#include "calibration.hpp"
|
2026-01-10 02:45:26 -06:00
|
|
|
#include "esp_pm.h"
|
2026-01-11 19:02:14 -06:00
|
|
|
#include "mainEventLoop.hpp"
|
2026-03-09 02:29:03 -05:00
|
|
|
#include "max17048.h"
|
2026-03-09 16:09:28 -05:00
|
|
|
#include "bms_test.hpp"
|
2025-12-28 20:52:11 -06:00
|
|
|
|
|
|
|
|
// Global encoder instances
|
2025-12-31 17:23:44 -06:00
|
|
|
Encoder* topEnc = new Encoder(ENCODER_PIN_A, ENCODER_PIN_B);
|
|
|
|
|
Encoder* bottomEnc = new Encoder(InputEnc_PIN_A, InputEnc_PIN_B);
|
|
|
|
|
|
2026-01-08 18:14:36 -06:00
|
|
|
void mainApp() {
|
|
|
|
|
esp_err_t ret = nvs_flash_init(); // change to secure init logic soon!!
|
|
|
|
|
// 2. If NVS is full or corrupt (common after flashing new code), erase and retry
|
|
|
|
|
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
|
|
|
|
ESP_ERROR_CHECK(nvs_flash_erase());
|
|
|
|
|
ret = nvs_flash_init();
|
|
|
|
|
}
|
|
|
|
|
ESP_ERROR_CHECK(ret);
|
|
|
|
|
|
2026-03-09 02:29:03 -05:00
|
|
|
main_event_queue = xQueueCreate(10, sizeof(main_event_type_t));
|
|
|
|
|
|
2026-01-10 22:48:24 -06:00
|
|
|
WiFi::init();
|
|
|
|
|
Calibration::init();
|
2026-01-08 18:14:36 -06:00
|
|
|
|
|
|
|
|
// Initialize encoders
|
|
|
|
|
topEnc->init();
|
|
|
|
|
bottomEnc->init();
|
|
|
|
|
servoInit();
|
2026-03-09 02:29:03 -05:00
|
|
|
max17048_init();
|
2026-01-08 18:14:36 -06:00
|
|
|
|
2026-01-11 19:02:14 -06:00
|
|
|
setupAndCalibrate();
|
|
|
|
|
|
2026-01-12 17:39:52 -06:00
|
|
|
xTaskCreate(wakeTimer, "wakeTimer", 2048, NULL, 5, &wakeTaskHandle);
|
2026-01-11 19:02:14 -06:00
|
|
|
|
|
|
|
|
mainEventLoop();
|
2025-12-28 12:46:09 -06:00
|
|
|
}
|
|
|
|
|
|
2026-01-10 02:45:26 -06:00
|
|
|
void pm_init() {
|
|
|
|
|
esp_pm_config_t pm_config = {
|
|
|
|
|
.max_freq_mhz = 160, // Max CPU frequency
|
|
|
|
|
.min_freq_mhz = 80, // Min CPU frequency (DFS)
|
|
|
|
|
.light_sleep_enable = true // ALLOW CPU to power down during idle
|
|
|
|
|
};
|
|
|
|
|
ESP_ERROR_CHECK(esp_pm_configure(&pm_config));
|
2025-12-28 12:46:09 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extern "C" void app_main() {
|
2026-03-09 16:09:28 -05:00
|
|
|
// pm_init();
|
|
|
|
|
// mainApp();
|
2026-03-11 18:26:59 -05:00
|
|
|
bms_test_LED();
|
2025-11-28 18:26:32 -06:00
|
|
|
}
|