Skip to content

Commit 903d24f

Browse files
committed
feat(underglow): support command for displaying board statuses
1 parent 7be955f commit 903d24f

File tree

9 files changed

+424
-16
lines changed

9 files changed

+424
-16
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright (c) 2020, The ZMK Contributors
2+
# SPDX-License-Identifier: MIT
3+
4+
description: Underglow indicators
5+
6+
compatible: "zmk,underglow-indicators"
7+
8+
properties:
9+
bat-lhs:
10+
type: array
11+
bat-rhs:
12+
type: array
13+
num-lock:
14+
type: int
15+
caps-lock:
16+
type: int
17+
scroll-lock:
18+
type: int
19+
layer-state:
20+
type: array
21+
ble-profiles:
22+
type: array
23+
usb-state:
24+
type: int
25+
output-fallback:
26+
type: int

app/include/dt-bindings/zmk/rgb.h

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#define RGB_EFR_CMD 12
2020
#define RGB_EFS_CMD 13
2121
#define RGB_COLOR_HSB_CMD 14
22+
#define RGB_STATUS_CMD 15
2223

2324
#define RGB_TOG RGB_TOG_CMD 0
2425
#define RGB_ON RGB_ON_CMD 0
@@ -33,6 +34,7 @@
3334
#define RGB_SPD RGB_SPD_CMD 0
3435
#define RGB_EFF RGB_EFF_CMD 0
3536
#define RGB_EFR RGB_EFR_CMD 0
37+
#define RGB_STATUS RGB_STATUS_CMD 0
3638
#define RGB_COLOR_HSB_VAL(h, s, v) (((h) << 16) + ((s) << 8) + (v))
3739
#define RGB_COLOR_HSB(h, s, v) RGB_COLOR_HSB_CMD##(RGB_COLOR_HSB_VAL(h, s, v))
3840
#define RGB_COLOR_HSV RGB_COLOR_HSB

app/include/zmk/ble.h

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ int zmk_ble_profile_index(const bt_addr_le_t *addr);
3232
bt_addr_le_t *zmk_ble_active_profile_addr(void);
3333
bool zmk_ble_active_profile_is_open(void);
3434
bool zmk_ble_active_profile_is_connected(void);
35+
int8_t zmk_ble_profile_status(uint8_t index);
3536
char *zmk_ble_active_profile_name(void);
3637

3738
int zmk_ble_unpair_all(void);

app/include/zmk/endpoints.h

+2
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,5 @@ int zmk_endpoints_send_mouse_report();
7575
#endif // IS_ENABLE(CONFIG_ZMK_MOUSE)
7676

7777
void zmk_endpoints_clear_current(void);
78+
79+
bool zmk_endpoints_preferred_transport_is_active();

app/include/zmk/rgb_underglow.h

+1
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ int zmk_rgb_underglow_change_sat(int direction);
2727
int zmk_rgb_underglow_change_brt(int direction);
2828
int zmk_rgb_underglow_change_spd(int direction);
2929
int zmk_rgb_underglow_set_hsb(struct zmk_led_hsb color);
30+
int zmk_rgb_underglow_status(void);

app/src/behaviors/behavior_rgb_underglow.c

+2
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
131131
return zmk_rgb_underglow_set_hsb((struct zmk_led_hsb){.h = (binding->param2 >> 16) & 0xFFFF,
132132
.s = (binding->param2 >> 8) & 0xFF,
133133
.b = binding->param2 & 0xFF});
134+
case RGB_STATUS_CMD:
135+
return zmk_rgb_underglow_status();
134136
}
135137

136138
return -ENOTSUP;

app/src/ble.c

+19
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,25 @@ bool zmk_ble_active_profile_is_connected(void) {
129129
return info.state == BT_CONN_STATE_CONNECTED;
130130
}
131131

132+
int8_t zmk_ble_profile_status(uint8_t index) {
133+
if (index >= ZMK_BLE_PROFILE_COUNT)
134+
return -1;
135+
136+
bt_addr_le_t *addr = &profiles[index].peer;
137+
struct bt_conn *conn;
138+
int result;
139+
if (!bt_addr_le_cmp(addr, BT_ADDR_LE_ANY)) {
140+
result = 0; // disconnected
141+
} else if ((conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, addr)) == NULL) {
142+
result = 1; // paired
143+
} else {
144+
result = 2; // connected
145+
bt_conn_unref(conn);
146+
}
147+
148+
return result;
149+
}
150+
132151
#define CHECKED_ADV_STOP() \
133152
err = bt_le_adv_stop(); \
134153
advertising_status = ZMK_ADV_NONE; \

app/src/endpoints.c

+4
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,10 @@ static int endpoint_listener(const zmk_event_t *eh) {
373373
return 0;
374374
}
375375

376+
bool zmk_endpoints_preferred_transport_is_active(void) {
377+
return preferred_transport == get_selected_transport();
378+
}
379+
376380
ZMK_LISTENER(endpoint_listener, endpoint_listener);
377381
#if IS_ENABLED(CONFIG_ZMK_USB)
378382
ZMK_SUBSCRIPTION(endpoint_listener, zmk_usb_conn_state_changed);

0 commit comments

Comments
 (0)