mirror of
https://github.com/qmk/qmk_firmware.git
synced 2025-06-03 15:02:47 +00:00
Renamed to momentum; moved implementation into dedicated files
This commit is contained in:
parent
f5025c4166
commit
12fcf80d3d
@ -105,6 +105,7 @@ endif
|
||||
ifeq ($(strip $(RGBLIGHT_ENABLE)), yes)
|
||||
OPT_DEFS += -DRGBLIGHT_ENABLE
|
||||
SRC += $(QUANTUM_DIR)/rgblight.c
|
||||
SRC += $(QUANTUM_DIR)/momentum.c
|
||||
CIE1931_CURVE = yes
|
||||
LED_BREATHING_TABLE = yes
|
||||
ifeq ($(strip $(RGBLIGHT_CUSTOM_DRIVER)), yes)
|
||||
|
32
quantum/momentum.c
Normal file
32
quantum/momentum.c
Normal file
@ -0,0 +1,32 @@
|
||||
#include "momentum.h"
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a,b) (((a)<(b))?(a):(b))
|
||||
#endif
|
||||
#ifndef MAX
|
||||
#define MAX(a,b) (((a)>(b))?(a):(b))
|
||||
#endif
|
||||
|
||||
#define TYPING_SPEED_MAX_VALUE 200
|
||||
uint8_t typing_speed = 0;
|
||||
|
||||
void momentum_accelerate() {
|
||||
if (typing_speed < TYPING_SPEED_MAX_VALUE) typing_speed += (TYPING_SPEED_MAX_VALUE / 100);
|
||||
}
|
||||
|
||||
void momentum_decay_task() {
|
||||
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 -= 3;
|
||||
decay_timer = timer_read();
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t match_momentum(uint8_t minValue, uint8_t maxValue) {
|
||||
return MAX(minValue, maxValue - (maxValue - minValue) * ((float)typing_speed / TYPING_SPEED_MAX_VALUE));
|
||||
}
|
11
quantum/momentum.h
Normal file
11
quantum/momentum.h
Normal file
@ -0,0 +1,11 @@
|
||||
#ifndef MOMENTUM_H
|
||||
#define MOMENTUM_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "timer.h"
|
||||
|
||||
void momentum_accelerate(void);
|
||||
void momentum_decay_task(void);
|
||||
uint8_t match_momentum(uint8_t minValue, uint8_t maxValue);
|
||||
|
||||
#endif
|
@ -194,7 +194,7 @@ bool process_record_quantum(keyrecord_t *record) {
|
||||
uint16_t keycode;
|
||||
|
||||
#ifdef RGBLIGHT_ENABLE
|
||||
if (typing_speed < TYPING_SPEED_MAX_VALUE) typing_speed += (TYPING_SPEED_MAX_VALUE / 100);
|
||||
momentum_accelerate();
|
||||
#endif
|
||||
|
||||
#if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS)
|
||||
|
@ -567,29 +567,11 @@ void rgblight_show_solid_color(uint8_t r, uint8_t g, uint8_t b) {
|
||||
rgblight_setrgb(r, g, b);
|
||||
}
|
||||
|
||||
uint8_t typing_speed = 0;
|
||||
void typing_speed_decay_task() {
|
||||
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 -= 3;
|
||||
decay_timer = timer_read();
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t typing_speed_matched_interval(uint8_t minValue, uint8_t maxValue) {
|
||||
return MAX(minValue, maxValue - (maxValue - minValue) * ((float)typing_speed / TYPING_SPEED_MAX_VALUE));
|
||||
}
|
||||
|
||||
void rgblight_task(void) {
|
||||
|
||||
if (rgblight_timer_enabled) {
|
||||
|
||||
typing_speed_decay_task();
|
||||
momentum_decay_task();
|
||||
|
||||
// mode = 1, static light, do nothing here
|
||||
if (rgblight_config.mode >= 2 && rgblight_config.mode <= 5) {
|
||||
@ -623,7 +605,7 @@ void rgblight_effect_breathing(uint8_t interval) {
|
||||
static uint16_t last_timer = 0;
|
||||
float val;
|
||||
|
||||
if (timer_elapsed(last_timer) < typing_speed_matched_interval(1, 100)) {
|
||||
if (timer_elapsed(last_timer) < match_momentum(1, 100)) {
|
||||
return;
|
||||
}
|
||||
last_timer = timer_read();
|
||||
@ -638,7 +620,7 @@ void rgblight_effect_rainbow_mood(uint8_t interval) {
|
||||
static uint16_t current_hue = 0;
|
||||
static uint16_t last_timer = 0;
|
||||
|
||||
if (timer_elapsed(last_timer) < typing_speed_matched_interval(5, 100)) {
|
||||
if (timer_elapsed(last_timer) < match_momentum(5, 100)) {
|
||||
return;
|
||||
}
|
||||
last_timer = timer_read();
|
||||
@ -651,7 +633,7 @@ void rgblight_effect_rainbow_swirl(uint8_t interval) {
|
||||
uint16_t hue;
|
||||
uint8_t i;
|
||||
|
||||
if (timer_elapsed(last_timer) < typing_speed_matched_interval(1, 100)) {
|
||||
if (timer_elapsed(last_timer) < match_momentum(1, 100)) {
|
||||
return;
|
||||
}
|
||||
last_timer = timer_read();
|
||||
@ -680,7 +662,7 @@ void rgblight_effect_snake(uint8_t interval) {
|
||||
if (interval % 2) {
|
||||
increment = -1;
|
||||
}
|
||||
if (timer_elapsed(last_timer) < typing_speed_matched_interval(1, 200)) {
|
||||
if (timer_elapsed(last_timer) < match_momentum(1, 200)) {
|
||||
return;
|
||||
}
|
||||
last_timer = timer_read();
|
||||
@ -711,7 +693,7 @@ void rgblight_effect_snake(uint8_t interval) {
|
||||
}
|
||||
void rgblight_effect_knight(uint8_t interval) {
|
||||
static uint16_t last_timer = 0;
|
||||
if (timer_elapsed(last_timer) < typing_speed_matched_interval(5, 100)) {
|
||||
if (timer_elapsed(last_timer) < match_momentum(5, 100)) {
|
||||
return;
|
||||
}
|
||||
last_timer = timer_read();
|
||||
|
@ -80,6 +80,8 @@
|
||||
#include <avr/pgmspace.h>
|
||||
#endif
|
||||
|
||||
#include "momentum.h"
|
||||
|
||||
extern LED_TYPE led[RGBLED_NUM];
|
||||
|
||||
extern const uint8_t RGBLED_BREATHING_INTERVALS[4] PROGMEM;
|
||||
@ -89,10 +91,6 @@ extern const uint8_t RGBLED_SNAKE_INTERVALS[3] PROGMEM;
|
||||
extern const uint8_t RGBLED_KNIGHT_INTERVALS[3] PROGMEM;
|
||||
extern const uint16_t RGBLED_RGBTEST_INTERVALS[1] PROGMEM;
|
||||
|
||||
//Used in rgblight.c and quantum.c to match RGB animation to typing speed
|
||||
extern uint8_t typing_speed;
|
||||
#define TYPING_SPEED_MAX_VALUE 200
|
||||
|
||||
typedef union {
|
||||
uint32_t raw;
|
||||
struct {
|
||||
@ -171,7 +169,4 @@ void rgblight_effect_knight(uint8_t interval);
|
||||
void rgblight_effect_christmas(void);
|
||||
void rgblight_effect_rgbtest(void);
|
||||
|
||||
void typing_speed_decay_task(void);
|
||||
uint8_t typing_speed_matched_interval(uint8_t minValue, uint8_t maxValue);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user