From 291fcfe40be034ff8900b179429df84ed55997b5 Mon Sep 17 00:00:00 2001 From: plodah Date: Sat, 17 Aug 2024 23:19:50 +0100 Subject: [PATCH] Add a typing indicator for some reason --- users/plodah/functions/indicators.c | 9 +++++++++ users/plodah/functions/kc_handler.c | 4 ++++ users/plodah/functions/typing_indicator.c | 23 +++++++++++++++++++++++ users/plodah/plodah.c | 10 ++++++++++ 4 files changed, 46 insertions(+) create mode 100644 users/plodah/functions/typing_indicator.c diff --git a/users/plodah/functions/indicators.c b/users/plodah/functions/indicators.c index 8f69e014b9e..869cd433092 100644 --- a/users/plodah/functions/indicators.c +++ b/users/plodah/functions/indicators.c @@ -70,6 +70,15 @@ bool plodah_indicator_handler(void) { } # endif // DYNAMIC_MACRO_ENABLE && PLODAH_DMAC_INDIC_INDEX +# ifdef PLODAH_TYPINGINDICATOR_RGBINDEX + if(!rgb_matrix_get_flags()){ + rgb_matrix_set_color(PLODAH_TYPINGINDICATOR_RGBINDEX, RGB_OFF); + } + if(plodah_typingindicator_active){ + rgb_matrix_set_color(PLODAH_TYPINGINDICATOR_RGBINDEX, PLODAH_TYPINGINDICATOR_RGBCOLOR); + } +# endif // PLODAH_TYPINGINDICATOR_RGBINDEX + # ifdef PLODAH_MODS_INDIC_LALT_INDEX if (!rgb_matrix_get_flags()) { rgb_matrix_set_color(PLODAH_MODS_INDIC_LALT_INDEX, RGB_OFF); diff --git a/users/plodah/functions/kc_handler.c b/users/plodah/functions/kc_handler.c index 89680c89a47..e926d176fc8 100644 --- a/users/plodah/functions/kc_handler.c +++ b/users/plodah/functions/kc_handler.c @@ -6,6 +6,10 @@ bool kc_handler(uint16_t keycode, keyrecord_t *record) { +# if defined(PLODAH_TYPINGINDICATOR_RGBINDEX) + plodah_typingindicator_start(); +# endif // PLODAH_TYPINGINDICATOR_RGBINDEX + switch (keycode) { // Static version keycode case PL_VERS: diff --git a/users/plodah/functions/typing_indicator.c b/users/plodah/functions/typing_indicator.c new file mode 100644 index 00000000000..750560414eb --- /dev/null +++ b/users/plodah/functions/typing_indicator.c @@ -0,0 +1,23 @@ +bool plodah_typingindicator_active = false; +uint16_t plodah_typingindicator_timer = 0; + +#ifndef PLODAH_TYPINGINDICATOR_RGBCOLOR +# define PLODAH_TYPINGINDICATOR_RGBCOLOR RGB_RED +#endif //PLODAH_TYPINGINDICATOR_RGBCOLOR + +#ifndef PLODAH_TYPINGINDICATOR_DURATION +# define PLODAH_TYPINGINDICATOR_DURATION 1000 +#endif //PLODAH_TYPINGINDICATOR_DURATION + +void plodah_typingindicator_start(void){ + plodah_typingindicator_timer = timer_read(); + plodah_typingindicator_active = true; +} + +void plodah_typingindicator_check(void){ + if(plodah_typingindicator_active){ + if(timer_elapsed(plodah_typingindicator_timer) > PLODAH_TYPINGINDICATOR_DURATION){ + plodah_typingindicator_active = false; + } + } +} diff --git a/users/plodah/plodah.c b/users/plodah/plodah.c index 59a9bce0690..8fb65ff7b24 100644 --- a/users/plodah/plodah.c +++ b/users/plodah/plodah.c @@ -51,6 +51,13 @@ }; #endif +//============================// +// TYPING INDICATOR // +//============================// +#if defined(PLODAH_TYPINGINDICATOR_RGBINDEX) +# include "functions/typing_indicator.c" +#endif // PLODAH_TYPINGINDICATOR_RGBINDEX + //===========================// // CUSTOM KEYCODES // //===========================// @@ -92,6 +99,9 @@ void matrix_scan_user(void) { # if defined(AUTOCORRECT_ENABLE) && defined(RGB_MATRIX_ENABLE) plodah_autocorrect_indicator_check(); # endif // AUTOCORRECT_ENABLE && RGB_MATRIX_ENABLE +# if defined (PLODAH_TYPINGINDICATOR_RGBINDEX) + plodah_typingindicator_check(); +# endif // PLODAH_TYPINGINDICATOR_RGBINDEX } //==========================//