From a0e33435b15b9fbce96185fd493bef4ff3dc6e74 Mon Sep 17 00:00:00 2001 From: Alexey Date: Tue, 18 Nov 2025 18:13:50 +0300 Subject: [PATCH 1/3] Update peripheral_status.c Add random shift for image pointers' array so images --- .../widgets/peripheral_status.c | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/boards/shields/nice_view_custom/widgets/peripheral_status.c b/boards/shields/nice_view_custom/widgets/peripheral_status.c index 3742cad..308455b 100644 --- a/boards/shields/nice_view_custom/widgets/peripheral_status.c +++ b/boards/shields/nice_view_custom/widgets/peripheral_status.c @@ -8,6 +8,9 @@ #include #include +#include +#include + #include LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); @@ -87,6 +90,23 @@ const lv_img_dsc_t *anim_imgs[] = { &hammerbeam30, }; +void rotateArr(const lv_img_dsc_t *arr[], int n, uint32_t d) { + const lv_img_dsc_t *tmp[n]; + for (int i = 0; i < n; i++) { + tmp[i] = arr[(i + d) % n]; + } + for (int i = 0; i < n; i++) { + arr[i] = tmp[i]; + } +} + +uint32_t d; + +void anim_imgs_shift_init(void) { + d = sys_rand32_get() % 30; + int n = 30; + rotateArr(anim_imgs, n, d); // rotate after d is set +} static sys_slist_t widgets = SYS_SLIST_STATIC_INIT(&widgets); @@ -176,6 +196,8 @@ int zmk_widget_status_init(struct zmk_widget_status *widget, lv_obj_t *parent) { lv_obj_align(top, LV_ALIGN_TOP_RIGHT, 0, 0); lv_canvas_set_buffer(top, widget->cbuf, CANVAS_SIZE, CANVAS_SIZE, LV_IMG_CF_TRUE_COLOR); + anim_imgs_shift_init(); + lv_obj_t * art = lv_animimg_create(widget->obj); lv_obj_center(art); lv_animimg_set_src(art, (const void **) anim_imgs, 30); @@ -191,4 +213,5 @@ int zmk_widget_status_init(struct zmk_widget_status *widget, lv_obj_t *parent) { return 0; } -lv_obj_t *zmk_widget_status_obj(struct zmk_widget_status *widget) { return widget->obj; } \ No newline at end of file + +lv_obj_t *zmk_widget_status_obj(struct zmk_widget_status *widget) { return widget->obj; } From 1f8ba92de2eeb60f6ee2c7b0046d33a1bb8d0a8c Mon Sep 17 00:00:00 2001 From: Alexey Date: Tue, 18 Nov 2025 18:20:11 +0300 Subject: [PATCH 2/3] Removed unnecessary headers from peripheral_status.c --- boards/shields/nice_view_custom/widgets/peripheral_status.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/boards/shields/nice_view_custom/widgets/peripheral_status.c b/boards/shields/nice_view_custom/widgets/peripheral_status.c index 308455b..f68cd9a 100644 --- a/boards/shields/nice_view_custom/widgets/peripheral_status.c +++ b/boards/shields/nice_view_custom/widgets/peripheral_status.c @@ -8,9 +8,6 @@ #include #include -#include -#include - #include LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); @@ -215,3 +212,4 @@ int zmk_widget_status_init(struct zmk_widget_status *widget, lv_obj_t *parent) { lv_obj_t *zmk_widget_status_obj(struct zmk_widget_status *widget) { return widget->obj; } + From 28db19257162162f2ea609978b6969014ee08268 Mon Sep 17 00:00:00 2001 From: Alexey Date: Tue, 18 Nov 2025 18:33:31 +0300 Subject: [PATCH 3/3] Update peripheral_status.c with necessary checks --- .../nice_view_custom/widgets/peripheral_status.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/boards/shields/nice_view_custom/widgets/peripheral_status.c b/boards/shields/nice_view_custom/widgets/peripheral_status.c index f68cd9a..ff61796 100644 --- a/boards/shields/nice_view_custom/widgets/peripheral_status.c +++ b/boards/shields/nice_view_custom/widgets/peripheral_status.c @@ -88,6 +88,10 @@ const lv_img_dsc_t *anim_imgs[] = { }; void rotateArr(const lv_img_dsc_t *arr[], int n, uint32_t d) { + if (n <= 1) return; + d = d % n; + if (d == 0) return; + const lv_img_dsc_t *tmp[n]; for (int i = 0; i < n; i++) { tmp[i] = arr[(i + d) % n]; @@ -100,9 +104,9 @@ void rotateArr(const lv_img_dsc_t *arr[], int n, uint32_t d) { uint32_t d; void anim_imgs_shift_init(void) { - d = sys_rand32_get() % 30; - int n = 30; - rotateArr(anim_imgs, n, d); // rotate after d is set + int n = sizeof(anim_imgs) / sizeof(anim_imgs[0]); + d = sys_rand32_get() % n; + rotateArr(anim_imgs, n, d); } static sys_slist_t widgets = SYS_SLIST_STATIC_INIT(&widgets); @@ -213,3 +217,4 @@ int zmk_widget_status_init(struct zmk_widget_status *widget, lv_obj_t *parent) { lv_obj_t *zmk_widget_status_obj(struct zmk_widget_status *widget) { return widget->obj; } +