Files
overland-controller/firmware/esp32-s3-dashboard/esp32-s3-dashboard.ino
T

140 lines
4.6 KiB
Arduino

#include <Arduino.h>
#include <esp_display_panel.hpp>
#include <lvgl.h>
#include "lvgl_v8_port.h"
using namespace esp_panel::drivers;
using namespace esp_panel::board;
static lv_obj_t *touch_count_label = nullptr;
static uint32_t touch_count = 0;
static void touch_test_event_cb(lv_event_t *event)
{
if (lv_event_get_code(event) != LV_EVENT_CLICKED) {
return;
}
touch_count++;
if (touch_count_label != nullptr) {
lv_label_set_text_fmt(touch_count_label, "Touch test count: %lu", (unsigned long)touch_count);
}
Serial.print("Touch test count: ");
Serial.println(touch_count);
}
static void create_overland_boot_screen()
{
lv_obj_t *screen = lv_scr_act();
lv_obj_clean(screen);
lv_obj_set_style_bg_color(screen, lv_color_hex(0x101418), 0);
lv_obj_t *title = lv_label_create(screen);
lv_label_set_text(title, "Overland Controller");
lv_obj_set_style_text_color(title, lv_color_hex(0xFFFFFF), 0);
lv_obj_set_style_text_font(title, &lv_font_montserrat_30, 0);
lv_obj_align(title, LV_ALIGN_TOP_MID, 0, 40);
lv_obj_t *subtitle = lv_label_create(screen);
lv_label_set_text(subtitle, "ESP32-S3 Dashboard Bring-Up");
lv_obj_set_style_text_color(subtitle, lv_color_hex(0xB8C0C8), 0);
lv_obj_set_style_text_font(subtitle, &lv_font_montserrat_30, 0);
lv_obj_align_to(subtitle, title, LV_ALIGN_OUT_BOTTOM_MID, 0, 12);
lv_obj_t *card = lv_obj_create(screen);
lv_obj_set_size(card, 760, 330);
lv_obj_align(card, LV_ALIGN_CENTER, 0, 25);
lv_obj_set_style_radius(card, 18, 0);
lv_obj_set_style_bg_color(card, lv_color_hex(0x1F2933), 0);
lv_obj_set_style_border_color(card, lv_color_hex(0x3A4652), 0);
lv_obj_set_style_border_width(card, 2, 0);
lv_obj_set_style_pad_all(card, 24, 0);
lv_obj_t *status = lv_label_create(card);
lv_label_set_text(
status,
"Hardware: Waveshare ESP32-S3 Touch LCD 5B\n"
"Display: 1024 x 600\n"
"Touch: Capacitive\n"
"Cargo API Base: /api/v1\n"
"WiFi: Not connected yet\n"
"Mode: Local dashboard bring-up"
);
lv_obj_set_style_text_color(status, lv_color_hex(0xFFFFFF), 0);
lv_obj_set_style_text_font(status, &lv_font_montserrat_30, 0);
lv_obj_set_style_text_line_space(status, 10, 0);
lv_obj_align(status, LV_ALIGN_TOP_LEFT, 0, 0);
lv_obj_t *button = lv_btn_create(card);
lv_obj_set_size(button, 260, 72);
lv_obj_align(button, LV_ALIGN_BOTTOM_LEFT, 0, 0);
lv_obj_add_event_cb(button, touch_test_event_cb, LV_EVENT_CLICKED, nullptr);
lv_obj_t *button_label = lv_label_create(button);
lv_label_set_text(button_label, "Touch Test");
lv_obj_set_style_text_font(button_label, &lv_font_montserrat_30, 0);
lv_obj_center(button_label);
touch_count_label = lv_label_create(card);
lv_label_set_text(touch_count_label, "Touch test count: 0");
lv_obj_set_style_text_color(touch_count_label, lv_color_hex(0xB8C0C8), 0);
lv_obj_set_style_text_font(touch_count_label, &lv_font_montserrat_30, 0);
lv_obj_align(touch_count_label, LV_ALIGN_BOTTOM_LEFT, 300, -22);
lv_obj_t *footer = lv_label_create(screen);
lv_label_set_text(footer, "Next: WiFi client -> GET /api/v1/status from Cargo ESP");
lv_obj_set_style_text_color(footer, lv_color_hex(0x7D8996), 0);
lv_obj_set_style_text_font(footer, &lv_font_montserrat_30, 0);
lv_obj_align(footer, LV_ALIGN_BOTTOM_MID, 0, -28);
}
void setup()
{
Serial.begin(115200);
delay(1000);
Serial.println();
Serial.println("================================");
Serial.println("Overland Controller Dashboard");
Serial.println("================================");
Serial.println("Target: Waveshare ESP32-S3 Touch LCD 5B");
Serial.println("Display: 1024x600");
Serial.println("API Base: /api/v1");
Serial.println("Initializing board");
Board *board = new Board();
board->init();
#if LVGL_PORT_AVOID_TEARING_MODE
auto lcd = board->getLCD();
lcd->configFrameBufferNumber(LVGL_PORT_DISP_BUFFER_NUM);
#if ESP_PANEL_DRIVERS_BUS_ENABLE_RGB && CONFIG_IDF_TARGET_ESP32S3
auto lcd_bus = lcd->getBus();
if (lcd_bus->getBasicAttributes().type == ESP_PANEL_BUS_TYPE_RGB) {
static_cast<BusRGB *>(lcd_bus)->configRGB_BounceBufferSize(lcd->getFrameWidth() * 10);
}
#endif
#endif
assert(board->begin());
Serial.println("Initializing LVGL");
lvgl_port_init(board->getLCD(), board->getTouch());
Serial.println("Creating Overland boot screen");
lvgl_port_lock(-1);
create_overland_boot_screen();
lvgl_port_unlock();
Serial.println("Dashboard boot screen ready");
}
void loop()
{
delay(1000);
}