skeletyl: add rgb timeout
This commit is contained in:
parent
af805693b2
commit
1162897377
2 changed files with 48 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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 */
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue