Browse Source
* Battery and output status widgets * Built in status screen combining them. * Ability to define a custom status screen factory function.xmkb
Pete Johanson
4 years ago
18 changed files with 362 additions and 24 deletions
@ -0,0 +1,11 @@ |
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020 Peter Johanson <peter@peterjohanson.com> |
||||||
|
* |
||||||
|
* SPDX-License-Identifier: MIT |
||||||
|
*/ |
||||||
|
|
||||||
|
#pragma once |
||||||
|
|
||||||
|
#include <lvgl.h> |
||||||
|
|
||||||
|
lv_obj_t *zmk_display_status_screen(); |
@ -0,0 +1,18 @@ |
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020 The ZMK Contributors |
||||||
|
* |
||||||
|
* SPDX-License-Identifier: MIT |
||||||
|
*/ |
||||||
|
|
||||||
|
#pragma once |
||||||
|
|
||||||
|
#include <lvgl.h> |
||||||
|
#include <kernel.h> |
||||||
|
|
||||||
|
struct zmk_widget_battery_status { |
||||||
|
sys_snode_t node; |
||||||
|
lv_obj_t *obj; |
||||||
|
}; |
||||||
|
|
||||||
|
int zmk_widget_battery_status_init(struct zmk_widget_battery_status *widget, lv_obj_t *parent); |
||||||
|
lv_obj_t *zmk_widget_battery_status_obj(struct zmk_widget_battery_status *widget); |
@ -0,0 +1,18 @@ |
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020 The ZMK Contributors |
||||||
|
* |
||||||
|
* SPDX-License-Identifier: MIT |
||||||
|
*/ |
||||||
|
|
||||||
|
#pragma once |
||||||
|
|
||||||
|
#include <lvgl.h> |
||||||
|
#include <kernel.h> |
||||||
|
|
||||||
|
struct zmk_widget_output_status { |
||||||
|
sys_snode_t node; |
||||||
|
lv_obj_t *obj; |
||||||
|
}; |
||||||
|
|
||||||
|
int zmk_widget_output_status_init(struct zmk_widget_output_status *widget, lv_obj_t *parent); |
||||||
|
lv_obj_t *zmk_widget_output_status_obj(struct zmk_widget_output_status *widget); |
@ -0,0 +1,5 @@ |
|||||||
|
|
||||||
|
target_sources_ifdef(CONFIG_ZMK_DISPLAY app PRIVATE main.c) |
||||||
|
target_sources_ifdef(CONFIG_ZMK_DISPLAY_STATUS_SCREEN_BUILT_IN app PRIVATE status_screen.c) |
||||||
|
|
||||||
|
add_subdirectory(widgets/) |
@ -0,0 +1,32 @@ |
|||||||
|
|
||||||
|
menuconfig ZMK_DISPLAY |
||||||
|
bool "Enable ZMK Display" |
||||||
|
default n |
||||||
|
select DISPLAY |
||||||
|
select LVGL |
||||||
|
select LVGL_THEMES |
||||||
|
select LVGL_THEME_MONO |
||||||
|
|
||||||
|
if ZMK_DISPLAY |
||||||
|
|
||||||
|
choice LVGL_TXT_ENC |
||||||
|
default LVGL_TXT_ENC_UTF8 |
||||||
|
|
||||||
|
endchoice |
||||||
|
|
||||||
|
choice ZMK_DISPLAY_STATUS_SCREEN |
||||||
|
prompt "Default status screen for displays" |
||||||
|
default ZMK_DISPLAY_STATUS_SCREEN_BUILT_IN |
||||||
|
|
||||||
|
config ZMK_DISPLAY_STATUS_SCREEN_BUILT_IN |
||||||
|
bool "Built in status screen" |
||||||
|
select LVGL_OBJ_LABEL |
||||||
|
|
||||||
|
config ZMK_DISPLAY_STATUS_SCREEN_CUSTOM |
||||||
|
bool "Custom status screen" |
||||||
|
|
||||||
|
endchoice |
||||||
|
|
||||||
|
rsource "widgets/Kconfig" |
||||||
|
|
||||||
|
endif |
@ -0,0 +1,46 @@ |
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020 Peter Johanson <peter@peterjohanson.com> |
||||||
|
* |
||||||
|
* SPDX-License-Identifier: MIT |
||||||
|
*/ |
||||||
|
|
||||||
|
#include <zmk/display/widgets/output_status.h> |
||||||
|
#include <zmk/display/widgets/battery_status.h> |
||||||
|
#include <zmk/display/status_screen.h> |
||||||
|
|
||||||
|
#include <logging/log.h> |
||||||
|
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); |
||||||
|
|
||||||
|
#if IS_ENABLED(CONFIG_ZMK_WIDGET_BATTERY_STATUS) |
||||||
|
static struct zmk_widget_battery_status battery_status_widget; |
||||||
|
#endif |
||||||
|
|
||||||
|
#if IS_ENABLED(CONFIG_ZMK_WIDGET_OUTPUT_STATUS) |
||||||
|
static struct zmk_widget_output_status output_status_widget; |
||||||
|
#endif |
||||||
|
|
||||||
|
lv_obj_t *zmk_display_status_screen() { |
||||||
|
lv_obj_t *screen; |
||||||
|
lv_obj_t *zmk_version_label; |
||||||
|
|
||||||
|
screen = lv_obj_create(NULL, NULL); |
||||||
|
|
||||||
|
zmk_version_label = lv_label_create(screen, NULL); |
||||||
|
|
||||||
|
#if IS_ENABLED(CONFIG_ZMK_WIDGET_BATTERY_STATUS) |
||||||
|
zmk_widget_battery_status_init(&battery_status_widget, screen); |
||||||
|
lv_obj_align(zmk_widget_battery_status_obj(&battery_status_widget), NULL, LV_ALIGN_IN_TOP_RIGHT, |
||||||
|
0, 0); |
||||||
|
#endif |
||||||
|
|
||||||
|
#if IS_ENABLED(CONFIG_ZMK_WIDGET_OUTPUT_STATUS) |
||||||
|
zmk_widget_output_status_init(&output_status_widget, screen); |
||||||
|
lv_obj_align(zmk_widget_output_status_obj(&output_status_widget), NULL, LV_ALIGN_IN_TOP_LEFT, 0, |
||||||
|
0); |
||||||
|
#endif |
||||||
|
|
||||||
|
lv_label_set_text(zmk_version_label, "ZMK v0.1.0"); |
||||||
|
lv_obj_align(zmk_version_label, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0); |
||||||
|
|
||||||
|
return screen; |
||||||
|
} |
@ -0,0 +1,3 @@ |
|||||||
|
|
||||||
|
target_sources_ifdef(CONFIG_ZMK_WIDGET_BATTERY_STATUS app PRIVATE battery_status.c) |
||||||
|
target_sources_ifdef(CONFIG_ZMK_WIDGET_OUTPUT_STATUS app PRIVATE output_status.c) |
@ -0,0 +1,18 @@ |
|||||||
|
|
||||||
|
menu "ZMK Display Widgets" |
||||||
|
|
||||||
|
config ZMK_WIDGET_BATTERY_STATUS |
||||||
|
bool "Widget for battery charge information, using small icons" |
||||||
|
depends on BT |
||||||
|
default y if BT |
||||||
|
select LVGL_OBJ_LABEL |
||||||
|
select LVGL_BUILD_IN_FONT_ROBOTO_16 |
||||||
|
|
||||||
|
config ZMK_WIDGET_OUTPUT_STATUS |
||||||
|
bool "Widget for keyboard output status icons" |
||||||
|
depends on BT |
||||||
|
default y if BT |
||||||
|
select LVGL_OBJ_LABEL |
||||||
|
select LVGL_BUILD_IN_FONT_ROBOTO_16 |
||||||
|
|
||||||
|
endmenu |
@ -0,0 +1,85 @@ |
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020 The ZMK Contributors |
||||||
|
* |
||||||
|
* SPDX-License-Identifier: MIT |
||||||
|
*/ |
||||||
|
|
||||||
|
#include <bluetooth/services/bas.h> |
||||||
|
|
||||||
|
#include <logging/log.h> |
||||||
|
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); |
||||||
|
|
||||||
|
#include <zmk/display/widgets/battery_status.h> |
||||||
|
#include <zmk/usb.h> |
||||||
|
#include <zmk/events/usb-conn-state-changed.h> |
||||||
|
#include <zmk/event-manager.h> |
||||||
|
#include <zmk/events/battery-state-changed.h> |
||||||
|
|
||||||
|
static sys_slist_t widgets = SYS_SLIST_STATIC_INIT(&widgets); |
||||||
|
static lv_style_t label_style; |
||||||
|
|
||||||
|
void battery_status_init() { |
||||||
|
if (label_style.text.font != NULL) { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
lv_style_copy(&label_style, &lv_style_plain); |
||||||
|
label_style.text.color = LV_COLOR_BLACK; |
||||||
|
label_style.text.font = &lv_font_roboto_16; |
||||||
|
label_style.text.letter_space = 1; |
||||||
|
label_style.text.line_space = 1; |
||||||
|
} |
||||||
|
|
||||||
|
void set_battery_symbol(lv_obj_t *label) { |
||||||
|
char text[2] = " "; |
||||||
|
u8_t level = bt_gatt_bas_get_battery_level(); |
||||||
|
|
||||||
|
#if IS_ENABLED(CONFIG_USB) |
||||||
|
if (zmk_usb_is_powered()) { |
||||||
|
strcpy(text, LV_SYMBOL_CHARGE); |
||||||
|
} |
||||||
|
#endif /* IS_ENABLED(CONFIG_USB) */ |
||||||
|
|
||||||
|
if (level > 95) { |
||||||
|
strcat(text, LV_SYMBOL_BATTERY_FULL); |
||||||
|
} else if (level > 65) { |
||||||
|
strcat(text, LV_SYMBOL_BATTERY_3); |
||||||
|
} else if (level > 35) { |
||||||
|
strcat(text, LV_SYMBOL_BATTERY_2); |
||||||
|
} else if (level > 5) { |
||||||
|
strcat(text, LV_SYMBOL_BATTERY_1); |
||||||
|
} else { |
||||||
|
strcat(text, LV_SYMBOL_BATTERY_EMPTY); |
||||||
|
} |
||||||
|
lv_label_set_text(label, text); |
||||||
|
} |
||||||
|
|
||||||
|
int zmk_widget_battery_status_init(struct zmk_widget_battery_status *widget, lv_obj_t *parent) { |
||||||
|
battery_status_init(); |
||||||
|
widget->obj = lv_label_create(parent, NULL); |
||||||
|
lv_label_set_style(widget->obj, LV_LABEL_STYLE_MAIN, &label_style); |
||||||
|
|
||||||
|
lv_obj_set_size(widget->obj, 40, 15); |
||||||
|
set_battery_symbol(widget->obj); |
||||||
|
|
||||||
|
sys_slist_append(&widgets, &widget->node); |
||||||
|
|
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
lv_obj_t *zmk_widget_battery_status_obj(struct zmk_widget_battery_status *widget) { |
||||||
|
LOG_DBG("Label: %p", widget->obj); |
||||||
|
return widget->obj; |
||||||
|
} |
||||||
|
|
||||||
|
int battery_status_listener(const struct zmk_event_header *eh) { |
||||||
|
struct zmk_widget_battery_status *widget; |
||||||
|
SYS_SLIST_FOR_EACH_CONTAINER(&widgets, widget, node) { set_battery_symbol(widget->obj); } |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
ZMK_LISTENER(widget_battery_status, battery_status_listener) |
||||||
|
ZMK_SUBSCRIPTION(widget_battery_status, battery_state_changed); |
||||||
|
#if IS_ENABLED(CONFIG_USB) |
||||||
|
ZMK_SUBSCRIPTION(widget_battery_status, usb_conn_state_changed); |
||||||
|
#endif /* IS_ENABLED(CONFIG_USB) */ |
@ -0,0 +1,95 @@ |
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020 The ZMK Contributors |
||||||
|
* |
||||||
|
* SPDX-License-Identifier: MIT |
||||||
|
*/ |
||||||
|
|
||||||
|
#include <bluetooth/services/bas.h> |
||||||
|
|
||||||
|
#include <logging/log.h> |
||||||
|
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); |
||||||
|
|
||||||
|
#include <zmk/display/widgets/output_status.h> |
||||||
|
#include <zmk/event-manager.h> |
||||||
|
#include <zmk/events/usb-conn-state-changed.h> |
||||||
|
#include <zmk/events/ble-active-profile-changed.h> |
||||||
|
#include <zmk/usb.h> |
||||||
|
#include <zmk/ble.h> |
||||||
|
#include <zmk/endpoints.h> |
||||||
|
|
||||||
|
static sys_slist_t widgets = SYS_SLIST_STATIC_INIT(&widgets); |
||||||
|
static lv_style_t label_style; |
||||||
|
|
||||||
|
void output_status_init() { |
||||||
|
if (label_style.text.font != NULL) { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
lv_style_copy(&label_style, &lv_style_plain); |
||||||
|
label_style.text.color = LV_COLOR_BLACK; |
||||||
|
label_style.text.font = &lv_font_roboto_16; |
||||||
|
label_style.text.letter_space = 1; |
||||||
|
label_style.text.line_space = 1; |
||||||
|
} |
||||||
|
|
||||||
|
void set_status_symbol(lv_obj_t *label) { |
||||||
|
enum zmk_endpoint selected_endpoint = zmk_endpoints_selected(); |
||||||
|
bool active_profile_connected = zmk_ble_active_profile_is_connected(); |
||||||
|
bool active_profie_bonded = !zmk_ble_active_profile_is_open(); |
||||||
|
u8_t active_profile_index = zmk_ble_active_profile_index(); |
||||||
|
char text[6] = {}; |
||||||
|
|
||||||
|
switch (selected_endpoint) { |
||||||
|
case ZMK_ENDPOINT_USB: |
||||||
|
LOG_DBG("USB, BOY!"); |
||||||
|
strcat(text, LV_SYMBOL_USB " "); |
||||||
|
break; |
||||||
|
case ZMK_ENDPOINT_BLE: |
||||||
|
if (active_profie_bonded) { |
||||||
|
if (active_profile_connected) { |
||||||
|
LOG_DBG("Bonded & connected!"); |
||||||
|
sprintf(text, LV_SYMBOL_WIFI "%i " LV_SYMBOL_OK, active_profile_index); |
||||||
|
} else { |
||||||
|
LOG_DBG("Bonded but not connected!"); |
||||||
|
sprintf(text, LV_SYMBOL_WIFI "%i " LV_SYMBOL_CLOSE, active_profile_index); |
||||||
|
} |
||||||
|
} else { |
||||||
|
LOG_DBG("NOT Bonded!"); |
||||||
|
sprintf(text, LV_SYMBOL_WIFI "%i " LV_SYMBOL_SETTINGS, active_profile_index); |
||||||
|
} |
||||||
|
break; |
||||||
|
} |
||||||
|
|
||||||
|
lv_label_set_text(label, text); |
||||||
|
} |
||||||
|
|
||||||
|
int zmk_widget_output_status_init(struct zmk_widget_output_status *widget, lv_obj_t *parent) { |
||||||
|
output_status_init(); |
||||||
|
widget->obj = lv_label_create(parent, NULL); |
||||||
|
lv_label_set_style(widget->obj, LV_LABEL_STYLE_MAIN, &label_style); |
||||||
|
|
||||||
|
lv_obj_set_size(widget->obj, 40, 15); |
||||||
|
set_status_symbol(widget->obj); |
||||||
|
|
||||||
|
sys_slist_append(&widgets, &widget->node); |
||||||
|
|
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
lv_obj_t *zmk_widget_output_status_obj(struct zmk_widget_output_status *widget) { |
||||||
|
return widget->obj; |
||||||
|
} |
||||||
|
|
||||||
|
int output_status_listener(const struct zmk_event_header *eh) { |
||||||
|
struct zmk_widget_output_status *widget; |
||||||
|
SYS_SLIST_FOR_EACH_CONTAINER(&widgets, widget, node) { set_status_symbol(widget->obj); } |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
ZMK_LISTENER(widget_output_status, output_status_listener) |
||||||
|
#if defined(CONFIG_USB) |
||||||
|
ZMK_SUBSCRIPTION(widget_output_status, usb_conn_state_changed); |
||||||
|
#endif |
||||||
|
#if defined(CONFIG_ZMK_BLE) |
||||||
|
ZMK_SUBSCRIPTION(widget_output_status, ble_active_profile_changed); |
||||||
|
#endif |
Loading…
Reference in new issue