espd

esp32 - UI 90%

Apr 3rd, 2025 (edited)
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.40 KB | None | 0 0
  1. #include <Arduino.h>
  2. #include <lvgl.h>
  3. #include <TFT_eSPI.h>
  4.  
  5. // Display & LVGL setup
  6. TFT_eSPI tft = TFT_eSPI();
  7. static lv_disp_draw_buf_t draw_buf;
  8. static lv_color_t buf[LV_HOR_RES_MAX * 10];
  9. lv_obj_t *table;
  10.  
  11. // LVGL Display Flush Callback
  12. void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p) {
  13.   uint16_t w = area->x2 - area->x1 + 1;
  14.   uint16_t h = area->y2 - area->y1 + 1;
  15.   tft.startWrite();
  16.   tft.setAddrWindow(area->x1, area->y1, w, h);
  17.   tft.pushColors((uint16_t *)&color_p->full, w * h, true);
  18.   tft.endWrite();
  19.   lv_disp_flush_ready(disp);
  20. }
  21.  
  22. // Initialize LVGL Table
  23. void create_table() {
  24.   table = lv_table_create(lv_scr_act());
  25.   //lv_obj_set_size(table, 200, 150);
  26.   lv_obj_align(table, LV_ALIGN_CENTER, 0, 0);
  27.  
  28.   lv_obj_clear_flag(lv_scr_act(), LV_OBJ_FLAG_SCROLLABLE);
  29.  
  30.   lv_obj_set_style_bg_color(lv_scr_act(), lv_color_make(255, 255, 255), LV_PART_MAIN);
  31.  
  32.   lv_obj_set_style_text_color(table, lv_color_black(), LV_PART_ITEMS);
  33.  
  34.   lv_obj_set_style_bg_color(table, lv_color_white(), LV_PART_MAIN);
  35.  
  36.   // Set table properties
  37.   lv_table_set_col_cnt(table, 4);
  38.   lv_table_set_row_cnt(table, 6);
  39.  
  40.   lv_obj_set_style_border_width(table, 1, LV_PART_ITEMS);
  41.   lv_obj_set_style_border_color(table, lv_palette_main(LV_PALETTE_BLUE), LV_PART_ITEMS);
  42.   lv_obj_set_style_border_side(table, LV_BORDER_SIDE_FULL, LV_PART_ITEMS);
  43.  
  44.   lv_table_set_col_width(table, 0, 60);
  45.   lv_table_set_col_width(table, 1, 100);
  46.   lv_table_set_col_width(table, 2, 60);
  47.   lv_table_set_col_width(table, 3, 100);
  48.  
  49.   lv_table_add_cell_ctrl(table, 5, 1, LV_TABLE_CELL_CTRL_MERGE_RIGHT);
  50.   lv_table_add_cell_ctrl(table, 5, 2, LV_TABLE_CELL_CTRL_MERGE_RIGHT);
  51.   lv_table_add_cell_ctrl(table, 5, 3, LV_TABLE_CELL_CTRL_MERGE_RIGHT);
  52.  
  53.   lv_table_set_cell_value(table, 0, 0, "RPM");
  54.   lv_table_set_cell_value(table, 0, 2, "SPD");
  55.   lv_table_set_cell_value(table, 1, 0, "AFR");
  56.   lv_table_set_cell_value(table, 1, 2, "CLT");
  57.   lv_table_set_cell_value(table, 2, 0, "TPS");
  58.   lv_table_set_cell_value(table, 2, 2, "BAT");
  59.   lv_table_set_cell_value(table, 3, 0, "MAP");
  60.   lv_table_set_cell_value(table, 3, 2, "BST");
  61.   lv_table_set_cell_value(table, 4, 0, "INJ");
  62.   lv_table_set_cell_value(table, 4, 2, "IGN");
  63.   lv_table_set_cell_value(table, 5, 0, "CEL");
  64. }
  65.  
  66. void setup() {
  67.   Serial.begin(115200);
  68.   tft.begin();
  69.   tft.setRotation(3);
  70.  
  71.   // Initialize LVGL
  72.   lv_init();
  73.   lv_disp_draw_buf_init(&draw_buf, buf, NULL, LV_HOR_RES_MAX * 10);
  74.  
  75.   // Setup LVGL Display Driver
  76.   static lv_disp_drv_t disp_drv;
  77.   lv_disp_drv_init(&disp_drv);
  78.   disp_drv.hor_res = 320;
  79.   disp_drv.ver_res = 240;
  80.   disp_drv.flush_cb = my_disp_flush;
  81.   disp_drv.draw_buf = &draw_buf;
  82.   lv_disp_drv_register(&disp_drv);
  83.  
  84.   // Create table
  85.   create_table();
  86. }
  87.  
  88. void loop() {
  89.  
  90.  
  91.   lv_table_set_cell_value(table, 0, 1, "1000");
  92.  
  93.   lv_table_set_cell_value(table, 0, 3, "50 KM/H");
  94.  
  95.  
  96.   lv_table_set_cell_value(table, 1, 1, "14.40");
  97.  
  98.   lv_table_set_cell_value(table, 1, 3, "75 *C");
  99.  
  100.  
  101.   lv_table_set_cell_value(table, 2, 1, "30 %");
  102.  
  103.   lv_table_set_cell_value(table, 2, 3, "14.5 V");
  104.  
  105.  
  106.   lv_table_set_cell_value(table, 3, 1, "0.54 BAR");
  107.  
  108.   lv_table_set_cell_value(table, 3, 3, "-0.46 BAR");
  109.  
  110.  
  111.   lv_table_set_cell_value(table, 4, 1, "10 %");
  112.  
  113.   lv_table_set_cell_value(table, 4, 3, "6 *");
  114.  
  115.  
  116.   lv_table_set_cell_value(table, 5, 1, "IAT");
  117.  
  118.  
  119.   // Run LVGL
  120.   lv_timer_handler();
  121.   delay(10);
  122. }
Advertisement
Add Comment
Please, Sign In to add comment