Skip to content

Commit

Permalink
refactor: Split endpoint to transport and instance
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
joelspadin authored and ReFil committed Oct 18, 2023
1 parent 7fe9ecd commit ffecfd9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions app/boards/arm/corneish_zen/widgets/output_status.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ static struct output_status_state get_state(const zmk_event_t *_eh) {
.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) {
Expand Down
4 changes: 2 additions & 2 deletions app/include/zmk/endpoints.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
*/
#define ZMK_ENDPOINT_COUNT (ZMK_ENDPOINT_USB_COUNT + ZMK_ENDPOINT_BLE_COUNT)

bool zmk_endpoint_instance_eq(struct zmk_endpoint_instance a, struct zmk_endpoint_instance b);
bool zmk_endpoint_instance_equals(struct zmk_endpoint_instance a, struct zmk_endpoint_instance b);

/**
* Writes a string identifying an endpoint instance.
Expand All @@ -45,7 +45,7 @@ bool zmk_endpoint_instance_eq(struct zmk_endpoint_instance a, struct zmk_endpoin
*
* @returns Number of characters written.
*/
int zmk_endpoint_instance_to_str(struct zmk_endpoint_instance endpoint, char *str, size_t len);
int zmk_endpoint_instance_print(char *str, size_t len, struct zmk_endpoint_instance endpoint);

/**
* Gets a unique index for an endpoint instance. This can be used together with
Expand Down
8 changes: 4 additions & 4 deletions app/src/endpoints.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static int endpoints_save_preferred(void) {
#endif
}

bool zmk_endpoint_instance_eq(struct zmk_endpoint_instance a, struct zmk_endpoint_instance b) {
bool zmk_endpoint_instance_equals(struct zmk_endpoint_instance a, struct zmk_endpoint_instance b) {
if (a.transport != b.transport) {
return false;
}
Expand All @@ -65,7 +65,7 @@ bool zmk_endpoint_instance_eq(struct zmk_endpoint_instance a, struct zmk_endpoin
return false;
}

int zmk_endpoint_instance_to_str(struct zmk_endpoint_instance endpoint, char *str, size_t len) {
int zmk_endpoint_instance_print(char *str, size_t len, struct zmk_endpoint_instance endpoint) {
switch (endpoint.transport) {
case ZMK_TRANSPORT_USB:
return snprintf(str, len, "USB");
Expand Down Expand Up @@ -305,14 +305,14 @@ static void disconnect_current_endpoint() {
static void update_current_endpoint(void) {
struct zmk_endpoint_instance new_instance = get_selected_instance();

if (!zmk_endpoint_instance_eq(new_instance, current_instance)) {
if (!zmk_endpoint_instance_equals(new_instance, current_instance)) {
// Cancel all current keypresses so keys don't stay held on the old endpoint.
disconnect_current_endpoint();

current_instance = new_instance;

char endpoint_str[ZMK_ENDPOINT_STR_LEN];
zmk_endpoint_instance_to_str(current_instance, endpoint_str, sizeof(endpoint_str));
zmk_endpoint_instance_print(endpoint_str, sizeof(endpoint_str), current_instance);
LOG_INF("Endpoint changed: %s", endpoint_str);

ZMK_EVENT_RAISE(
Expand Down

0 comments on commit ffecfd9

Please sign in to comment.