Move velocikey to within rgblight (#22123)
This commit is contained in:
parent
1052c03a5b
commit
339bff6339
16 changed files with 124 additions and 150 deletions
|
@ -27,9 +27,6 @@
|
|||
#ifdef EEPROM_ENABLE
|
||||
# include "eeprom.h"
|
||||
#endif
|
||||
#ifdef VELOCIKEY_ENABLE
|
||||
# include "velocikey.h"
|
||||
#endif
|
||||
|
||||
#ifdef RGBLIGHT_SPLIT
|
||||
/* for split keyboard */
|
||||
|
@ -198,12 +195,13 @@ void eeconfig_update_rgblight_current(void) {
|
|||
}
|
||||
|
||||
void eeconfig_update_rgblight_default(void) {
|
||||
rgblight_config.enable = 1;
|
||||
rgblight_config.mode = RGBLIGHT_DEFAULT_MODE;
|
||||
rgblight_config.hue = RGBLIGHT_DEFAULT_HUE;
|
||||
rgblight_config.sat = RGBLIGHT_DEFAULT_SAT;
|
||||
rgblight_config.val = RGBLIGHT_DEFAULT_VAL;
|
||||
rgblight_config.speed = RGBLIGHT_DEFAULT_SPD;
|
||||
rgblight_config.enable = 1;
|
||||
rgblight_config.velocikey = 0;
|
||||
rgblight_config.mode = RGBLIGHT_DEFAULT_MODE;
|
||||
rgblight_config.hue = RGBLIGHT_DEFAULT_HUE;
|
||||
rgblight_config.sat = RGBLIGHT_DEFAULT_SAT;
|
||||
rgblight_config.val = RGBLIGHT_DEFAULT_VAL;
|
||||
rgblight_config.speed = RGBLIGHT_DEFAULT_SPD;
|
||||
RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS;
|
||||
eeconfig_update_rgblight(rgblight_config.raw);
|
||||
}
|
||||
|
@ -211,6 +209,7 @@ void eeconfig_update_rgblight_default(void) {
|
|||
void eeconfig_debug_rgblight(void) {
|
||||
dprintf("rgblight_config EEPROM:\n");
|
||||
dprintf("rgblight_config.enable = %d\n", rgblight_config.enable);
|
||||
dprintf("rgblight_config.velocikey = %d\n", rgblight_config.velocikey);
|
||||
dprintf("rghlight_config.mode = %d\n", rgblight_config.mode);
|
||||
dprintf("rgblight_config.hue = %d\n", rgblight_config.hue);
|
||||
dprintf("rgblight_config.sat = %d\n", rgblight_config.sat);
|
||||
|
@ -689,9 +688,9 @@ void rgblight_sethsv_at(uint8_t hue, uint8_t sat, uint8_t val, uint8_t index) {
|
|||
static uint8_t get_interval_time(const uint8_t *default_interval_address, uint8_t velocikey_min, uint8_t velocikey_max) {
|
||||
return
|
||||
# ifdef VELOCIKEY_ENABLE
|
||||
velocikey_enabled() ? velocikey_match_speed(velocikey_min, velocikey_max) :
|
||||
rgblight_velocikey_enabled() ? rgblight_velocikey_match_speed(velocikey_min, velocikey_max) :
|
||||
# endif
|
||||
pgm_read_byte(default_interval_address);
|
||||
pgm_read_byte(default_interval_address);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -1049,7 +1048,7 @@ static void rgblight_effect_dummy(animation_status_t *anim) {
|
|||
**/
|
||||
}
|
||||
|
||||
void rgblight_task(void) {
|
||||
void rgblight_timer_task(void) {
|
||||
if (rgblight_status.timer_enabled) {
|
||||
effect_func_t effect_func = rgblight_effect_dummy;
|
||||
uint16_t interval_time = 2000; // dummy interval
|
||||
|
@ -1519,3 +1518,61 @@ void rgblight_effect_twinkle(animation_status_t *anim) {
|
|||
rgblight_set();
|
||||
}
|
||||
#endif
|
||||
|
||||
void preprocess_rgblight(void) {
|
||||
#ifdef VELOCIKEY_ENABLE
|
||||
if (rgblight_velocikey_enabled()) {
|
||||
rgblight_velocikey_accelerate();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void rgblight_task(void) {
|
||||
#ifdef RGBLIGHT_USE_TIMER
|
||||
rgblight_timer_task();
|
||||
#endif
|
||||
|
||||
#ifdef VELOCIKEY_ENABLE
|
||||
if (rgblight_velocikey_enabled()) {
|
||||
rgblight_velocikey_decelerate();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef VELOCIKEY_ENABLE
|
||||
# define TYPING_SPEED_MAX_VALUE 200
|
||||
|
||||
static uint8_t typing_speed = 0;
|
||||
|
||||
bool rgblight_velocikey_enabled(void) {
|
||||
return rgblight_config.velocikey;
|
||||
}
|
||||
|
||||
void rgblight_velocikey_toggle(void) {
|
||||
dprintf("rgblight velocikey toggle [EEPROM]: rgblight_config.velocikey = %u\n", !rgblight_config.velocikey);
|
||||
rgblight_config.velocikey = !rgblight_config.velocikey;
|
||||
eeconfig_update_rgblight_current();
|
||||
}
|
||||
|
||||
void rgblight_velocikey_accelerate(void) {
|
||||
if (typing_speed < TYPING_SPEED_MAX_VALUE) typing_speed += (TYPING_SPEED_MAX_VALUE / 100);
|
||||
}
|
||||
|
||||
void rgblight_velocikey_decelerate(void) {
|
||||
static uint16_t decay_timer = 0;
|
||||
|
||||
if (timer_elapsed(decay_timer) > 500 || decay_timer == 0) {
|
||||
if (typing_speed > 0) typing_speed -= 1;
|
||||
// Decay a little faster at half of max speed
|
||||
if (typing_speed > TYPING_SPEED_MAX_VALUE / 2) typing_speed -= 1;
|
||||
// Decay even faster at 3/4 of max speed
|
||||
if (typing_speed > TYPING_SPEED_MAX_VALUE / 4 * 3) typing_speed -= 2;
|
||||
decay_timer = timer_read();
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t rgblight_velocikey_match_speed(uint8_t minValue, uint8_t maxValue) {
|
||||
return MAX(minValue, maxValue - (maxValue - minValue) * ((float)typing_speed / TYPING_SPEED_MAX_VALUE));
|
||||
}
|
||||
|
||||
#endif
|
|
@ -248,7 +248,8 @@ typedef union {
|
|||
uint64_t raw;
|
||||
struct {
|
||||
bool enable : 1;
|
||||
uint8_t mode : 7;
|
||||
bool velocikey : 1;
|
||||
uint8_t mode : 6;
|
||||
uint8_t hue : 8;
|
||||
uint8_t sat : 8;
|
||||
uint8_t val : 8;
|
||||
|
@ -385,14 +386,15 @@ void rgblight_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom);
|
|||
#define EZ_RGB(val) rgblight_show_solid_color((val >> 16) & 0xFF, (val >> 8) & 0xFF, val & 0xFF)
|
||||
void rgblight_show_solid_color(uint8_t r, uint8_t g, uint8_t b);
|
||||
|
||||
#ifdef RGBLIGHT_USE_TIMER
|
||||
void preprocess_rgblight(void);
|
||||
void rgblight_task(void);
|
||||
|
||||
#ifdef RGBLIGHT_USE_TIMER
|
||||
void rgblight_timer_init(void);
|
||||
void rgblight_timer_enable(void);
|
||||
void rgblight_timer_disable(void);
|
||||
void rgblight_timer_toggle(void);
|
||||
#else
|
||||
# define rgblight_task()
|
||||
# define rgblight_timer_init()
|
||||
# define rgblight_timer_enable()
|
||||
# define rgblight_timer_disable()
|
||||
|
@ -446,3 +448,14 @@ void rgblight_effect_alternating(animation_status_t *anim);
|
|||
void rgblight_effect_twinkle(animation_status_t *anim);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef VELOCIKEY_ENABLE
|
||||
bool rgblight_velocikey_enabled(void);
|
||||
void rgblight_velocikey_toggle(void);
|
||||
void rgblight_velocikey_accelerate(void);
|
||||
void rgblight_velocikey_decelerate(void);
|
||||
uint8_t rgblight_velocikey_match_speed(uint8_t minValue, uint8_t maxValue);
|
||||
|
||||
# define velocikey_enabled rgblight_velocikey_enabled
|
||||
# define velocikey_toggle rgblight_velocikey_toggle
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue