From ae7327f4d6c5940045a5ac12dc29c8ec85c2fec0 Mon Sep 17 00:00:00 2001 From: Sadek Baroudi Date: Sun, 17 Jan 2021 01:45:39 -0800 Subject: [PATCH] Added lighting timeout on inactivity --- keyboards/crkbd/keymaps/sadekbaroudi/keymap.c | 42 +++++++++++++++---- .../crkbd/keymaps/sadekbaroudi/readme.md | 7 ++++ 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/keyboards/crkbd/keymaps/sadekbaroudi/keymap.c b/keyboards/crkbd/keymaps/sadekbaroudi/keymap.c index e70b6a986c..f0e52b8c96 100644 --- a/keyboards/crkbd/keymaps/sadekbaroudi/keymap.c +++ b/keyboards/crkbd/keymaps/sadekbaroudi/keymap.c @@ -20,14 +20,13 @@ along with this program. If not, see . #define LAYER_IS_ON(layer_state, layer_num) ((layer_state & (1 << layer_num)) > 0) -// TODO: Add support for backlight timeout... Here's a snippet, but get the rest from: +////// Start RGB backlight timeout // https://gist.github.com/MaxWinterstein/c99594a5f4f8da942feb72c8233445aa/ -// Backlight timeout feature -// #define BACKLIGHT_TIMEOUT 10 // in minutes -// static uint16_t idle_timer = 0; -// static uint8_t halfmin_counter = 0; -// static uint8_t old_backlight_level = -1; -// static bool led_on = true; +#define BACKLIGHT_TIMEOUT 1 // in minutes +static uint16_t idle_timer = 0; +static uint8_t halfmin_counter = 0; +static bool led_on = true; +////// End RGB backlight timeout // Begin layer lighting const rgblight_segment_t PROGMEM layer_0_rgb[] = RGBLIGHT_LAYER_SEGMENTS( @@ -247,7 +246,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { //---------------------+----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+-------------------+ _______, _______, _______, L_GITCOMMIT, _______, _______, _______, _______, _______, _______, _______, _______, //---------------------+----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+-------------------+ - XXXXXXX, _______, _______, _______, _______, XXXXXXX + XXXXXXX, _______, EEPROM_RESET, EEPROM_RESET, _______, XXXXXXX // +----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+ ), @@ -363,11 +362,38 @@ void oled_task_user(void) { } } +void matrix_scan_user(void) { + ////// Start RGB backlight timeout + // idle_timer needs to be set one time + if (idle_timer == 0) idle_timer = timer_read(); + + if ( led_on && timer_elapsed(idle_timer) > 30000) { + halfmin_counter++; + idle_timer = timer_read(); + } + + if ( led_on && halfmin_counter >= BACKLIGHT_TIMEOUT * 2) { + rgblight_disable_noeeprom(); + led_on = false; + halfmin_counter = 0; + } + ////// End RGB backlight timeout +} + bool process_record_user(uint16_t keycode, keyrecord_t *record) { if (record->event.pressed) { set_keylog(keycode, record); } + ////// Start RGB backlight timeout + if (led_on == false) { + rgblight_enable_noeeprom(); + led_on = true; + } + idle_timer = timer_read(); + halfmin_counter = 0; + ////// End RGB backlight timeout + // do stuff when macro keys are pressed switch (keycode) { case VIM_W: diff --git a/keyboards/crkbd/keymaps/sadekbaroudi/readme.md b/keyboards/crkbd/keymaps/sadekbaroudi/readme.md index a0930f07be..c5e4b869bf 100644 --- a/keyboards/crkbd/keymaps/sadekbaroudi/readme.md +++ b/keyboards/crkbd/keymaps/sadekbaroudi/readme.md @@ -1,2 +1,9 @@ # Sadek Baroudi's keymap for Corne (crkbd) +Don't forget that you have to make and flash both sides for RGB related features: +// For the left side (or whatever the master side is) +make crkbd:sadekbaroudi + +// For the right side (or whatever the slave side is) +make crkbd:sadekbaroudi RGB_MATRIX_SPLIT_RIGHT=yes +