switched to lvgl 9.1

This commit is contained in:
KlausMu 2024-04-08 10:27:52 +02:00
parent 1a1530789f
commit a1ce03d9d5
18 changed files with 267 additions and 325 deletions

View File

@ -3,30 +3,30 @@
#include "sleep_hal_esp32.h" #include "sleep_hal_esp32.h"
// ----------------------- // -----------------------
// https://docs.lvgl.io/8.3/porting/display.html?highlight=lv_disp_draw_buf_init#buffering-modes // https://docs.lvgl.io/master/porting/display.html#two-buffers
// With two buffers, the rendering and refreshing of the display become parallel operations // With two buffers, the rendering and refreshing of the display become parallel operations
// Second buffer needs 15.360 bytes more memory in heap. // Second buffer needs 15.360 bytes more memory in heap.
#define useTwoBuffersForlvgl #define useTwoBuffersForlvgl
// Display flushing // Display flushing
void my_disp_flush( lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p ){ static void my_disp_flush( lv_display_t *disp, const lv_area_t *area, uint8_t *px_map ) {
uint32_t w = ( area->x2 - area->x1 + 1 ); uint32_t w = (area->x2 - area->x1 + 1);
uint32_t h = ( area->y2 - area->y1 + 1 ); uint32_t h = (area->y2 - area->y1 + 1);
tft.startWrite(); tft.startWrite();
tft.setAddrWindow(area->x1, area->y1, w, h); tft.setAddrWindow(area->x1, area->y1, w, h);
#ifdef useTwoBuffersForlvgl #ifdef useTwoBuffersForlvgl
tft.pushPixelsDMA((uint16_t*)&color_p->full, w * h); tft.pushPixelsDMA((uint16_t*)px_map, w * h);
#else #else
tft.pushColors((uint16_t*)&color_p->full, w * h, true); tft.pushColors((uint16_t *)px_map, w * h, true);
#endif #endif
tft.endWrite(); tft.endWrite();
lv_disp_flush_ready( disp ); lv_display_flush_ready(disp);
} }
// Read the touchpad // Read the touchpad
void my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data){ static void my_touchpad_read(lv_indev_t *indev_driver, lv_indev_data_t *data) {
int16_t touchX; int16_t touchX;
int16_t touchY; int16_t touchY;
get_touchpoint(&touchX, &touchY); get_touchpoint(&touchX, &touchY);
@ -38,10 +38,10 @@ void my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data){
} }
if( !touched ){ if( !touched ){
data->state = LV_INDEV_STATE_REL; data->state = LV_INDEV_STATE_RELEASED;
} }
else{ else{
data->state = LV_INDEV_STATE_PR; data->state = LV_INDEV_STATE_PRESSED;
// Set the coordinates // Set the coordinates
data->point.x = SCR_WIDTH - touchX; data->point.x = SCR_WIDTH - touchX;
@ -56,35 +56,40 @@ void my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data){
} }
} }
static lv_disp_draw_buf_t draw_buf; /*LVGL draw into this buffer, 1/10 screen size usually works well. The size is in bytes*/
#define DRAW_BUF_SIZE (SCR_WIDTH * SCR_HEIGHT / 10 * (LV_COLOR_DEPTH / 8))
static uint32_t my_tick_get_cb(void) {
return millis();
}
void init_lvgl_HAL() { void init_lvgl_HAL() {
// first init TFT // first init TFT
init_tft(); init_tft();
// new in lvgl 9
lv_tick_set_cb(my_tick_get_cb);
// https://github.com/lvgl/lvgl/blob/release/v9.0/docs/CHANGELOG.rst#display-api
// https://docs.lvgl.io/master/get-started/quick-overview.html#add-lvgl-into-your-project
lv_display_t *disp = lv_display_create(SCR_WIDTH, SCR_HEIGHT);
lv_display_set_flush_cb(disp, my_disp_flush);
// https://github.com/lvgl/lvgl/blob/release/v9.0/docs/CHANGELOG.rst#migration-guide
// lv_display_set_buffers(display, buf1, buf2, buf_size_byte, mode) is more or less the equivalent of lv_disp_draw_buf_init(&draw_buf_dsc, buf1, buf2, buf_size_px) from v8, however in v9 the buffer size is set in bytes.
#ifdef useTwoBuffersForlvgl #ifdef useTwoBuffersForlvgl
lv_color_t * bufA = (lv_color_t *) malloc(sizeof(lv_color_t) * SCR_WIDTH * SCR_HEIGHT / 10); uint8_t *bufA = (uint8_t *) malloc(DRAW_BUF_SIZE);
lv_color_t * bufB = (lv_color_t *) malloc(sizeof(lv_color_t) * SCR_WIDTH * SCR_HEIGHT / 10); uint8_t *bufB = (uint8_t *) malloc(DRAW_BUF_SIZE);
lv_disp_draw_buf_init(&draw_buf, bufA, bufB, SCR_WIDTH * SCR_HEIGHT / 10); lv_display_set_buffers(disp, bufA, bufB, DRAW_BUF_SIZE, LV_DISPLAY_RENDER_MODE_PARTIAL);
#else #else
lv_color_t * bufA = (lv_color_t *) malloc(sizeof(lv_color_t) * SCR_WIDTH * SCR_HEIGHT / 10); uint8_t *bufA = (uint8_t *) malloc(DRAW_BUF_SIZE);
lv_disp_draw_buf_init(&draw_buf, bufA, NULL, SCR_WIDTH * SCR_HEIGHT / 10); lv_display_set_buffers(disp, bufA, NULL, DRAW_BUF_SIZE, LV_DISPLAY_RENDER_MODE_PARTIAL);
#endif #endif
// Initialize the display driver --------------------------------------------------------------------------
static lv_disp_drv_t disp_drv;
lv_disp_drv_init( &disp_drv );
disp_drv.hor_res = SCR_WIDTH;
disp_drv.ver_res = SCR_HEIGHT;
disp_drv.flush_cb = my_disp_flush;
disp_drv.draw_buf = &draw_buf;
lv_disp_drv_register( &disp_drv );
// Initialize the touchscreen driver // Initialize the touchscreen driver
static lv_indev_drv_t indev_drv; // https://github.com/lvgl/lvgl/blob/release/v9.0/docs/CHANGELOG.rst#indev-api
lv_indev_drv_init( &indev_drv ); static lv_indev_t * indev = lv_indev_create();
indev_drv.type = LV_INDEV_TYPE_POINTER; lv_indev_set_type(indev, LV_INDEV_TYPE_POINTER);
indev_drv.read_cb = my_touchpad_read; lv_indev_set_read_cb(indev, my_touchpad_read);
lv_indev_drv_register( &indev_drv );
} }

View File

@ -23,7 +23,7 @@ long HeapUsed()
#elif defined(__linux__) #elif defined(__linux__)
long HeapUsed() { long HeapUsed() {
// don't know how to get used heap size in linux // don't know how to get used heap size in linux
return 800000; return 80000;
} }
#endif #endif

View File

@ -1,44 +1,4 @@
#include <stdlib.h>
#include <sys/time.h>
#include <lvgl.h> #include <lvgl.h>
#include <SDL2/SDL_thread.h>
#include "sdl/sdl.h"
#include "SDL2/SDL_events.h"
long long current_timestamp_hal_windowsLinux() {
struct timeval te;
gettimeofday(&te, NULL); // get current time
long long milliseconds = te.tv_sec*1000LL + te.tv_usec/1000; // calculate milliseconds
// printf("milliseconds: %lld\r\n", milliseconds);
return milliseconds;
}
/**
* A task to measure the elapsed time for LittlevGL
* @param data unused
* @return never return
*/
static int tick_thread(void * data)
{
(void)data;
long long lastTimestamp = current_timestamp_hal_windowsLinux();
long long newTimestamp = 0;
while(1) {
// we don't use this blackbox
// SDL_Delay(5); /*Sleep for 5 millisecond*/
// lv_tick_inc(5); /*Tell lvgl that 5 milliseconds were elapsed*/
newTimestamp = current_timestamp_hal_windowsLinux();
if ((newTimestamp - lastTimestamp) > 5) {
lv_tick_inc(newTimestamp - lastTimestamp);
lastTimestamp = newTimestamp;
}
}
return 0;
}
static lv_disp_draw_buf_t draw_buf;
void init_lvgl_HAL() { void init_lvgl_HAL() {
// Workaround for sdl2 `-m32` crash // Workaround for sdl2 `-m32` crash
@ -47,63 +7,33 @@ void init_lvgl_HAL() {
setenv("DBUS_FATAL_WARNINGS", "0", 1); setenv("DBUS_FATAL_WARNINGS", "0", 1);
#endif #endif
#ifdef useTwoBuffersForlvgl // https://github.com/lvgl/lv_platformio/issues/59
lv_color_t * bufA = (lv_color_t *) malloc(sizeof(lv_color_t) * SDL_HOR_RES * SDL_VER_RES / 10); // https://github.com/lvgl/lv_port_pc_eclipse/blob/master/main.c#L111
lv_color_t * bufB = (lv_color_t *) malloc(sizeof(lv_color_t) * SDL_HOR_RES * SDL_VER_RES / 10); // https://github.com/lvgl/lv_port_pc_eclipse/blob/master/lv_conf.h#L832-L839
lv_disp_draw_buf_init(&draw_buf, bufA, bufB, SDL_HOR_RES * SDL_VER_RES / 10); lv_group_set_default(lv_group_create());
#else
lv_color_t * bufA = (lv_color_t *) malloc(sizeof(lv_color_t) * SDL_HOR_RES * SDL_VER_RES / 10);
lv_disp_draw_buf_init(&draw_buf, bufA, NULL, SDL_HOR_RES * SDL_VER_RES / 10);
#endif
// Initialize the display driver -------------------------------------------------------------------------- lv_display_t * disp = lv_sdl_window_create(SDL_HOR_RES, SDL_VER_RES);
static lv_disp_drv_t disp_drv; lv_display_set_default(disp);
lv_disp_drv_init( &disp_drv );
disp_drv.hor_res = SDL_HOR_RES;
disp_drv.ver_res = SDL_VER_RES;
disp_drv.flush_cb = sdl_display_flush; /*Used when `LV_VDB_SIZE != 0` in lv_conf.h (buffered drawing)*/
disp_drv.draw_buf = &draw_buf;
//disp_drv.disp_fill = monitor_fill; /*Used when `LV_VDB_SIZE == 0` in lv_conf.h (unbuffered drawing)*/
//disp_drv.disp_map = monitor_map; /*Used when `LV_VDB_SIZE == 0` in lv_conf.h (unbuffered drawing)*/
lv_disp_drv_register( &disp_drv );
/* Add the mouse as input device lv_indev_t * mouse = lv_sdl_mouse_create();
* Use the 'mouse' driver which reads the PC's mouse*/ lv_indev_set_group(mouse, lv_group_get_default());
static lv_indev_drv_t indev_drv_mouse; lv_indev_set_display(mouse, disp);
lv_indev_drv_init( &indev_drv_mouse );
indev_drv_mouse.type = LV_INDEV_TYPE_POINTER;
indev_drv_mouse.read_cb = sdl_mouse_read; /*This function will be called periodically (by the library) to get the mouse position and state*/
lv_indev_drv_register( &indev_drv_mouse );
// /* Add the keyboard as input device // LV_IMAGE_DECLARE(mouse_cursor_icon); /*Declare the image file.*/
// * did not work */ // lv_obj_t * cursor_obj;
// static lv_indev_drv_t indev_drv_keyboard; // cursor_obj = lv_image_create(lv_screen_active()); /*Create an image object for the cursor */
// lv_indev_drv_init( &indev_drv_keyboard ); // lv_image_set_src(cursor_obj, &mouse_cursor_icon); /*Set the image source*/
// indev_drv_keyboard.type = LV_INDEV_TYPE_KEYPAD; // lv_indev_set_cursor(mouse, cursor_obj); /*Connect the image object to the driver*/
// indev_drv_keyboard.read_cb = sdl_keyboard_read; /*This function will be called periodically (by the library) to get the keyboard events*/
// lv_indev_t *keyboard_device = lv_indev_drv_register( &indev_drv_keyboard );
// lv_group_t *group = lv_group_create();
// lv_indev_set_group(keyboard_device, group);
// lv_group_add_obj(group, lv_scr_act());
// lv_group_add_obj(group, tabview);
// lv_group_add_obj(group, lv_tabview_get_content(tabview));
// lv_group_add_obj(group, tabs);
//
// need to be in a loop
// printf("last key: %d\n",lv_indev_get_key(keyboard_device));
sdl_init(); lv_indev_t * mousewheel = lv_sdl_mousewheel_create();
lv_indev_set_display(mousewheel, disp);
lv_indev_set_group(mousewheel, lv_group_get_default());
// Get the SDL window via an event lv_indev_t * keyboard = lv_sdl_keyboard_create();
SDL_Event aWindowIdFinder; lv_indev_set_display(keyboard, disp);
SDL_PollEvent(&aWindowIdFinder); lv_indev_set_group(keyboard, lv_group_get_default());
SDL_Window *mSimWindow = SDL_GetWindowFromID(aWindowIdFinder.window.windowID);
SDL_SetWindowTitle(mSimWindow, "OMOTE simulator");
/* Tick init. lv_sdl_window_set_title(disp, "OMOTE simulator");
* You have to call 'lv_tick_inc()' in periodically to inform lvgl about how much time were elapsed lv_sdl_window_set_zoom(disp, SDL_ZOOM);
* Create an SDL thread to do this*/
SDL_CreateThread(tick_thread, "tick", NULL);
} }

View File

@ -16,7 +16,7 @@ default_envs = esp32
custom_screen_width = 240 custom_screen_width = 240
custom_screen_heigth = 320 custom_screen_heigth = 320
lib_deps = lib_deps =
lvgl/lvgl@^8.3.11 lvgl/lvgl@^9.1.0
build_flags = build_flags =
;-- OMOTE ----------------------------------------------------------------- ;-- OMOTE -----------------------------------------------------------------
-D ENABLE_WIFI_AND_MQTT=1 -D ENABLE_WIFI_AND_MQTT=1
@ -28,14 +28,12 @@ build_flags =
-D SCR_HEIGHT=${env.custom_screen_heigth} -D SCR_HEIGHT=${env.custom_screen_heigth}
;-- lvgl ------------------------------------------------------------------ ;-- lvgl ------------------------------------------------------------------
; lvgl variant 1: ; lvgl variant 1:
; Don't use lv_conf.h. Tweak params via platfom.ini. See lv_conf_internal.h line 31. Don't change this line. ; Don't use lv_conf.h. Tweak params via platfom.ini. See lv_conf_internal.h line 49. Don't change this line.
-D LV_CONF_SKIP=1 -D LV_CONF_SKIP=1
; Set this in specific environments below. Will be different in Arduino and Windows/Linux
;-D LV_TICK_CUSTOM=1
; dynamic memory. Takes as much as it gets from heap (DRAM). Needs approx. 25%-30% more memory than static memory. ; dynamic memory. Takes as much as it gets from heap (DRAM). Needs approx. 25%-30% more memory than static memory.
;-D LV_MEM_CUSTOM=1 ;-D LV_USE_STDLIB_MALLOC=1
; Set this in specific environments below. 32 bit and 64 bit need differenz sizes. ; Set this in specific environments below. 32 bit and 64 bit need differenz sizes.
;-D LV_MEM_CUSTOM=0 ;-D LV_USE_STDLIB_MALLOC=0
;-D LV_MEM_SIZE="(32U * 1024U)" ;-D LV_MEM_SIZE="(32U * 1024U)"
; fonts and theme ; fonts and theme
-D LV_FONT_MONTSERRAT_10=1 -D LV_FONT_MONTSERRAT_10=1
@ -48,14 +46,13 @@ build_flags =
; Enable the log module ; Enable the log module
-D LV_USE_LOG=1 -D LV_USE_LOG=1
-D LV_LOG_PRINTF=1 -D LV_LOG_PRINTF=1
; trace really gives a lot of messages ...
;-D LV_LOG_LEVEL=LV_LOG_LEVEL_TRACE ;-D LV_LOG_LEVEL=LV_LOG_LEVEL_TRACE
;-D LV_LOG_LEVEL=LV_LOG_LEVEL_INFO ;-D LV_LOG_LEVEL=LV_LOG_LEVEL_INFO
;-D LV_LOG_LEVEL=LV_LOG_LEVEL_WARN ;-D LV_LOG_LEVEL=LV_LOG_LEVEL_WARN
-D LV_LOG_LEVEL=LV_LOG_LEVEL_ERROR -D LV_LOG_LEVEL=LV_LOG_LEVEL_ERROR
;-D LV_LOG_LEVEL=LV_LOG_LEVEL_USER ;-D LV_LOG_LEVEL=LV_LOG_LEVEL_USER
;-D LV_LOG_LEVEL=LV_LOG_LEVEL_NONE ;-D LV_LOG_LEVEL=LV_LOG_LEVEL_NONE
; trace really gives a lot of messages ...
;-D LV_LOG_LEVEL=LV_LOG_LEVEL_TRACE
; --- ; ---
; Enable asserts if an operation is failed or an invalid data is found. ; Enable asserts if an operation is failed or an invalid data is found.
; If LV_USE_LOG is enabled an error message will be printed on failure*/ ; If LV_USE_LOG is enabled an error message will be printed on failure*/
@ -68,8 +65,10 @@ build_flags =
; --------- ; ---------
; lvgl variant 2: ; lvgl variant 2:
; or define where lv_conf.h is, relative to the `lvgl` folder ; or define where lv_conf.h is, relative to the `lvgl` folder
;-D LV_CONF_PATH=../../../../src/gui_general_and_keys/lv_conf.h ;-D LV_CONF_PATH=../../../../src/gui/lv_conf.h
; --- interesting lvgl debug infos (OSD) ; --- interesting lvgl debug infos (OSD)
; LV_USE_SYSMON needs to be set for LV_USE_PERF_MONITOR and LV_USE_MEM_MONITOR to work
;-D LV_USE_SYSMON=1
;-D LV_USE_PERF_MONITOR=1 ;-D LV_USE_PERF_MONITOR=1
;-D LV_USE_MEM_MONITOR=1 ;-D LV_USE_MEM_MONITOR=1
;-D LV_USE_REFR_DEBUG=1 ;-D LV_USE_REFR_DEBUG=1
@ -109,11 +108,9 @@ build_flags =
;-D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG ;-D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG
;-D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE ;-D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE
;-- lvgl arduino ---------------------------------------------------------- ;-- lvgl arduino ----------------------------------------------------------
; use millis() from "Arduino.h" to tell the elapsed time in milliseconds
-D LV_TICK_CUSTOM=1
; static memory, will be allocated in static DRAM ; static memory, will be allocated in static DRAM
-D LV_MEM_CUSTOM=0 -D LV_USE_STDLIB_MALLOC=0
-D LV_MEM_SIZE="(32U * 1024U)" -D LV_MEM_SIZE="(44U * 1024U)"
;-- TFT_eSPI -------------------------------------------------------------- ;-- TFT_eSPI --------------------------------------------------------------
-D DISABLE_ALL_LIBRARY_WARNINGS=1 -D DISABLE_ALL_LIBRARY_WARNINGS=1
; The following lines replace the TFT_eSPI User_setup.h-file ; The following lines replace the TFT_eSPI User_setup.h-file
@ -151,30 +148,23 @@ build_src_filter =
; use this if you are using Ubuntu or WSL2 (64 bit compiler) ; use this if you are using Ubuntu or WSL2 (64 bit compiler)
[env:linux_64bit] [env:linux_64bit]
platform = native@^1.2.1 platform = native@^1.2.1
lib_deps =
${env.lib_deps}
;we need the master branch from github because of this commit https://github.com/lvgl/lv_drivers/commit/7b9dee11c93ad27e2591182457c1eba7677473be
lv_drivers=https://github.com/lvgl/lv_drivers
;lvgl/lv_drivers@^8.3.0
build_flags = build_flags =
${env.build_flags} ${env.build_flags}
;-- lvgl ------------------------------------------------------------------ ;-- lvgl ------------------------------------------------------------------
; in lvgl 9, lv_drivers is not needed anymore
-D LV_USE_SDL=1
; 64 bit needs a lot more static memory ; 64 bit needs a lot more static memory
-D LV_MEM_CUSTOM=0 -D LV_USE_STDLIB_MALLOC=0
-D LV_MEM_SIZE="(64U * 1024U)" -D LV_MEM_SIZE="(88U * 1024U)"
;SDL2 from msys64 ;-- OMOTE -----------------------------------------------------------------
-l SDL2
; settings for lv_drivers
-D LV_LVGL_H_INCLUDE_SIMPLE
-D LV_DRV_NO_CONF
-D USE_SDL
-D SDL_INCLUDE_PATH="\"SDL2/SDL.h\""
-D SDL_HOR_RES=${env.custom_screen_width} -D SDL_HOR_RES=${env.custom_screen_width}
-D SDL_VER_RES=${env.custom_screen_heigth} -D SDL_VER_RES=${env.custom_screen_heigth}
-D SDL_ZOOM=2 -D SDL_ZOOM=2
;-- hardware abstraction, needed to find hardwareLayer.h ------------------ ;-- hardware abstraction, needed to find hardwareLayer.h ------------------
-I hardware -I hardware
-I hardware/windows_linux/lib/MQTT-C/include -I hardware/windows_linux/lib/MQTT-C/include
;SDL2 from msys64
-l SDL2
build_src_filter = build_src_filter =
+<*> +<*>
+<../hardware/windows_linux/*> +<../hardware/windows_linux/*>
@ -193,14 +183,14 @@ extends = env:windows_64bit
build_unflags = build_unflags =
${env:windows_64bit.build_unflags} ${env:windows_64bit.build_unflags}
;-- lvgl ------------------------------------------------------------------ ;-- lvgl ------------------------------------------------------------------
-D LV_MEM_CUSTOM=0 -D LV_USE_STDLIB_MALLOC=0
-D LV_MEM_SIZE="(64U * 1024U)" -D LV_MEM_SIZE="(88U * 1024U)"
build_flags = build_flags =
${env:windows_64bit.build_flags} ${env:windows_64bit.build_flags}
;-- lvgl ------------------------------------------------------------------ ;-- lvgl ------------------------------------------------------------------
; 32 bit needs exact the same lvgl memory as on ESP32 ; 32 bit needs exact the same lvgl memory as on ESP32
-D LV_MEM_CUSTOM=0 -D LV_MEM_CUSTOM=0
-D LV_MEM_SIZE="(32U * 1024U)" -D LV_MEM_SIZE="(44U * 1024U)"
; Take care. If you have a 64 bit compiler, this setting will tell the compiler to cross compile to 32 bit. ; Take care. If you have a 64 bit compiler, this setting will tell the compiler to cross compile to 32 bit.
; Compiling is successfull, but linker fails. So use this env only with a 32 bit compiler. ; Compiling is successfull, but linker fails. So use this env only with a 32 bit compiler.
; Probably a custom linker script would be needed for cross compiling to work. ; Probably a custom linker script would be needed for cross compiling to work.

View File

@ -7,7 +7,9 @@
#include "scenes/scene__default.h" #include "scenes/scene__default.h"
lv_color_t color_primary = lv_color_hex(0x303030); // gray lv_color_t color_primary = lv_color_hex(0x303030); // gray
lv_obj_t* MemoryUsageLabel = NULL; lv_span_t* MemoryUsageSpanHeap = NULL;
lv_span_t* MemoryUsageSpanSeparator = NULL;
lv_span_t* MemoryUsageSpanLVGLmemory = NULL;
lv_obj_t* WifiLabel = NULL; lv_obj_t* WifiLabel = NULL;
lv_obj_t* BluetoothLabel = NULL; lv_obj_t* BluetoothLabel = NULL;
lv_obj_t* BattPercentageLabel = NULL; lv_obj_t* BattPercentageLabel = NULL;
@ -41,8 +43,8 @@ void sceneLabel_or_pageIndicator_event_cb(lv_event_t* e) {
// callback for swipe down event to navigate to the scene selection page // callback for swipe down event to navigate to the scene selection page
void screen_gesture_event_cb(lv_event_t* e) { void screen_gesture_event_cb(lv_event_t* e) {
lv_obj_t* screen = lv_event_get_current_target(e); lv_obj_t* screen = (lv_obj_t*)lv_event_get_current_target(e);
lv_dir_t dir = lv_indev_get_gesture_dir(lv_indev_get_act()); lv_dir_t dir = lv_indev_get_gesture_dir(lv_indev_active());
if (dir == LV_DIR_BOTTOM) { if (dir == LV_DIR_BOTTOM) {
Serial.println("- Scene selection: swipe down received for navigating to scene selection page"); Serial.println("- Scene selection: swipe down received for navigating to scene selection page");
executeCommand(SCENE_SELECTION); executeCommand(SCENE_SELECTION);
@ -58,7 +60,7 @@ void tabview_content_is_scrolling_event_cb(lv_event_t* e){
// screenwidth indicator ?? 2 small hidden buttons ?? // screenwidth indicator ?? 2 small hidden buttons ??
int offset = SCR_WIDTH / 2 - 150 / 2 - 8 - 2*50 / 2 -4; int offset = SCR_WIDTH / 2 - 150 / 2 - 8 - 2*50 / 2 -4;
// get the object to which the event is sent // get the object to which the event is sent
lv_obj_t* tabviewContent = lv_event_get_target(e); lv_obj_t* tabviewContent = (lv_obj_t*)lv_event_get_target(e);
// Get the x coordinate of object and scroll panel accordingly // Get the x coordinate of object and scroll panel accordingly
int16_t tabviewX = lv_obj_get_scroll_x(tabviewContent); int16_t tabviewX = lv_obj_get_scroll_x(tabviewContent);
@ -94,19 +96,17 @@ void tabview_tab_changed_event_cb(lv_event_t* e) {
if (lv_event_get_code(e) == LV_EVENT_VALUE_CHANGED) { if (lv_event_get_code(e) == LV_EVENT_VALUE_CHANGED) {
oldTabID = currentTabID; oldTabID = currentTabID;
currentTabID = lv_tabview_get_tab_act(lv_event_get_target(e)); currentTabID = lv_tabview_get_tab_active((lv_obj_t*)lv_event_get_target(e));
// Wait until the animation ended, then call "guis_doAfterSliding(oldTabID, currentTabID, false);" // Wait until the animation ended, then call "guis_doAfterSliding(oldTabID, currentTabID, false);"
// https://forum.lvgl.io/t/delete-a-tab-after-the-tabview-scroll-animation-is-complete/3155/4 // https://forum.lvgl.io/t/delete-a-tab-after-the-tabview-scroll-animation-is-complete/3155/4
lv_obj_t* myTabview = lv_event_get_target(e); lv_obj_t* myTabview = (lv_obj_t*)lv_event_get_target(e);
lv_obj_t* tabContainer = lv_tabview_get_content(myTabview); lv_obj_t* tabContainer = lv_tabview_get_content(myTabview);
// https://docs.lvgl.io/8.3/overview/animation.html?highlight=lv_anim_get#_CPPv411lv_anim_getPv18lv_anim_exec_xcb_t lv_anim_t* anim = lv_anim_get(tabContainer, NULL);
// (lv_anim_exec_xcb_t) lv_obj_set_x does not find an animation. NULL is good as well.
lv_anim_t* anim = lv_anim_get(tabContainer, NULL); // (lv_anim_exec_xcb_t) lv_obj_set_x);
if(anim) { if(anim) {
// Swipe is not yet complete. User released the touch screen, an animation will bring it to the end. // Swipe is not yet complete. User released the touch screen, an animation will bring it to the end.
// That's the normal (and only?) case for the tft touchscreen // That's the normal (and only?) case for the tft touchscreen
lv_anim_set_ready_cb(anim, tabview_animation_ready_cb); lv_anim_set_completed_cb(anim, tabview_animation_ready_cb);
} else { } else {
// Swipe is complete, no additional animation is needed. Most likely only possible in simulator // Swipe is complete, no additional animation is needed. Most likely only possible in simulator
Serial.println("Change of tab detected, without animation at the end. Will directly do my job after sliding."); Serial.println("Change of tab detected, without animation at the end. Will directly do my job after sliding.");
@ -141,7 +141,7 @@ void init_gui(void) {
#endif #endif
} }
// Set the background color ------------------------------------------------------------------------------- // Set the background color -------------------------------------------------------------------------------
lv_obj_set_style_bg_color(lv_scr_act(), lv_color_black(), LV_PART_MAIN); lv_obj_set_style_bg_color(lv_screen_active(), lv_color_black(), LV_PART_MAIN);
// set default height and position of main widgets // set default height and position of main widgets
setMainWidgetsHeightAndPosition(); setMainWidgetsHeightAndPosition();
// At startup, set current GUI according to get_currentGUIname(), and create the content of that tab (and the previous and the next) for the first time // At startup, set current GUI according to get_currentGUIname(), and create the content of that tab (and the previous and the next) for the first time
@ -152,7 +152,7 @@ void init_gui(void) {
init_gui_status_bar(); init_gui_status_bar();
// register callback for swipe down event to navigate to the scene selection page // register callback for swipe down event to navigate to the scene selection page
lv_obj_add_event_cb(lv_scr_act(), screen_gesture_event_cb, LV_EVENT_GESTURE, NULL); lv_obj_add_event_cb(lv_screen_active(), screen_gesture_event_cb, LV_EVENT_GESTURE, NULL);
} }
@ -192,7 +192,7 @@ void showMemoryUsageBar(bool showBar) {
return; return;
if (showBar) { if (showBar) {
// lv_obj_clear_flag(memoryUsageBar, LV_OBJ_FLAG_HIDDEN); // lv_obj_remove_flag(memoryUsageBar, LV_OBJ_FLAG_HIDDEN);
lv_obj_set_size(memoryUsageBar, SCR_WIDTH, memoryUsageBarHeight); lv_obj_set_size(memoryUsageBar, SCR_WIDTH, memoryUsageBarHeight);
lv_obj_align(memoryUsageBar, LV_ALIGN_TOP_MID, 0, memoryUsageBarTop); lv_obj_align(memoryUsageBar, LV_ALIGN_TOP_MID, 0, memoryUsageBarTop);
lv_obj_set_size(statusbar, SCR_WIDTH, statusbarHeight); lv_obj_set_size(statusbar, SCR_WIDTH, statusbarHeight);
@ -207,7 +207,7 @@ void showMemoryUsageBar(bool showBar) {
void init_gui_memoryUsage_bar() { void init_gui_memoryUsage_bar() {
// Create a memory status text bar at the top ------------------------------------------------------------- // Create a memory status text bar at the top -------------------------------------------------------------
memoryUsageBar = lv_btn_create(lv_scr_act()); memoryUsageBar = lv_button_create(lv_screen_active());
lv_obj_set_size(memoryUsageBar, SCR_WIDTH, memoryUsageBarHeight); lv_obj_set_size(memoryUsageBar, SCR_WIDTH, memoryUsageBarHeight);
lv_obj_set_style_shadow_width(memoryUsageBar, 0, LV_PART_MAIN); lv_obj_set_style_shadow_width(memoryUsageBar, 0, LV_PART_MAIN);
lv_obj_set_style_bg_color(memoryUsageBar, lv_color_black(), LV_PART_MAIN); lv_obj_set_style_bg_color(memoryUsageBar, lv_color_black(), LV_PART_MAIN);
@ -218,17 +218,21 @@ void init_gui_memoryUsage_bar() {
lv_obj_set_style_pad_all(memoryUsageBar, 0, LV_PART_MAIN); lv_obj_set_style_pad_all(memoryUsageBar, 0, LV_PART_MAIN);
lv_obj_align(memoryUsageBar, LV_ALIGN_TOP_MID, 0, memoryUsageBarTop); lv_obj_align(memoryUsageBar, LV_ALIGN_TOP_MID, 0, memoryUsageBarTop);
MemoryUsageLabel = lv_label_create(memoryUsageBar); lv_obj_t * memoryUsageSpangroup = lv_spangroup_create(memoryUsageBar);
lv_label_set_text(MemoryUsageLabel, ""); lv_obj_align(memoryUsageSpangroup, LV_ALIGN_TOP_LEFT, 0, labelsPositionTop);
lv_obj_align(MemoryUsageLabel, LV_ALIGN_TOP_LEFT, 0, labelsPositionTop); lv_obj_set_style_text_font(memoryUsageSpangroup, &lv_font_montserrat_12, LV_PART_MAIN);
lv_obj_set_style_text_font(MemoryUsageLabel, &lv_font_montserrat_12, LV_PART_MAIN); // label for heap usage
lv_label_set_recolor(MemoryUsageLabel, true); MemoryUsageSpanHeap = lv_spangroup_new_span(memoryUsageSpangroup);
// separator
MemoryUsageSpanSeparator = lv_spangroup_new_span(memoryUsageSpangroup);
// label for lvgl memory usage
MemoryUsageSpanLVGLmemory = lv_spangroup_new_span(memoryUsageSpangroup);
} }
void init_gui_status_bar() { void init_gui_status_bar() {
// Create a status bar at the top ------------------------------------------------------------------------- // Create a status bar at the top -------------------------------------------------------------------------
statusbar = lv_btn_create(lv_scr_act()); statusbar = lv_button_create(lv_screen_active());
lv_obj_clear_flag(statusbar, LV_OBJ_FLAG_CLICKABLE); lv_obj_remove_flag(statusbar, LV_OBJ_FLAG_CLICKABLE);
lv_obj_set_size(statusbar, SCR_WIDTH, statusbarHeight); lv_obj_set_size(statusbar, SCR_WIDTH, statusbarHeight);
lv_obj_set_style_shadow_width(statusbar, 0, LV_PART_MAIN); lv_obj_set_style_shadow_width(statusbar, 0, LV_PART_MAIN);
lv_obj_set_style_bg_color(statusbar, lv_color_black(), LV_PART_MAIN); lv_obj_set_style_bg_color(statusbar, lv_color_black(), LV_PART_MAIN);
@ -308,13 +312,13 @@ void guis_doAfterSliding(int oldTabID, int newTabID, bool newGuiList) {
void setActiveTab(uint32_t index, lv_anim_enable_t anim_en) { void setActiveTab(uint32_t index, lv_anim_enable_t anim_en) {
// unsigned long startTime = millis(); // unsigned long startTime = millis();
if (anim_en == LV_ANIM_ON) { if (anim_en == LV_ANIM_ON) {
lv_tabview_set_act(tabview, index, LV_ANIM_ON); lv_tabview_set_active(tabview, index, LV_ANIM_ON);
// startTime = millis(); // startTime = millis();
// while (millis() - startTime < 1000) { // while (millis() - startTime < 1000) {
// lv_timer_handler(); // lv_timer_handler();
// } // }
} else { } else {
lv_tabview_set_act(tabview, index, LV_ANIM_OFF); lv_tabview_set_active(tabview, index, LV_ANIM_OFF);
// lv_timer_handler(); // lv_timer_handler();
// log_memory(); // log_memory();
} }

View File

@ -3,7 +3,9 @@
#include <lvgl.h> #include <lvgl.h>
// used by memoryUsage.cpp // used by memoryUsage.cpp
extern lv_obj_t* MemoryUsageLabel; extern lv_span_t* MemoryUsageSpanHeap;
extern lv_span_t* MemoryUsageSpanSeparator;
extern lv_span_t* MemoryUsageSpanLVGLmemory;
// used by guiStatusUpdate.cpp // used by guiStatusUpdate.cpp
extern lv_obj_t* BluetoothLabel; extern lv_obj_t* BluetoothLabel;
extern lv_obj_t* BattPercentageLabel; extern lv_obj_t* BattPercentageLabel;

View File

@ -12,10 +12,8 @@ const LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_LARGE_CONST LV_ATTRIBUTE_IMG_GRADIENTL
0xfa, 0xf2, 0xea, 0xe2, 0xda, 0xd1, 0xc7, 0xbe, 0xb7, 0xae, 0xa6, 0x9e, 0x95, 0x8d, 0x84, 0x7d, 0x74, 0x6c, 0x62, 0x5a, 0x51, 0x48, 0x41, 0x38, 0x2f, 0x28, 0x1f, 0x17, 0x0f, 0x07, 0xfa, 0xf2, 0xea, 0xe2, 0xda, 0xd1, 0xc7, 0xbe, 0xb7, 0xae, 0xa6, 0x9e, 0x95, 0x8d, 0x84, 0x7d, 0x74, 0x6c, 0x62, 0x5a, 0x51, 0x48, 0x41, 0x38, 0x2f, 0x28, 0x1f, 0x17, 0x0f, 0x07,
}; };
const lv_img_dsc_t gradientLeft = { const lv_image_dsc_t gradientLeft = {
.header.cf = LV_IMG_CF_ALPHA_8BIT, .header.cf = LV_COLOR_FORMAT_A8,
.header.always_zero = 0,
.header.reserved = 0,
.header.w = 30, .header.w = 30,
.header.h = 1, .header.h = 1,
.data_size = 30, .data_size = 30,
@ -31,10 +29,8 @@ const LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_LARGE_CONST LV_ATTRIBUTE_IMG_GRADIENTR
0x07, 0x0f, 0x17, 0x1f, 0x28, 0x2f, 0x38, 0x41, 0x48, 0x51, 0x5a, 0x62, 0x6c, 0x74, 0x7d, 0x84, 0x8d, 0x95, 0x9e, 0xa6, 0xae, 0xb7, 0xbe, 0xc7, 0xd1, 0xda, 0xe2, 0xea, 0xf2, 0xfa, 0x07, 0x0f, 0x17, 0x1f, 0x28, 0x2f, 0x38, 0x41, 0x48, 0x51, 0x5a, 0x62, 0x6c, 0x74, 0x7d, 0x84, 0x8d, 0x95, 0x9e, 0xa6, 0xae, 0xb7, 0xbe, 0xc7, 0xd1, 0xda, 0xe2, 0xea, 0xf2, 0xfa,
}; };
const lv_img_dsc_t gradientRight = { const lv_image_dsc_t gradientRight = {
.header.cf = LV_IMG_CF_ALPHA_8BIT, .header.cf = LV_COLOR_FORMAT_A8,
.header.always_zero = 0,
.header.reserved = 0,
.header.w = 30, .header.w = 30,
.header.h = 1, .header.h = 1,
.data_size = 30, .data_size = 30,

View File

@ -42,7 +42,7 @@ void clear_tabview(lv_obj_t* tabview) {
lv_obj_remove_event_cb(tabview, tabview_tab_changed_event_cb); lv_obj_remove_event_cb(tabview, tabview_tab_changed_event_cb);
lv_obj_remove_event_cb(tabview, tabview_content_is_scrolling_event_cb); lv_obj_remove_event_cb(tabview, tabview_content_is_scrolling_event_cb);
// delete tabview // delete tabview
lv_obj_del(tabview); lv_obj_delete(tabview);
tabview = NULL; tabview = NULL;
} }
@ -55,15 +55,15 @@ void clear_tabview(lv_obj_t* tabview) {
void clear_panel(lv_obj_t* panel, lv_obj_t* img1, lv_obj_t* img2) { void clear_panel(lv_obj_t* panel, lv_obj_t* img1, lv_obj_t* img2) {
if (panel != NULL) { if (panel != NULL) {
lv_obj_del(panel); lv_obj_delete(panel);
panel = NULL; panel = NULL;
} }
if (img1 != NULL) { if (img1 != NULL) {
lv_obj_del(img1); lv_obj_delete(img1);
img1 = NULL; img1 = NULL;
} }
if (img2 != NULL) { if (img2 != NULL) {
lv_obj_del(img2); lv_obj_delete(img2);
img2 = NULL; img2 = NULL;
} }
@ -71,7 +71,9 @@ void clear_panel(lv_obj_t* panel, lv_obj_t* img1, lv_obj_t* img2) {
lv_obj_t* create_tabview() { lv_obj_t* create_tabview() {
// Setup a scrollable tabview for devices and settings ---------------------------------------------------- // Setup a scrollable tabview for devices and settings ----------------------------------------------------
lv_obj_t* tabview = lv_tabview_create(lv_scr_act(), LV_DIR_TOP, 0); // Hide tab labels by setting their height to 0 lv_obj_t* tabview = lv_tabview_create(lv_screen_active()); // Hide tab labels by setting their height to 0
lv_tabview_set_tab_bar_position(tabview, LV_DIR_TOP);
lv_tabview_set_tab_bar_size(tabview, 0);
#ifdef drawRedBorderAroundMainWidgets #ifdef drawRedBorderAroundMainWidgets
lv_obj_add_style(tabview, &style_red_border, LV_PART_MAIN); lv_obj_add_style(tabview, &style_red_border, LV_PART_MAIN);
#endif #endif
@ -83,9 +85,9 @@ lv_obj_t* create_tabview() {
lv_obj_t* create_panel() { lv_obj_t* create_panel() {
// Create a page indicator at the bottom ------------------------------------------------------------------ // Create a page indicator at the bottom ------------------------------------------------------------------
lv_obj_t* panel = lv_obj_create(lv_scr_act()); lv_obj_t* panel = lv_obj_create(lv_screen_active());
lv_obj_clear_flag(panel, LV_OBJ_FLAG_CLICKABLE); // This indicator will not be clickable lv_obj_remove_flag(panel, LV_OBJ_FLAG_CLICKABLE); // This indicator will not be clickable
lv_obj_clear_flag(panel, LV_OBJ_FLAG_SCROLLABLE); // This indicator will not be scrollable lv_obj_remove_flag(panel, LV_OBJ_FLAG_SCROLLABLE); // This indicator will not be scrollable
lv_obj_set_size(panel, SCR_WIDTH, panelHeight); lv_obj_set_size(panel, SCR_WIDTH, panelHeight);
lv_obj_set_flex_flow(panel, LV_FLEX_FLOW_ROW); lv_obj_set_flex_flow(panel, LV_FLEX_FLOW_ROW);
lv_obj_align(panel, LV_ALIGN_BOTTOM_MID, 0, 0); lv_obj_align(panel, LV_ALIGN_BOTTOM_MID, 0, 0);
@ -232,8 +234,8 @@ void doTabCreation_strategyMax3(lv_obj_t* tabview, uint32_t oldTabID, uint32_t n
} }
} }
LV_IMG_DECLARE(gradientLeft); LV_IMAGE_DECLARE(gradientLeft);
LV_IMG_DECLARE(gradientRight); LV_IMAGE_DECLARE(gradientRight);
void getBreadcrumpPosition(uint8_t* breadcrumpPosition, std::string nameOfTab) { void getBreadcrumpPosition(uint8_t* breadcrumpPosition, std::string nameOfTab) {
*breadcrumpPosition = 0; *breadcrumpPosition = 0;
@ -263,7 +265,7 @@ void fillPanelWithPageIndicator_strategyMax3(lv_obj_t* panel, lv_obj_t* img1, lv
} }
// This small hidden button enables the page indicator to scroll further // This small hidden button enables the page indicator to scroll further
lv_obj_t* btn = lv_btn_create(panel); lv_obj_t* btn = lv_button_create(panel);
lv_obj_set_size(btn, 50, lv_pct(100)); lv_obj_set_size(btn, 50, lv_pct(100));
lv_obj_set_style_shadow_width(btn, 0, LV_PART_MAIN); lv_obj_set_style_shadow_width(btn, 0, LV_PART_MAIN);
lv_obj_set_style_opa(btn, LV_OPA_TRANSP, LV_PART_MAIN); lv_obj_set_style_opa(btn, LV_OPA_TRANSP, LV_PART_MAIN);
@ -281,8 +283,8 @@ void fillPanelWithPageIndicator_strategyMax3(lv_obj_t* panel, lv_obj_t* img1, lv
3 4 -1 p p p b 1 <- last state, special case 3 4 -1 p p p b 1 <- last state, special case
*/ */
// first page indicator before the first tab // first page indicator before the first tab
btn = lv_btn_create(panel); btn = lv_button_create(panel);
lv_obj_clear_flag(btn, LV_OBJ_FLAG_CLICKABLE); lv_obj_remove_flag(btn, LV_OBJ_FLAG_CLICKABLE);
lv_obj_set_size(btn, 150, lv_pct(100)); lv_obj_set_size(btn, 150, lv_pct(100));
if (tabs_in_memory[0].listIndex == 0) { if (tabs_in_memory[0].listIndex == 0) {
lv_obj_set_style_bg_color(btn, lv_color_black(), LV_PART_MAIN); lv_obj_set_style_bg_color(btn, lv_color_black(), LV_PART_MAIN);
@ -304,7 +306,7 @@ void fillPanelWithPageIndicator_strategyMax3(lv_obj_t* panel, lv_obj_t* img1, lv
getBreadcrumpPosition(&breadcrumpPosition, nameOfTab); getBreadcrumpPosition(&breadcrumpPosition, nameOfTab);
// Create actual buttons for every tab // Create actual buttons for every tab
lv_obj_t* btn = lv_btn_create(panel); lv_obj_t* btn = lv_button_create(panel);
// only if this is the button for the currently active tab, make it clickable to get to scene selection gui // only if this is the button for the currently active tab, make it clickable to get to scene selection gui
if (nameOfTab == get_currentGUIname()) { if (nameOfTab == get_currentGUIname()) {
lv_obj_add_flag(btn, LV_OBJ_FLAG_CLICKABLE); lv_obj_add_flag(btn, LV_OBJ_FLAG_CLICKABLE);
@ -342,8 +344,8 @@ void fillPanelWithPageIndicator_strategyMax3(lv_obj_t* panel, lv_obj_t* img1, lv
} }
// last page indicator after the last tab // last page indicator after the last tab
btn = lv_btn_create(panel); btn = lv_button_create(panel);
lv_obj_clear_flag(btn, LV_OBJ_FLAG_CLICKABLE); lv_obj_remove_flag(btn, LV_OBJ_FLAG_CLICKABLE);
lv_obj_set_size(btn, 150, lv_pct(100)); lv_obj_set_size(btn, 150, lv_pct(100));
// 4 at last position 4 at middle position only one tab available overall // 4 at last position 4 at middle position only one tab available overall
if ((tabs_in_memory[2].listIndex == get_gui_list(get_currentScene())->size()-1) || (tabs_in_memory[1].listIndex == get_gui_list(get_currentScene())->size()-1) || (tabs_in_memory[1].listIndex == -1)) { if ((tabs_in_memory[2].listIndex == get_gui_list(get_currentScene())->size()-1) || (tabs_in_memory[1].listIndex == get_gui_list(get_currentScene())->size()-1) || (tabs_in_memory[1].listIndex == -1)) {
@ -353,14 +355,14 @@ void fillPanelWithPageIndicator_strategyMax3(lv_obj_t* panel, lv_obj_t* img1, lv
} }
// This small hidden button enables the page indicator to scroll further // This small hidden button enables the page indicator to scroll further
btn = lv_btn_create(panel); btn = lv_button_create(panel);
lv_obj_set_size(btn, 50, lv_pct(100)); lv_obj_set_size(btn, 50, lv_pct(100));
lv_obj_set_style_shadow_width(btn, 0, LV_PART_MAIN); lv_obj_set_style_shadow_width(btn, 0, LV_PART_MAIN);
lv_obj_set_style_opa(btn, LV_OPA_TRANSP, LV_PART_MAIN); lv_obj_set_style_opa(btn, LV_OPA_TRANSP, LV_PART_MAIN);
// creation of style was moved to init_gui(void) // creation of style was moved to init_gui(void)
// otherwise repeated calls of lv_style_init will lead to a memory leak of about 46 bytes each time // otherwise repeated calls of lv_style_init will lead to a memory leak of about 46 bytes each time
// https://docs.lvgl.io/8.3/overview/style.html?highlight=lv_style_t#initialize-styles-and-set-get-properties // https://docs.lvgl.io/master/overview/style.html?highlight=lv_style_t#initialize-styles-and-set-get-properties
lv_obj_add_style(panel, &panel_style, 0); lv_obj_add_style(panel, &panel_style, 0);
#ifdef drawRedBorderAroundMainWidgets #ifdef drawRedBorderAroundMainWidgets
lv_obj_add_style(panel, &style_red_border, LV_PART_MAIN); lv_obj_add_style(panel, &style_red_border, LV_PART_MAIN);
@ -369,18 +371,20 @@ void fillPanelWithPageIndicator_strategyMax3(lv_obj_t* panel, lv_obj_t* img1, lv
// Make the indicator fade out at the sides using gradient bitmaps // Make the indicator fade out at the sides using gradient bitmaps
// Bitmaps are above the buttons and labels // Bitmaps are above the buttons and labels
// don't create it here // don't create it here
// img1 = lv_img_create(lv_scr_act()); // img1 = lv_image_create(lv_screen_active());
lv_img_set_src(img1, &gradientLeft);
lv_obj_align(img1, LV_ALIGN_BOTTOM_LEFT, 0, 0);
lv_obj_set_size(img1, panelHeight, panelHeight); // stretch the 1-pixel high image to 30px lv_obj_set_size(img1, panelHeight, panelHeight); // stretch the 1-pixel high image to 30px
lv_obj_align(img1, LV_ALIGN_BOTTOM_LEFT, 0, 0);
lv_image_set_src(img1, &gradientLeft);
lv_image_set_inner_align(img1, LV_IMAGE_ALIGN_STRETCH);
#ifdef drawRedBorderAroundMainWidgets #ifdef drawRedBorderAroundMainWidgets
lv_obj_add_style(img1, &style_red_border, LV_PART_MAIN); lv_obj_add_style(img1, &style_red_border, LV_PART_MAIN);
#endif #endif
// don't create it here // don't create it here
// img2 = lv_img_create(lv_scr_act()); // img2 = lv_image_create(lv_screen_active());
lv_img_set_src(img2, &gradientRight);
lv_obj_align(img2, LV_ALIGN_BOTTOM_RIGHT, 0, 0);
lv_obj_set_size(img2, panelHeight, panelHeight); lv_obj_set_size(img2, panelHeight, panelHeight);
lv_obj_align(img2, LV_ALIGN_BOTTOM_RIGHT, 0, 0);
lv_image_set_src(img2, &gradientRight);
lv_image_set_inner_align(img2, LV_IMAGE_ALIGN_STRETCH);
#ifdef drawRedBorderAroundMainWidgets #ifdef drawRedBorderAroundMainWidgets
lv_obj_add_style(img2, &style_red_border, LV_PART_MAIN); lv_obj_add_style(img2, &style_red_border, LV_PART_MAIN);
#endif #endif
@ -455,12 +459,12 @@ void gui_memoryOptimizer_doAfterSliding_deletionAndCreation(lv_obj_t** tabview,
// only optional: delete and create the whole screen. Not necessary. // only optional: delete and create the whole screen. Not necessary.
// Only used for a test. init_gui_status_bar() would need to be called again at a suitable place, because the status bar would also be deleted. // Only used for a test. init_gui_status_bar() would need to be called again at a suitable place, because the status bar would also be deleted.
// lv_obj_t* oldscr = lv_scr_act(); // lv_obj_t* oldscr = lv_screen_active();
// // create new screen // // create new screen
// lv_obj_t* newscr = lv_obj_create(NULL); // lv_obj_t* newscr = lv_obj_create(NULL);
// // load this new screen // // load this new screen
// lv_scr_load(newscr); // lv_screen_load(newscr);
// lv_obj_del(oldscr); // lv_obj_delete(oldscr);
if (newGuiList) { if (newGuiList) {
// If we are switching to a new gui list, then we need to set tabs_in_memory_previous_listIndex[0] = -1; // If we are switching to a new gui list, then we need to set tabs_in_memory_previous_listIndex[0] = -1;
@ -478,15 +482,15 @@ void gui_memoryOptimizer_doAfterSliding_deletionAndCreation(lv_obj_t** tabview,
// Create the panel for the page indicator. Panel itself takes about 2136 bytes for three tabs. // Create the panel for the page indicator. Panel itself takes about 2136 bytes for three tabs.
lv_obj_t* newPanel = create_panel(); lv_obj_t* newPanel = create_panel();
*panel = newPanel; *panel = newPanel;
*img1 = lv_img_create(lv_scr_act()); *img1 = lv_image_create(lv_screen_active());
*img2 = lv_img_create(lv_scr_act()); *img2 = lv_image_create(lv_screen_active());
fillPanelWithPageIndicator_strategyMax3(*panel, *img1, *img2); fillPanelWithPageIndicator_strategyMax3(*panel, *img1, *img2);
// now, as the correct tab is active, register again the events for the tabview // now, as the correct tab is active, register again the events for the tabview
lv_obj_add_event_cb(*tabview, tabview_tab_changed_event_cb, LV_EVENT_VALUE_CHANGED, NULL); lv_obj_add_event_cb(*tabview, tabview_tab_changed_event_cb, LV_EVENT_VALUE_CHANGED, NULL);
lv_obj_add_event_cb(lv_tabview_get_content(*tabview), tabview_content_is_scrolling_event_cb, LV_EVENT_SCROLL, NULL); lv_obj_add_event_cb(lv_tabview_get_content(*tabview), tabview_content_is_scrolling_event_cb, LV_EVENT_SCROLL, NULL);
// Initialize scroll position of the page indicator // Initialize scroll position of the page indicator
lv_event_send(lv_tabview_get_content(*tabview), LV_EVENT_SCROLL, NULL); lv_obj_send_event(lv_tabview_get_content(*tabview), LV_EVENT_SCROLL, NULL);
Serial.printf("------------ End of tab deletion and creation\r\n"); Serial.printf("------------ End of tab deletion and creation\r\n");

View File

@ -4,7 +4,7 @@
bool showMemoryUsage = 0; bool showMemoryUsage = 0;
#if LV_MEM_CUSTOM == 0 #if (LV_USE_STDLIB_MALLOC == 0)
lv_mem_monitor_t mon; lv_mem_monitor_t mon;
#endif #endif
@ -42,7 +42,7 @@ void doLogMemoryUsage() {
bool doESPHeapWarning = (freeSystemHeap < thresholdForESP32HeapFreeWarning); bool doESPHeapWarning = (freeSystemHeap < thresholdForESP32HeapFreeWarning);
bool doLVGLMemoryWarning = false; bool doLVGLMemoryWarning = false;
#if LV_MEM_CUSTOM == 0 #if (LV_USE_STDLIB_MALLOC == 0)
int thresholdForLVGLmemoryFreeWarning = 20; // in percentage free int thresholdForLVGLmemoryFreeWarning = 20; // in percentage free
lv_mem_monitor(&mon); lv_mem_monitor(&mon);
doLVGLMemoryWarning = ((100 - mon.used_pct) < thresholdForLVGLmemoryFreeWarning); doLVGLMemoryWarning = ((100 - mon.used_pct) < thresholdForLVGLmemoryFreeWarning);
@ -64,7 +64,7 @@ void doLogMemoryUsage() {
freeSystemHeap, float(freeSystemHeap) / systemHeapSize * 100, freeSystemHeap, float(freeSystemHeap) / systemHeapSize * 100,
maxAllocSystemHeap, minfreeSystemHeap); maxAllocSystemHeap, minfreeSystemHeap);
#if LV_MEM_CUSTOM == 0 #if (LV_USE_STDLIB_MALLOC == 0)
if (doLVGLMemoryWarning) { if (doLVGLMemoryWarning) {
Serial.println("WARNING: LVGL memory is getting low. You GUI might stop working. In that case, increase \"-D LV_MEM_SIZE\" in platformio.ini"); Serial.println("WARNING: LVGL memory is getting low. You GUI might stop working. In that case, increase \"-D LV_MEM_SIZE\" in platformio.ini");
} }
@ -81,46 +81,69 @@ void doLogMemoryUsage() {
#endif #endif
if (showMemoryUsage) { if (showMemoryUsage) {
char buffer[80]; char bufferHeap[40];
std::string ESP32HeapWarnBegin = "#00ff00 "; // green char bufferLVGLmemory[40];
std::string ESP32HeapWarnEnd = "#"; #ifdef SHOW_USED_MEMORY_INSTEAD_OF_FREE_IN_GUI
std::string LVGLMemorWarnBegin = "#00ff00 "; // green //sprintf(buffer, ESP32HeapWarnBegin.append("%lu/%lu (%.0f%%)").append(ESP32HeapWarnEnd).append(" / ").append(LVGLMemorWarnBegin).append("%lu/%lu (%d%%)").append(LVGLMemorWarnEnd).c_str(), systemHeapSize-freeSystemHeap, systemHeapSize, float(systemHeapSize-freeSystemHeap) / systemHeapSize * 100, mon.total_size - mon.free_size, mon.total_size, mon.used_pct);
std::string LVGLMemorWarnEnd = "#"; sprintf(bufferHeap, std::string("").append("%lu/%lu (%.0f%%)\0").c_str(), systemHeapSize-freeSystemHeap, systemHeapSize, float(systemHeapSize-freeSystemHeap) / systemHeapSize * 100);
if (doESPHeapWarning) { #if (LV_USE_STDLIB_MALLOC == 0)
ESP32HeapWarnBegin = "#ff0000 "; // red sprintf(bufferLVGLmemory, std::string("").append("%lu/%lu (%d%%)\0").c_str(), mon.total_size - mon.free_size, mon.total_size, mon.used_pct);
ESP32HeapWarnEnd = "#";
}
if (doLVGLMemoryWarning) {
LVGLMemorWarnBegin = "#ff0000 "; // red
LVGLMemorWarnEnd = "#";
}
#if LV_MEM_CUSTOM != 0
#ifdef SHOW_USED_MEMORY_INSTEAD_OF_FREE_IN_GUI
sprintf(buffer, ESP32HeapWarnBegin.append("%lu/%lu (%.0f%%)").append(ESP32HeapWarnEnd).c_str() , systemHeapSize-freeSystemHeap, systemHeapSize, float(systemHeapSize-freeSystemHeap) / systemHeapSize * 100);
#else
sprintf(buffer, ESP32HeapWarnBegin.append("%lu/%lu (%.0f%%)").append(ESP32HeapWarnEnd).c_str() , freeSystemHeap, systemHeapSize, float(freeSystemHeap) / systemHeapSize * 100);
#endif #endif
#else #else
#ifdef SHOW_USED_MEMORY_INSTEAD_OF_FREE_IN_GUI //sprintf(buffer, ESP32HeapWarnBegin.append("%lu/%lu (%.0f%%)").append(ESP32HeapWarnEnd).append(" / ").append(LVGLMemorWarnBegin).append("%lu/%lu (%d%%)").append(LVGLMemorWarnEnd).c_str(), freeSystemHeap, systemHeapSize, float(freeSystemHeap) / systemHeapSize * 100, mon.free_size, mon.total_size, 100-mon.used_pct);
sprintf(buffer, ESP32HeapWarnBegin.append("%lu/%lu (%.0f%%)").append(ESP32HeapWarnEnd).append(" / ").append(LVGLMemorWarnBegin).append("%lu/%lu (%d%%)").append(LVGLMemorWarnEnd).c_str(), systemHeapSize-freeSystemHeap, systemHeapSize, float(systemHeapSize-freeSystemHeap) / systemHeapSize * 100, mon.total_size - mon.free_size, mon.total_size, mon.used_pct); sprintf(bufferHeap, std::string("").append("%lu/%lu (%.0f%%)\0").c_str(), freeSystemHeap, systemHeapSize, float(freeSystemHeap) / systemHeapSize * 100);
#else #if (LV_USE_STDLIB_MALLOC == 0)
sprintf(buffer, ESP32HeapWarnBegin.append("%lu/%lu (%.0f%%)").append(ESP32HeapWarnEnd).append(" / ").append(LVGLMemorWarnBegin).append("%lu/%lu (%d%%)").append(LVGLMemorWarnEnd).c_str(), freeSystemHeap, systemHeapSize, float(freeSystemHeap) / systemHeapSize * 100, mon.free_size, mon.total_size, 100-mon.used_pct); sprintf(bufferLVGLmemory, std::string("").append("%lu/%lu (%d%%)\0").c_str(), mon.free_size, mon.total_size, 100-mon.used_pct);
#endif #endif
#endif #endif
for (int i=0; i<strlen(buffer); i++) { // convert "." to ","
if (buffer[i] == '.') { for (int i=0; i<strlen(bufferHeap); i++) {
buffer[i] = ','; if (bufferHeap[i] == '.') {
bufferHeap[i] = ',';
} }
} }
if (MemoryUsageLabel != NULL) { for (int i=0; i<strlen(bufferLVGLmemory); i++) {
// Serial.printf("inside doLogMemoryUsage: will do GUI log %s\r\n", buffer); if (bufferLVGLmemory[i] == '.') {
lv_label_set_text(MemoryUsageLabel, buffer); bufferLVGLmemory[i] = ',';
}
} }
// set text and color of heap used
if (MemoryUsageSpanHeap != NULL) {
lv_span_set_text(MemoryUsageSpanHeap, bufferHeap);
if (doESPHeapWarning) {
lv_style_set_text_color(&MemoryUsageSpanHeap->style, lv_palette_main(LV_PALETTE_RED));
} else {
lv_style_set_text_color(&MemoryUsageSpanHeap->style, lv_palette_main(LV_PALETTE_GREEN));
}
}
// only if LVGL's built in implementation of memory management is used
#if (LV_USE_STDLIB_MALLOC == 0)
// first the separator
if (MemoryUsageSpanSeparator != NULL) {
lv_span_set_text(MemoryUsageSpanSeparator, " / ");
}
// set text and color of LVGL memory used
if (MemoryUsageSpanLVGLmemory != NULL) {
lv_span_set_text(MemoryUsageSpanLVGLmemory, bufferLVGLmemory);
if (doLVGLMemoryWarning) {
lv_style_set_text_color(&MemoryUsageSpanLVGLmemory->style, lv_palette_main(LV_PALETTE_RED));
} else {
lv_style_set_text_color(&MemoryUsageSpanLVGLmemory->style, lv_palette_main(LV_PALETTE_GREEN));
}
}
#endif
} else { } else {
if (MemoryUsageLabel != NULL) { // we don't show memory usage, so clear text
lv_label_set_text(MemoryUsageLabel, ""); if (MemoryUsageSpanHeap != NULL) {
lv_span_set_text(MemoryUsageSpanHeap, "");
}
if (MemoryUsageSpanLVGLmemory != NULL) {
lv_span_set_text(MemoryUsageSpanLVGLmemory, "");
} }
} }
} }

View File

@ -8,9 +8,9 @@
#include "devices/mediaPlayer/device_appleTV/device_appleTV.h" #include "devices/mediaPlayer/device_appleTV/device_appleTV.h"
// LVGL declarations // LVGL declarations
LV_IMG_DECLARE(appleTvIcon); LV_IMAGE_DECLARE(appleTvIcon);
LV_IMG_DECLARE(appleDisplayIcon); LV_IMAGE_DECLARE(appleDisplayIcon);
LV_IMG_DECLARE(appleBackIcon); LV_IMAGE_DECLARE(appleBackIcon);
// Apple Key Event handler // Apple Key Event handler
static void appleKey_event_cb(lv_event_t* e) { static void appleKey_event_cb(lv_event_t* e) {
@ -24,34 +24,34 @@ void create_tab_content_appleTV(lv_obj_t* tab) {
// Add content to the Apple TV tab // Add content to the Apple TV tab
// Add a nice apple tv logo // Add a nice apple tv logo
lv_obj_t* appleImg = lv_img_create(tab); lv_obj_t* appleImg = lv_image_create(tab);
lv_img_set_src(appleImg, &appleTvIcon); lv_image_set_src(appleImg, &appleTvIcon);
lv_obj_align(appleImg, LV_ALIGN_CENTER, 0, -60); lv_obj_align(appleImg, LV_ALIGN_CENTER, 0, -60);
// create two buttons and add their icons accordingly // create two buttons and add their icons accordingly
lv_obj_t* button = lv_btn_create(tab); lv_obj_t* button = lv_button_create(tab);
lv_obj_align(button, LV_ALIGN_BOTTOM_LEFT, 10, 0); lv_obj_align(button, LV_ALIGN_BOTTOM_LEFT, 10, 0);
lv_obj_set_size(button, 60, 60); lv_obj_set_size(button, 60, 60);
lv_obj_set_style_radius(button, 30, LV_PART_MAIN); lv_obj_set_style_radius(button, 30, LV_PART_MAIN);
lv_obj_set_style_bg_color(button, color_primary, LV_PART_MAIN); lv_obj_set_style_bg_color(button, color_primary, LV_PART_MAIN);
lv_obj_add_event_cb(button, appleKey_event_cb, LV_EVENT_CLICKED, (void*)1); lv_obj_add_event_cb(button, appleKey_event_cb, LV_EVENT_CLICKED, (void*)1);
appleImg = lv_img_create(button); appleImg = lv_image_create(button);
lv_img_set_src(appleImg, &appleBackIcon); lv_image_set_src(appleImg, &appleBackIcon);
lv_obj_set_style_img_recolor(appleImg, lv_color_white(), LV_PART_MAIN); lv_obj_set_style_image_recolor(appleImg, lv_color_white(), LV_PART_MAIN);
lv_obj_set_style_img_recolor_opa(appleImg, LV_OPA_COVER, LV_PART_MAIN); lv_obj_set_style_image_recolor_opa(appleImg, LV_OPA_COVER, LV_PART_MAIN);
lv_obj_align(appleImg, LV_ALIGN_CENTER, -3, 0); lv_obj_align(appleImg, LV_ALIGN_CENTER, -3, 0);
button = lv_btn_create(tab); button = lv_button_create(tab);
lv_obj_align(button, LV_ALIGN_BOTTOM_RIGHT, -10, 0); lv_obj_align(button, LV_ALIGN_BOTTOM_RIGHT, -10, 0);
lv_obj_set_size(button, 60, 60); lv_obj_set_size(button, 60, 60);
lv_obj_set_style_radius(button, 30, LV_PART_MAIN); lv_obj_set_style_radius(button, 30, LV_PART_MAIN);
lv_obj_set_style_bg_color(button, color_primary, LV_PART_MAIN); lv_obj_set_style_bg_color(button, color_primary, LV_PART_MAIN);
lv_obj_add_event_cb(button, appleKey_event_cb, LV_EVENT_CLICKED, (void*)2); lv_obj_add_event_cb(button, appleKey_event_cb, LV_EVENT_CLICKED, (void*)2);
appleImg = lv_img_create(button); appleImg = lv_image_create(button);
lv_img_set_src(appleImg, &appleDisplayIcon); lv_image_set_src(appleImg, &appleDisplayIcon);
lv_obj_set_style_img_recolor(appleImg, lv_color_white(), LV_PART_MAIN); lv_obj_set_style_image_recolor(appleImg, lv_color_white(), LV_PART_MAIN);
lv_obj_set_style_img_recolor_opa(appleImg, LV_OPA_COVER, LV_PART_MAIN); lv_obj_set_style_image_recolor_opa(appleImg, LV_OPA_COVER, LV_PART_MAIN);
lv_obj_align(appleImg, LV_ALIGN_CENTER, 0, 0); lv_obj_align(appleImg, LV_ALIGN_CENTER, 0, 0);
} }

View File

@ -54,13 +54,11 @@ const LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_LARGE_CONST uint8_t appleTvIcon_map[]
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6e, 0x73, 0xf8, 0xc5, 0xba, 0xd6, 0xd7, 0xbd, 0xf0, 0x83, 0xa3, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49, 0x4a, 0xf3, 0x9c, 0xf8, 0xc5, 0x59, 0xce, 0x55, 0xad, 0x08, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xae, 0x73, 0x76, 0xb5, 0x39, 0xce, 0x7a, 0xd6, 0x39, 0xce, 0xd7, 0xbd, 0xd3, 0x9c, 0xec, 0x62, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x4a, 0x0c, 0x63, 0x0c, 0x63, 0x0c, 0x63, 0x0c, 0x63, 0x0c, 0x63, 0x0c, 0x63, 0x0c, 0x63, 0x49, 0x4a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6e, 0x73, 0xf8, 0xc5, 0xba, 0xd6, 0xd7, 0xbd, 0xf0, 0x83, 0xa3, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49, 0x4a, 0xf3, 0x9c, 0xf8, 0xc5, 0x59, 0xce, 0x55, 0xad, 0x08, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xae, 0x73, 0x76, 0xb5, 0x39, 0xce, 0x7a, 0xd6, 0x39, 0xce, 0xd7, 0xbd, 0xd3, 0x9c, 0xec, 0x62, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x4a, 0x0c, 0x63, 0x0c, 0x63, 0x0c, 0x63, 0x0c, 0x63, 0x0c, 0x63, 0x0c, 0x63, 0x0c, 0x63, 0x49, 0x4a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
}; };
const lv_img_dsc_t appleTvIcon = { const lv_image_dsc_t appleTvIcon = {
.header.cf = LV_IMG_CF_TRUE_COLOR, .header.cf = LV_COLOR_FORMAT_NATIVE,
.header.always_zero = 0,
.header.reserved = 0,
.header.w = 91, .header.w = 91,
.header.h = 42, .header.h = 42,
.data_size = 3822 * LV_COLOR_SIZE / 8, .data_size = 3822 * LV_COLOR_DEPTH / 8,
.data = appleTvIcon_map, .data = appleTvIcon_map,
}; };
@ -92,10 +90,8 @@ const LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_LARGE_CONST uint8_t appleDisplayIcon_m
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0xd3, 0xde, 0xde, 0xde, 0xde, 0xde, 0xde, 0xde, 0xde, 0xde, 0xdb, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0xd3, 0xde, 0xde, 0xde, 0xde, 0xde, 0xde, 0xde, 0xde, 0xde, 0xdb, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
}; };
const lv_img_dsc_t appleDisplayIcon = { const lv_image_dsc_t appleDisplayIcon = {
.header.cf = LV_IMG_CF_ALPHA_8BIT, .header.cf = LV_COLOR_FORMAT_A8,
.header.always_zero = 0,
.header.reserved = 0,
.header.w = 25, .header.w = 25,
.header.h = 20, .header.h = 20,
.data_size = 500, .data_size = 500,
@ -135,10 +131,8 @@ const LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_LARGE_CONST LV_ATTRIBUTE_IMG_APPLEBACK
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x28, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x28, 0x18,
}; };
const lv_img_dsc_t appleBackIcon = { const lv_image_dsc_t appleBackIcon = {
.header.cf = LV_IMG_CF_ALPHA_8BIT, .header.cf = LV_COLOR_FORMAT_A8,
.header.always_zero = 0,
.header.reserved = 0,
.header.w = 13, .header.w = 13,
.header.h = 25, .header.h = 25,
.data_size = 325, .data_size = 325,

View File

@ -8,7 +8,7 @@
#include "devices/misc/device_smarthome/device_smarthome.h" #include "devices/misc/device_smarthome/device_smarthome.h"
// LVGL declarations // LVGL declarations
LV_IMG_DECLARE(lightbulb); LV_IMAGE_DECLARE(lightbulb);
static lv_obj_t* lightToggleA; static lv_obj_t* lightToggleA;
static lv_obj_t* lightToggleB; static lv_obj_t* lightToggleB;
@ -23,7 +23,7 @@ static int32_t sliderBvalue = 0;
// Smart Home Toggle Event handler // Smart Home Toggle Event handler
static void smartHomeToggle_event_cb(lv_event_t* e){ static void smartHomeToggle_event_cb(lv_event_t* e){
std::string payload; std::string payload;
if (lv_obj_has_state(lv_event_get_target(e), LV_STATE_CHECKED)) payload = "true"; if (lv_obj_has_state((lv_obj_t*)lv_event_get_target(e), LV_STATE_CHECKED)) payload = "true";
else payload = "false"; else payload = "false";
// Publish an MQTT message based on the event user data // Publish an MQTT message based on the event user data
#if (ENABLE_WIFI_AND_MQTT == 1) #if (ENABLE_WIFI_AND_MQTT == 1)
@ -35,7 +35,7 @@ static void smartHomeToggle_event_cb(lv_event_t* e){
// Smart Home Slider Event handler // Smart Home Slider Event handler
static void smartHomeSlider_event_cb(lv_event_t* e){ static void smartHomeSlider_event_cb(lv_event_t* e){
lv_obj_t* slider = lv_event_get_target(e); lv_obj_t* slider = (lv_obj_t*)lv_event_get_target(e);
char payload[8]; char payload[8];
sprintf(payload, "%.2f", float(lv_slider_get_value(slider))); sprintf(payload, "%.2f", float(lv_slider_get_value(slider)));
std::string payload_str(payload); std::string payload_str(payload);
@ -63,10 +63,10 @@ void create_tab_content_smarthome(lv_obj_t* tab) {
lv_obj_set_style_bg_color(menuBox, color_primary, LV_PART_MAIN); lv_obj_set_style_bg_color(menuBox, color_primary, LV_PART_MAIN);
lv_obj_set_style_border_width(menuBox, 0, LV_PART_MAIN); lv_obj_set_style_border_width(menuBox, 0, LV_PART_MAIN);
lv_obj_t* bulbIcon = lv_img_create(menuBox); lv_obj_t* bulbIcon = lv_image_create(menuBox);
lv_img_set_src(bulbIcon, &lightbulb); lv_image_set_src(bulbIcon, &lightbulb);
lv_obj_set_style_img_recolor(bulbIcon, lv_color_white(), LV_PART_MAIN); lv_obj_set_style_image_recolor(bulbIcon, lv_color_white(), LV_PART_MAIN);
lv_obj_set_style_img_recolor_opa(bulbIcon, LV_OPA_COVER, LV_PART_MAIN); lv_obj_set_style_image_recolor_opa(bulbIcon, LV_OPA_COVER, LV_PART_MAIN);
lv_obj_align(bulbIcon, LV_ALIGN_TOP_LEFT, 0, 0); lv_obj_align(bulbIcon, LV_ALIGN_TOP_LEFT, 0, 0);
menuLabel = lv_label_create(menuBox); menuLabel = lv_label_create(menuBox);
@ -76,7 +76,7 @@ void create_tab_content_smarthome(lv_obj_t* tab) {
if (lightToggleAstate) { if (lightToggleAstate) {
lv_obj_add_state(lightToggleA, LV_STATE_CHECKED); lv_obj_add_state(lightToggleA, LV_STATE_CHECKED);
} else { } else {
// lv_obj_clear_state(lightToggleA, LV_STATE_CHECKED); // lv_obj_remove_state(lightToggleA, LV_STATE_CHECKED);
} }
lv_obj_set_size(lightToggleA, 40, 22); lv_obj_set_size(lightToggleA, 40, 22);
lv_obj_align(lightToggleA, LV_ALIGN_TOP_RIGHT, 0, 0); lv_obj_align(lightToggleA, LV_ALIGN_TOP_RIGHT, 0, 0);
@ -103,10 +103,10 @@ void create_tab_content_smarthome(lv_obj_t* tab) {
lv_obj_set_style_bg_color(menuBox, color_primary, LV_PART_MAIN); lv_obj_set_style_bg_color(menuBox, color_primary, LV_PART_MAIN);
lv_obj_set_style_border_width(menuBox, 0, LV_PART_MAIN); lv_obj_set_style_border_width(menuBox, 0, LV_PART_MAIN);
bulbIcon = lv_img_create(menuBox); bulbIcon = lv_image_create(menuBox);
lv_img_set_src(bulbIcon, &lightbulb); lv_image_set_src(bulbIcon, &lightbulb);
lv_obj_set_style_img_recolor(bulbIcon, lv_color_white(), LV_PART_MAIN); lv_obj_set_style_image_recolor(bulbIcon, lv_color_white(), LV_PART_MAIN);
lv_obj_set_style_img_recolor_opa(bulbIcon, LV_OPA_COVER, LV_PART_MAIN); lv_obj_set_style_image_recolor_opa(bulbIcon, LV_OPA_COVER, LV_PART_MAIN);
lv_obj_align(bulbIcon, LV_ALIGN_TOP_LEFT, 0, 0); lv_obj_align(bulbIcon, LV_ALIGN_TOP_LEFT, 0, 0);
menuLabel = lv_label_create(menuBox); menuLabel = lv_label_create(menuBox);
@ -116,7 +116,7 @@ void create_tab_content_smarthome(lv_obj_t* tab) {
if (lightToggleBstate) { if (lightToggleBstate) {
lv_obj_add_state(lightToggleB, LV_STATE_CHECKED); lv_obj_add_state(lightToggleB, LV_STATE_CHECKED);
} else { } else {
// lv_obj_clear_state(lightToggleB, LV_STATE_CHECKED); // lv_obj_remove_state(lightToggleB, LV_STATE_CHECKED);
} }
lv_obj_set_size(lightToggleB, 40, 22); lv_obj_set_size(lightToggleB, 40, 22);
lv_obj_align(lightToggleB, LV_ALIGN_TOP_RIGHT, 0, 0); lv_obj_align(lightToggleB, LV_ALIGN_TOP_RIGHT, 0, 0);

View File

@ -31,10 +31,8 @@ const LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_LARGE_CONST LV_ATTRIBUTE_IMG_LIGHTBULB
0x00, 0x00, 0x00, 0x01, 0x21, 0x22, 0x22, 0x21, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x21, 0x22, 0x22, 0x21, 0x01, 0x00, 0x00, 0x00,
}; };
const lv_img_dsc_t lightbulb = { const lv_image_dsc_t lightbulb = {
.header.cf = LV_IMG_CF_ALPHA_8BIT, .header.cf = LV_COLOR_FORMAT_A8,
.header.always_zero = 0,
.header.reserved = 0,
.header.w = 12, .header.w = 12,
.header.h = 20, .header.h = 20,
.data_size = 240, .data_size = 240,

View File

@ -88,7 +88,7 @@ void showNewIRmessage(std::string message) {
// IR receiver on Switch Event handler // IR receiver on Switch Event handler
static void IRReceiverOnSetting_event_cb(lv_event_t* e){ static void IRReceiverOnSetting_event_cb(lv_event_t* e){
set_irReceiverEnabled(lv_obj_has_state(lv_event_get_target(e), LV_STATE_CHECKED)); set_irReceiverEnabled(lv_obj_has_state((lv_obj_t*)lv_event_get_target(e), LV_STATE_CHECKED));
if (get_irReceiverEnabled()) { if (get_irReceiverEnabled()) {
Serial.println("will turn on IR receiver"); Serial.println("will turn on IR receiver");
start_infraredReceiver(); start_infraredReceiver();

View File

@ -12,8 +12,8 @@
// Virtual Keypad Event handler // Virtual Keypad Event handler
static void virtualKeypad_event_cb(lv_event_t* e) { static void virtualKeypad_event_cb(lv_event_t* e) {
lv_obj_t* target = lv_event_get_target(e); lv_obj_t* target = (lv_obj_t*)lv_event_get_target(e);
lv_obj_t* cont = lv_event_get_current_target(e); lv_obj_t* cont = (lv_obj_t*)lv_event_get_current_target(e);
if (target == cont) return; // stop if container was clicked if (target == cont) return; // stop if container was clicked
int user_data = (intptr_t)(target->user_data); int user_data = (intptr_t)(target->user_data);
@ -37,8 +37,8 @@ void create_tab_content_numpad(lv_obj_t* tab) {
// Configure number button grid // Configure number button grid
// A variable declared static inside a function is visible only inside that function, exists only once (not created/destroyed for each call) and is permanent. It is in a sense a private global variable. // A variable declared static inside a function is visible only inside that function, exists only once (not created/destroyed for each call) and is permanent. It is in a sense a private global variable.
static lv_coord_t col_dsc[] = { LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST }; // equal x distribution static int32_t col_dsc[] = { LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST }; // equal x distribution
static lv_coord_t row_dsc[] = { 52, 52, 52, 52, LV_GRID_TEMPLATE_LAST }; // manual y distribution to compress the grid a bit static int32_t row_dsc[] = { 52, 52, 52, 52, LV_GRID_TEMPLATE_LAST }; // manual y distribution to compress the grid a bit
// Create a container with grid for tab // Create a container with grid for tab
lv_obj_set_style_pad_all(tab, 0, LV_PART_MAIN); lv_obj_set_style_pad_all(tab, 0, LV_PART_MAIN);
@ -62,7 +62,7 @@ void create_tab_content_numpad(lv_obj_t* tab) {
uint8_t row = i / 3; uint8_t row = i / 3;
// Create the button object // Create the button object
if ((row == 3) && ((col == 0) || (col == 2))) continue; // Do not create a complete fourth row, only a 0 button if ((row == 3) && ((col == 0) || (col == 2))) continue; // Do not create a complete fourth row, only a 0 button
obj = lv_btn_create(cont); obj = lv_button_create(cont);
lv_obj_set_grid_cell(obj, LV_GRID_ALIGN_STRETCH, col, 1, LV_GRID_ALIGN_STRETCH, row, 1); lv_obj_set_grid_cell(obj, LV_GRID_ALIGN_STRETCH, col, 1, LV_GRID_ALIGN_STRETCH, row, 1);
lv_obj_set_style_bg_color(obj, color_primary, LV_PART_MAIN); lv_obj_set_style_bg_color(obj, color_primary, LV_PART_MAIN);
lv_obj_set_style_radius(obj, 14, LV_PART_MAIN); lv_obj_set_style_radius(obj, 14, LV_PART_MAIN);

View File

@ -102,7 +102,7 @@ void create_tab_content_sceneSelection(lv_obj_t* tab) {
scene_list scenes = get_scenes_on_sceneSelectionGUI(); scene_list scenes = get_scenes_on_sceneSelectionGUI();
if ((scenes != NULL) && (scenes->size() > 0)) { if ((scenes != NULL) && (scenes->size() > 0)) {
for (int i=0; i<scenes->size(); i++) { for (int i=0; i<scenes->size(); i++) {
lv_obj_t* button = lv_btn_create(tab); lv_obj_t* button = lv_button_create(tab);
lv_obj_set_size(button, lv_pct(100), 42); lv_obj_set_size(button, lv_pct(100), 42);
lv_obj_set_style_radius(button, 30, LV_PART_MAIN); lv_obj_set_style_radius(button, 30, LV_PART_MAIN);
lv_obj_set_style_bg_color(button, color_primary, LV_PART_MAIN); lv_obj_set_style_bg_color(button, color_primary, LV_PART_MAIN);

View File

@ -6,8 +6,8 @@
#include "guis/gui_settings.h" #include "guis/gui_settings.h"
// LVGL declarations // LVGL declarations
LV_IMG_DECLARE(high_brightness); LV_IMAGE_DECLARE(high_brightness);
LV_IMG_DECLARE(low_brightness); LV_IMAGE_DECLARE(low_brightness);
lv_obj_t* objBattSettingsVoltage; lv_obj_t* objBattSettingsVoltage;
lv_obj_t* objBattSettingsPercentage; lv_obj_t* objBattSettingsPercentage;
@ -15,7 +15,7 @@ lv_obj_t* objBattSettingsPercentage;
// Slider Event handler // Slider Event handler
static void bl_slider_event_cb(lv_event_t* e){ static void bl_slider_event_cb(lv_event_t* e){
lv_obj_t* slider = lv_event_get_target(e); lv_obj_t* slider = (lv_obj_t*)lv_event_get_target(e);
int32_t slider_value = lv_slider_get_value(slider); int32_t slider_value = lv_slider_get_value(slider);
if (slider_value < 60) {slider_value = 60;} if (slider_value < 60) {slider_value = 60;}
if (slider_value > 255) {slider_value = 255;} if (slider_value > 255) {slider_value = 255;}
@ -24,12 +24,12 @@ static void bl_slider_event_cb(lv_event_t* e){
// Wakeup by IMU Switch Event handler // Wakeup by IMU Switch Event handler
static void WakeEnableSetting_event_cb(lv_event_t* e){ static void WakeEnableSetting_event_cb(lv_event_t* e){
set_wakeupByIMUEnabled(lv_obj_has_state(lv_event_get_target(e), LV_STATE_CHECKED)); set_wakeupByIMUEnabled(lv_obj_has_state((lv_obj_t*)lv_event_get_target(e), LV_STATE_CHECKED));
} }
// timout event handler // timout event handler
static void timout_event_cb(lv_event_t* e){ static void timout_event_cb(lv_event_t* e){
lv_obj_t* drop = lv_event_get_target(e); lv_obj_t* drop = (lv_obj_t*)lv_event_get_target(e);
uint16_t selected = lv_dropdown_get_selected(drop); uint16_t selected = lv_dropdown_get_selected(drop);
switch (selected) { switch (selected) {
case 0: {set_sleepTimeout( 10000); break;} case 0: {set_sleepTimeout( 10000); break;}
@ -48,7 +48,7 @@ static void timout_event_cb(lv_event_t* e){
// show memory usage event handler // show memory usage event handler
static void showMemoryUsage_event_cb(lv_event_t* e) { static void showMemoryUsage_event_cb(lv_event_t* e) {
setShowMemoryUsage(lv_obj_has_state(lv_event_get_target(e), LV_STATE_CHECKED)); setShowMemoryUsage(lv_obj_has_state((lv_obj_t*)lv_event_get_target(e), LV_STATE_CHECKED));
} }
void create_tab_content_settings(lv_obj_t* tab) { void create_tab_content_settings(lv_obj_t* tab) {
@ -68,10 +68,10 @@ void create_tab_content_settings(lv_obj_t* tab) {
lv_obj_set_style_bg_color(menuBox, color_primary, LV_PART_MAIN); lv_obj_set_style_bg_color(menuBox, color_primary, LV_PART_MAIN);
lv_obj_set_style_border_width(menuBox, 0, LV_PART_MAIN); lv_obj_set_style_border_width(menuBox, 0, LV_PART_MAIN);
lv_obj_t* brightnessIcon = lv_img_create(menuBox); lv_obj_t* brightnessIcon = lv_image_create(menuBox);
lv_img_set_src(brightnessIcon, &low_brightness); lv_image_set_src(brightnessIcon, &low_brightness);
lv_obj_set_style_img_recolor(brightnessIcon, lv_color_white(), LV_PART_MAIN); lv_obj_set_style_image_recolor(brightnessIcon, lv_color_white(), LV_PART_MAIN);
lv_obj_set_style_img_recolor_opa(brightnessIcon, LV_OPA_COVER, LV_PART_MAIN); lv_obj_set_style_image_recolor_opa(brightnessIcon, LV_OPA_COVER, LV_PART_MAIN);
lv_obj_align(brightnessIcon, LV_ALIGN_TOP_LEFT, 0, 0); lv_obj_align(brightnessIcon, LV_ALIGN_TOP_LEFT, 0, 0);
lv_obj_t* slider = lv_slider_create(menuBox); lv_obj_t* slider = lv_slider_create(menuBox);
lv_slider_set_range(slider, 60, 255); lv_slider_set_range(slider, 60, 255);
@ -81,10 +81,10 @@ void create_tab_content_settings(lv_obj_t* tab) {
lv_slider_set_value(slider, get_backlightBrightness(), LV_ANIM_OFF); lv_slider_set_value(slider, get_backlightBrightness(), LV_ANIM_OFF);
lv_obj_set_size(slider, lv_pct(66), 10); lv_obj_set_size(slider, lv_pct(66), 10);
lv_obj_align(slider, LV_ALIGN_TOP_MID, 0, 3); lv_obj_align(slider, LV_ALIGN_TOP_MID, 0, 3);
brightnessIcon = lv_img_create(menuBox); brightnessIcon = lv_image_create(menuBox);
lv_img_set_src(brightnessIcon, &high_brightness); lv_image_set_src(brightnessIcon, &high_brightness);
lv_obj_set_style_img_recolor(brightnessIcon, lv_color_white(), LV_PART_MAIN); lv_obj_set_style_image_recolor(brightnessIcon, lv_color_white(), LV_PART_MAIN);
lv_obj_set_style_img_recolor_opa(brightnessIcon, LV_OPA_COVER, LV_PART_MAIN); lv_obj_set_style_image_recolor_opa(brightnessIcon, LV_OPA_COVER, LV_PART_MAIN);
lv_obj_align(brightnessIcon, LV_ALIGN_TOP_RIGHT, 0, -1); lv_obj_align(brightnessIcon, LV_ALIGN_TOP_RIGHT, 0, -1);
lv_obj_add_event_cb(slider, bl_slider_event_cb, LV_EVENT_VALUE_CHANGED, NULL); lv_obj_add_event_cb(slider, bl_slider_event_cb, LV_EVENT_VALUE_CHANGED, NULL);
@ -99,7 +99,7 @@ void create_tab_content_settings(lv_obj_t* tab) {
if (get_wakeupByIMUEnabled()) { if (get_wakeupByIMUEnabled()) {
lv_obj_add_state(wakeToggle, LV_STATE_CHECKED); lv_obj_add_state(wakeToggle, LV_STATE_CHECKED);
} else { } else {
// lv_obj_clear_state(wakeToggle, LV_STATE_CHECKED); // lv_obj_remove_state(wakeToggle, LV_STATE_CHECKED);
} }
menuLabel = lv_label_create(menuBox); menuLabel = lv_label_create(menuBox);
@ -192,7 +192,7 @@ void create_tab_content_settings(lv_obj_t* tab) {
if (getShowMemoryUsage()) { if (getShowMemoryUsage()) {
lv_obj_add_state(memoryUsageToggle, LV_STATE_CHECKED); lv_obj_add_state(memoryUsageToggle, LV_STATE_CHECKED);
} else { } else {
// lv_obj_clear_state(memoryUsageToggle, LV_STATE_CHECKED); // lv_obj_remove_state(memoryUsageToggle, LV_STATE_CHECKED);
} }
} }

View File

@ -29,10 +29,8 @@ const LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_LARGE_CONST LV_ATTRIBUTE_IMG_HIGH_BRIG
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc1, 0xc1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc1, 0xc1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
}; };
const lv_img_dsc_t high_brightness = { const lv_image_dsc_t high_brightness = {
.header.cf = LV_IMG_CF_ALPHA_8BIT, .header.cf = LV_COLOR_FORMAT_A8,
.header.always_zero = 0,
.header.reserved = 0,
.header.w = 18, .header.w = 18,
.header.h = 18, .header.h = 18,
.data_size = 324, .data_size = 324,
@ -63,10 +61,8 @@ const LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_LARGE_CONST LV_ATTRIBUTE_IMG_LOW_BRIGH
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x43, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x43, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
}; };
const lv_img_dsc_t low_brightness = { const lv_image_dsc_t low_brightness = {
.header.cf = LV_IMG_CF_ALPHA_8BIT, .header.cf = LV_COLOR_FORMAT_A8,
.header.always_zero = 0,
.header.reserved = 0,
.header.w = 16, .header.w = 16,
.header.h = 16, .header.h = 16,
.data_size = 256, .data_size = 256,