Skip to content

Commit

Permalink
screen: Rework for LVGL 8.2
Browse files Browse the repository at this point in the history
  • Loading branch information
xingrz committed Apr 10, 2023
1 parent f397176 commit 94215ef
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 57 deletions.
10 changes: 5 additions & 5 deletions config/app/behaviors/behavior_lvgl_key_press.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
#define LVKP_MSGQ_COUNT 10
K_MSGQ_DEFINE(lvkp_msgq, sizeof(lv_indev_data_t), LVKP_MSGQ_COUNT, 4);

static lv_indev_drv_t indev_drv;
static lv_indev_t *indev = NULL;

static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
Expand All @@ -30,7 +31,7 @@ static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,

lv_indev_data_t data = {
.key = binding->param1,
.state = LV_INDEV_STATE_PR,
.state = LV_INDEV_STATE_PRESSED,
};

int ret = k_msgq_put(&lvkp_msgq, &data, K_NO_WAIT);
Expand All @@ -50,7 +51,7 @@ static int on_keymap_binding_released(struct zmk_behavior_binding *binding,

lv_indev_data_t data = {
.key = binding->param1,
.state = LV_INDEV_STATE_REL,
.state = LV_INDEV_STATE_RELEASED,
};

int ret = k_msgq_put(&lvkp_msgq, &data, K_NO_WAIT);
Expand All @@ -66,21 +67,20 @@ static const struct behavior_driver_api behavior_lvgl_key_press_driver_api = {
.binding_released = on_keymap_binding_released
};

static bool indev_read_cb(lv_indev_drv_t *drv, lv_indev_data_t *data)
static void indev_read_cb(lv_indev_drv_t *drv, lv_indev_data_t *data)
{
ARG_UNUSED(drv);

if (k_msgq_get(&lvkp_msgq, data, K_NO_WAIT) == 0) {
LOG_DBG("Got key %d: %d", data->key, data->state);
}

return k_msgq_num_used_get(&lvkp_msgq) > 0;
data->continue_reading = k_msgq_num_used_get(&lvkp_msgq) > 0;
}

lv_indev_t *behavior_lvgl_get_indev(void)
{
if (!indev) {
lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_KEYPAD;
indev_drv.read_cb = indev_read_cb;
Expand Down
14 changes: 7 additions & 7 deletions config/boards/arm/hw75_dynamic/app/screen/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# SPDX-License-Identifier: MIT

config ZMK_DISPLAY_STATUS_SCREEN_CUSTOM
select LVGL_USE_LABEL
select LVGL_USE_BTN
select LVGL_USE_CONT
select LVGL_USE_LIST
select LVGL_USE_PAGE
select LVGL_USE_GROUP
select LVGL_USE_ANIMATION
select LV_USE_LABEL
select LV_USE_BTN
select LV_USE_LIST
select LV_USE_FLEX
select LV_USE_PAGE
select LV_USE_GROUP
select LV_USE_ANIMATION
81 changes: 37 additions & 44 deletions config/boards/arm/hw75_dynamic/app/screen/layer_status.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ static lv_obj_t *layer_items[KEYMAP_LAYERS_NUM] = {};
static lv_style_t st_name;
static lv_style_t st_list;
static lv_style_t st_item;
static lv_style_t st_item_focused;

struct layer_status_state {
uint8_t index;
};

static void update_layer_status(struct layer_status_state *state)
{
lv_list_focus_btn(layer_list, layer_items[state->index]);
lv_list_focus(layer_items[state->index], LV_ANIM_ON);
lv_group_focus_obj(layer_items[state->index]);
lv_label_set_text(layer_name, layer_names[state->index]);
}

Expand All @@ -78,64 +78,57 @@ ZMK_DISPLAY_WIDGET_LISTENER(layer_status_subscribtion, struct layer_status_state

ZMK_SUBSCRIPTION(layer_status_subscribtion, zmk_layer_state_changed);

static void layer_button_selected(lv_obj_t *obj, lv_event_t event)
static void layer_button_selected(lv_event_t *event)
{
if (event == LV_EVENT_FOCUSED) {
int layer_id = (int)lv_obj_get_user_data(obj);
if (layer_id != zmk_keymap_highest_layer_active()) {
zmk_keymap_layer_to((uint8_t)layer_id);
}
int layer_id = (int)event->user_data;
if (layer_id != zmk_keymap_highest_layer_active()) {
zmk_keymap_layer_to((uint8_t)layer_id);
}
}

int layer_status_init(lv_obj_t *parent, lv_group_t *group)
{
lv_style_init(&st_name);
lv_style_set_pad_ver(&st_name, LV_STATE_DEFAULT, 4);
lv_style_set_pad_hor(&st_name, LV_STATE_DEFAULT, 0);
lv_style_set_text_font(&st_name, LV_STATE_DEFAULT, &zfull_9);
lv_style_set_pad_ver(&st_name, 4);
lv_style_set_text_font(&st_name, &zfull_9);
lv_style_set_text_align(&st_name, LV_TEXT_ALIGN_CENTER);

lv_style_init(&st_list);
lv_style_set_radius(&st_list, LV_STATE_DEFAULT, 0);
lv_style_set_pad_all(&st_list, LV_STATE_DEFAULT, 0);
lv_style_set_margin_all(&st_list, LV_STATE_DEFAULT, 0);
lv_style_set_flex_grow(&st_list, 1);

lv_style_init(&st_item);
lv_style_set_radius(&st_item, LV_STATE_DEFAULT, 2);
lv_style_set_border_width(&st_item, LV_STATE_DEFAULT, 0);
lv_style_set_border_color(&st_item, LV_STATE_DEFAULT, LV_COLOR_BLACK);
lv_style_set_margin_all(&st_item, LV_STATE_DEFAULT, 0);
lv_style_set_bg_opa(&st_item, LV_STATE_DEFAULT, LV_OPA_100);
lv_style_set_bg_color(&st_item, LV_STATE_DEFAULT, LV_COLOR_TRANSP);
lv_style_set_text_color(&st_item, LV_STATE_DEFAULT, LV_COLOR_BLACK);
lv_style_set_bg_color(&st_item, LV_STATE_FOCUSED, LV_COLOR_BLACK);
lv_style_set_text_color(&st_item, LV_STATE_FOCUSED, LV_COLOR_WHITE);
lv_style_set_text_font(&st_item, LV_STATE_DEFAULT, &mono_19);

lv_obj_t *cont = lv_cont_create(parent, NULL);
lv_cont_set_layout(cont, LV_LAYOUT_COLUMN_MID);
lv_cont_set_fit(cont, LV_FIT_NONE);
lv_obj_set_size(cont, SCREEN_W, SCREEN_H);

lv_obj_t *name = layer_name = lv_label_create(cont, NULL);
lv_label_set_align(name, LV_LABEL_ALIGN_CENTER);
lv_obj_add_style(name, LV_LABEL_PART_MAIN, &st_name);

lv_obj_t *list = layer_list = lv_list_create(cont, NULL);
lv_list_set_layout(list, LV_LAYOUT_COLUMN_MID);
lv_obj_add_style(list, LV_OBJ_PART_MAIN, &st_list);
lv_obj_set_size(list, SCREEN_W, SCREEN_H - 20);
lv_style_set_radius(&st_item, 3);
lv_style_set_flex_main_place(&st_item, LV_FLEX_ALIGN_CENTER);
lv_style_set_flex_track_place(&st_item, LV_FLEX_ALIGN_CENTER);
lv_style_set_bg_opa(&st_item, LV_OPA_0);
lv_style_set_bg_color(&st_item, lv_color_black());
lv_style_set_text_color(&st_item, lv_color_black());
lv_style_set_text_font(&st_item, &mono_19);

lv_style_init(&st_item_focused);
lv_style_set_bg_opa(&st_item_focused, LV_OPA_100);
lv_style_set_text_color(&st_item_focused, lv_color_white());

lv_obj_t *cont = lv_obj_create(parent);
lv_obj_set_size(cont, LV_PCT(100), LV_PCT(100));
lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_COLUMN);

lv_obj_t *name = layer_name = lv_label_create(cont);
lv_obj_add_style(name, &st_name, LV_PART_MAIN);
lv_obj_set_size(name, LV_PCT(100), LV_SIZE_CONTENT);

lv_obj_t *list = layer_list = lv_list_create(cont);
lv_obj_add_style(list, &st_list, LV_PART_MAIN);

for (int i = 0; i < KEYMAP_LAYERS_NUM; i++) {
lv_obj_t *btn = layer_items[i] = lv_list_add_btn(list, NULL, layer_icons[i]);
lv_obj_add_style(btn, LV_BTN_PART_MAIN, &st_item);
lv_btn_set_fit(btn, LV_FIT_NONE);
lv_obj_add_style(btn, &st_item, LV_PART_MAIN);
lv_obj_add_style(btn, &st_item_focused, LV_PART_MAIN | LV_STATE_FOCUSED);
lv_obj_set_size(btn, ITEM_SIZE, ITEM_SIZE);
lv_obj_set_user_data(btn, (void *)i);
lv_obj_set_event_cb(btn, layer_button_selected);
lv_obj_add_event_cb(btn, layer_button_selected, LV_EVENT_FOCUSED, (void *)i);

lv_obj_t *label = lv_list_get_btn_label(btn);
lv_label_set_align(label, LV_LABEL_ALIGN_CENTER);
lv_obj_t *label = lv_obj_get_child(btn, 0);
lv_obj_set_flex_grow(label, 0);

lv_group_add_obj(group, btn);
}
Expand Down
2 changes: 1 addition & 1 deletion config/boards/arm/hw75_dynamic/app/screen/status_screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ lv_obj_t *zmk_display_status_screen()
{
lv_group_t *group = lv_group_create();

lv_obj_t *screen = lv_obj_create(NULL, NULL);
lv_obj_t *screen = lv_obj_create(NULL);
layer_status_init(screen, group);

lv_indev_t *indev = behavior_lvgl_get_indev();
Expand Down

0 comments on commit 94215ef

Please sign in to comment.