feat(widget): bongo cat is now interactive only
This commit is contained in:
parent
5513f16d71
commit
79bac9d9e4
4 changed files with 6 additions and 55 deletions
|
@ -12,9 +12,7 @@
|
|||
struct zmk_widget_bongo_cat {
|
||||
sys_snode_t node;
|
||||
lv_obj_t *obj;
|
||||
#if !IS_ENABLED(CONFIG_ZMK_WIDGET_BONGO_CAT_INTERACTIVE)
|
||||
lv_anim_t anim;
|
||||
#endif
|
||||
bool is_right;
|
||||
};
|
||||
|
||||
int zmk_widget_bongo_cat_init(struct zmk_widget_bongo_cat *widget, lv_obj_t *parent);
|
||||
|
|
|
@ -38,22 +38,5 @@ config ZMK_WIDGET_BONGO_CAT
|
|||
depends on !ZMK_SPLIT || ZMK_SPLIT_BLE_ROLE_CENTRAL
|
||||
select LVGL_USE_LABEL
|
||||
select LVGL_USE_IMG
|
||||
select LVGL_USE_ANIMATION if !ZMK_WIDGET_BONGO_CAT_INTERACTIVE
|
||||
|
||||
if ZMK_WIDGET_BONGO_CAT
|
||||
|
||||
config ZMK_WIDGET_BONGO_CAT_INTERACTIVE
|
||||
bool "Bongo cat responds to key press"
|
||||
default y
|
||||
|
||||
if !ZMK_WIDGET_BONGO_CAT_INTERACTIVE
|
||||
|
||||
config ZMK_WIDGET_BONGO_CAT_ANIMATION_INTERVAL
|
||||
int "Time delay in ms for bongo cat animation"
|
||||
default 531
|
||||
|
||||
endif
|
||||
|
||||
endif # ZMK_WIDGET_BONGO_CAT
|
||||
|
||||
endmenu
|
||||
|
|
|
@ -10,17 +10,12 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
|||
#include <zmk/display.h>
|
||||
#include <zmk/display/widgets/bongo_cat.h>
|
||||
#include <zmk/event_manager.h>
|
||||
|
||||
#if IS_ENABLED(CONFIG_ZMK_WIDGET_BONGO_CAT_INTERACTIVE)
|
||||
#include <zmk/events/position_state_changed.h>
|
||||
#endif
|
||||
|
||||
static sys_slist_t widgets = SYS_SLIST_STATIC_INIT(&widgets);
|
||||
|
||||
LV_IMG_DECLARE(left);
|
||||
LV_IMG_DECLARE(right);
|
||||
|
||||
#if IS_ENABLED(CONFIG_ZMK_WIDGET_BONGO_CAT_INTERACTIVE)
|
||||
LV_IMG_DECLARE(none);
|
||||
LV_IMG_DECLARE(both);
|
||||
|
||||
|
@ -36,33 +31,11 @@ const void *images[] = {
|
|||
&right,
|
||||
&both
|
||||
};
|
||||
#else
|
||||
const void *images[] = {
|
||||
&left,
|
||||
&right
|
||||
};
|
||||
|
||||
void set_bongo_state(void *var, lv_anim_value_t val) {
|
||||
lv_img_set_src( (lv_obj_t *)var, images[val]);
|
||||
}
|
||||
#endif /* IS_ENABLED(CONFIG_ZMK_WIDGET_BONGO_CAT_INTERACTIVE) */
|
||||
|
||||
int zmk_widget_bongo_cat_init(struct zmk_widget_bongo_cat *widget, lv_obj_t *parent) {
|
||||
widget->obj = lv_img_create(parent, NULL);
|
||||
|
||||
#if IS_ENABLED(CONFIG_ZMK_WIDGET_BONGO_CAT_INTERACTIVE)
|
||||
lv_img_set_src(widget->obj, &none);
|
||||
current_bongo_state = bongo_state_none;
|
||||
#else
|
||||
lv_anim_init(&widget->anim);
|
||||
lv_anim_set_exec_cb(&widget->anim, (lv_anim_exec_xcb_t) set_bongo_state);
|
||||
lv_anim_set_var(&widget->anim, widget->obj);
|
||||
lv_anim_set_time(&widget->anim, CONFIG_ZMK_WIDGET_BONGO_CAT_ANIMATION_INTERVAL);
|
||||
lv_anim_set_values(&widget->anim, 0, 1);
|
||||
lv_anim_set_repeat_count(&widget->anim, LV_ANIM_REPEAT_INFINITE);
|
||||
lv_anim_set_repeat_delay(&widget->anim, CONFIG_ZMK_WIDGET_BONGO_CAT_ANIMATION_INTERVAL);
|
||||
lv_anim_start(&widget->anim);
|
||||
#endif /* IS_ENABLED(CONFIG_ZMK_WIDGET_BONGO_CAT_INTERACTIVE) */
|
||||
|
||||
sys_slist_append(&widgets, &widget->node);
|
||||
|
||||
|
@ -73,13 +46,12 @@ lv_obj_t *zmk_widget_bongo_cat_obj(struct zmk_widget_bongo_cat *widget) {
|
|||
return widget->obj;
|
||||
}
|
||||
|
||||
#if IS_ENABLED(CONFIG_ZMK_WIDGET_BONGO_CAT_INTERACTIVE)
|
||||
void set_bongo_state(lv_obj_t *img, struct zmk_position_state_changed *ev) {
|
||||
void set_bongo_state(struct zmk_widget_bongo_cat *widget, struct zmk_position_state_changed *ev) {
|
||||
if (ev == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t tmp = bongo_state_left;
|
||||
uint8_t tmp = bongo_state_left << widget->is_right;
|
||||
if (ev->state) {
|
||||
if (current_bongo_state & (bongo_state_left | bongo_state_right)) {
|
||||
tmp = bongo_state_left | bongo_state_right;
|
||||
|
@ -87,20 +59,20 @@ void set_bongo_state(lv_obj_t *img, struct zmk_position_state_changed *ev) {
|
|||
} else {
|
||||
if (current_bongo_state ^ (bongo_state_left | bongo_state_right)) {
|
||||
tmp = bongo_state_none;
|
||||
widget->is_right = !widget->is_right;
|
||||
}
|
||||
}
|
||||
|
||||
current_bongo_state = tmp;
|
||||
lv_img_set_src(img, images[current_bongo_state]);
|
||||
lv_img_set_src(widget->obj, images[current_bongo_state]);
|
||||
}
|
||||
|
||||
int bongo_cat_listener(const zmk_event_t *eh) {
|
||||
struct zmk_widget_bongo_cat *widget;
|
||||
struct zmk_position_state_changed *ev = as_zmk_position_state_changed(eh);
|
||||
SYS_SLIST_FOR_EACH_CONTAINER(&widgets, widget, node) { set_bongo_state(widget->obj, ev); }
|
||||
SYS_SLIST_FOR_EACH_CONTAINER(&widgets, widget, node) { set_bongo_state(widget, ev); }
|
||||
return ZMK_EV_EVENT_BUBBLE;
|
||||
}
|
||||
|
||||
ZMK_LISTENER(widget_bongo_cat, bongo_cat_listener)
|
||||
ZMK_SUBSCRIPTION(widget_bongo_cat, zmk_position_state_changed);
|
||||
#endif /* IS_ENABLED(CONFIG_ZMK_WIDGET_BONGO_CAT_INTERACTIVE) */
|
||||
|
|
|
@ -106,7 +106,6 @@ const lv_img_dsc_t right = {
|
|||
.data = right_map,
|
||||
};
|
||||
|
||||
#if IS_ENABLED(CONFIG_ZMK_WIDGET_BONGO_CAT_INTERACTIVE)
|
||||
#ifndef LV_ATTRIBUTE_IMG_NONE
|
||||
#define LV_ATTRIBUTE_IMG_NONE
|
||||
#endif
|
||||
|
@ -208,4 +207,3 @@ const lv_img_dsc_t both = {
|
|||
.data_size = 256,
|
||||
.data = both_map,
|
||||
};
|
||||
#endif /* IS_ENABLED(CONFIG_ZMK_WIDGET_BONGO_CAT_INTERACTIVE) */
|
||||
|
|
Loading…
Add table
Reference in a new issue