forked from kofal.net/zmk
refactor: Split endpoint to transport and instance
Changed the endpoints code to rename the existing endpoint types to "transport" and add the concept of "endpoint instances". A transport is the method by which data is sent, while instances allow describing multiple endpoints that use the same transport (e.g. bluetooth profiles) Also added new APIs to get the total number of possible endpoint instances and assign each instance a unique index, which can be used for tracking separate state for each endpoint in other code files.
This commit is contained in:
committed by
Pete Johanson
parent
2f05ad55ca
commit
651ed05e9a
@@ -14,9 +14,8 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
||||
#include <zmk/display.h>
|
||||
#include "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/events/endpoint_selection_changed.h>
|
||||
#include <zmk/events/endpoint_changed.h>
|
||||
#include <zmk/usb.h>
|
||||
#include <zmk/ble.h>
|
||||
#include <zmk/endpoints.h>
|
||||
@@ -39,31 +38,31 @@ LV_IMG_DECLARE(USB_connected);
|
||||
static sys_slist_t widgets = SYS_SLIST_STATIC_INIT(&widgets);
|
||||
|
||||
struct output_status_state {
|
||||
enum zmk_endpoint selected_endpoint;
|
||||
struct zmk_endpoint_instance selected_endpoint;
|
||||
bool active_profile_connected;
|
||||
bool active_profile_bonded;
|
||||
uint8_t active_profile_index;
|
||||
};
|
||||
|
||||
static struct output_status_state get_state(const zmk_event_t *_eh) {
|
||||
return (struct output_status_state){.selected_endpoint = zmk_endpoints_selected(),
|
||||
.active_profile_connected =
|
||||
zmk_ble_active_profile_is_connected(),
|
||||
.active_profile_bonded = !zmk_ble_active_profile_is_open(),
|
||||
.active_profile_index = zmk_ble_active_profile_index()};
|
||||
return (struct output_status_state){
|
||||
.selected_endpoint = zmk_endpoints_selected(),
|
||||
.active_profile_connected = zmk_ble_active_profile_is_connected(),
|
||||
.active_profile_bonded = !zmk_ble_active_profile_is_open(),
|
||||
};
|
||||
;
|
||||
}
|
||||
|
||||
static void set_status_symbol(lv_obj_t *icon, struct output_status_state state) {
|
||||
switch (state.selected_endpoint) {
|
||||
case ZMK_ENDPOINT_USB:
|
||||
switch (state.selected_endpoint.transport) {
|
||||
case ZMK_TRANSPORT_USB:
|
||||
lv_img_set_src(icon, &USB_connected);
|
||||
break;
|
||||
case ZMK_ENDPOINT_BLE:
|
||||
case ZMK_TRANSPORT_BLE:
|
||||
if (state.active_profile_bonded) {
|
||||
if (state.active_profile_connected) {
|
||||
// sprintf(text, LV_SYMBOL_BLUETOOTH "%i " LV_SYMBOL_OK, active_profile_index);
|
||||
switch (state.active_profile_index) {
|
||||
switch (state.selected_endpoint.ble.profile_index) {
|
||||
case 0:
|
||||
lv_img_set_src(icon, &bluetooth_connected_1);
|
||||
break;
|
||||
@@ -84,7 +83,7 @@ static void set_status_symbol(lv_obj_t *icon, struct output_status_state state)
|
||||
lv_img_set_src(icon, &bluetooth_disconnected_right);
|
||||
}
|
||||
} else {
|
||||
switch (state.active_profile_index) {
|
||||
switch (state.selected_endpoint.ble.profile_index) {
|
||||
case 0:
|
||||
lv_img_set_src(icon, &bluetooth_advertising_1);
|
||||
break;
|
||||
@@ -113,11 +112,9 @@ static void output_status_update_cb(struct output_status_state 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 IS_ENABLED(CONFIG_USB_DEVICE_STACK)
|
||||
ZMK_SUBSCRIPTION(widget_output_status, zmk_usb_conn_state_changed);
|
||||
#endif
|
||||
ZMK_SUBSCRIPTION(widget_output_status, zmk_endpoint_changed);
|
||||
// We don't get an endpoint changed event when the active profile connects/disconnects
|
||||
// but there wasn't another endpoint to switch from/to, so update on BLE events too.
|
||||
#if defined(CONFIG_ZMK_BLE)
|
||||
ZMK_SUBSCRIPTION(widget_output_status, zmk_ble_active_profile_changed);
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user