85 lines
2.1 KiB
C++
85 lines
2.1 KiB
C++
#include "shell.h"
|
|
#include "input_manager.h"
|
|
#include "tft_handler.h"
|
|
#include "event_manager.h"
|
|
#include "GLOBALS.h"
|
|
#include "system_manager.h"
|
|
#include <vector>
|
|
|
|
Shell* _shell;
|
|
InputManager* im;
|
|
TFT_Handler* th;
|
|
SystemManager* sm;
|
|
|
|
DISPLAY_STATE* _display_state;
|
|
|
|
TaskHandle_t InputTask;
|
|
|
|
void input_task(void* pvParameters) {
|
|
for(;;) {
|
|
im->update();
|
|
vTaskDelay(1);
|
|
}
|
|
}
|
|
|
|
void setup() {
|
|
Serial.begin(115200);
|
|
Serial.println("Initializing...");
|
|
|
|
CALIBRATION_IDLE _calibration_idle;
|
|
|
|
// Calibration phase, measure idle baseline over 3 seconds
|
|
Serial.println("Calibrating CPU baseline... please wait 3 seconds");
|
|
uint32_t calibration_start = xTaskGetIdleRunTimeCounter();
|
|
vTaskDelay(pdMS_TO_TICKS(3000));
|
|
uint32_t calibration_end = xTaskGetIdleRunTimeCounter();
|
|
|
|
// Calculate average idle iterations per millisecond during calibration
|
|
_calibration_idle.max_idle_iterations = (calibration_end - calibration_start) / 3000;
|
|
|
|
Serial.print("Baseline calibrated. Max idle iterations per ms: ");
|
|
Serial.println(_calibration_idle.max_idle_iterations);
|
|
|
|
_calibration_idle.idle_count_last = xTaskGetIdleRunTimeCounter();
|
|
|
|
// Create shared state
|
|
_display_state = new DISPLAY_STATE();
|
|
_display_state->update_display.store(false);
|
|
|
|
// Create managers
|
|
_shell = new Shell();
|
|
im = new InputManager();
|
|
th = new TFT_Handler();
|
|
sm = new SystemManager();
|
|
|
|
// Initialize in order
|
|
th->init(_display_state);
|
|
|
|
// Initialize event manager (creates dispatcher task)
|
|
EventManager::getInstance().init();
|
|
|
|
// Initialize system manager with shell and tft references
|
|
sm->init(_display_state, _shell, th, _calibration_idle);
|
|
|
|
// Initialize components (they subscribe to events)
|
|
im->init(_display_state, th);
|
|
_shell->init(th, _display_state, sm);
|
|
|
|
// Create input task on Core 0
|
|
xTaskCreatePinnedToCore(input_task, "input_task", 4096, NULL, 1, &InputTask, 0);
|
|
|
|
delay(100);
|
|
|
|
Serial.println("Initialization complete");
|
|
}
|
|
|
|
void loop() {
|
|
// Only handle rendering in main loop
|
|
if (_display_state->update_display.load()) {
|
|
_shell->draw_all();
|
|
im->draw_button();
|
|
_display_state->update_display.store(false);
|
|
}
|
|
|
|
delay(0);
|
|
} |