Skip to content

feature: Migrate project from LVGL 8.3 to 9.3. #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 8 additions & 17 deletions webscreen/dynamic_js.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,43 @@

#include "pins_config.h"
#include "rm67162.h"
#include "lvgl_elk.h" // Contains init_lvgl_display(), init_lv_fs(), etc.
#include "lvgl_elk.h"
#include "globals.h"

// Initialize with the default script filename
String g_script_filename = "/app.js";

void dynamic_js_setup() {
LOG("DYNAMIC_JS: Setting up Elk + script scenario...");

// If needed, mount the SD again (or confirm it’s already mounted):
SD_MMC.setPins(PIN_SD_CLK, PIN_SD_CMD, PIN_SD_D0);
if(!SD_MMC.begin("/sdcard", true, false, 1000000)) {
LOG("Card Mount Failed => can't run dynamic JS code properly");
return;
}

// 1) Wi-Fi (station mode) - or skip if already connected
WiFi.mode(WIFI_STA);

// 2) Initialize LVGL display
init_lvgl_display();

// 3) 'S' driver for normal SD usage
init_lv_fs();

// 4) 'M' driver for memory usage (GIF)
init_mem_fs();

// 5) Init memory storage
init_ram_images();

// 6) Spawn Elk task
xTaskCreatePinnedToCore(
elk_task,
"ElkTask",
16384,
NULL,
1,
NULL,
0
elk_task,
"ElkTask",
16384,
NULL,
1,
NULL,
0
);

LOG("DYNAMIC_JS: setup done!");
}

void dynamic_js_loop() {
// The Elk code runs in the FreeRTOS task (elk_task).
vTaskDelay(pdMS_TO_TICKS(50));
}
95 changes: 41 additions & 54 deletions webscreen/fallback.cpp
Original file line number Diff line number Diff line change
@@ -1,49 +1,43 @@
#include <Arduino.h>
#include "fallback.h"
#include "pins_config.h"
#include "rm67162.h" // LCD driver
#include <lvgl.h> // Ensure you have LVGL
#include "notification.h" // For the GIF data
#include "rm67162.h"
#include <lvgl.h>
#include "notification.h"
#include "globals.h"
#include "tick.h"
#include "lvgl_elk.h" // We need init_mem_fs() and its globals

// We'll store references to the fallback label + gif
static lv_obj_t* fb_label = nullptr;
static lv_obj_t* fb_gif = nullptr;
static lv_obj_t* fb_image_anim = nullptr;

// A local display buffer/driver just for fallback, if you want separate from dynamic
static lv_disp_draw_buf_t fbDrawBuf;
static lv_color_t* fbBuf = nullptr;

// The flush callback
static void fallback_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p) {
static void fallback_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 h = (area->y2 - area->y1 + 1);
lcd_PushColors(area->x1, area->y1, w, h, (uint16_t *)&color_p->full);
lv_disp_flush_ready(disp);
lcd_PushColors(area->x1, area->y1, w, h, (uint16_t *)px_map);
lv_display_flush_ready(disp);
}

// Animation callback
static void scroll_anim_cb(void *var, int32_t v) {
lv_obj_set_y((lv_obj_t *)var, v);
}

// Helper to create the scrolling animation
static void create_scroll_animation(lv_obj_t *obj, int32_t start, int32_t end, uint32_t duration) {
lv_anim_t a;
lv_anim_init(&a);
lv_anim_set_var(&a, obj);
lv_anim_set_values(&a, start, end);
lv_anim_set_time(&a, duration);
lv_anim_set_duration(&a, duration);
lv_anim_set_exec_cb(&a, scroll_anim_cb);
lv_anim_set_path_cb(&a, lv_anim_path_ease_in_out); // Smooth
lv_anim_set_repeat_count(&a, 2); // Repeat twice
lv_anim_set_path_cb(&a, lv_anim_path_ease_in_out);
lv_anim_set_repeat_count(&a, 2);

// On animation finish, hide label, show GIF
lv_anim_set_ready_cb(&a, [](lv_anim_t *anim) {
lv_anim_set_completed_cb(&a, [](lv_anim_t *anim) {
lv_obj_t *obj = (lv_obj_t *)anim->var;
lv_obj_add_flag(obj, LV_OBJ_FLAG_HIDDEN);
lv_obj_clear_flag(fb_gif, LV_OBJ_FLAG_HIDDEN);
lv_obj_remove_flag(fb_image_anim, LV_OBJ_FLAG_HIDDEN);
});

lv_anim_start(&a);
Expand All @@ -52,39 +46,27 @@ static void create_scroll_animation(lv_obj_t *obj, int32_t start, int32_t end, u
void fallback_setup() {
LOG("FALLBACK: Setting up scrolling label + GIF...");

// 1) Minimal LVGL init (only if not already done).
// If your main code calls lv_init() elsewhere,
// you might skip or check if it’s safe to call again.
lv_init();
start_lvgl_tick();

// 2) Power on the screen, set backlight
init_mem_fs(); // This registers the 'M:' driver for our C array

pinMode(PIN_LED, OUTPUT);
digitalWrite(PIN_LED, HIGH);

// 3) Init your display driver
rm67162_init();
lcd_setRotation(1);

// 4) Allocate a buffer for fallback usage
fbBuf = (lv_color_t*) ps_malloc(sizeof(lv_color_t) * LVGL_LCD_BUF_SIZE);
if(!fbBuf) {
LOG("FALLBACK: Failed to allocate buffer");
LOG("FALLBACK: Failed to allocate display buffer");
return;
}

lv_disp_draw_buf_init(&fbDrawBuf, fbBuf, nullptr, LVGL_LCD_BUF_SIZE);

// 5) Register fallback display driver
static lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv);
disp_drv.hor_res = 536;
disp_drv.ver_res = 240;
disp_drv.flush_cb = fallback_disp_flush;
disp_drv.draw_buf = &fbDrawBuf;
lv_disp_drv_register(&disp_drv);
lv_display_t * disp = lv_display_create(536, 240);
lv_display_set_flush_cb(disp, fallback_disp_flush);
lv_display_set_buffers(disp, fbBuf, nullptr, sizeof(lv_color_t) * LVGL_LCD_BUF_SIZE, LV_DISPLAY_RENDER_MODE_PARTIAL);

// 6) Create a style for the label
static lv_style_t style;
lv_style_init(&style);
lv_style_set_text_font(&style, &lv_font_montserrat_40);
Expand All @@ -93,10 +75,9 @@ void fallback_setup() {
lv_style_set_pad_all(&style, 5);
lv_style_set_text_align(&style, LV_TEXT_ALIGN_CENTER);

// 7) Create the label
fb_label = lv_label_create(lv_scr_act());
fb_label = lv_label_create(lv_screen_active());
lv_obj_add_style(fb_label, &style, 0);
lv_label_set_text(fb_label,
lv_label_set_text(fb_label,
"/\\_/\\\n"
"= ( • . • ) =\n"
" / \\ \n"
Expand All @@ -108,32 +89,38 @@ void fallback_setup() {
lv_obj_set_width(fb_label, 525);
lv_obj_align(fb_label, LV_ALIGN_CENTER, 0, 0);

// 8) Create the scroll animation
create_scroll_animation(fb_label, 240, -lv_obj_get_height(fb_label), 10000);

// 9) Create the GIF
fb_gif = lv_gif_create(lv_scr_act());
lv_gif_set_src(fb_gif, &notification); // from notification.h
lv_obj_align(fb_gif, LV_ALIGN_CENTER, 0, 0);
// --- GIF SETUP ---
// 1. Point the memory filesystem's global buffer to your C array data.
g_gifBuffer = (uint8_t *)notification_map;
g_gifSize = notification_map_size;

// 2. Create an image widget.
fb_image_anim = lv_image_create(lv_screen_active());

// Show label first, hide GIF
lv_obj_clear_flag(fb_label, LV_OBJ_FLAG_HIDDEN);
lv_obj_add_flag(fb_gif, LV_OBJ_FLAG_HIDDEN);
// 3. Set the source using the memory driver path.
// LVGL will automatically use its GIF decoder and allocate memory from the
// large pool we defined in lv_conf.h.
lv_image_set_src(fb_image_anim, "M:/notification.gif");
lv_obj_align(fb_image_anim, LV_ALIGN_CENTER, 0, 0);

// --- End of GIF Setup ---

lv_obj_remove_flag(fb_label, LV_OBJ_FLAG_HIDDEN);
lv_obj_add_flag(fb_image_anim, LV_OBJ_FLAG_HIDDEN);
}

void fallback_loop() {
// Let LVGL run
lv_timer_handler();

// If serial data arrives, treat that as an input to update label
if (Serial.available()) {
String line = Serial.readStringUntil('\n');
lv_label_set_text(fb_label, line.c_str());
lv_obj_align(fb_label, LV_ALIGN_CENTER, 0, 0);
lv_obj_clear_flag(fb_label, LV_OBJ_FLAG_HIDDEN);
lv_obj_add_flag(fb_gif, LV_OBJ_FLAG_HIDDEN);
lv_obj_remove_flag(fb_label, LV_OBJ_FLAG_HIDDEN);
lv_obj_add_flag(fb_image_anim, LV_OBJ_FLAG_HIDDEN);

// re-run animation
create_scroll_animation(fb_label, 240, -lv_obj_get_height(fb_label), 10000);
}
}
}
Loading