Skip to content

Commit aca523d

Browse files
donaldsycamorechrisandreae
authored andcommitted
RGB underglow status support
Adds Glove80's status indicator using RGB underglow support. Requires ZMK PR#999 and PR#1243. The underglow status is able to show layer state, battery levels, caps/num/scroll-lock, BLE and USB state. The underglow positions selected for each of these indicators is configured using the new devicetree node zmk,underglow-indicators, which takes an array of integer LED positions for each feature.
1 parent d45882f commit aca523d

File tree

9 files changed

+340
-20
lines changed

9 files changed

+340
-20
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
required: true
12+
bat-rhs:
13+
type: array
14+
required: true
15+
capslock:
16+
type: int
17+
required: true
18+
numlock:
19+
type: int
20+
required: true
21+
scrolllock:
22+
type: int
23+
required: true
24+
layer-state:
25+
type: array
26+
required: true
27+
ble-state:
28+
type: array
29+
required: true
30+
usb-state:
31+
type: int
32+
required: true
33+
output-fallback:
34+
type: int
35+
required: true

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
@@ -33,6 +33,7 @@ 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);
3535
char *zmk_ble_active_profile_name(void);
36+
int8_t zmk_ble_profile_status(uint8_t index);
3637

3738
int zmk_ble_unpair_all(void);
3839

app/include/zmk/endpoints.h

+2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ int zmk_endpoints_toggle_transport(void);
6868
*/
6969
struct zmk_endpoint_instance zmk_endpoints_selected(void);
7070

71+
bool zmk_endpoints_preferred_transport_is_active();
72+
7173
int zmk_endpoints_send_report(uint16_t usage_page);
7274

7375
#if IS_ENABLED(CONFIG_ZMK_MOUSE)

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

+17
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,23 @@ 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+
bt_addr_le_t *addr = &profiles[index].peer;
136+
struct bt_conn *conn;
137+
int result;
138+
if (!bt_addr_le_cmp(addr, BT_ADDR_LE_ANY)) {
139+
result = 0; // disconnected
140+
} else if ((conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, addr)) == NULL) {
141+
result = 1; // paired
142+
} else {
143+
result = 2; // connected
144+
bt_conn_unref(conn);
145+
}
146+
return result;
147+
}
148+
132149
#define CHECKED_ADV_STOP() \
133150
err = bt_le_adv_stop(); \
134151
advertising_status = ZMK_ADV_NONE; \

app/src/endpoints.c

+4
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,10 @@ static struct zmk_endpoint_instance get_selected_instance(void) {
302302
return instance;
303303
}
304304

305+
bool zmk_endpoints_preferred_transport_is_active(void) {
306+
return preferred_transport == get_selected_transport();
307+
}
308+
305309
static int zmk_endpoints_init(void) {
306310
#if IS_ENABLED(CONFIG_SETTINGS)
307311
settings_subsys_init();

0 commit comments

Comments
 (0)