Skip to content

Commit 188ce5b

Browse files
committed
indicator-underglow: allow omissions; allow right-hand battery indicators.
This commit does two things: 1. Provides default values for all indicator-underglow properties, which allows you to omit them entirely if you do not want that indicator. 2. Allows the right side to specify battery indicators. I changed the phrasing of the battery left/right properties to be self/other instead. For (2), note that this currently does not work with the default Glove80 definition for the magic (indicator) key, since the right side does not received the macro-wrapped `&rgb_ug RGB_STATUS` keypress. See the usptream issue zmkfirmware#1494 for more. (I resolved this for my own build by incorporating the changes from zmkfirmware#1630.)
1 parent 2fad527 commit 188ce5b

File tree

4 files changed

+57
-35
lines changed

4 files changed

+57
-35
lines changed

app/boards/arm/glove80/glove80_lh.dts

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
underglow_indicators: underglow-indicators {
5555
compatible = "zmk,underglow-indicators";
5656
layer-state = <35 29 23 17 11 6>;
57-
bat-lhs = <36 30 24 18 12 7>;
58-
bat-rhs = <37 31 25 19 13 8>;
57+
bat-self = <36 30 24 18 12 7>;
58+
bat-other = <37 31 25 19 13 8>;
5959
capslock = <22>;
6060
numlock = <16>;
6161
scrolllock = <10>;

app/boards/arm/glove80/glove80_rh.dts

+19-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* SPDX-License-Identifier: MIT
55
*/
66

7-
87
#include "glove80.dtsi"
98
#include "glove80_rh-pinctrl.dtsi"
109

@@ -18,6 +17,7 @@
1817
zmk,underglow = &led_strip;
1918
zmk,backlight = &back_led_backlight;
2019
zmk,battery = &vbatt;
20+
zmk,underglow-indicators = &underglow_indicators;
2121
};
2222

2323
back_led_backlight: pwmleds {
@@ -37,6 +37,24 @@
3737
vbatt: vbatt {
3838
compatible = "zmk,battery-nrf-vddh";
3939
};
40+
41+
/*
42+
MoErgo 40 LEDs
43+
44+
10 16 22 28 34
45+
6 11 17 23 29 35
46+
7 12 18 24 30 36
47+
8 13 19 25 31 37
48+
9 14 20 26 32 38
49+
15 21 27 33 39
50+
2 1 0
51+
5 4 3
52+
*/
53+
54+
underglow_indicators: underglow-indicators {
55+
compatible = "zmk,underglow-indicators";
56+
// Default: no indicators. Only `bat-self` is supported at the moment.
57+
};
4058
};
4159

4260
&spi3 {

app/dts/bindings/zmk,underglow-indicators.yaml

+11-11
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,30 @@ description: Underglow indicators
66
compatible: "zmk,underglow-indicators"
77

88
properties:
9-
bat-lhs:
9+
bat-self:
1010
type: array
11-
required: true
12-
bat-rhs:
11+
default: []
12+
bat-other:
1313
type: array
14-
required: true
14+
default: []
1515
capslock:
1616
type: int
17-
required: true
17+
default: -1
1818
numlock:
1919
type: int
20-
required: true
20+
default: -1
2121
scrolllock:
2222
type: int
23-
required: true
23+
default: -1
2424
layer-state:
2525
type: array
26-
required: true
26+
default: []
2727
ble-state:
2828
type: array
29-
required: true
29+
default: []
3030
usb-state:
3131
type: int
32-
required: true
32+
default: -1
3333
output-fallback:
3434
type: int
35-
required: true
35+
default: -1

app/src/rgb_underglow.c

+25-21
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,8 @@ static int zmk_led_generate_status(void) { return 0; }
273273

274274
const uint8_t underglow_layer_state[] = DT_PROP(UNDERGLOW_INDICATORS, layer_state);
275275
const uint8_t underglow_ble_state[] = DT_PROP(UNDERGLOW_INDICATORS, ble_state);
276-
const uint8_t underglow_bat_lhs[] = DT_PROP(UNDERGLOW_INDICATORS, bat_lhs);
277-
const uint8_t underglow_bat_rhs[] = DT_PROP(UNDERGLOW_INDICATORS, bat_rhs);
276+
const uint8_t underglow_bat_self[] = DT_PROP(UNDERGLOW_INDICATORS, bat_self);
277+
const uint8_t underglow_bat_other[] = DT_PROP(UNDERGLOW_INDICATORS, bat_other);
278278

279279
#define HEXRGB(R, G, B) \
280280
((struct led_rgb){ \
@@ -327,31 +327,32 @@ static int zmk_led_generate_status(void) {
327327
}
328328

329329
// BATTERY STATUS
330-
zmk_led_battery_level(zmk_battery_state_of_charge(), underglow_bat_lhs,
331-
DT_PROP_LEN(UNDERGLOW_INDICATORS, bat_lhs));
330+
zmk_led_battery_level(zmk_battery_state_of_charge(), underglow_bat_self,
331+
DT_PROP_LEN(UNDERGLOW_INDICATORS, bat_self));
332332

333333
#if IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_CENTRAL_BATTERY_LEVEL_FETCHING)
334334
uint8_t peripheral_level = 0;
335335
int rc = zmk_split_get_peripheral_battery_level(0, &peripheral_level);
336336

337337
if (rc == 0) {
338-
zmk_led_battery_level(peripheral_level, underglow_bat_rhs,
339-
DT_PROP_LEN(UNDERGLOW_INDICATORS, bat_rhs));
338+
zmk_led_battery_level(peripheral_level, underglow_bat_other,
339+
DT_PROP_LEN(UNDERGLOW_INDICATORS, bat_other));
340340
} else if (rc == -ENOTCONN) {
341-
zmk_led_fill(red, underglow_bat_rhs, DT_PROP_LEN(UNDERGLOW_INDICATORS, bat_rhs));
341+
zmk_led_fill(red, underglow_bat_other, DT_PROP_LEN(UNDERGLOW_INDICATORS, bat_other));
342342
} else if (rc == -EINVAL) {
343343
LOG_ERR("Invalid peripheral index requested for battery level read: 0");
344344
}
345345
#endif
346346

347+
#if !IS_ENABLED(CONFIG_ZMK_SPLIT) || IS_ENABLED(CONFIG_ZMK_SPLIT_ROLE_CENTRAL)
347348
// CAPSLOCK/NUMLOCK/SCROLLOCK STATUS
348349
zmk_hid_indicators_t led_flags = zmk_hid_indicators_get_current_profile();
349350

350-
if (led_flags & ZMK_LED_CAPSLOCK_BIT)
351+
if (led_flags & ZMK_LED_CAPSLOCK_BIT && DT_PROP(UNDERGLOW_INDICATORS, capslock) != -1)
351352
status_pixels[DT_PROP(UNDERGLOW_INDICATORS, capslock)] = red;
352-
if (led_flags & ZMK_LED_NUMLOCK_BIT)
353+
if (led_flags & ZMK_LED_NUMLOCK_BIT && DT_PROP(UNDERGLOW_INDICATORS, numlock) != -1)
353354
status_pixels[DT_PROP(UNDERGLOW_INDICATORS, numlock)] = red;
354-
if (led_flags & ZMK_LED_SCROLLLOCK_BIT)
355+
if (led_flags & ZMK_LED_SCROLLLOCK_BIT && DT_PROP(UNDERGLOW_INDICATORS, scrolllock) != -1)
355356
status_pixels[DT_PROP(UNDERGLOW_INDICATORS, scrolllock)] = red;
356357

357358
// LAYER STATUS
@@ -362,7 +363,7 @@ static int zmk_led_generate_status(void) {
362363

363364
struct zmk_endpoint_instance active_endpoint = zmk_endpoints_selected();
364365

365-
if (!zmk_endpoints_preferred_transport_is_active())
366+
if (DT_PROP(UNDERGLOW_INDICATORS, output_fallback) != -1 && !zmk_endpoints_preferred_transport_is_active())
366367
status_pixels[DT_PROP(UNDERGLOW_INDICATORS, output_fallback)] = red;
367368

368369
int active_ble_profile_index = zmk_ble_active_profile_index();
@@ -382,17 +383,20 @@ static int zmk_led_generate_status(void) {
382383
}
383384
}
384385

385-
enum zmk_usb_conn_state usb_state = zmk_usb_get_conn_state();
386-
if (usb_state == ZMK_USB_CONN_HID &&
387-
active_endpoint.transport == ZMK_TRANSPORT_USB) { // connected AND active
388-
status_pixels[DT_PROP(UNDERGLOW_INDICATORS, usb_state)] = white;
389-
} else if (usb_state == ZMK_USB_CONN_HID) { // connected
390-
status_pixels[DT_PROP(UNDERGLOW_INDICATORS, usb_state)] = dull_green;
391-
} else if (usb_state == ZMK_USB_CONN_POWERED) { // powered
392-
status_pixels[DT_PROP(UNDERGLOW_INDICATORS, usb_state)] = red;
393-
} else if (usb_state == ZMK_USB_CONN_NONE) { // disconnected
394-
status_pixels[DT_PROP(UNDERGLOW_INDICATORS, usb_state)] = lilac;
386+
if (DT_PROP(UNDERGLOW_INDICATORS, usb_state) != -1) {
387+
enum zmk_usb_conn_state usb_state = zmk_usb_get_conn_state();
388+
if (usb_state == ZMK_USB_CONN_HID &&
389+
active_endpoint.transport == ZMK_TRANSPORT_USB) { // connected AND active
390+
status_pixels[DT_PROP(UNDERGLOW_INDICATORS, usb_state)] = white;
391+
} else if (usb_state == ZMK_USB_CONN_HID) { // connected
392+
status_pixels[DT_PROP(UNDERGLOW_INDICATORS, usb_state)] = dull_green;
393+
} else if (usb_state == ZMK_USB_CONN_POWERED) { // powered
394+
status_pixels[DT_PROP(UNDERGLOW_INDICATORS, usb_state)] = red;
395+
} else if (usb_state == ZMK_USB_CONN_NONE) { // disconnected
396+
status_pixels[DT_PROP(UNDERGLOW_INDICATORS, usb_state)] = lilac;
397+
}
395398
}
399+
#endif
396400

397401
int16_t blend = 256;
398402
if (state.status_animation_step < (500 / 25)) {

0 commit comments

Comments
 (0)