Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Arduino.h>
- #include <lvgl.h>
- #include <TFT_eSPI.h>
- // Display & LVGL setup
- TFT_eSPI tft = TFT_eSPI();
- static lv_disp_draw_buf_t draw_buf;
- static lv_color_t buf[LV_HOR_RES_MAX * 10];
- lv_obj_t *table;
- // LVGL Display Flush Callback
- void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p) {
- uint16_t w = area->x2 - area->x1 + 1;
- uint16_t h = area->y2 - area->y1 + 1;
- tft.startWrite();
- tft.setAddrWindow(area->x1, area->y1, w, h);
- tft.pushColors((uint16_t *)&color_p->full, w * h, true);
- tft.endWrite();
- lv_disp_flush_ready(disp);
- }
- // Initialize LVGL Table
- void create_table() {
- table = lv_table_create(lv_scr_act());
- //lv_obj_set_size(table, 200, 150);
- lv_obj_align(table, LV_ALIGN_CENTER, 0, 0);
- lv_obj_clear_flag(lv_scr_act(), LV_OBJ_FLAG_SCROLLABLE);
- lv_obj_set_style_bg_color(lv_scr_act(), lv_color_make(255, 255, 255), LV_PART_MAIN);
- lv_obj_set_style_text_color(table, lv_color_black(), LV_PART_ITEMS);
- lv_obj_set_style_bg_color(table, lv_color_white(), LV_PART_MAIN);
- // Set table properties
- lv_table_set_col_cnt(table, 4);
- lv_table_set_row_cnt(table, 6);
- lv_obj_set_style_border_width(table, 1, LV_PART_ITEMS);
- lv_obj_set_style_border_color(table, lv_palette_main(LV_PALETTE_BLUE), LV_PART_ITEMS);
- lv_obj_set_style_border_side(table, LV_BORDER_SIDE_FULL, LV_PART_ITEMS);
- lv_table_set_col_width(table, 0, 60);
- lv_table_set_col_width(table, 1, 100);
- lv_table_set_col_width(table, 2, 60);
- lv_table_set_col_width(table, 3, 100);
- lv_table_add_cell_ctrl(table, 5, 1, LV_TABLE_CELL_CTRL_MERGE_RIGHT);
- lv_table_add_cell_ctrl(table, 5, 2, LV_TABLE_CELL_CTRL_MERGE_RIGHT);
- lv_table_add_cell_ctrl(table, 5, 3, LV_TABLE_CELL_CTRL_MERGE_RIGHT);
- lv_table_set_cell_value(table, 0, 0, "RPM");
- lv_table_set_cell_value(table, 0, 2, "SPD");
- lv_table_set_cell_value(table, 1, 0, "AFR");
- lv_table_set_cell_value(table, 1, 2, "CLT");
- lv_table_set_cell_value(table, 2, 0, "TPS");
- lv_table_set_cell_value(table, 2, 2, "BAT");
- lv_table_set_cell_value(table, 3, 0, "MAP");
- lv_table_set_cell_value(table, 3, 2, "BST");
- lv_table_set_cell_value(table, 4, 0, "INJ");
- lv_table_set_cell_value(table, 4, 2, "IGN");
- lv_table_set_cell_value(table, 5, 0, "CEL");
- }
- void setup() {
- Serial.begin(115200);
- tft.begin();
- tft.setRotation(3);
- // Initialize LVGL
- lv_init();
- lv_disp_draw_buf_init(&draw_buf, buf, NULL, LV_HOR_RES_MAX * 10);
- // Setup LVGL Display Driver
- static lv_disp_drv_t disp_drv;
- lv_disp_drv_init(&disp_drv);
- disp_drv.hor_res = 320;
- disp_drv.ver_res = 240;
- disp_drv.flush_cb = my_disp_flush;
- disp_drv.draw_buf = &draw_buf;
- lv_disp_drv_register(&disp_drv);
- // Create table
- create_table();
- }
- void loop() {
- lv_table_set_cell_value(table, 0, 1, "1000");
- lv_table_set_cell_value(table, 0, 3, "50 KM/H");
- lv_table_set_cell_value(table, 1, 1, "14.40");
- lv_table_set_cell_value(table, 1, 3, "75 *C");
- lv_table_set_cell_value(table, 2, 1, "30 %");
- lv_table_set_cell_value(table, 2, 3, "14.5 V");
- lv_table_set_cell_value(table, 3, 1, "0.54 BAR");
- lv_table_set_cell_value(table, 3, 3, "-0.46 BAR");
- lv_table_set_cell_value(table, 4, 1, "10 %");
- lv_table_set_cell_value(table, 4, 3, "6 *");
- lv_table_set_cell_value(table, 5, 1, "IAT");
- // Run LVGL
- lv_timer_handler();
- delay(10);
- }
Advertisement
Add Comment
Please, Sign In to add comment