Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

indicator-underglow: allow omissions; allow right-hand battery indicators. #29

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure this is right, but I didn't exhaustively check it.

*/

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought I'd stub this out for discoverability. Per the PR description, this is actually kind of a trap, because it doesn't work with the default definition of the magic key without pulling in an upstream bugfix.

};
};

&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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what the right way to define "nothing" was here, since I don't think these are nullable. 🤷

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