feat(display): Add label widget
This commit is contained in:
parent
cd25c12ce9
commit
9e6f91f30f
6 changed files with 98 additions and 9 deletions
18
app/include/zmk/display/widgets/label.h
Normal file
18
app/include/zmk/display/widgets/label.h
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020 The ZMK Contributors
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <lvgl.h>
|
||||||
|
#include <zephyr/kernel.h>
|
||||||
|
|
||||||
|
struct zmk_widget_label {
|
||||||
|
sys_snode_t node;
|
||||||
|
lv_obj_t *obj;
|
||||||
|
};
|
||||||
|
|
||||||
|
int zmk_widget_label_init(struct zmk_widget_label *widget, lv_obj_t *parent);
|
||||||
|
lv_obj_t *zmk_widget_label_obj(struct zmk_widget_label *widget);
|
|
@ -9,6 +9,7 @@
|
||||||
#include <zmk/display/widgets/battery_status.h>
|
#include <zmk/display/widgets/battery_status.h>
|
||||||
#include <zmk/display/widgets/layer_status.h>
|
#include <zmk/display/widgets/layer_status.h>
|
||||||
#include <zmk/display/widgets/wpm_status.h>
|
#include <zmk/display/widgets/wpm_status.h>
|
||||||
|
#include <zmk/display/widgets/label.h>
|
||||||
#include <zmk/display/status_screen.h>
|
#include <zmk/display/status_screen.h>
|
||||||
|
|
||||||
#include <zephyr/logging/log.h>
|
#include <zephyr/logging/log.h>
|
||||||
|
@ -34,6 +35,10 @@ static struct zmk_widget_layer_status layer_status_widget;
|
||||||
static struct zmk_widget_wpm_status wpm_status_widget;
|
static struct zmk_widget_wpm_status wpm_status_widget;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if IS_ENABLED(CONFIG_ZMK_WIDGET_LABEL)
|
||||||
|
static struct zmk_widget_label label_widget;
|
||||||
|
#endif
|
||||||
|
|
||||||
lv_obj_t *zmk_display_status_screen() {
|
lv_obj_t *zmk_display_status_screen() {
|
||||||
lv_obj_t *screen;
|
lv_obj_t *screen;
|
||||||
screen = lv_obj_create(NULL);
|
screen = lv_obj_create(NULL);
|
||||||
|
@ -65,5 +70,12 @@ lv_obj_t *zmk_display_status_screen() {
|
||||||
zmk_widget_wpm_status_init(&wpm_status_widget, screen);
|
zmk_widget_wpm_status_init(&wpm_status_widget, screen);
|
||||||
lv_obj_align(zmk_widget_wpm_status_obj(&wpm_status_widget), LV_ALIGN_BOTTOM_RIGHT, 0, 0);
|
lv_obj_align(zmk_widget_wpm_status_obj(&wpm_status_widget), LV_ALIGN_BOTTOM_RIGHT, 0, 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if IS_ENABLED(CONFIG_ZMK_WIDGET_LABEL)
|
||||||
|
zmk_widget_label_init(&label_widget, screen);
|
||||||
|
lv_obj_set_style_text_font(zmk_widget_label_obj(&label_widget), lv_theme_get_font_small(screen),
|
||||||
|
LV_PART_MAIN);
|
||||||
|
lv_obj_align(zmk_widget_label_obj(&label_widget), LV_ALIGN_CENTER, 0, 0);
|
||||||
|
#endif
|
||||||
return screen;
|
return screen;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,3 +6,4 @@ target_sources_ifdef(CONFIG_ZMK_WIDGET_OUTPUT_STATUS app PRIVATE output_status.c
|
||||||
target_sources_ifdef(CONFIG_ZMK_WIDGET_PERIPHERAL_STATUS app PRIVATE peripheral_status.c)
|
target_sources_ifdef(CONFIG_ZMK_WIDGET_PERIPHERAL_STATUS app PRIVATE peripheral_status.c)
|
||||||
target_sources_ifdef(CONFIG_ZMK_WIDGET_LAYER_STATUS app PRIVATE layer_status.c)
|
target_sources_ifdef(CONFIG_ZMK_WIDGET_LAYER_STATUS app PRIVATE layer_status.c)
|
||||||
target_sources_ifdef(CONFIG_ZMK_WIDGET_WPM_STATUS app PRIVATE wpm_status.c)
|
target_sources_ifdef(CONFIG_ZMK_WIDGET_WPM_STATUS app PRIVATE wpm_status.c)
|
||||||
|
target_sources_ifdef(CONFIG_ZMK_WIDGET_LABEL app PRIVATE label.c)
|
||||||
|
|
|
@ -36,4 +36,12 @@ config ZMK_WIDGET_WPM_STATUS
|
||||||
select LV_USE_LABEL
|
select LV_USE_LABEL
|
||||||
select ZMK_WPM
|
select ZMK_WPM
|
||||||
|
|
||||||
|
config ZMK_WIDGET_LABEL
|
||||||
|
bool "Widget for displaying custom messages"
|
||||||
|
select LV_USE_LABEL
|
||||||
|
|
||||||
|
config ZMK_WIDGET_LABEL_TEXT
|
||||||
|
string "Custom message to display, up to 7 characters"
|
||||||
|
default "ZMK"
|
||||||
|
|
||||||
endmenu
|
endmenu
|
||||||
|
|
48
app/src/display/widgets/label.c
Normal file
48
app/src/display/widgets/label.c
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020 The ZMK Contributors
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <zephyr/kernel.h>
|
||||||
|
|
||||||
|
#include <zephyr/logging/log.h>
|
||||||
|
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
||||||
|
|
||||||
|
#include <zmk/display.h>
|
||||||
|
#include <zmk/display/widgets/label.h>
|
||||||
|
#include <zmk/events/activity_state_changed.h>
|
||||||
|
#include <zmk/event_manager.h>
|
||||||
|
|
||||||
|
static sys_slist_t widgets = SYS_SLIST_STATIC_INIT(&widgets);
|
||||||
|
|
||||||
|
struct label_state {};
|
||||||
|
|
||||||
|
static struct label_state get_state(const zmk_event_t *_eh) { return (struct label_state){}; }
|
||||||
|
|
||||||
|
static void set_label_symbol(lv_obj_t *label) {
|
||||||
|
char text[7] = {};
|
||||||
|
|
||||||
|
strcat(text, CONFIG_ZMK_WIDGET_LABEL_TEXT);
|
||||||
|
|
||||||
|
lv_label_set_text(label, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void label_update_cb() {
|
||||||
|
struct zmk_widget_label *widget;
|
||||||
|
SYS_SLIST_FOR_EACH_CONTAINER(&widgets, widget, node) { set_label_symbol(widget->obj); }
|
||||||
|
}
|
||||||
|
|
||||||
|
ZMK_DISPLAY_WIDGET_LISTENER(widget_label, struct label_state, label_update_cb, get_state)
|
||||||
|
ZMK_SUBSCRIPTION(widget_label, zmk_activity_state_changed);
|
||||||
|
|
||||||
|
int zmk_widget_label_init(struct zmk_widget_label *widget, lv_obj_t *parent) {
|
||||||
|
widget->obj = lv_label_create(parent);
|
||||||
|
|
||||||
|
sys_slist_append(&widgets, &widget->node);
|
||||||
|
|
||||||
|
widget_label_init();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
lv_obj_t *zmk_widget_label_obj(struct zmk_widget_label *widget) { return widget->obj; }
|
|
@ -14,15 +14,17 @@ Definition files:
|
||||||
- [zmk/app/src/display/Kconfig](https://github.com/zmkfirmware/zmk/blob/main/app/src/display/Kconfig)
|
- [zmk/app/src/display/Kconfig](https://github.com/zmkfirmware/zmk/blob/main/app/src/display/Kconfig)
|
||||||
- [zmk/app/src/display/widgets/Kconfig](https://github.com/zmkfirmware/zmk/blob/main/app/src/display/widgets/Kconfig)
|
- [zmk/app/src/display/widgets/Kconfig](https://github.com/zmkfirmware/zmk/blob/main/app/src/display/widgets/Kconfig)
|
||||||
|
|
||||||
| Config | Type | Description | Default |
|
| Config | Type | Description | Default |
|
||||||
| -------------------------------------------------- | ---- | -------------------------------------------------------------- | ------- |
|
| -------------------------------------------------- | ------ | -------------------------------------------------------------- | ------- |
|
||||||
| `CONFIG_ZMK_DISPLAY` | bool | Enable support for displays | n |
|
| `CONFIG_ZMK_DISPLAY` | bool | Enable support for displays | n |
|
||||||
| `CONFIG_ZMK_DISPLAY_INVERT` | bool | Invert display colors from black-on-white to white-on-black | n |
|
| `CONFIG_ZMK_DISPLAY_INVERT` | bool | Invert display colors from black-on-white to white-on-black | n |
|
||||||
| `CONFIG_ZMK_WIDGET_LAYER_STATUS` | bool | Enable a widget to show the highest, active layer | y |
|
| `CONFIG_ZMK_WIDGET_LAYER_STATUS` | bool | Enable a widget to show the highest, active layer | y |
|
||||||
| `CONFIG_ZMK_WIDGET_BATTERY_STATUS` | bool | Enable a widget to show battery charge information | y |
|
| `CONFIG_ZMK_WIDGET_BATTERY_STATUS` | bool | Enable a widget to show battery charge information | y |
|
||||||
| `CONFIG_ZMK_WIDGET_BATTERY_STATUS_SHOW_PERCENTAGE` | bool | If battery widget is enabled, show percentage instead of icons | n |
|
| `CONFIG_ZMK_WIDGET_BATTERY_STATUS_SHOW_PERCENTAGE` | bool | If battery widget is enabled, show percentage instead of icons | n |
|
||||||
| `CONFIG_ZMK_WIDGET_OUTPUT_STATUS` | bool | Enable a widget to show the current output (USB/BLE) | y |
|
| `CONFIG_ZMK_WIDGET_OUTPUT_STATUS` | bool | Enable a widget to show the current output (USB/BLE) | y |
|
||||||
| `CONFIG_ZMK_WIDGET_WPM_STATUS` | bool | Enable a widget to show words per minute | n |
|
| `CONFIG_ZMK_WIDGET_WPM_STATUS` | bool | Enable a widget to show words per minute | n |
|
||||||
|
| `ZMK_WIDGET_LABEL` | bool | Enable a widget to display custom messages | n |
|
||||||
|
| `ZMK_WIDGET_LABEL_TEXT` | string | Custom message to display, up to 7 characters | ZMK |
|
||||||
|
|
||||||
Note that `CONFIG_ZMK_DISPLAY_INVERT` setting might not work as expected with custom status screens that utilize images.
|
Note that `CONFIG_ZMK_DISPLAY_INVERT` setting might not work as expected with custom status screens that utilize images.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue