commit 009a6da255fa53c58f299daa846d738c58b18fa0
parent 801ff400f1bfde00564b6ff516a9d4e71921a6f3
Author: René Wagner <rwa@clttr.info>
Date: Sun, 24 Dec 2023 16:32:49 +0100
fade out backlight after ~1 minute
Diffstat:
1 file changed, 29 insertions(+), 1 deletion(-)
diff --git a/reform2-keyboard-fw/keyboard.c b/reform2-keyboard-fw/keyboard.c
@@ -98,6 +98,10 @@ bool circle = 0; // Am I holding circle?
bool help_display = 0; // Is the Hyper help screen displayed?
bool should_run_fade_anim = false;
+int led_brightness;
+int led_dimmed = 0;
+uint32_t led_idle_counter = 0;
+
// enter the menu
void enter_meta_mode(void) {
active_meta_mode = 1;
@@ -313,7 +317,31 @@ int process_keyboard(uint8_t* resulting_scancodes) {
render_keymods(active_keymods);
}
// if no more keys are held down, allow a new meta command
- if (total_pressed<1) last_meta_key = 0;
+ if (total_pressed < 1) {
+ last_meta_key = 0;
+ if (led_dimmed < 2) {
+ led_idle_counter++;
+ if (led_dimmed == 0 && led_idle_counter > 120000) {
+ led_dimmed = 1;
+ led_brightness = kbd_brightness_get();
+ } else if (led_dimmed == 1) {
+ if (led_idle_counter % 500 == 0) {
+ kbd_brightness_dec();
+ }
+ if (kbd_brightness_get() == 0) {
+ led_dimmed = 2;
+ }
+ }
+ }
+ }
+ // If a key is held down, and the backlight is dimmed, brighten it and reset the timer
+ else {
+ if (led_dimmed > 0) {
+ kbd_brightness_set(led_brightness);
+ led_idle_counter = 0;
+ led_dimmed = 0;
+ }
+ }
return used_key_codes;
}