Skip to content

Commit

Permalink
indicator-underglow: allow omissions; allow right-hand battery indica…
Browse files Browse the repository at this point in the history
…tors.

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.)
  • Loading branch information
seansfkelley committed Mar 11, 2024
1 parent 2fad527 commit 188ce5b
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 35 deletions.
4 changes: 2 additions & 2 deletions app/boards/arm/glove80/glove80_lh.dts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
underglow_indicators: underglow-indicators {
compatible = "zmk,underglow-indicators";
layer-state = <35 29 23 17 11 6>;
bat-lhs = <36 30 24 18 12 7>;
bat-rhs = <37 31 25 19 13 8>;
bat-self = <36 30 24 18 12 7>;
bat-other = <37 31 25 19 13 8>;
capslock = <22>;
numlock = <16>;
scrolllock = <10>;
Expand Down
20 changes: 19 additions & 1 deletion app/boards/arm/glove80/glove80_rh.dts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* SPDX-License-Identifier: MIT
*/


#include "glove80.dtsi"
#include "glove80_rh-pinctrl.dtsi"

Expand All @@ -18,6 +17,7 @@
zmk,underglow = &led_strip;
zmk,backlight = &back_led_backlight;
zmk,battery = &vbatt;
zmk,underglow-indicators = &underglow_indicators;
};

back_led_backlight: pwmleds {
Expand All @@ -37,6 +37,24 @@
vbatt: vbatt {
compatible = "zmk,battery-nrf-vddh";
};

/*
MoErgo 40 LEDs

10 16 22 28 34
6 11 17 23 29 35
7 12 18 24 30 36
8 13 19 25 31 37
9 14 20 26 32 38
15 21 27 33 39
2 1 0
5 4 3
*/

underglow_indicators: underglow-indicators {
compatible = "zmk,underglow-indicators";
// Default: no indicators. Only `bat-self` is supported at the moment.
};
};

&spi3 {
Expand Down
22 changes: 11 additions & 11 deletions app/dts/bindings/zmk,underglow-indicators.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,30 @@ description: Underglow indicators
compatible: "zmk,underglow-indicators"

properties:
bat-lhs:
bat-self:
type: array
required: true
bat-rhs:
default: []
bat-other:
type: array
required: true
default: []
capslock:
type: int
required: true
default: -1
numlock:
type: int
required: true
default: -1
scrolllock:
type: int
required: true
default: -1
layer-state:
type: array
required: true
default: []
ble-state:
type: array
required: true
default: []
usb-state:
type: int
required: true
default: -1
output-fallback:
type: int
required: true
default: -1
46 changes: 25 additions & 21 deletions app/src/rgb_underglow.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ static int zmk_led_generate_status(void) { return 0; }

const uint8_t underglow_layer_state[] = DT_PROP(UNDERGLOW_INDICATORS, layer_state);
const uint8_t underglow_ble_state[] = DT_PROP(UNDERGLOW_INDICATORS, ble_state);
const uint8_t underglow_bat_lhs[] = DT_PROP(UNDERGLOW_INDICATORS, bat_lhs);
const uint8_t underglow_bat_rhs[] = DT_PROP(UNDERGLOW_INDICATORS, bat_rhs);
const uint8_t underglow_bat_self[] = DT_PROP(UNDERGLOW_INDICATORS, bat_self);
const uint8_t underglow_bat_other[] = DT_PROP(UNDERGLOW_INDICATORS, bat_other);

#define HEXRGB(R, G, B) \
((struct led_rgb){ \
Expand Down Expand Up @@ -327,31 +327,32 @@ static int zmk_led_generate_status(void) {
}

// BATTERY STATUS
zmk_led_battery_level(zmk_battery_state_of_charge(), underglow_bat_lhs,
DT_PROP_LEN(UNDERGLOW_INDICATORS, bat_lhs));
zmk_led_battery_level(zmk_battery_state_of_charge(), underglow_bat_self,
DT_PROP_LEN(UNDERGLOW_INDICATORS, bat_self));

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

if (rc == 0) {
zmk_led_battery_level(peripheral_level, underglow_bat_rhs,
DT_PROP_LEN(UNDERGLOW_INDICATORS, bat_rhs));
zmk_led_battery_level(peripheral_level, underglow_bat_other,
DT_PROP_LEN(UNDERGLOW_INDICATORS, bat_other));
} else if (rc == -ENOTCONN) {
zmk_led_fill(red, underglow_bat_rhs, DT_PROP_LEN(UNDERGLOW_INDICATORS, bat_rhs));
zmk_led_fill(red, underglow_bat_other, DT_PROP_LEN(UNDERGLOW_INDICATORS, bat_other));
} else if (rc == -EINVAL) {
LOG_ERR("Invalid peripheral index requested for battery level read: 0");
}
#endif

#if !IS_ENABLED(CONFIG_ZMK_SPLIT) || IS_ENABLED(CONFIG_ZMK_SPLIT_ROLE_CENTRAL)
// CAPSLOCK/NUMLOCK/SCROLLOCK STATUS
zmk_hid_indicators_t led_flags = zmk_hid_indicators_get_current_profile();

if (led_flags & ZMK_LED_CAPSLOCK_BIT)
if (led_flags & ZMK_LED_CAPSLOCK_BIT && DT_PROP(UNDERGLOW_INDICATORS, capslock) != -1)
status_pixels[DT_PROP(UNDERGLOW_INDICATORS, capslock)] = red;
if (led_flags & ZMK_LED_NUMLOCK_BIT)
if (led_flags & ZMK_LED_NUMLOCK_BIT && DT_PROP(UNDERGLOW_INDICATORS, numlock) != -1)
status_pixels[DT_PROP(UNDERGLOW_INDICATORS, numlock)] = red;
if (led_flags & ZMK_LED_SCROLLLOCK_BIT)
if (led_flags & ZMK_LED_SCROLLLOCK_BIT && DT_PROP(UNDERGLOW_INDICATORS, scrolllock) != -1)
status_pixels[DT_PROP(UNDERGLOW_INDICATORS, scrolllock)] = red;

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

struct zmk_endpoint_instance active_endpoint = zmk_endpoints_selected();

if (!zmk_endpoints_preferred_transport_is_active())
if (DT_PROP(UNDERGLOW_INDICATORS, output_fallback) != -1 && !zmk_endpoints_preferred_transport_is_active())
status_pixels[DT_PROP(UNDERGLOW_INDICATORS, output_fallback)] = red;

int active_ble_profile_index = zmk_ble_active_profile_index();
Expand All @@ -382,17 +383,20 @@ static int zmk_led_generate_status(void) {
}
}

enum zmk_usb_conn_state usb_state = zmk_usb_get_conn_state();
if (usb_state == ZMK_USB_CONN_HID &&
active_endpoint.transport == ZMK_TRANSPORT_USB) { // connected AND active
status_pixels[DT_PROP(UNDERGLOW_INDICATORS, usb_state)] = white;
} else if (usb_state == ZMK_USB_CONN_HID) { // connected
status_pixels[DT_PROP(UNDERGLOW_INDICATORS, usb_state)] = dull_green;
} else if (usb_state == ZMK_USB_CONN_POWERED) { // powered
status_pixels[DT_PROP(UNDERGLOW_INDICATORS, usb_state)] = red;
} else if (usb_state == ZMK_USB_CONN_NONE) { // disconnected
status_pixels[DT_PROP(UNDERGLOW_INDICATORS, usb_state)] = lilac;
if (DT_PROP(UNDERGLOW_INDICATORS, usb_state) != -1) {
enum zmk_usb_conn_state usb_state = zmk_usb_get_conn_state();
if (usb_state == ZMK_USB_CONN_HID &&
active_endpoint.transport == ZMK_TRANSPORT_USB) { // connected AND active
status_pixels[DT_PROP(UNDERGLOW_INDICATORS, usb_state)] = white;
} else if (usb_state == ZMK_USB_CONN_HID) { // connected
status_pixels[DT_PROP(UNDERGLOW_INDICATORS, usb_state)] = dull_green;
} else if (usb_state == ZMK_USB_CONN_POWERED) { // powered
status_pixels[DT_PROP(UNDERGLOW_INDICATORS, usb_state)] = red;
} else if (usb_state == ZMK_USB_CONN_NONE) { // disconnected
status_pixels[DT_PROP(UNDERGLOW_INDICATORS, usb_state)] = lilac;
}
}
#endif

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

0 comments on commit 188ce5b

Please sign in to comment.