|
|
@ -4,11 +4,13 @@ |
|
|
|
* SPDX-License-Identifier: MIT |
|
|
|
* SPDX-License-Identifier: MIT |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <kernel.h> |
|
|
|
#include <bluetooth/services/bas.h> |
|
|
|
#include <bluetooth/services/bas.h> |
|
|
|
|
|
|
|
|
|
|
|
#include <logging/log.h> |
|
|
|
#include <logging/log.h> |
|
|
|
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); |
|
|
|
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <zmk/display.h> |
|
|
|
#include <zmk/display/widgets/output_status.h> |
|
|
|
#include <zmk/display/widgets/output_status.h> |
|
|
|
#include <zmk/event_manager.h> |
|
|
|
#include <zmk/event_manager.h> |
|
|
|
#include <zmk/events/usb_conn_state_changed.h> |
|
|
|
#include <zmk/events/usb_conn_state_changed.h> |
|
|
@ -23,7 +25,14 @@ static lv_style_t label_style; |
|
|
|
|
|
|
|
|
|
|
|
static bool style_initialized = false; |
|
|
|
static bool style_initialized = false; |
|
|
|
|
|
|
|
|
|
|
|
void output_status_init() { |
|
|
|
struct output_status_state { |
|
|
|
|
|
|
|
enum zmk_endpoint selected_endpoint; |
|
|
|
|
|
|
|
bool active_profile_connected; |
|
|
|
|
|
|
|
bool active_profile_bonded; |
|
|
|
|
|
|
|
uint8_t active_profile_index; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void output_status_init() { |
|
|
|
if (style_initialized) { |
|
|
|
if (style_initialized) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
@ -36,26 +45,34 @@ void output_status_init() { |
|
|
|
lv_style_set_text_line_space(&label_style, LV_STATE_DEFAULT, 1); |
|
|
|
lv_style_set_text_line_space(&label_style, LV_STATE_DEFAULT, 1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void set_status_symbol(lv_obj_t *label) { |
|
|
|
static struct output_status_state get_state(const zmk_event_t *_eh) { |
|
|
|
enum zmk_endpoint selected_endpoint = zmk_endpoints_selected(); |
|
|
|
return (struct output_status_state){.selected_endpoint = zmk_endpoints_selected(), |
|
|
|
bool active_profile_connected = zmk_ble_active_profile_is_connected(); |
|
|
|
.active_profile_connected = |
|
|
|
bool active_profie_bonded = !zmk_ble_active_profile_is_open(); |
|
|
|
zmk_ble_active_profile_is_connected(), |
|
|
|
uint8_t active_profile_index = zmk_ble_active_profile_index(); |
|
|
|
.active_profile_bonded = !zmk_ble_active_profile_is_open(), |
|
|
|
|
|
|
|
.active_profile_index = zmk_ble_active_profile_index()}; |
|
|
|
|
|
|
|
; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void set_status_symbol(lv_obj_t *label, struct output_status_state state) { |
|
|
|
char text[6] = {}; |
|
|
|
char text[6] = {}; |
|
|
|
|
|
|
|
|
|
|
|
switch (selected_endpoint) { |
|
|
|
switch (state.selected_endpoint) { |
|
|
|
case ZMK_ENDPOINT_USB: |
|
|
|
case ZMK_ENDPOINT_USB: |
|
|
|
strcat(text, LV_SYMBOL_USB " "); |
|
|
|
strcat(text, LV_SYMBOL_USB " "); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case ZMK_ENDPOINT_BLE: |
|
|
|
case ZMK_ENDPOINT_BLE: |
|
|
|
if (active_profie_bonded) { |
|
|
|
if (state.active_profile_bonded) { |
|
|
|
if (active_profile_connected) { |
|
|
|
if (state.active_profile_connected) { |
|
|
|
sprintf(text, LV_SYMBOL_WIFI "%i " LV_SYMBOL_OK, active_profile_index); |
|
|
|
snprintf(text, sizeof(text), LV_SYMBOL_WIFI "%i " LV_SYMBOL_OK, |
|
|
|
|
|
|
|
state.active_profile_index); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
sprintf(text, LV_SYMBOL_WIFI "%i " LV_SYMBOL_CLOSE, active_profile_index); |
|
|
|
snprintf(text, sizeof(text), LV_SYMBOL_WIFI "%i " LV_SYMBOL_CLOSE, |
|
|
|
|
|
|
|
state.active_profile_index); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
sprintf(text, LV_SYMBOL_WIFI "%i " LV_SYMBOL_SETTINGS, active_profile_index); |
|
|
|
snprintf(text, sizeof(text), LV_SYMBOL_WIFI "%i " LV_SYMBOL_SETTINGS, |
|
|
|
|
|
|
|
state.active_profile_index); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
@ -63,35 +80,36 @@ void set_status_symbol(lv_obj_t *label) { |
|
|
|
lv_label_set_text(label, text); |
|
|
|
lv_label_set_text(label, text); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void output_status_update_cb(struct output_status_state state) { |
|
|
|
|
|
|
|
struct zmk_widget_output_status *widget; |
|
|
|
|
|
|
|
SYS_SLIST_FOR_EACH_CONTAINER(&widgets, widget, node) { set_status_symbol(widget->obj, state); } |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ZMK_DISPLAY_WIDGET_LISTENER(widget_output_status, struct output_status_state, |
|
|
|
|
|
|
|
output_status_update_cb, get_state) |
|
|
|
|
|
|
|
ZMK_SUBSCRIPTION(widget_output_status, zmk_endpoint_selection_changed); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(CONFIG_USB) |
|
|
|
|
|
|
|
ZMK_SUBSCRIPTION(widget_output_status, zmk_usb_conn_state_changed); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
#if defined(CONFIG_ZMK_BLE) |
|
|
|
|
|
|
|
ZMK_SUBSCRIPTION(widget_output_status, zmk_ble_active_profile_changed); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
int zmk_widget_output_status_init(struct zmk_widget_output_status *widget, lv_obj_t *parent) { |
|
|
|
int zmk_widget_output_status_init(struct zmk_widget_output_status *widget, lv_obj_t *parent) { |
|
|
|
output_status_init(); |
|
|
|
output_status_init(); |
|
|
|
|
|
|
|
|
|
|
|
widget->obj = lv_label_create(parent, NULL); |
|
|
|
widget->obj = lv_label_create(parent, NULL); |
|
|
|
lv_obj_add_style(widget->obj, LV_LABEL_PART_MAIN, &label_style); |
|
|
|
lv_obj_add_style(widget->obj, LV_LABEL_PART_MAIN, &label_style); |
|
|
|
|
|
|
|
|
|
|
|
lv_obj_set_size(widget->obj, 40, 15); |
|
|
|
lv_obj_set_size(widget->obj, 40, 15); |
|
|
|
set_status_symbol(widget->obj); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sys_slist_append(&widgets, &widget->node); |
|
|
|
sys_slist_append(&widgets, &widget->node); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
widget_output_status_init(); |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
lv_obj_t *zmk_widget_output_status_obj(struct zmk_widget_output_status *widget) { |
|
|
|
lv_obj_t *zmk_widget_output_status_obj(struct zmk_widget_output_status *widget) { |
|
|
|
return widget->obj; |
|
|
|
return widget->obj; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int output_status_listener(const zmk_event_t *eh) { |
|
|
|
|
|
|
|
struct zmk_widget_output_status *widget; |
|
|
|
|
|
|
|
SYS_SLIST_FOR_EACH_CONTAINER(&widgets, widget, node) { set_status_symbol(widget->obj); } |
|
|
|
|
|
|
|
return ZMK_EV_EVENT_BUBBLE; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ZMK_LISTENER(widget_output_status, output_status_listener) |
|
|
|
|
|
|
|
ZMK_SUBSCRIPTION(widget_output_status, zmk_endpoint_selection_changed); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(CONFIG_USB) |
|
|
|
|
|
|
|
ZMK_SUBSCRIPTION(widget_output_status, zmk_usb_conn_state_changed); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
#if defined(CONFIG_ZMK_BLE) |
|
|
|
|
|
|
|
ZMK_SUBSCRIPTION(widget_output_status, zmk_ble_active_profile_changed); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|