aboutsummaryrefslogtreecommitdiff
path: root/users
diff options
context:
space:
mode:
authorstanrc85 <47038504+stanrc85@users.noreply.github.com>2021-07-01 04:06:06 -0400
committerGitHub <noreply@github.com>2021-07-01 01:06:06 -0700
commitfb405c27ad07313f5d564c02bf03130d9aaf59c7 (patch)
tree92391e41350145e51f88735d0afbd1e62db63e60 /users
parent13533508e236666b8827b62f2b2d6819d473ef2b (diff)
downloadqmk_firmware-fb405c27ad07313f5d564c02bf03130d9aaf59c7.tar.gz
qmk_firmware-fb405c27ad07313f5d564c02bf03130d9aaf59c7.zip
[Keymap] RGB Timeout added to userspace (#13339)
Diffstat (limited to 'users')
-rw-r--r--users/stanrc85/rgb_timeout.c62
-rw-r--r--users/stanrc85/rules.mk6
2 files changed, 68 insertions, 0 deletions
diff --git a/users/stanrc85/rgb_timeout.c b/users/stanrc85/rgb_timeout.c
new file mode 100644
index 000000000..4aa242781
--- /dev/null
+++ b/users/stanrc85/rgb_timeout.c
@@ -0,0 +1,62 @@
1/*
2Copyright 2021 Stanrc85
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17#include "stanrc85.h"
18
19// Backlight timeout feature
20// Modified from https://www.reddit.com/r/MechanicalKeyboards/comments/ix65z0/looking_for_qmk_led_idle_timeout_info/g64yov7/
21#define BACKLIGHT_TIMEOUT 10 // in minutes
22static uint16_t idle_timer = 0;
23static uint8_t halfmin_counter = 0;
24static bool led_on = true;
25static bool rgb_on = true;
26static bool rgb_was_on = false;
27
28void matrix_scan_user(void) {
29 // idle_timer needs to be set one time
30 if (idle_timer == 0) idle_timer = timer_read();
31 if ( (led_on && timer_elapsed(idle_timer) > 30000) || (rgb_on && timer_elapsed(idle_timer) > 30000)) {
32 halfmin_counter++;
33 idle_timer = timer_read();
34 }
35
36 if ( (led_on && halfmin_counter >= BACKLIGHT_TIMEOUT * 2) || (rgb_on && halfmin_counter >= BACKLIGHT_TIMEOUT * 2)) {
37 if(rgblight_is_enabled()) {
38 rgb_was_on = true;
39 rgblight_disable_noeeprom();
40 led_on = false;
41 rgb_on = false;
42 } else {
43 rgb_was_on = false;
44 }
45 halfmin_counter = 0;
46 }
47};
48
49bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
50 if (record->event.pressed) {
51 if (led_on == false || rgb_on == false ) {
52 if (rgb_was_on) {
53 rgblight_enable_noeeprom();
54 led_on = true;
55 rgb_on = true;
56 }
57 }
58 idle_timer = timer_read();
59 halfmin_counter = 0;
60 }
61 return true;
62}
diff --git a/users/stanrc85/rules.mk b/users/stanrc85/rules.mk
index 805a2929f..45929575c 100644
--- a/users/stanrc85/rules.mk
+++ b/users/stanrc85/rules.mk
@@ -36,3 +36,9 @@ ifeq ($(strip $(KEYBOARD)), jacky_studio/bear_65)
36 RGB_MATRIX_ENABLE = yes 36 RGB_MATRIX_ENABLE = yes
37 RGBLIGHT_ENABLE = no 37 RGBLIGHT_ENABLE = no
38endif 38endif
39ifeq ($(strip $(KEYBOARD)), tkc/portico)
40 SRC += rgb_timeout.c
41endif
42ifeq ($(strip $(KEYBOARD)), kiwikey/wanderland)
43 SRC += rgb_timeout.c
44endif