Skip to content

Commit

Permalink
Battery life improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ReFil committed Oct 1, 2022
1 parent 10b605e commit a981282
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 49 deletions.
10 changes: 10 additions & 0 deletions app/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ config ZMK_RGB_UNDERGLOW_BRT_MAX
range ZMK_RGB_UNDERGLOW_BRT_MIN 100
default 100

config ZMK_RGB_UNDERGLOW_BRT_SCALE
int "RGB underglow brightness scale factor in percent"
range 0 100
default 5

config ZMK_RGB_UNDERGLOW_HUE_STEP
int "RGB underglow hue step in degrees"
range 0 359
Expand Down Expand Up @@ -269,6 +274,11 @@ config ZMK_BACKLIGHT_BRT_START
range 1 100
default 40

config ZMK_BACKLIGHT_BRT_SCALE
int "Default brightness in percent"
range 0 100
default 100

config ZMK_BACKLIGHT_ON_START
bool "Default backlight state"
default y
Expand Down
2 changes: 1 addition & 1 deletion app/src/backlight.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static int zmk_backlight_update() {
#if ZMK_BLE_IS_CENTRAL
zmk_backlight_central_send();
#endif
uint8_t brt = zmk_backlight_get_brt();
uint8_t brt = ((zmk_backlight_get_brt() * CONFIG_ZMK_BACKLIGHT_BRT_SCALE) / 100);
LOG_DBG("Update backlight brightness: %d%%", brt);

for (int i = 0; i < BACKLIGHT_NUM_LEDS; i++) {
Expand Down
100 changes: 52 additions & 48 deletions app/src/rgb_underglow.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
#define SAT_MAX 100
#define BRT_MAX 100

#define LED_BRIGHTNESS 5

BUILD_ASSERT(CONFIG_ZMK_RGB_UNDERGLOW_BRT_MIN <= CONFIG_ZMK_RGB_UNDERGLOW_BRT_MAX,
"ERROR: RGB underglow maximum brightness is less than minimum brightness");

Expand Down Expand Up @@ -221,29 +219,29 @@ static void zmk_rgb_underglow_effect_kinesis() {
led_data.indicators = zmk_leds_get_current_flags();
led_data.layer = zmk_keymap_highest_layer_active();

pixels[0].r = (led_data.indicators & ZMK_LED_CAPSLOCK_BIT) * LED_BRIGHTNESS;
pixels[0].g = (led_data.indicators & ZMK_LED_CAPSLOCK_BIT) * LED_BRIGHTNESS;
pixels[0].b = (led_data.indicators & ZMK_LED_CAPSLOCK_BIT) * LED_BRIGHTNESS;
pixels[0].r = (led_data.indicators & ZMK_LED_CAPSLOCK_BIT) * CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
pixels[0].g = (led_data.indicators & ZMK_LED_CAPSLOCK_BIT) * CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
pixels[0].b = (led_data.indicators & ZMK_LED_CAPSLOCK_BIT) * CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
// set second led as bluetooth state
switch (zmk_ble_active_profile_index()) {
case 0:
pixels[1].r = LED_BRIGHTNESS;
pixels[1].g = LED_BRIGHTNESS;
pixels[1].b = LED_BRIGHTNESS;
pixels[1].r = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
pixels[1].g = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
pixels[1].b = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
break;
case 1:
pixels[1].r = 0;
pixels[1].g = 0;
pixels[1].b = LED_BRIGHTNESS;
pixels[1].b = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
break;
case 2:
pixels[1].r = LED_BRIGHTNESS;
pixels[1].r = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
pixels[1].g = 0;
pixels[1].b = 0;
break;
case 3:
pixels[1].r = 0;
pixels[1].g = LED_BRIGHTNESS;
pixels[1].g = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
pixels[1].b = 0;
break;
}
Expand Down Expand Up @@ -275,38 +273,38 @@ static void zmk_rgb_underglow_effect_kinesis() {
pixels[2].b = 0;
break;
case 1:
pixels[2].r = LED_BRIGHTNESS;
pixels[2].g = LED_BRIGHTNESS;
pixels[2].b = LED_BRIGHTNESS;
pixels[2].r = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
pixels[2].g = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
pixels[2].b = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
break;
case 2:
pixels[2].r = 0;
pixels[2].g = 0;
pixels[2].b = LED_BRIGHTNESS;
pixels[2].b = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
break;
case 3:
pixels[2].r = 0;
pixels[2].g = LED_BRIGHTNESS;
pixels[2].g = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
pixels[2].b = 0;
break;
case 4:
pixels[2].r = LED_BRIGHTNESS;
pixels[2].r = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
pixels[2].g = 0;
pixels[2].b = 0;
break;
case 5:
pixels[2].r = LED_BRIGHTNESS;
pixels[2].r = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
pixels[2].g = 0;
pixels[2].b = LED_BRIGHTNESS;
pixels[2].b = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
break;
case 6:
pixels[2].r = 0;
pixels[2].g = LED_BRIGHTNESS;
pixels[2].b = LED_BRIGHTNESS;
pixels[2].g = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
pixels[2].b = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
break;
case 7:
pixels[2].r = LED_BRIGHTNESS;
pixels[2].g = LED_BRIGHTNESS;
pixels[2].r = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
pixels[2].g = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
pixels[2].b = 0;
break;
default:
Expand All @@ -320,14 +318,14 @@ static void zmk_rgb_underglow_effect_kinesis() {
}
#else
// leds for peripheral(right) side
/*if (zmk_ble_active_profile_is_open()) {
pixels[0].r = LED_BRIGHTNESS * last_ble_state[0];
/* if (zmk_ble_active_profile_is_open()) {
pixels[0].r = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE * last_ble_state[0];
pixels[0].g = 0;
pixels[0].b = 0;
pixels[1].r = LED_BRIGHTNESS * last_ble_state[0];
pixels[1].r = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE * last_ble_state[0];
pixels[1].g = 0;
pixels[1].b = 0;
pixels[2].r = LED_BRIGHTNESS * last_ble_state[0];
pixels[2].r = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE * last_ble_state[0];
pixels[2].g = 0;
pixels[2].b = 0;
if (state.animation_step > 3) {
Expand All @@ -337,13 +335,13 @@ static void zmk_rgb_underglow_effect_kinesis() {
state.animation_step++;
} else */
if (!zmk_split_bt_peripheral_is_connected()) {
pixels[0].r = LED_BRIGHTNESS * last_ble_state[1];
pixels[0].r = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE * last_ble_state[1];
pixels[0].g = 0;
pixels[0].b = 0;
pixels[1].r = LED_BRIGHTNESS * last_ble_state[1];
pixels[1].r = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE * last_ble_state[1];
pixels[1].g = 0;
pixels[1].b = 0;
pixels[2].r = LED_BRIGHTNESS * last_ble_state[1];
pixels[2].r = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE * last_ble_state[1];
pixels[2].g = 0;
pixels[2].b = 0;
if (state.animation_step > 14) {
Expand All @@ -353,13 +351,19 @@ static void zmk_rgb_underglow_effect_kinesis() {
state.animation_step++;
} else {
// set first led as LED_NUMLOCK
pixels[2].r = (led_data.indicators & ZMK_LED_NUMLOCK_BIT) * LED_BRIGHTNESS;
pixels[2].g = (led_data.indicators & ZMK_LED_NUMLOCK_BIT) * LED_BRIGHTNESS;
pixels[2].b = (led_data.indicators & ZMK_LED_NUMLOCK_BIT) * LED_BRIGHTNESS;
pixels[2].r =
(led_data.indicators & ZMK_LED_NUMLOCK_BIT) * CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
pixels[2].g =
(led_data.indicators & ZMK_LED_NUMLOCK_BIT) * CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
pixels[2].b =
(led_data.indicators & ZMK_LED_NUMLOCK_BIT) * CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
// set second led as scroll Lock
pixels[1].r = (led_data.indicators & ZMK_LED_SCROLLLOCK_BIT) * LED_BRIGHTNESS;
pixels[1].g = (led_data.indicators & ZMK_LED_SCROLLLOCK_BIT) * LED_BRIGHTNESS;
pixels[1].b = (led_data.indicators & ZMK_LED_SCROLLLOCK_BIT) * LED_BRIGHTNESS;
pixels[1].r =
(led_data.indicators & ZMK_LED_SCROLLLOCK_BIT) * CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
pixels[1].g =
(led_data.indicators & ZMK_LED_SCROLLLOCK_BIT) * CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
pixels[1].b =
(led_data.indicators & ZMK_LED_SCROLLLOCK_BIT) * CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
// set third led as layer
switch (led_data.layer) {
case 0:
Expand All @@ -368,38 +372,38 @@ static void zmk_rgb_underglow_effect_kinesis() {
pixels[0].b = 0;
break;
case 1:
pixels[0].r = LED_BRIGHTNESS;
pixels[0].g = LED_BRIGHTNESS;
pixels[0].b = LED_BRIGHTNESS;
pixels[0].r = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
pixels[0].g = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
pixels[0].b = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
break;
case 2:
pixels[0].r = 0;
pixels[0].g = 0;
pixels[0].b = LED_BRIGHTNESS;
pixels[0].b = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
break;
case 3:
pixels[0].r = 0;
pixels[0].g = LED_BRIGHTNESS;
pixels[0].g = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
pixels[0].b = 0;
break;
case 4:
pixels[0].r = LED_BRIGHTNESS;
pixels[0].r = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
pixels[0].g = 0;
pixels[0].b = 0;
break;
case 5:
pixels[0].r = LED_BRIGHTNESS;
pixels[0].r = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
pixels[0].g = 0;
pixels[0].b = LED_BRIGHTNESS;
pixels[0].b = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
break;
case 6:
pixels[0].r = 0;
pixels[0].g = LED_BRIGHTNESS;
pixels[0].b = LED_BRIGHTNESS;
pixels[0].g = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
pixels[0].b = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
break;
case 7:
pixels[0].r = LED_BRIGHTNESS;
pixels[0].g = LED_BRIGHTNESS;
pixels[0].r = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
pixels[0].g = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
pixels[0].b = 0;
break;
default:
Expand Down

0 comments on commit a981282

Please sign in to comment.