knxdisplay/main/main.cpp
2026-01-19 10:46:45 +01:00

82 lines
2.1 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 "Nvs.hpp"
#include "KnxWorker.hpp"
#include "Wifi.hpp"
#define TAG "App"
// This is a simple wrapper for the application logic
class Application {
public:
void init() {
// Initialize hardware
nvs.init();
Wifi::instance().init();
display.init();
touch.init();
// Initialize LVGL adapter
esp_lv_adapter_config_t cfg = ESP_LV_ADAPTER_DEFAULT_CONFIG();
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
);
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());
ESP_LOGI(TAG, "INIT SUCCESS");
}
void run() {
ESP_LOGI(TAG, "Creating UI");
knxWorker.init();
gui.create();
ESP_LOGI(TAG, "Application running");
while (true) {
vTaskDelay(pdMS_TO_TICKS(10));
knxWorker.loop();
}
}
private:
Display display;
Touch touch;
Gui gui;
Nvs nvs;
KnxWorker knxWorker;
};
extern "C" void app_main(void)
{
ESP_LOGI(TAG, "Starting Application");
Application app;
app.init();
app.run();
}