diff options
author | lokher <lokher@gmail.com> | 2022-09-22 17:33:56 +0800 |
---|---|---|
committer | lokher <lokher@gmail.com> | 2022-09-22 17:33:56 +0800 |
commit | f67150f16cb0e5bc71dc3320750ff96ba99e96dc (patch) | |
tree | 559bf802f0737dac2e0d4892577818d10d7c9f39 /quantum | |
parent | 9581289745736ce068a1040f44cec37a2ca8830d (diff) |
refactor indicator.c; fix LED/RGB_MATRIX_BRIGHTNESS_TURN_OFF_VAL related issue
Diffstat (limited to 'quantum')
-rw-r--r-- | quantum/led_matrix/led_matrix.c | 38 | ||||
-rw-r--r-- | quantum/led_matrix/led_matrix.h | 1 | ||||
-rw-r--r-- | quantum/rgb_matrix/rgb_matrix.c | 38 | ||||
-rw-r--r-- | quantum/rgb_matrix/rgb_matrix.h | 1 | ||||
-rw-r--r-- | quantum/via.c | 10 |
5 files changed, 53 insertions, 35 deletions
diff --git a/quantum/led_matrix/led_matrix.c b/quantum/led_matrix/led_matrix.c index 67898d5f18..b421480d41 100644 --- a/quantum/led_matrix/led_matrix.c +++ b/quantum/led_matrix/led_matrix.c @@ -87,6 +87,9 @@ const led_point_t k_led_matrix_center = LED_MATRIX_CENTER; # define LED_MATRIX_STARTUP_SPD UINT8_MAX / 2 #endif +#if defined(LED_MATRIX_BRIGHTNESS_TURN_OFF_VAL) && (LED_MATRIX_BRIGHTNESS_TURN_OFF_VAL >= LED_MATRIX_MAXIMUM_BRIGHTNESS) +# pragma error("LED_MATRIX_BRIGHTNESS_TURN_OFF_VAL must be less than LED_MATRIX_MAXIMUM_BRIGHTNESS") +#endif // globals led_eeconfig_t led_matrix_eeconfig; // TODO: would like to prefix this with g_ for global consistancy, do this in another pr uint32_t g_led_timer; @@ -101,7 +104,6 @@ last_hit_t g_last_hit_tracker; #ifdef LED_MATRIX_DRIVER_SHUTDOWN_ENABLE static bool driver_shutdown = false; #endif -static uint8_t led_enable_eeprom = false; static bool suspend_state = false; static uint8_t led_last_enable = UINT8_MAX; static uint8_t led_last_effect = UINT8_MAX; @@ -125,6 +127,8 @@ const uint8_t k_led_matrix_split[2] = LED_MATRIX_SPLIT; EECONFIG_DEBOUNCE_HELPER(led_matrix, EECONFIG_LED_MATRIX, led_matrix_eeconfig); +void led_matrix_increase_val_helper(bool write_to_eeprom); + void eeconfig_update_led_matrix(void) { eeconfig_flush_led_matrix(true); } @@ -413,11 +417,6 @@ void led_matrix_task(void) { } } -static inline void led_enable_state_backup(void) { - dprintf("led_enable_state_backup\n"); - led_enable_eeprom = led_matrix_eeconfig.enable; -} - void led_matrix_indicators(void) { led_matrix_indicators_kb(); led_matrix_indicators_user(); @@ -478,7 +477,6 @@ void led_matrix_init(void) { dprintf("led_matrix_init_drivers led_matrix_eeconfig.mode = 0. Write default values to EEPROM.\n"); eeconfig_update_led_matrix_default(); } - led_enable_state_backup(); eeconfig_debug_led_matrix(); // display current eeprom values } @@ -500,8 +498,12 @@ void led_matrix_toggle_eeprom_helper(bool write_to_eeprom) { led_matrix_eeconfig.enable ^= 1; led_task_state = STARTING; eeconfig_flag_led_matrix(write_to_eeprom); - if (write_to_eeprom) led_enable_state_backup(); dprintf("led matrix toggle [%s]: led_matrix_eeconfig.enable = %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.enable); +#ifdef LED_MATRIX_BRIGHTNESS_TURN_OFF_VAL + while (led_matrix_eeconfig.enable && led_matrix_eeconfig.val <= LED_MATRIX_BRIGHTNESS_TURN_OFF_VAL) { + led_matrix_increase_val_helper(write_to_eeprom); + } +#endif } void led_matrix_toggle_noeeprom(void) { led_matrix_toggle_eeprom_helper(false); @@ -513,18 +515,26 @@ void led_matrix_toggle(void) { void led_matrix_enable(void) { led_matrix_enable_noeeprom(); eeconfig_flag_led_matrix(true); - led_enable_state_backup(); +#ifdef LED_MATRIX_BRIGHTNESS_TURN_OFF_VAL + while (led_matrix_eeconfig.val <= LED_MATRIX_BRIGHTNESS_TURN_OFF_VAL) { + led_matrix_increase_val_helper(true); + } +#endif } void led_matrix_enable_noeeprom(void) { if (!led_matrix_eeconfig.enable) led_task_state = STARTING; led_matrix_eeconfig.enable = 1; +#ifdef LED_MATRIX_BRIGHTNESS_TURN_OFF_VAL + while (led_matrix_eeconfig.val <= LED_MATRIX_BRIGHTNESS_TURN_OFF_VAL) { + led_matrix_increase_val_helper(false); + } +#endif } void led_matrix_disable(void) { led_matrix_disable_noeeprom(); eeconfig_flag_led_matrix(true); - led_enable_state_backup(); } void led_matrix_disable_noeeprom(void) { @@ -536,11 +546,6 @@ uint8_t led_matrix_is_enabled(void) { return led_matrix_eeconfig.enable; } - -uint8_t led_matrix_is_enabled_eeprom(void) { - return led_enable_eeprom; -} - void led_matrix_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) { if (!led_matrix_eeconfig.enable) { return; @@ -611,8 +616,8 @@ uint8_t led_matrix_get_val(void) { void led_matrix_increase_val_helper(bool write_to_eeprom) { #ifdef LED_MATRIX_BRIGHTNESS_TURN_OFF_VAL if (!led_matrix_eeconfig.enable) { - dprintf("increase_val to enable"); led_matrix_toggle_eeprom_helper(write_to_eeprom); + return; } #endif led_matrix_set_val_eeprom_helper(qadd8(led_matrix_eeconfig.val, LED_MATRIX_VAL_STEP), write_to_eeprom); @@ -628,7 +633,6 @@ void led_matrix_decrease_val_helper(bool write_to_eeprom) { led_matrix_set_val_eeprom_helper(qsub8(led_matrix_eeconfig.val, LED_MATRIX_VAL_STEP), write_to_eeprom); #ifdef LED_MATRIX_BRIGHTNESS_TURN_OFF_VAL if (led_matrix_eeconfig.enable && led_matrix_eeconfig.val <= LED_MATRIX_BRIGHTNESS_TURN_OFF_VAL) { - dprintf("decrease_val to disable\n"); led_matrix_toggle_eeprom_helper(write_to_eeprom); } #endif diff --git a/quantum/led_matrix/led_matrix.h b/quantum/led_matrix/led_matrix.h index 936083c259..d5da114c92 100644 --- a/quantum/led_matrix/led_matrix.h +++ b/quantum/led_matrix/led_matrix.h @@ -143,7 +143,6 @@ void led_matrix_enable_noeeprom(void); void led_matrix_disable(void); void led_matrix_disable_noeeprom(void); uint8_t led_matrix_is_enabled(void); -uint8_t led_matrix_is_enabled_eeprom(void); void led_matrix_mode(uint8_t mode); void led_matrix_mode_noeeprom(uint8_t mode); uint8_t led_matrix_get_mode(void); diff --git a/quantum/rgb_matrix/rgb_matrix.c b/quantum/rgb_matrix/rgb_matrix.c index 92da08b31c..1ba1686b44 100644 --- a/quantum/rgb_matrix/rgb_matrix.c +++ b/quantum/rgb_matrix/rgb_matrix.c @@ -110,6 +110,10 @@ __attribute__((weak)) RGB rgb_matrix_hsv_to_rgb(HSV hsv) { # define RGB_MATRIX_STARTUP_SPD UINT8_MAX / 2 #endif +#if defined(RGB_MATRIX_BRIGHTNESS_TURN_OFF_VAL) && (RGB_MATRIX_BRIGHTNESS_TURN_OFF_VAL >= RGB_MATRIX_MAXIMUM_BRIGHTNESS) +# pragma error("RGB_MATRIX_BRIGHTNESS_TURN_OFF_VAL must be less than RGB_MATRIX_MAXIMUM_BRIGHTNESS") +#endif + // globals rgb_config_t rgb_matrix_config; // TODO: would like to prefix this with g_ for global consistancy, do this in another pr uint32_t g_rgb_timer; @@ -124,7 +128,6 @@ last_hit_t g_last_hit_tracker; #ifdef RGB_MATRIX_DRIVER_SHUTDOWN_ENABLE static bool driver_shutdown = false; #endif -static uint8_t rgb_enable_eeprom = false; static bool suspend_state = false; static uint8_t rgb_last_enable = UINT8_MAX; static uint8_t rgb_last_effect = UINT8_MAX; @@ -148,6 +151,8 @@ const uint8_t k_rgb_matrix_split[2] = RGB_MATRIX_SPLIT; EECONFIG_DEBOUNCE_HELPER(rgb_matrix, EECONFIG_RGB_MATRIX, rgb_matrix_config); +void rgb_matrix_increase_val_helper(bool write_to_eeprom); + void eeconfig_update_rgb_matrix(void) { eeconfig_flush_rgb_matrix(true); } @@ -473,11 +478,6 @@ void rgb_matrix_task(void) { } } -static inline void rgb_enable_state_backup(void) { - dprintf("rgb_enable_state_backup\n"); - rgb_enable_eeprom = rgb_matrix_config.enable; -} - void rgb_matrix_indicators(void) { rgb_matrix_indicators_kb(); rgb_matrix_indicators_user(); @@ -538,7 +538,6 @@ void rgb_matrix_init(void) { dprintf("rgb_matrix_init_drivers rgb_matrix_config.mode = 0. Write default values to EEPROM.\n"); eeconfig_update_rgb_matrix_default(); } - rgb_enable_state_backup(); eeconfig_debug_rgb_matrix(); // display current eeprom values } @@ -560,8 +559,12 @@ void rgb_matrix_toggle_eeprom_helper(bool write_to_eeprom) { rgb_matrix_config.enable ^= 1; rgb_task_state = STARTING; eeconfig_flag_rgb_matrix(write_to_eeprom); - if (write_to_eeprom) rgb_enable_state_backup(); dprintf("rgb matrix toggle [%s]: rgb_matrix_config.enable = %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.enable); +#ifdef RGB_MATRIX_BRIGHTNESS_TURN_OFF_VAL + while (rgb_matrix_config.enable && rgb_matrix_config.hsv.v < RGB_MATRIX_BRIGHTNESS_TURN_OFF_VAL) { + rgb_matrix_increase_val_helper(write_to_eeprom); + } +#endif } void rgb_matrix_toggle_noeeprom(void) { rgb_matrix_toggle_eeprom_helper(false); @@ -573,18 +576,26 @@ void rgb_matrix_toggle(void) { void rgb_matrix_enable(void) { rgb_matrix_enable_noeeprom(); eeconfig_flag_rgb_matrix(true); - rgb_enable_state_backup(); +#ifdef RGB_MATRIX_BRIGHTNESS_TURN_OFF_VAL + while (rgb_matrix_config.hsv.v < RGB_MATRIX_BRIGHTNESS_TURN_OFF_VAL) { + rgb_matrix_increase_val_helper(true); + } +#endif } void rgb_matrix_enable_noeeprom(void) { if (!rgb_matrix_config.enable) rgb_task_state = STARTING; rgb_matrix_config.enable = 1; +#ifdef RGB_MATRIX_BRIGHTNESS_TURN_OFF_VAL + while (rgb_matrix_config.hsv.v < RGB_MATRIX_BRIGHTNESS_TURN_OFF_VAL) { + rgb_matrix_increase_val_helper(false); + } +#endif } void rgb_matrix_disable(void) { rgb_matrix_disable_noeeprom(); eeconfig_flag_rgb_matrix(true); - rgb_enable_state_backup(); } void rgb_matrix_disable_noeeprom(void) { @@ -596,10 +607,6 @@ uint8_t rgb_matrix_is_enabled(void) { return rgb_matrix_config.enable; } -uint8_t rgb_matrix_is_enabled_eeprom(void) { - return rgb_enable_eeprom; -} - void rgb_matrix_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) { if (!rgb_matrix_config.enable) { return; @@ -721,8 +728,8 @@ void rgb_matrix_decrease_sat(void) { void rgb_matrix_increase_val_helper(bool write_to_eeprom) { #ifdef RGB_MATRIX_BRIGHTNESS_TURN_OFF_VAL if (!rgb_matrix_config.enable) { - dprintf("increase_val to enable"); rgb_matrix_toggle_eeprom_helper(write_to_eeprom); + return; } #endif rgb_matrix_sethsv_eeprom_helper(rgb_matrix_config.hsv.h, rgb_matrix_config.hsv.s, qadd8(rgb_matrix_config.hsv.v, RGB_MATRIX_VAL_STEP), write_to_eeprom); @@ -738,7 +745,6 @@ void rgb_matrix_decrease_val_helper(bool write_to_eeprom) { rgb_matrix_sethsv_eeprom_helper(rgb_matrix_config.hsv.h, rgb_matrix_config.hsv.s, qsub8(rgb_matrix_config.hsv.v, RGB_MATRIX_VAL_STEP), write_to_eeprom); #ifdef RGB_MATRIX_BRIGHTNESS_TURN_OFF_VAL if (rgb_matrix_config.enable && rgb_matrix_config.hsv.v <= RGB_MATRIX_BRIGHTNESS_TURN_OFF_VAL) { - dprintf("decrease_val to disable\n"); rgb_matrix_toggle_eeprom_helper(write_to_eeprom); } #endif diff --git a/quantum/rgb_matrix/rgb_matrix.h b/quantum/rgb_matrix/rgb_matrix.h index 3b11cf7781..dca07cf367 100644 --- a/quantum/rgb_matrix/rgb_matrix.h +++ b/quantum/rgb_matrix/rgb_matrix.h @@ -154,7 +154,6 @@ void rgb_matrix_enable_noeeprom(void); void rgb_matrix_disable(void); void rgb_matrix_disable_noeeprom(void); uint8_t rgb_matrix_is_enabled(void); -uint8_t rgb_matrix_is_enabled_eeprom(void); void rgb_matrix_mode(uint8_t mode); void rgb_matrix_mode_noeeprom(uint8_t mode); uint8_t rgb_matrix_get_mode(void); diff --git a/quantum/via.c b/quantum/via.c index f70cf26347..83239ae773 100644 --- a/quantum/via.c +++ b/quantum/via.c @@ -604,7 +604,17 @@ void via_qmk_rgb_matrix_set_value(uint8_t *data) { uint8_t *value_data = &(data[1]); switch (*value_id) { case id_qmk_rgblight_brightness: +#ifdef RGB_MATRIX_TURN_OFF_VAL + if (!rgb_matrix_is_enabled() && value_data[0] >= RGB_MATRIX_TURN_OFF_VAL) { + rgb_matrix_toggle_noeeprom(); + } +#endif rgb_matrix_sethsv_noeeprom(rgb_matrix_get_hue(), rgb_matrix_get_sat(), scale8(value_data[0], RGB_MATRIX_MAXIMUM_BRIGHTNESS)); +#ifdef RGB_MATRIX_TURN_OFF_VAL + if (rgb_matrix_is_enabled() && value_data[0] < RGB_MATRIX_TURN_OFF_VAL) { + rgb_matrix_toggle_noeeprom(); + } +#endif break; case id_qmk_rgblight_effect: rgb_matrix_mode_noeeprom(value_data[0]); |