diff options
| author | Michael Grote | 2024-03-20 18:22:01 +0100 |
|---|---|---|
| committer | Michael Grote | 2024-08-05 14:44:36 +0200 |
| commit | 86c40985ed4205b46cf2de3e5ae3be5d2cf97e44 (patch) | |
| tree | a9eb20ecc117457af76a399c87179a182d313350 | |
| parent | bb9e940f12901fc2b76afd30a19d31db85af44fc (diff) | |
skeletyl: add rgb timeout
| -rw-r--r-- | keyboards/bastardkb/skeletyl/keymaps/quotengrote/config.h | 3 | ||||
| -rw-r--r-- | keyboards/bastardkb/skeletyl/keymaps/quotengrote/keymap.c | 45 |
2 files changed, 48 insertions, 0 deletions
diff --git a/keyboards/bastardkb/skeletyl/keymaps/quotengrote/config.h b/keyboards/bastardkb/skeletyl/keymaps/quotengrote/config.h index 43190a044d..2a93aea25d 100644 --- a/keyboards/bastardkb/skeletyl/keymaps/quotengrote/config.h +++ b/keyboards/bastardkb/skeletyl/keymaps/quotengrote/config.h @@ -15,3 +15,6 @@ #define RGB_MATRIX_MAXIMUM_BRIGHTNESS 255 #define SPLIT_LAYER_STATE_ENABLE // for layer indicators #define RGB_TRIGGER_ON_KEYDOWN // Triggers RGB keypress events on key down. This makes RGB control feel more responsive. This may cause RGB to not function properly on some boards +// rgb timeout; https://gist.github.com/aashreys/01cb34605a290a7cfb94a856bdabc94c +#define RGBLIGHT_SLEEP // allows us to use rgblight_suspend() and rgblight_wakeup() in keymap.c +#define RGBLIGHT_TIMEOUT 10000 // 10 seconds diff --git a/keyboards/bastardkb/skeletyl/keymaps/quotengrote/keymap.c b/keyboards/bastardkb/skeletyl/keymaps/quotengrote/keymap.c index cf1aeb1798..b9faaf21b3 100644 --- a/keyboards/bastardkb/skeletyl/keymaps/quotengrote/keymap.c +++ b/keyboards/bastardkb/skeletyl/keymaps/quotengrote/keymap.c @@ -112,6 +112,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { ) }; + // https://github.com/qmk/qmk_firmware/blob/master/docs/mod_tap.md#changing-hold-function bool process_record_user(uint16_t keycode, keyrecord_t *record) { switch (keycode) { @@ -161,3 +162,47 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { } return true; } + +// rgb timeout; https://gist.github.com/aashreys/01cb34605a290a7cfb94a856bdabc94c +static uint16_t key_timer; // timer to track the last keyboard activity +static void refresh_rgb(void); // refreshes the activity timer and RGB, invoke whenever activity happens +static void check_rgb_timeout(void); // checks if enough time has passed for RGB to timeout +bool is_rgb_timeout = false; // store if RGB has timed out or not in a boolean + +void refresh_rgb() { + key_timer = timer_read(); // store time of last refresh + if (is_rgb_timeout) { // only do something if rgb has timed out + print("Activity detected, removing timeout\n"); + is_rgb_timeout = false; + rgblight_wakeup(); + } +} + +void check_rgb_timeout() { + if (!is_rgb_timeout && timer_elapsed(key_timer) > RGBLIGHT_TIMEOUT) { + rgblight_suspend(); + is_rgb_timeout = true; + } +} +/* Then, call the above functions from QMK's built in post processing functions like so */ +/* Runs at the end of each scan loop, check if RGB timeout has occured */ +void housekeeping_task_user(void) { + #ifdef RGBLIGHT_TIMEOUT + check_rgb_timeout(); + #endif + /* rest of the function code here */ +} +/* Runs after each key press, check if activity occurred */ +void post_process_record_user(uint16_t keycode, keyrecord_t *record) { + #ifdef RGBLIGHT_TIMEOUT + if (record->event.pressed) refresh_rgb(); + #endif + /* rest of the function code here */ +} +/* Runs after each encoder tick, check if activity occurred */ +void post_encoder_update_user(uint8_t index, bool clockwise) { + #ifdef RGBLIGHT_TIMEOUT + refresh_rgb(); + #endif + /* rest of the function code here */ +} |