Skip to content

Commit

Permalink
RGB underglow status support
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
donaldsycamore authored and chrisandreae committed Feb 10, 2024
1 parent d45882f commit aca523d
Show file tree
Hide file tree
Showing 9 changed files with 340 additions and 20 deletions.
35 changes: 35 additions & 0 deletions app/dts/bindings/zmk,underglow-indicators.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright (c) 2020, The ZMK Contributors
# SPDX-License-Identifier: MIT

description: Underglow indicators

compatible: "zmk,underglow-indicators"

properties:
bat-lhs:
type: array
required: true
bat-rhs:
type: array
required: true
capslock:
type: int
required: true
numlock:
type: int
required: true
scrolllock:
type: int
required: true
layer-state:
type: array
required: true
ble-state:
type: array
required: true
usb-state:
type: int
required: true
output-fallback:
type: int
required: true
2 changes: 2 additions & 0 deletions app/include/dt-bindings/zmk/rgb.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define RGB_EFR_CMD 12
#define RGB_EFS_CMD 13
#define RGB_COLOR_HSB_CMD 14
#define RGB_STATUS_CMD 15

#define RGB_TOG RGB_TOG_CMD 0
#define RGB_ON RGB_ON_CMD 0
Expand All @@ -33,6 +34,7 @@
#define RGB_SPD RGB_SPD_CMD 0
#define RGB_EFF RGB_EFF_CMD 0
#define RGB_EFR RGB_EFR_CMD 0
#define RGB_STATUS RGB_STATUS_CMD 0
#define RGB_COLOR_HSB_VAL(h, s, v) (((h) << 16) + ((s) << 8) + (v))
#define RGB_COLOR_HSB(h, s, v) RGB_COLOR_HSB_CMD##(RGB_COLOR_HSB_VAL(h, s, v))
#define RGB_COLOR_HSV RGB_COLOR_HSB
1 change: 1 addition & 0 deletions app/include/zmk/ble.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ bt_addr_le_t *zmk_ble_active_profile_addr(void);
bool zmk_ble_active_profile_is_open(void);
bool zmk_ble_active_profile_is_connected(void);
char *zmk_ble_active_profile_name(void);
int8_t zmk_ble_profile_status(uint8_t index);

int zmk_ble_unpair_all(void);

Expand Down
2 changes: 2 additions & 0 deletions app/include/zmk/endpoints.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ int zmk_endpoints_toggle_transport(void);
*/
struct zmk_endpoint_instance zmk_endpoints_selected(void);

bool zmk_endpoints_preferred_transport_is_active();

int zmk_endpoints_send_report(uint16_t usage_page);

#if IS_ENABLED(CONFIG_ZMK_MOUSE)
Expand Down
1 change: 1 addition & 0 deletions app/include/zmk/rgb_underglow.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ int zmk_rgb_underglow_change_sat(int direction);
int zmk_rgb_underglow_change_brt(int direction);
int zmk_rgb_underglow_change_spd(int direction);
int zmk_rgb_underglow_set_hsb(struct zmk_led_hsb color);
int zmk_rgb_underglow_status(void);
2 changes: 2 additions & 0 deletions app/src/behaviors/behavior_rgb_underglow.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
return zmk_rgb_underglow_set_hsb((struct zmk_led_hsb){.h = (binding->param2 >> 16) & 0xFFFF,
.s = (binding->param2 >> 8) & 0xFF,
.b = binding->param2 & 0xFF});
case RGB_STATUS_CMD:
return zmk_rgb_underglow_status();
}

return -ENOTSUP;
Expand Down
17 changes: 17 additions & 0 deletions app/src/ble.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,23 @@ bool zmk_ble_active_profile_is_connected(void) {
return info.state == BT_CONN_STATE_CONNECTED;
}

int8_t zmk_ble_profile_status(uint8_t index) {
if (index >= ZMK_BLE_PROFILE_COUNT)
return -1;
bt_addr_le_t *addr = &profiles[index].peer;
struct bt_conn *conn;
int result;
if (!bt_addr_le_cmp(addr, BT_ADDR_LE_ANY)) {
result = 0; // disconnected
} else if ((conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, addr)) == NULL) {
result = 1; // paired
} else {
result = 2; // connected
bt_conn_unref(conn);
}
return result;
}

#define CHECKED_ADV_STOP() \
err = bt_le_adv_stop(); \
advertising_status = ZMK_ADV_NONE; \
Expand Down
4 changes: 4 additions & 0 deletions app/src/endpoints.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ static struct zmk_endpoint_instance get_selected_instance(void) {
return instance;
}

bool zmk_endpoints_preferred_transport_is_active(void) {
return preferred_transport == get_selected_transport();
}

static int zmk_endpoints_init(void) {
#if IS_ENABLED(CONFIG_SETTINGS)
settings_subsys_init();
Expand Down
Loading

0 comments on commit aca523d

Please sign in to comment.