Skip to content

Commit

Permalink
feat(underglow): support command for displaying board statuses
Browse files Browse the repository at this point in the history
  • Loading branch information
nVitius committed Jul 1, 2024
1 parent 7be955f commit 903d24f
Show file tree
Hide file tree
Showing 9 changed files with 424 additions and 16 deletions.
26 changes: 26 additions & 0 deletions app/dts/bindings/zmk,underglow-indicators.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright (c) 2020, The ZMK Contributors
# SPDX-License-Identifier: MIT

description: Underglow indicators

compatible: "zmk,underglow-indicators"

properties:
bat-lhs:
type: array
bat-rhs:
type: array
num-lock:
type: int
caps-lock:
type: int
scroll-lock:
type: int
layer-state:
type: array
ble-profiles:
type: array
usb-state:
type: int
output-fallback:
type: int
2 changes: 2 additions & 0 deletions app/include/dt-bindings/zmk/rgb.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define RGB_EFR_CMD 12
#define RGB_EFS_CMD 13
#define RGB_COLOR_HSB_CMD 14
#define RGB_STATUS_CMD 15

#define RGB_TOG RGB_TOG_CMD 0
#define RGB_ON RGB_ON_CMD 0
Expand All @@ -33,6 +34,7 @@
#define RGB_SPD RGB_SPD_CMD 0
#define RGB_EFF RGB_EFF_CMD 0
#define RGB_EFR RGB_EFR_CMD 0
#define RGB_STATUS RGB_STATUS_CMD 0
#define RGB_COLOR_HSB_VAL(h, s, v) (((h) << 16) + ((s) << 8) + (v))
#define RGB_COLOR_HSB(h, s, v) RGB_COLOR_HSB_CMD##(RGB_COLOR_HSB_VAL(h, s, v))
#define RGB_COLOR_HSV RGB_COLOR_HSB
1 change: 1 addition & 0 deletions app/include/zmk/ble.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ int zmk_ble_profile_index(const bt_addr_le_t *addr);
bt_addr_le_t *zmk_ble_active_profile_addr(void);
bool zmk_ble_active_profile_is_open(void);
bool zmk_ble_active_profile_is_connected(void);
int8_t zmk_ble_profile_status(uint8_t index);
char *zmk_ble_active_profile_name(void);

int zmk_ble_unpair_all(void);
Expand Down
2 changes: 2 additions & 0 deletions app/include/zmk/endpoints.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,5 @@ int zmk_endpoints_send_mouse_report();
#endif // IS_ENABLE(CONFIG_ZMK_MOUSE)

void zmk_endpoints_clear_current(void);

bool zmk_endpoints_preferred_transport_is_active();
1 change: 1 addition & 0 deletions app/include/zmk/rgb_underglow.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ int zmk_rgb_underglow_change_sat(int direction);
int zmk_rgb_underglow_change_brt(int direction);
int zmk_rgb_underglow_change_spd(int direction);
int zmk_rgb_underglow_set_hsb(struct zmk_led_hsb color);
int zmk_rgb_underglow_status(void);
2 changes: 2 additions & 0 deletions app/src/behaviors/behavior_rgb_underglow.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
return zmk_rgb_underglow_set_hsb((struct zmk_led_hsb){.h = (binding->param2 >> 16) & 0xFFFF,
.s = (binding->param2 >> 8) & 0xFF,
.b = binding->param2 & 0xFF});
case RGB_STATUS_CMD:
return zmk_rgb_underglow_status();
}

return -ENOTSUP;
Expand Down
19 changes: 19 additions & 0 deletions app/src/ble.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,25 @@ bool zmk_ble_active_profile_is_connected(void) {
return info.state == BT_CONN_STATE_CONNECTED;
}

int8_t zmk_ble_profile_status(uint8_t index) {
if (index >= ZMK_BLE_PROFILE_COUNT)
return -1;

bt_addr_le_t *addr = &profiles[index].peer;
struct bt_conn *conn;
int result;
if (!bt_addr_le_cmp(addr, BT_ADDR_LE_ANY)) {
result = 0; // disconnected
} else if ((conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, addr)) == NULL) {
result = 1; // paired
} else {
result = 2; // connected
bt_conn_unref(conn);
}

return result;
}

#define CHECKED_ADV_STOP() \
err = bt_le_adv_stop(); \
advertising_status = ZMK_ADV_NONE; \
Expand Down
4 changes: 4 additions & 0 deletions app/src/endpoints.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,10 @@ static int endpoint_listener(const zmk_event_t *eh) {
return 0;
}

bool zmk_endpoints_preferred_transport_is_active(void) {
return preferred_transport == get_selected_transport();
}

ZMK_LISTENER(endpoint_listener, endpoint_listener);
#if IS_ENABLED(CONFIG_ZMK_USB)
ZMK_SUBSCRIPTION(endpoint_listener, zmk_usb_conn_state_changed);
Expand Down
Loading

0 comments on commit 903d24f

Please sign in to comment.