104 lines
2.0 KiB
C++
104 lines
2.0 KiB
C++
#include "window_manager.h"
|
|
#include "desktop_hander.h"
|
|
#include "input_manager.h"
|
|
#include "tft_handler.h"
|
|
#include "event_manager.h"
|
|
#include "GLOBALS.h"
|
|
|
|
WindowManager* wm;
|
|
Desktop_Hander* dh;
|
|
InputManager* im;
|
|
TFT_Handler* th;
|
|
|
|
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...");
|
|
|
|
// Create shared state
|
|
_display_state = new DISPLAY_STATE();
|
|
_display_state->update_display.store(false);
|
|
|
|
// Create managers
|
|
wm = new WindowManager();
|
|
dh = new Desktop_Hander();
|
|
im = new InputManager();
|
|
th = new TFT_Handler();
|
|
|
|
// Initialize in order
|
|
th->init(_display_state);
|
|
|
|
// Initialize event manager (creates dispatcher task)
|
|
EventManager::getInstance().init();
|
|
|
|
// Initialize components (they subscribe to events)
|
|
im->init(_display_state, th);
|
|
dh->init(th, _display_state);
|
|
wm->init(th, _display_state);
|
|
|
|
// Create input task on Core 0
|
|
xTaskCreatePinnedToCore(
|
|
input_task,
|
|
"input_task",
|
|
4096,
|
|
NULL,
|
|
1,
|
|
&InputTask,
|
|
0
|
|
);
|
|
|
|
delay(100);
|
|
|
|
// Create test windows
|
|
Window win1 = {
|
|
.id = 0,
|
|
.x = 10,
|
|
.y = 30,
|
|
.width = 350,
|
|
.height = 250,
|
|
.background_color = 0xbdf7,
|
|
.foreground_color = COL_DARK_BLUE,
|
|
.focused = false,
|
|
.title = "Hello World!",
|
|
.window_actions = {},
|
|
};
|
|
wm->create_window(win1);
|
|
|
|
Window win2 = {
|
|
.id = 1,
|
|
.x = 30,
|
|
.y = 50,
|
|
.width = 350,
|
|
.height = 250,
|
|
.background_color = 0xbdf7,
|
|
.foreground_color = COL_DARK_BLUE,
|
|
.focused = true,
|
|
.title = "Second Window",
|
|
.window_actions = {},
|
|
};
|
|
wm->create_window(win2);
|
|
|
|
Serial.println("Initialization complete");
|
|
}
|
|
|
|
void loop() {
|
|
// Only handle rendering in main loop
|
|
if (_display_state->update_display.load()) {
|
|
dh->re_draw_desktop();
|
|
wm->draw_all();
|
|
im->draw_button();
|
|
_display_state->update_display.store(false);
|
|
}
|
|
|
|
delay(50);
|
|
} |