forked from mirrors/qmk_userspace
Move velocikey to within rgblight (#22123)
This commit is contained in:
parent
1052c03a5b
commit
339bff6339
16 changed files with 124 additions and 150 deletions
|
@ -57,7 +57,7 @@ void eeconfig_init_quantum(void) {
|
|||
eeprom_update_byte(EECONFIG_AUDIO, 0xFF); // On by default
|
||||
eeprom_update_dword(EECONFIG_RGBLIGHT, 0);
|
||||
eeprom_update_byte(EECONFIG_RGBLIGHT_EXTENDED, 0);
|
||||
eeprom_update_byte(EECONFIG_VELOCIKEY, 0);
|
||||
eeprom_update_byte(EECONFIG_UNUSED, 0);
|
||||
eeprom_update_byte(EECONFIG_UNICODEMODE, 0);
|
||||
eeprom_update_byte(EECONFIG_STENOMODE, 0);
|
||||
uint64_t dummy = 0;
|
||||
|
|
|
@ -39,7 +39,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#define EECONFIG_HANDEDNESS (uint8_t *)14
|
||||
#define EECONFIG_KEYBOARD (uint32_t *)15
|
||||
#define EECONFIG_USER (uint32_t *)19
|
||||
#define EECONFIG_VELOCIKEY (uint8_t *)23
|
||||
#define EECONFIG_UNUSED (uint8_t *)23
|
||||
// Mutually exclusive
|
||||
#define EECONFIG_LED_MATRIX (uint32_t *)24
|
||||
#define EECONFIG_RGB_MATRIX (uint64_t *)24
|
||||
|
|
|
@ -99,9 +99,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#ifdef ST7565_ENABLE
|
||||
# include "st7565.h"
|
||||
#endif
|
||||
#ifdef VELOCIKEY_ENABLE
|
||||
# include "velocikey.h"
|
||||
#endif
|
||||
#ifdef VIA_ENABLE
|
||||
# include "via.h"
|
||||
#endif
|
||||
|
@ -708,12 +705,6 @@ void keyboard_task(void) {
|
|||
midi_task();
|
||||
#endif
|
||||
|
||||
#ifdef VELOCIKEY_ENABLE
|
||||
if (velocikey_enabled()) {
|
||||
velocikey_decelerate();
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef JOYSTICK_ENABLE
|
||||
joystick_task();
|
||||
#endif
|
||||
|
|
|
@ -68,10 +68,6 @@
|
|||
# include "process_unicode_common.h"
|
||||
#endif
|
||||
|
||||
#ifdef VELOCIKEY_ENABLE
|
||||
# include "velocikey.h"
|
||||
#endif
|
||||
|
||||
#ifdef AUDIO_ENABLE
|
||||
# ifndef GOODBYE_SONG
|
||||
# define GOODBYE_SONG SONG(GOODBYE_SOUND)
|
||||
|
@ -288,9 +284,9 @@ bool process_record_quantum(keyrecord_t *record) {
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef VELOCIKEY_ENABLE
|
||||
if (velocikey_enabled() && record->event.pressed) {
|
||||
velocikey_accelerate();
|
||||
#ifdef RGBLIGHT_ENABLE
|
||||
if (record->event.pressed) {
|
||||
preprocess_rgblight();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
#include "velocikey.h"
|
||||
#include "timer.h"
|
||||
#include "eeconfig.h"
|
||||
#include "eeprom.h"
|
||||
#include "util.h"
|
||||
|
||||
#define TYPING_SPEED_MAX_VALUE 200
|
||||
uint8_t typing_speed = 0;
|
||||
|
||||
bool velocikey_enabled(void) {
|
||||
return eeprom_read_byte(EECONFIG_VELOCIKEY) == 1;
|
||||
}
|
||||
|
||||
void velocikey_toggle(void) {
|
||||
if (velocikey_enabled())
|
||||
eeprom_update_byte(EECONFIG_VELOCIKEY, 0);
|
||||
else
|
||||
eeprom_update_byte(EECONFIG_VELOCIKEY, 1);
|
||||
}
|
||||
|
||||
void velocikey_accelerate(void) {
|
||||
if (typing_speed < TYPING_SPEED_MAX_VALUE) typing_speed += (TYPING_SPEED_MAX_VALUE / 100);
|
||||
}
|
||||
|
||||
void 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 velocikey_match_speed(uint8_t minValue, uint8_t maxValue) {
|
||||
return MAX(minValue, maxValue - (maxValue - minValue) * ((float)typing_speed / TYPING_SPEED_MAX_VALUE));
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
bool velocikey_enabled(void);
|
||||
void velocikey_toggle(void);
|
||||
void velocikey_accelerate(void);
|
||||
void velocikey_decelerate(void);
|
||||
uint8_t velocikey_match_speed(uint8_t minValue, uint8_t maxValue);
|
Loading…
Add table
Add a link
Reference in a new issue