|
| 1 | +#include "../new_common.h" |
| 2 | +#include "../new_pins.h" |
| 3 | +#include "../new_cfg.h" |
| 4 | +#include "../logging/logging.h" |
| 5 | +#include "../hal/hal_pins.h" |
| 6 | +#include "drv_display_shared.h" |
| 7 | + |
| 8 | +#if defined(PLATFORM_ESPIDF) && defined(ENABLE_DISPLAY) |
| 9 | + |
| 10 | +#include <lvgl.h> |
| 11 | +#include "display/lvgl_v8_port.h" |
| 12 | +#include "esp_heap_caps.h" |
| 13 | +#include "esp_chip_info.h" |
| 14 | + |
| 15 | +static lv_obj_t *screen_main; |
| 16 | +static lv_obj_t *mem_label; |
| 17 | +static lv_obj_t *chip_label; |
| 18 | +static lv_obj_t *chart; |
| 19 | +static lv_chart_series_t * ser; |
| 20 | +static int tick_count = 0; |
| 21 | + |
| 22 | +static void gui_build_main_screen() { |
| 23 | + screen_main = lv_obj_create(NULL); |
| 24 | + // Dark background |
| 25 | + lv_obj_set_style_bg_color(screen_main, lv_color_hex(0x121220), LV_PART_MAIN); |
| 26 | + |
| 27 | + // Create a tab view |
| 28 | + lv_obj_t * tabview = lv_tabview_create(screen_main, LV_DIR_TOP, 50); |
| 29 | + lv_obj_set_style_bg_color(tabview, lv_color_hex(0x121220), LV_PART_MAIN); |
| 30 | + |
| 31 | + // Get the buttons part of the tabview and style it |
| 32 | + lv_obj_t * tab_btns = lv_tabview_get_tab_btns(tabview); |
| 33 | + lv_obj_set_style_bg_color(tab_btns, lv_color_hex(0x1A1A2E), LV_PART_MAIN); |
| 34 | + lv_obj_set_style_text_color(tab_btns, lv_color_hex(0xAAAAAA), LV_PART_MAIN); |
| 35 | + lv_obj_set_style_text_color(tab_btns, lv_color_hex(0xFFFFFF), LV_PART_ITEMS | LV_STATE_CHECKED); |
| 36 | + |
| 37 | + // Add 3 tabs |
| 38 | + lv_obj_t * tab1 = lv_tabview_add_tab(tabview, "Controls"); |
| 39 | + lv_obj_t * tab2 = lv_tabview_add_tab(tabview, "Dashboard"); |
| 40 | + lv_obj_t * tab3 = lv_tabview_add_tab(tabview, "System"); |
| 41 | + |
| 42 | + // --- TAB 1: Controls --- |
| 43 | + // A slider |
| 44 | + lv_obj_t * slider = lv_slider_create(tab1); |
| 45 | + lv_obj_align(slider, LV_ALIGN_TOP_MID, 0, 20); |
| 46 | + lv_obj_set_width(slider, 200); |
| 47 | + lv_obj_set_style_bg_color(slider, lv_color_hex(0x0F3460), LV_PART_MAIN); |
| 48 | + lv_obj_set_style_bg_color(slider, lv_color_hex(0xE94560), LV_PART_INDICATOR); |
| 49 | + |
| 50 | + // A switch |
| 51 | + lv_obj_t * sw = lv_switch_create(tab1); |
| 52 | + lv_obj_align(sw, LV_ALIGN_CENTER, -60, 20); |
| 53 | + lv_obj_set_style_bg_color(sw, lv_color_hex(0xE94560), LV_PART_INDICATOR | LV_STATE_CHECKED); |
| 54 | + |
| 55 | + // An arc |
| 56 | + lv_obj_t * arc = lv_arc_create(tab1); |
| 57 | + lv_obj_set_size(arc, 100, 100); |
| 58 | + lv_obj_align(arc, LV_ALIGN_CENTER, 60, 20); |
| 59 | + lv_arc_set_value(arc, 40); |
| 60 | + lv_obj_set_style_arc_color(arc, lv_color_hex(0x0F3460), LV_PART_MAIN); |
| 61 | + lv_obj_set_style_arc_color(arc, lv_color_hex(0xE94560), LV_PART_INDICATOR); |
| 62 | + |
| 63 | + // --- TAB 2: Dashboard --- |
| 64 | + chart = lv_chart_create(tab2); |
| 65 | + lv_obj_set_size(chart, 240, 150); |
| 66 | + lv_obj_align(chart, LV_ALIGN_CENTER, 0, 0); |
| 67 | + lv_chart_set_type(chart, LV_CHART_TYPE_LINE); |
| 68 | + lv_obj_set_style_bg_color(chart, lv_color_hex(0x16213E), LV_PART_MAIN); |
| 69 | + lv_obj_set_style_line_color(chart, lv_color_hex(0x00FF00), LV_PART_ITEMS); |
| 70 | + |
| 71 | + // Add data series |
| 72 | + ser = lv_chart_add_series(chart, lv_color_hex(0xE94560), LV_CHART_AXIS_PRIMARY_Y); |
| 73 | + for(int i = 0; i < 10; i++) { |
| 74 | + lv_chart_set_next_value(chart, ser, lv_rand(10, 90)); |
| 75 | + } |
| 76 | + |
| 77 | + // --- TAB 3: System --- |
| 78 | + mem_label = lv_label_create(tab3); |
| 79 | + lv_label_set_text(mem_label, "Mem: --"); |
| 80 | + lv_obj_align(mem_label, LV_ALIGN_TOP_LEFT, 10, 10); |
| 81 | + lv_obj_set_style_text_color(mem_label, lv_color_hex(0xAAAAAA), LV_PART_MAIN); |
| 82 | + |
| 83 | + chip_label = lv_label_create(tab3); |
| 84 | + esp_chip_info_t chip_info; |
| 85 | + esp_chip_info(&chip_info); |
| 86 | + char cbuf[128]; |
| 87 | + snprintf(cbuf, sizeof(cbuf), "Cores: %d\nRev: %d", chip_info.cores, chip_info.revision); |
| 88 | + lv_label_set_text(chip_label, cbuf); |
| 89 | + lv_obj_align(chip_label, LV_ALIGN_TOP_LEFT, 10, 60); |
| 90 | + lv_obj_set_style_text_color(chip_label, lv_color_hex(0xAAAAAA), LV_PART_MAIN); |
| 91 | +} |
| 92 | + |
| 93 | +extern "C" void DisplayDemo_Init() { |
| 94 | + if (!Display_PreInit()) { |
| 95 | + return; |
| 96 | + } |
| 97 | + |
| 98 | + lvgl_port_lock(-1); |
| 99 | + gui_build_main_screen(); |
| 100 | + lv_scr_load(screen_main); |
| 101 | + lvgl_port_unlock(); |
| 102 | + |
| 103 | + Display_PostInit(); |
| 104 | +} |
| 105 | + |
| 106 | +extern "C" void DisplayDemo_OnEverySecond() { |
| 107 | + if(!g_display_ready) return; |
| 108 | + |
| 109 | + tick_count++; |
| 110 | + |
| 111 | + char mbuf[128]; |
| 112 | + size_t free_int = heap_caps_get_free_size(MALLOC_CAP_INTERNAL); |
| 113 | + size_t max_int = heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL); |
| 114 | + size_t free_spi = heap_caps_get_free_size(MALLOC_CAP_SPIRAM); |
| 115 | + size_t max_spi = heap_caps_get_largest_free_block(MALLOC_CAP_SPIRAM); |
| 116 | + snprintf(mbuf, sizeof(mbuf), "INT: %u (%u max)\nSPI: %u (%u max)", |
| 117 | + (unsigned)free_int, (unsigned)max_int, (unsigned)free_spi, (unsigned)max_spi); |
| 118 | + |
| 119 | + lvgl_port_lock(-1); |
| 120 | + if(mem_label) { |
| 121 | + lv_label_set_text(mem_label, mbuf); |
| 122 | + } |
| 123 | + if (chart && ser) { |
| 124 | + lv_chart_set_next_value(chart, ser, lv_rand(10, 90)); |
| 125 | + } |
| 126 | + lvgl_port_unlock(); |
| 127 | +} |
| 128 | + |
| 129 | +extern "C" void DisplayDemo_Shutdown() { |
| 130 | + Display_Shutdown(); |
| 131 | +} |
| 132 | + |
| 133 | +#else |
| 134 | + |
| 135 | +extern "C" void DisplayDemo_Init() {} |
| 136 | +extern "C" void DisplayDemo_OnEverySecond() {} |
| 137 | +extern "C" void DisplayDemo_Shutdown() {} |
| 138 | + |
| 139 | +#endif |
0 commit comments