summaryrefslogtreecommitdiff
path: root/quantum
diff options
context:
space:
mode:
Diffstat (limited to 'quantum')
-rw-r--r--quantum/quantum.c17
-rw-r--r--quantum/quantum_keycodes.h3
-rw-r--r--quantum/rgblight.c40
-rw-r--r--quantum/velocikey.c46
-rw-r--r--quantum/velocikey.h13
5 files changed, 113 insertions, 6 deletions
diff --git a/quantum/quantum.c b/quantum/quantum.c
index cb4d5ee806..46d404029f 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -47,6 +47,10 @@ extern backlight_config_t backlight_config;
#include "process_midi.h"
#endif
+#ifdef VELOCIKEY_ENABLE
+#include "velocikey.h"
+#endif
+
#ifdef HAPTIC_ENABLE
#include "haptic.h"
#endif
@@ -251,6 +255,10 @@ bool process_record_quantum(keyrecord_t *record) {
// return false;
// }
+ #ifdef VELOCIKEY_ENABLE
+ if (velocikey_enabled() && record->event.pressed) { velocikey_accelerate(); }
+ #endif
+
#ifdef TAP_DANCE_ENABLE
preprocess_tap_dance(keycode, record);
#endif
@@ -568,7 +576,14 @@ bool process_record_quantum(keyrecord_t *record) {
#endif
return false;
#endif // defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
- #ifdef PROTOCOL_LUFA
+ #ifdef VELOCIKEY_ENABLE
+ case VLK_TOG:
+ if (record->event.pressed) {
+ velocikey_toggle();
+ }
+ return false;
+ #endif
+ #ifdef PROTOCOL_LUFA
case OUT_AUTO:
if (record->event.pressed) {
set_output(OUTPUT_AUTO);
diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h
index 00c84cbf53..1ced6ae37e 100644
--- a/quantum/quantum_keycodes.h
+++ b/quantum/quantum_keycodes.h
@@ -422,6 +422,9 @@ enum quantum_keycodes {
RGB_MODE_GRADIENT,
RGB_MODE_RGBTEST,
+ //Momentum matching toggle
+ VLK_TOG,
+
// Left shift, open paren
KC_LSPO,
diff --git a/quantum/rgblight.c b/quantum/rgblight.c
index 45d521786e..57de56df70 100644
--- a/quantum/rgblight.c
+++ b/quantum/rgblight.c
@@ -30,6 +30,9 @@
#include "rgblight.h"
#include "debug.h"
#include "led_tables.h"
+#ifdef VELOCIKEY_ENABLE
+ #include "velocikey.h"
+#endif
#define _RGBM_SINGLE_STATIC(sym) RGBLIGHT_MODE_ ## sym,
#define _RGBM_SINGLE_DYNAMIC(sym)
@@ -607,6 +610,19 @@ void rgblight_sethsv_at(uint16_t hue, uint8_t sat, uint8_t val, uint8_t index) {
rgblight_setrgb_at(tmp_led.r, tmp_led.g, tmp_led.b, index);
}
+#if defined(RGBLIGHT_EFFECT_BREATHING) || defined(RGBLIGHT_EFFECT_RAINBOW_MOOD) || defined(RGBLIGHT_EFFECT_RAINBOW_SWIRL) \
+ || defined(RGBLIGHT_EFFECT_SNAKE) || defined(RGBLIGHT_EFFECT_KNIGHT)
+
+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) :
+#endif
+ pgm_read_byte(default_interval_address);
+}
+
+#endif
+
void rgblight_setrgb_range(uint8_t r, uint8_t g, uint8_t b, uint8_t start, uint8_t end) {
if (!rgblight_config.enable || start < 0 || start >= end || end > RGBLED_NUM) { return; }
@@ -707,6 +723,7 @@ void rgblight_show_solid_color(uint8_t r, uint8_t g, uint8_t b) {
}
void rgblight_task(void) {
+
if (rgblight_timer_enabled) {
// static light mode, do nothing here
if ( 1 == 0 ) { //dummy
@@ -778,7 +795,9 @@ void rgblight_effect_breathing(uint8_t interval) {
static uint16_t last_timer = 0;
float val;
- if (timer_elapsed(last_timer) < pgm_read_byte(&RGBLED_BREATHING_INTERVALS[interval])) {
+ uint8_t interval_time = get_interval_time(&RGBLED_RAINBOW_SWIRL_INTERVALS[interval / 2], 1, 100);
+
+ if (timer_elapsed(last_timer) < interval_time) {
return;
}
last_timer = timer_read();
@@ -798,7 +817,9 @@ 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) < pgm_read_byte(&RGBLED_RAINBOW_MOOD_INTERVALS[interval])) {
+ uint8_t interval_time = get_interval_time(&RGBLED_RAINBOW_MOOD_INTERVALS[interval], 5, 100);
+
+ if (timer_elapsed(last_timer) < interval_time) {
return;
}
last_timer = timer_read();
@@ -820,7 +841,10 @@ void rgblight_effect_rainbow_swirl(uint8_t interval) {
static uint16_t last_timer = 0;
uint16_t hue;
uint8_t i;
- if (timer_elapsed(last_timer) < pgm_read_byte(&RGBLED_RAINBOW_SWIRL_INTERVALS[interval / 2])) {
+
+ uint8_t interval_time = get_interval_time(&RGBLED_RAINBOW_SWIRL_INTERVALS[interval / 2], 1, 100);
+
+ if (timer_elapsed(last_timer) < interval_time) {
return;
}
last_timer = timer_read();
@@ -855,7 +879,10 @@ void rgblight_effect_snake(uint8_t interval) {
if (interval % 2) {
increment = -1;
}
- if (timer_elapsed(last_timer) < pgm_read_byte(&RGBLED_SNAKE_INTERVALS[interval / 2])) {
+
+ uint8_t interval_time = get_interval_time(&RGBLED_SNAKE_INTERVALS[interval / 2], 1, 200);
+
+ if (timer_elapsed(last_timer) < interval_time) {
return;
}
last_timer = timer_read();
@@ -892,7 +919,10 @@ const uint8_t RGBLED_KNIGHT_INTERVALS[] PROGMEM = {127, 63, 31};
void rgblight_effect_knight(uint8_t interval) {
static uint16_t last_timer = 0;
- if (timer_elapsed(last_timer) < pgm_read_byte(&RGBLED_KNIGHT_INTERVALS[interval])) {
+
+ uint8_t interval_time = get_interval_time(&RGBLED_KNIGHT_INTERVALS[interval], 5, 100);
+
+ if (timer_elapsed(last_timer) < interval_time) {
return;
}
last_timer = timer_read();
diff --git a/quantum/velocikey.c b/quantum/velocikey.c
new file mode 100644
index 0000000000..550c3b70a6
--- /dev/null
+++ b/quantum/velocikey.c
@@ -0,0 +1,46 @@
+#include "velocikey.h"
+#include "timer.h"
+#include "eeconfig.h"
+#include "eeprom.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;
+
+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));
+}
diff --git a/quantum/velocikey.h b/quantum/velocikey.h
new file mode 100644
index 0000000000..1910f0f4e9
--- /dev/null
+++ b/quantum/velocikey.h
@@ -0,0 +1,13 @@
+#ifndef VELOCIKEY_H
+#define VELOCIKEY_H
+
+#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);
+
+#endif \ No newline at end of file