120 lines
3.5 KiB
C++
120 lines
3.5 KiB
C++
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.h"
|
|
#include "esp_log.h"
|
|
#include "esp_lv_adapter.h"
|
|
#include "lvgl.h"
|
|
#include "Display.hpp"
|
|
#include "Touch.hpp"
|
|
#include "Gui.hpp"
|
|
#include "WidgetManager.hpp"
|
|
#include "Nvs.hpp"
|
|
#include "KnxWorker.hpp"
|
|
#include "Wifi.hpp"
|
|
#include "Hardware/Eth.hpp"
|
|
#include "WebServer.hpp"
|
|
#include "SdCard.hpp"
|
|
#include "Fonts.hpp"
|
|
|
|
#define TAG "App"
|
|
|
|
static void knx_task(void* arg) {
|
|
KnxWorker* worker = static_cast<KnxWorker*>(arg);
|
|
worker->init();
|
|
while (true) {
|
|
worker->loop();
|
|
vTaskDelay(pdMS_TO_TICKS(10));
|
|
}
|
|
}
|
|
|
|
// This is a simple wrapper for the application logic
|
|
class Application {
|
|
public:
|
|
void init() {
|
|
// Initialize hardware
|
|
nvs.init();
|
|
//Wifi::instance().init();
|
|
Eth::instance().init();
|
|
display.init();
|
|
touch.init();
|
|
|
|
// Initialize LVGL adapter
|
|
esp_lv_adapter_config_t cfg = ESP_LV_ADAPTER_DEFAULT_CONFIG();
|
|
cfg.stack_in_psram = false; // Use internal RAM for stack
|
|
cfg.task_stack_size = 32 * 1024;
|
|
ESP_ERROR_CHECK(esp_lv_adapter_init(&cfg));
|
|
|
|
// Register display
|
|
esp_lv_adapter_display_config_t disp_cfg = ESP_LV_ADAPTER_DISPLAY_MIPI_DEFAULT_CONFIG(
|
|
display.getPanelHandle(),
|
|
NULL,
|
|
800, // Horizontal resolution
|
|
1280, // Vertical resolution
|
|
ESP_LV_ADAPTER_ROTATE_90 // Rotation
|
|
);
|
|
disp_cfg.profile.buffer_height = 34; // Reduced to 20 to fit in RAM (32KB)
|
|
lv_disp_t* lv_display = esp_lv_adapter_register_display(&disp_cfg);
|
|
assert(lv_display != NULL);
|
|
|
|
// Register touch
|
|
esp_lv_adapter_touch_config_t touch_cfg = ESP_LV_ADAPTER_TOUCH_DEFAULT_CONFIG(lv_display, touch.getTouchHandle());
|
|
lv_indev_t* lv_touch = esp_lv_adapter_register_touch(&touch_cfg);
|
|
assert(lv_touch != NULL);
|
|
lv_indev_set_user_data(lv_touch, &touch); // Set 'this' Touch object as user data
|
|
lv_indev_set_read_cb(lv_touch, Touch::lv_indev_read_cb); // Register the static callback
|
|
|
|
ESP_ERROR_CHECK(esp_lv_adapter_start());
|
|
|
|
// Test LVGL lock right after start
|
|
ESP_LOGI(TAG, "Testing LVGL lock after adapter start...");
|
|
vTaskDelay(pdMS_TO_TICKS(100));
|
|
if (esp_lv_adapter_lock(1000) == ESP_OK) {
|
|
ESP_LOGI(TAG, "LVGL lock OK after adapter start");
|
|
esp_lv_adapter_unlock();
|
|
} else {
|
|
ESP_LOGE(TAG, "LVGL lock BLOCKED right after adapter start!");
|
|
}
|
|
|
|
ESP_LOGI(TAG, "INIT SUCCESS");
|
|
}
|
|
|
|
void run() {
|
|
// Initialize SD card for web content and config storage
|
|
if (!SdCard::instance().init()) {
|
|
ESP_LOGW(TAG, "SD card not available, using defaults");
|
|
}
|
|
|
|
ESP_LOGI(TAG, "START KNX");
|
|
BaseType_t knx_ok = xTaskCreatePinnedToCore(
|
|
knx_task, "knx", 4096, &Gui::knxWorker, 5, nullptr, 1);
|
|
if (knx_ok != pdPASS) {
|
|
ESP_LOGE(TAG, "Failed to start KNX task");
|
|
}
|
|
ESP_LOGI(TAG, "START WEBSERVER");
|
|
WebServer::instance().start();
|
|
ESP_LOGI(TAG, "INIT FONTS");
|
|
Fonts::init();
|
|
ESP_LOGI(TAG, "CREATE GUI");
|
|
gui.create();
|
|
|
|
ESP_LOGI(TAG, "Application running");
|
|
while (true) {
|
|
vTaskDelay(pdMS_TO_TICKS(10));
|
|
}
|
|
}
|
|
|
|
private:
|
|
Display display;
|
|
Touch touch;
|
|
Gui gui;
|
|
Nvs nvs;
|
|
};
|
|
|
|
extern "C" void app_main(void)
|
|
{
|
|
ESP_LOGI(TAG, "Starting Application");
|
|
Application app;
|
|
app.init();
|
|
app.run();
|
|
}
|