feat(display): Always display current BLE profile

Display USB or BLE active transport symbol (USB if BLE is disabled)

To the right, If BLE is enabled, always show the current BLE profile
index and its connection status (not bonded / disconnected / connected).

The previous behavior was to show the USB symbol only, if that was the
active transport. It's useful to see the active BLE profile index and
status even if it is not the active transport. It is what you will
connect to if you toggle USB to BLE. It is possible to browse for a free
profile without unplugging USB.
This commit is contained in:
Andrew Howe 2025-06-24 20:19:06 +00:00
parent 6b44d33db2
commit a2c337e0c8
1 changed files with 24 additions and 13 deletions

View File

@ -22,12 +22,14 @@ static sys_slist_t widgets = SYS_SLIST_STATIC_INIT(&widgets);
struct output_status_state {
struct zmk_endpoint_instance selected_endpoint;
int active_profile_index;
bool active_profile_connected;
bool active_profile_bonded;
};
static struct output_status_state get_state(const zmk_event_t *_eh) {
return (struct output_status_state){.selected_endpoint = zmk_endpoints_selected(),
.active_profile_index = zmk_ble_active_profile_index(),
.active_profile_connected =
zmk_ble_active_profile_is_connected(),
.active_profile_bonded = !zmk_ble_active_profile_is_open()};
@ -35,29 +37,38 @@ static struct output_status_state get_state(const zmk_event_t *_eh) {
}
static void set_status_symbol(lv_obj_t *label, struct output_status_state state) {
#if defined(CONFIG_ZMK_BLE)
char text[20] = {};
const char *transport_symbol = "?";
switch (state.selected_endpoint.transport) {
case ZMK_TRANSPORT_USB:
strcat(text, LV_SYMBOL_USB);
transport_symbol = LV_SYMBOL_USB;
break;
case ZMK_TRANSPORT_BLE:
if (state.active_profile_bonded) {
if (state.active_profile_connected) {
snprintf(text, sizeof(text), LV_SYMBOL_WIFI " %i " LV_SYMBOL_OK,
state.selected_endpoint.ble.profile_index + 1);
} else {
snprintf(text, sizeof(text), LV_SYMBOL_WIFI " %i " LV_SYMBOL_CLOSE,
state.selected_endpoint.ble.profile_index + 1);
}
} else {
snprintf(text, sizeof(text), LV_SYMBOL_WIFI " %i " LV_SYMBOL_SETTINGS,
state.selected_endpoint.ble.profile_index + 1);
}
transport_symbol = LV_SYMBOL_WIFI;
break;
}
const char *connection_symbol = LV_SYMBOL_SETTINGS;
if (state.active_profile_bonded) {
if (state.active_profile_connected) {
connection_symbol = LV_SYMBOL_OK;
} else {
connection_symbol = LV_SYMBOL_CLOSE;
}
}
// Display active transport (USB/BLE), active BLE profile index (1-based) and connection status
// of active BLE profile
snprintf(text, sizeof(text), "%s %i %s", transport_symbol, state.active_profile_index + 1,
connection_symbol);
lv_label_set_text(label, text);
#else // !defined(CONFIG_ZMK_BLE)
// If BLE is not enabled, just show USB symbol
lv_label_set_text(label, LV_SYMBOL_USB);
#endif
}
static void output_status_update_cb(struct output_status_state state) {