#include "window_manager.h" #include "desktop_hander.h" #include "input_manager.h" #include "tft_handler.h" #include "GLOBALS.h" WindowManager* wm; // Globals Desktop_Hander* dh; InputManager* im; TFT_Handler* th; DISPLAY_STATE* _display_state; CLICK_EVENT* _click_event; uint32_t totalHeap = ESP.getHeapSize(); uint32_t freeHeap = ESP.getFreeHeap(); uint32_t usedHeap = totalHeap - freeHeap; float percentUsed = (float)usedHeap * 100.0 / totalHeap; TaskHandle_t Task1; void setup() { Serial.begin(115200); Serial.println("Initializing..."); _display_state = new DISPLAY_STATE(); _display_state->update_display.store(false); _click_event = new CLICK_EVENT(); _click_event->event = CLICK_EVENTS::NONE; wm = new WindowManager(); dh = new Desktop_Hander(); im = new InputManager(); th = new TFT_Handler(); th->init(_display_state); im->init(_display_state, th, _click_event); dh->init(th); wm->init(th); delay(500); // Create InputManager thread xTaskCreatePinnedToCore( task1, /* Task function. */ "task1", /* name of task. */ 10000, /* Stack size of task */ NULL, /* parameter of the task */ 1, /* priority of the task */ &Task1, /* Task handle to keep track of created task */ 0); /* pin task to core 0 */ delay(500); Window win1 = { .id = 0, .x = 10, .y = 30, .width = 350, .height = 250, .background_color = 0xbdf7, // Blue .foreground_color = COL_DARK_BLUE, // White .focused = false, .title = "Hello Worl!", .window_actions = {}, }; wm->create_window(win1); Window win2 = { .id = 1, .x = 30, .y = 50, .width = 350, .height = 250, .background_color = 0xbdf7, // Blue .foreground_color = COL_DARK_BLUE, // White .focused = true, .title = "lmao", .window_actions = {}, }; wm->create_window(win2); } void loop() { totalHeap = ESP.getHeapSize(); freeHeap = ESP.getFreeHeap(); usedHeap = totalHeap - freeHeap; percentUsed = (float)usedHeap * 100.0 / totalHeap; int start = millis(); int id = wm->click_event(*_click_event); if (id >= 0) _display_state->update_display.store(true); _click_event->event = CLICK_EVENTS::NONE; if (_display_state->update_display.load()) { dh->re_draw_desktop(); wm->draw_all(); im->draw_button(); _display_state->update_display.store(false); } int stop = millis(); //Serial.print("Total mem: "); Serial.println(ESP.getHeapSize()); //Serial.print("Mem left: "); Serial.println(ESP.getFreeHeap()); //Serial.print("Mem % used: "); Serial.println(percentUsed); //Serial.println(stop - start); delay(50); } void task1(void * pvParameters) { for(;;) { im->update(); vTaskDelay(1); } }