Skip to content

Commit 1bba83e

Browse files
Fix Windows build and add fully featured LVGL DisplayDemo
1 parent 811ae91 commit 1bba83e

7 files changed

Lines changed: 153 additions & 7 deletions

File tree

openBeken_win32_mvsc2017.vcxproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,6 @@
235235
<ClCompile Include="src\driver\drv_httpButtons.c" />
236236
<ClCompile Include="src\driver\drv_hue.c" />
237237
<ClCompile Include="src\driver\drv_ir.cpp" />
238-
<ClCompile Include="src\driver\drv_display_shared.cpp" />
239-
<ClCompile Include="src\driver\drv_display_hello.cpp" />
240238
<ClCompile Include="src\driver\drv_kp18058.c" />
241239
<ClCompile Include="src\driver\drv_kp18068.c" />
242240
<ClCompile Include="src\driver\drv_leds_shared.c" />

openBeken_win32_mvsc2017.vcxproj.filters

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@
5454
<ClCompile Include="src\driver\drv_httpButtons.c" />
5555
<ClCompile Include="src\driver\drv_hue.c" />
5656
<ClCompile Include="src\driver\drv_ir.cpp" />
57-
<ClCompile Include="src\driver\drv_display_shared.cpp" />
58-
<ClCompile Include="src\driver\drv_display_hello.cpp" />
5957
<ClCompile Include="src\driver\drv_kp18058.c" />
6058
<ClCompile Include="src\driver\drv_kp18068.c" />
6159
<ClCompile Include="src\driver\drv_main.c" />

platforms/obk_main.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ set(OBKM_SRC_CXX
182182
${OBK_SRCS}driver/drv_ir_new.cpp
183183
${OBK_SRCS}driver/drv_display_shared.cpp
184184
${OBK_SRCS}driver/drv_display_hello.cpp
185+
${OBK_SRCS}driver/drv_display_demo.cpp
185186
${OBK_SRCS}driver/display/lvgl_v8_port.cpp
186187
${OBK_SRCS}libraries/IRremoteESP8266/src/IRac.cpp
187188
${OBK_SRCS}libraries/IRremoteESP8266/src/IRproto.cpp

platforms/obk_main.mk

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,6 @@ OBKM_SRC += $(OBK_SRCS)i2c/drv_i2c_tc74.c
187187
OBKM_SRC_CXX += $(OBK_SRCS)driver/drv_ir.cpp
188188
OBKM_SRC_CXX += $(OBK_SRCS)driver/drv_rc.cpp
189189
OBKM_SRC_CXX += $(OBK_SRCS)driver/drv_ir_new.cpp
190-
OBKM_SRC_CXX += $(OBK_SRCS)driver/drv_display_shared.cpp
191-
OBKM_SRC_CXX += $(OBK_SRCS)driver/drv_display_hello.cpp
192190
OBKM_SRC_CXX += $(OBK_SRCS)libraries/rc-switch/src/RCSwitch.cpp
193191
OBKM_SRC_CXX += $(OBK_SRCS)libraries/IRremoteESP8266/src/IRac.cpp
194192
OBKM_SRC_CXX += $(OBK_SRCS)libraries/IRremoteESP8266/src/IRproto.cpp

src/cmnds/cmd_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,7 @@ void CMD_Init_Delayed() {
11751175
}
11761176
#endif
11771177
#if ENABLE_DRIVER_DISPLAY
1178-
CMD_ExecuteCommand("startDriver DisplayHello", 0);
1178+
CMD_ExecuteCommand("startDriver DisplayDemo", 0);
11791179
#endif
11801180
#if PLATFORM_BEKEN || WINDOWS || PLATFORM_BL602 || PLATFORM_ESPIDF || PLATFORM_ESP8266 \
11811181
|| PLATFORM_REALTEK || PLATFORM_ECR6600 || PLATFORM_XRADIO

src/driver/drv_display_demo.cpp

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
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

src/driver/drv_main.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ void DisplayHello_Init();
2828
void DisplayHello_OnEverySecond();
2929
void DisplayHello_Shutdown();
3030

31+
void DisplayDemo_Init();
32+
void DisplayDemo_OnEverySecond();
33+
void DisplayDemo_Shutdown();
34+
3135
void DRV_MQTTServer_Init();
3236
void DRV_MQTTServer_AppendInformationToHTTPIndexPage(http_request_t *request, int bPreState);
3337
void DRV_MQTTServer_RunEverySecond();
@@ -1534,6 +1538,14 @@ static driver_t g_drivers[] = {
15341538
NULL, // appendInformationToHTTPIndexPage
15351539
NULL, // runQuickTick
15361540
DisplayHello_Shutdown, // stopFunction
1541+
NULL }, // onEveryMinute
1542+
{ "DisplayDemo", // Driver Name
1543+
DisplayDemo_Init, // Init
1544+
DisplayDemo_OnEverySecond, // onEverySecond
1545+
NULL, // appendInformationToHTTPIndexPage
1546+
NULL, // runQuickTick
1547+
DisplayDemo_Shutdown, // stopFunction
1548+
NULL }, // onEveryMinute
15371549
NULL, // onChannelChanged
15381550
NULL, // onHassDiscovery
15391551
false, // loaded

0 commit comments

Comments
 (0)