From 58cd0fd6820cb5c89c21fb26eed667b79d677950 Mon Sep 17 00:00:00 2001 From: plodah Date: Sun, 18 Aug 2024 00:30:55 +0100 Subject: [PATCH] Further separate autocorrect indicator into sepeate c --- .../plodah/functions/autocorrect_indicator.c | 112 ++++++++++-------- users/plodah/plodah.c | 18 +-- 2 files changed, 64 insertions(+), 66 deletions(-) diff --git a/users/plodah/functions/autocorrect_indicator.c b/users/plodah/functions/autocorrect_indicator.c index 7f0d410192c..999be0aa11a 100644 --- a/users/plodah/functions/autocorrect_indicator.c +++ b/users/plodah/functions/autocorrect_indicator.c @@ -1,64 +1,78 @@ -bool autocorrect_indicator_on = false; -uint8_t autocorrect_indicator_count = 255; -uint16_t autocorrect_indicator_timer = 0; -HSV curhsv; -HSV indhsv; -uint8_t useval; +#if defined(RGB_MATRIX_ENABLE) + bool autocorrect_indicator_on = false; + uint8_t autocorrect_indicator_count = 255; + uint16_t autocorrect_indicator_timer = 0; + HSV curhsv; + HSV indhsv; + uint8_t useval; -#ifndef PLODAH_AUTOCORRECT_INDICATOR_DURATION -# define PLODAH_AUTOCORRECT_INDICATOR_DURATION 200 -#endif //PLODAH_AUTOCORRECT_INDICATOR_DURATION + #ifndef PLODAH_AUTOCORRECT_INDICATOR_DURATION + # define PLODAH_AUTOCORRECT_INDICATOR_DURATION 200 + #endif //PLODAH_AUTOCORRECT_INDICATOR_DURATION -#ifndef PLODAH_AUTOCORRECT_INDICATOR_BLINKCOUNT -# define PLODAH_AUTOCORRECT_INDICATOR_BLINKCOUNT 3 -#endif // PLODAH_AUTOCORRECT_INDICATOR_BLINKCOUNT + #ifndef PLODAH_AUTOCORRECT_INDICATOR_BLINKCOUNT + # define PLODAH_AUTOCORRECT_INDICATOR_BLINKCOUNT 3 + #endif // PLODAH_AUTOCORRECT_INDICATOR_BLINKCOUNT -#ifndef PLODAH_AUTOCORRECT_INDICATOR_COLOUR -# define PLODAH_AUTOCORRECT_INDICATOR_COLOUR HSV_RED -#endif //PLODAH_AUTOCORRECT_INDICATOR_COLOUR + #ifndef PLODAH_AUTOCORRECT_INDICATOR_COLOUR + # define PLODAH_AUTOCORRECT_INDICATOR_COLOUR HSV_RED + #endif //PLODAH_AUTOCORRECT_INDICATOR_COLOUR -#ifndef PLODAH_AUTOCORRECT_INDICATOR_MINVAL -# define PLODAH_AUTOCORRECT_INDICATOR_MINVAL 85 -#endif // PLODAH_AUTOCORRECT_INDICATOR_MINVAL + #ifndef PLODAH_AUTOCORRECT_INDICATOR_MINVAL + # define PLODAH_AUTOCORRECT_INDICATOR_MINVAL 85 + #endif // PLODAH_AUTOCORRECT_INDICATOR_MINVAL -void plodah_autocorrect_indicator_on(void){ - HSV indhsv = { PLODAH_AUTOCORRECT_INDICATOR_COLOUR }; - if(PLODAH_AUTOCORRECT_INDICATOR_MINVAL > curhsv.v){ - useval = PLODAH_AUTOCORRECT_INDICATOR_MINVAL; - } - else{ - useval = curhsv.v; + void plodah_autocorrect_indicator_on(void){ + HSV indhsv = { PLODAH_AUTOCORRECT_INDICATOR_COLOUR }; + if(PLODAH_AUTOCORRECT_INDICATOR_MINVAL > curhsv.v){ + useval = PLODAH_AUTOCORRECT_INDICATOR_MINVAL; + } + else{ + useval = curhsv.v; + } + autocorrect_indicator_on = true; + rgb_matrix_mode_noeeprom(RGB_MATRIX_SOLID_COLOR); + rgb_matrix_sethsv_noeeprom(indhsv.s, indhsv.s, useval); + autocorrect_indicator_timer = timer_read(); } - autocorrect_indicator_on = true; - rgb_matrix_mode_noeeprom(RGB_MATRIX_SOLID_COLOR); - rgb_matrix_sethsv_noeeprom(indhsv.s, indhsv.s, useval); - autocorrect_indicator_timer = timer_read(); -} -void plodah_autocorrect_indicator_off(void){ - autocorrect_indicator_count ++; - autocorrect_indicator_on = false; - rgb_matrix_reload_from_eeprom(); - autocorrect_indicator_timer = timer_read(); -} + void plodah_autocorrect_indicator_off(void){ + autocorrect_indicator_count ++; + autocorrect_indicator_on = false; + rgb_matrix_reload_from_eeprom(); + autocorrect_indicator_timer = timer_read(); + } -void plodah_autocorrect_indicator_start(void){ - autocorrect_indicator_count = 0; - if (autocorrect_indicator_count == 0){ - curhsv = rgb_matrix_get_hsv(); + void plodah_autocorrect_indicator_start(void){ + autocorrect_indicator_count = 0; + if (autocorrect_indicator_count == 0){ + curhsv = rgb_matrix_get_hsv(); + } } -} -void plodah_autocorrect_indicator_check(void){ - if (autocorrect_indicator_count < PLODAH_AUTOCORRECT_INDICATOR_BLINKCOUNT){ - if (timer_elapsed(autocorrect_indicator_timer) > PLODAH_AUTOCORRECT_INDICATOR_DURATION){ - if (autocorrect_indicator_on){ - plodah_autocorrect_indicator_off(); - } - else{ - plodah_autocorrect_indicator_on(); + void plodah_autocorrect_indicator_check(void){ + if (autocorrect_indicator_count < PLODAH_AUTOCORRECT_INDICATOR_BLINKCOUNT){ + if (timer_elapsed(autocorrect_indicator_timer) > PLODAH_AUTOCORRECT_INDICATOR_DURATION){ + if (autocorrect_indicator_on){ + plodah_autocorrect_indicator_off(); + } + else{ + plodah_autocorrect_indicator_on(); + } } } } + +#endif // RGB_MATRIX_ENABLE + +bool apply_autocorrect(uint8_t backspaces, const char *str, char *typo, char *correct) { +# if defined(RGB_MATRIX_ENABLE) + for (uint8_t i = 0; i < backspaces; ++i) { + tap_code(KC_BSPC); + } + send_string_P(str); + plodah_autocorrect_indicator_start(); +# endif // RGB_MATRIX_ENABLE + return false; } diff --git a/users/plodah/plodah.c b/users/plodah/plodah.c index 8fb65ff7b24..bde4c8fe734 100644 --- a/users/plodah/plodah.c +++ b/users/plodah/plodah.c @@ -36,9 +36,7 @@ // AUTOCORRECT // //=======================// #if defined(AUTOCORRECT_ENABLE) -# if defined(RGB_MATRIX_ENABLE) -# include "functions/autocorrect_indicator.c" -# endif // RGB_MATRIX_ENABLE +# include "functions/autocorrect_indicator.c" #endif // AUTOCORRECT_ENABLE //====================// @@ -133,20 +131,6 @@ void matrix_scan_user(void) { } #endif // CAPS_WORD_ENABLE -//=======================// -// AUTOCORRECT // -//=======================// -#if defined(AUTOCORRECT_ENABLE) && defined(RGB_MATRIX_ENABLE) - bool apply_autocorrect(uint8_t backspaces, const char *str, char *typo, char *correct) { - for (uint8_t i = 0; i < backspaces; ++i) { - tap_code(KC_BSPC); - } - send_string_P(str); - plodah_autocorrect_indicator_start(); - return false; - } -#endif // AUTOCORRECT_ENABLE && RGB_MATRIX_ENABLE - //==========================// // DYNAMIC MACROS // //==========================//