commit 0dfce038bbd78a751bc046db11b720dc3d65c155
parent 33337f1c8bb8ad07fb9f0f17907210d7fa518333
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
@@ -102,6 +102,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;
@@ -317,7 +321,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 % 1000 == 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 {
+ led_idle_counter = 0;
+ if (led_dimmed > 0) {
+ kbd_brightness_set(led_brightness);
+ led_dimmed = 0;
+ }
+ }
return used_key_codes;
}