aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lewis <chris@chrislewisdev.com>2019-02-22 02:22:46 +1100
committerMechMerlin <30334081+mechmerlin@users.noreply.github.com>2019-02-21 07:22:46 -0800
commitc1c5922aae7b60b7c7d13d3769350eed9dda17ab (patch)
tree7c3805d9b949ef2d802bd3df4e9238662a5cdc0b
parent9f1d781fcb7129a07e671a46461e501e3f1ae59d (diff)
downloadqmk_firmware-c1c5922aae7b60b7c7d13d3769350eed9dda17ab.tar.gz
qmk_firmware-c1c5922aae7b60b7c7d13d3769350eed9dda17ab.zip
Velocikey: Match RGB animation speed to typing speed (#3754)
* Draft commit of typing speed RGB control * More information in the readme * Support all RGB animation modes (Fixes #1) * Added support for all RGB light modes to use typing speed Except christmas lights because that is seizure-inducing at high speeds! * Introduced a value range specific to each RGB mode Because some modes are a little too much when running at full speed! * Update readme.md * Update readme.md * Re-arrange typing_speed definitions (Fixes #5) (#6) * Re-arrange variable definitions to avoid including quantum.h from rgblight.c * Fix a compilation error when trying to run make test:all * Tweaks to the typing speed decay rate * Renamed to momentum; moved implementation into dedicated files * Groundwork for toggling momentum on/off (currently always on) * Add EEPROM toggle for momentum-matching * Moved momentum out of RGBLIGHT_ENABLE toggles so it's more generic * Move momentum decay task out of rgblight_task() * Fix missing momentum.h in lufa.c * Experimental LED support (untested) * Draft commit of typing speed RGB control * More information in the readme * Support all RGB animation modes (Fixes #1) * Added support for all RGB light modes to use typing speed Except christmas lights because that is seizure-inducing at high speeds! * Introduced a value range specific to each RGB mode Because some modes are a little too much when running at full speed! * Update readme.md * Update readme.md * Re-arrange typing_speed definitions (Fixes #5) (#6) * Re-arrange variable definitions to avoid including quantum.h from rgblight.c * Fix a compilation error when trying to run make test:all * Tweaks to the typing speed decay rate * Renamed to momentum; moved implementation into dedicated files * Groundwork for toggling momentum on/off (currently always on) * Add EEPROM toggle for momentum-matching * Moved momentum out of RGBLIGHT_ENABLE toggles so it's more generic * Move momentum decay task out of rgblight_task() * Fix missing momentum.h in lufa.c * Added documentation * Renamed feature to velocikey * Reverted readme to original state * Correct the readme title * Updated feature name in the docs * Update EECONFIG name * Add compile-time toggles for velocikey * Update feature documentation * Revert "Merge branch 'led-support' into master" This reverts commit e123ff5febf61639b9a9020748e1c2e2313460ff, reversing changes made to df111a55b9d4929182e16108b1c0ead15b16df97. * Move velocikey EECONFIG definition to depend on VELOCIKEY_ENABLE * Rename decay_task function to decelerate * Apply suggestions from code review Co-Authored-By: chrislewisdev <chris@chrislewisdev.com> * Re-order eeconfig definitions * Apply coding conventions * Apply #ifdef check in lufa.c * Refactored interval time checks into one functionc * Small rename * Fix unused function error for layouts not using all rgb effects * Only update EEPROM if Velocikey is enabled * Incorporate code review feedback * Small adjustment to top-end decay rate * Add Velocikey documentation to table of contents * Bring tetris:default keymap size down by disabling audio
-rw-r--r--common_features.mk5
-rw-r--r--docs/_summary.md1
-rw-r--r--docs/feature_velocikey.md30
-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
-rw-r--r--tmk_core/common/eeconfig.c1
-rw-r--r--tmk_core/common/eeconfig.h1
-rw-r--r--tmk_core/common/keyboard.c7
11 files changed, 158 insertions, 6 deletions
diff --git a/common_features.mk b/common_features.mk
index 3d3b8506e..f5bef3d5d 100644
--- a/common_features.mk
+++ b/common_features.mk
@@ -266,6 +266,11 @@ ifeq ($(strip $(HD44780_ENABLE)), yes)
266 OPT_DEFS += -DHD44780_ENABLE 266 OPT_DEFS += -DHD44780_ENABLE
267endif 267endif
268 268
269ifeq ($(strip $(VELOCIKEY_ENABLE)), yes)
270 OPT_DEFS += -DVELOCIKEY_ENABLE
271 SRC += $(QUANTUM_DIR)/velocikey.c
272endif
273
269ifeq ($(strip $(DYNAMIC_KEYMAP_ENABLE)), yes) 274ifeq ($(strip $(DYNAMIC_KEYMAP_ENABLE)), yes)
270 OPT_DEFS += -DDYNAMIC_KEYMAP_ENABLE 275 OPT_DEFS += -DDYNAMIC_KEYMAP_ENABLE
271 SRC += $(QUANTUM_DIR)/dynamic_keymap.c 276 SRC += $(QUANTUM_DIR)/dynamic_keymap.c
diff --git a/docs/_summary.md b/docs/_summary.md
index 6bc747189..09ea9e6e7 100644
--- a/docs/_summary.md
+++ b/docs/_summary.md
@@ -76,6 +76,7 @@
76 * [Thermal Printer](feature_thermal_printer.md) 76 * [Thermal Printer](feature_thermal_printer.md)
77 * [Unicode](feature_unicode.md) 77 * [Unicode](feature_unicode.md)
78 * [Userspace](feature_userspace.md) 78 * [Userspace](feature_userspace.md)
79 * [Velocikey](feature_velocikey.md)
79 80
80* For Makers and Modders 81* For Makers and Modders
81 * [Hand Wiring Guide](hand_wire.md) 82 * [Hand Wiring Guide](hand_wire.md)
diff --git a/docs/feature_velocikey.md b/docs/feature_velocikey.md
new file mode 100644
index 000000000..5d9841073
--- /dev/null
+++ b/docs/feature_velocikey.md
@@ -0,0 +1,30 @@
1# Velocikey
2
3Velocikey is a feature that lets you control the speed of lighting effects (like the Rainbow Swirl effect) with the speed of your typing. The faster you type, the faster the lights will go!
4
5## Usage
6For Velocikey to take effect, there are two steps. First, when compiling your keyboard, you'll need to set `VELOCIKEY_ENABLE=yes` in `rules.mk`, e.g.:
7
8```
9BOOTMAGIC_ENABLE = no
10MOUSEKEY_ENABLE = no
11STENO_ENABLE = no
12EXTRAKEY_ENABLE = yes
13VELOCIKEY_ENABLE = yes
14```
15
16Then, while using your keyboard, you need to also turn it on with the VLK_TOG keycode, which toggles the feature on and off.
17
18The following light effects will all be controlled by Velocikey when it is enabled:
19 - RGB Breathing
20 - RGB Rainbow Mood
21 - RGB Rainbow Swirl
22 - RGB Snake
23 - RGB Knight
24
25Support for LED breathing effects is planned but not available yet.
26
27 As long as Velocikey is enabled, it will control the speed regardless of any other speed setting that your RGB lights are currently on.
28
29 ## Configuration
30 Velocikey doesn't currently support any configuration via keyboard settings. If you want to adjust something like the speed increase or decay rate, you would need to edit `velocikey.c` and adjust the values there to achieve the kinds of speeds that you like.
diff --git a/quantum/quantum.c b/quantum/quantum.c
index cb4d5ee80..46d404029 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -47,6 +47,10 @@ extern backlight_config_t backlight_config;
47#include "process_midi.h" 47#include "process_midi.h"
48#endif 48#endif
49 49
50#ifdef VELOCIKEY_ENABLE
51#include "velocikey.h"
52#endif
53
50#ifdef HAPTIC_ENABLE 54#ifdef HAPTIC_ENABLE
51 #include "haptic.h" 55 #include "haptic.h"
52#endif 56#endif
@@ -251,6 +255,10 @@ bool process_record_quantum(keyrecord_t *record) {
251 // return false; 255 // return false;
252 // } 256 // }
253 257
258 #ifdef VELOCIKEY_ENABLE
259 if (velocikey_enabled() && record->event.pressed) { velocikey_accelerate(); }
260 #endif
261
254 #ifdef TAP_DANCE_ENABLE 262 #ifdef TAP_DANCE_ENABLE
255 preprocess_tap_dance(keycode, record); 263 preprocess_tap_dance(keycode, record);
256 #endif 264 #endif
@@ -568,7 +576,14 @@ bool process_record_quantum(keyrecord_t *record) {
568 #endif 576 #endif
569 return false; 577 return false;
570 #endif // defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE) 578 #endif // defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
571 #ifdef PROTOCOL_LUFA 579 #ifdef VELOCIKEY_ENABLE
580 case VLK_TOG:
581 if (record->event.pressed) {
582 velocikey_toggle();
583 }
584 return false;
585 #endif
586 #ifdef PROTOCOL_LUFA
572 case OUT_AUTO: 587 case OUT_AUTO:
573 if (record->event.pressed) { 588 if (record->event.pressed) {
574 set_output(OUTPUT_AUTO); 589 set_output(OUTPUT_AUTO);
diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h
index 00c84cbf5..1ced6ae37 100644
--- a/quantum/quantum_keycodes.h
+++ b/quantum/quantum_keycodes.h
@@ -422,6 +422,9 @@ enum quantum_keycodes {
422 RGB_MODE_GRADIENT, 422 RGB_MODE_GRADIENT,
423 RGB_MODE_RGBTEST, 423 RGB_MODE_RGBTEST,
424 424
425 //Momentum matching toggle
426 VLK_TOG,
427
425 // Left shift, open paren 428 // Left shift, open paren
426 KC_LSPO, 429 KC_LSPO,
427 430
diff --git a/quantum/rgblight.c b/quantum/rgblight.c
index 45d521786..57de56df7 100644
--- a/quantum/rgblight.c
+++ b/quantum/rgblight.c
@@ -30,6 +30,9 @@
30#include "rgblight.h" 30#include "rgblight.h"
31#include "debug.h" 31#include "debug.h"
32#include "led_tables.h" 32#include "led_tables.h"
33#ifdef VELOCIKEY_ENABLE
34 #include "velocikey.h"
35#endif
33 36
34#define _RGBM_SINGLE_STATIC(sym) RGBLIGHT_MODE_ ## sym, 37#define _RGBM_SINGLE_STATIC(sym) RGBLIGHT_MODE_ ## sym,
35#define _RGBM_SINGLE_DYNAMIC(sym) 38#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) {
607 rgblight_setrgb_at(tmp_led.r, tmp_led.g, tmp_led.b, index); 610 rgblight_setrgb_at(tmp_led.r, tmp_led.g, tmp_led.b, index);
608} 611}
609 612
613#if defined(RGBLIGHT_EFFECT_BREATHING) || defined(RGBLIGHT_EFFECT_RAINBOW_MOOD) || defined(RGBLIGHT_EFFECT_RAINBOW_SWIRL) \
614 || defined(RGBLIGHT_EFFECT_SNAKE) || defined(RGBLIGHT_EFFECT_KNIGHT)
615
616static uint8_t get_interval_time(const uint8_t* default_interval_address, uint8_t velocikey_min, uint8_t velocikey_max) {
617 return
618#ifdef VELOCIKEY_ENABLE
619 velocikey_enabled() ? velocikey_match_speed(velocikey_min, velocikey_max) :
620#endif
621 pgm_read_byte(default_interval_address);
622}
623
624#endif
625
610void rgblight_setrgb_range(uint8_t r, uint8_t g, uint8_t b, uint8_t start, uint8_t end) { 626void rgblight_setrgb_range(uint8_t r, uint8_t g, uint8_t b, uint8_t start, uint8_t end) {
611 if (!rgblight_config.enable || start < 0 || start >= end || end > RGBLED_NUM) { return; } 627 if (!rgblight_config.enable || start < 0 || start >= end || end > RGBLED_NUM) { return; }
612 628
@@ -707,6 +723,7 @@ void rgblight_show_solid_color(uint8_t r, uint8_t g, uint8_t b) {
707} 723}
708 724
709void rgblight_task(void) { 725void rgblight_task(void) {
726
710 if (rgblight_timer_enabled) { 727 if (rgblight_timer_enabled) {
711 // static light mode, do nothing here 728 // static light mode, do nothing here
712 if ( 1 == 0 ) { //dummy 729 if ( 1 == 0 ) { //dummy
@@ -778,7 +795,9 @@ void rgblight_effect_breathing(uint8_t interval) {
778 static uint16_t last_timer = 0; 795 static uint16_t last_timer = 0;
779 float val; 796 float val;
780 797
781 if (timer_elapsed(last_timer) < pgm_read_byte(&RGBLED_BREATHING_INTERVALS[interval])) { 798 uint8_t interval_time = get_interval_time(&RGBLED_RAINBOW_SWIRL_INTERVALS[interval / 2], 1, 100);
799
800 if (timer_elapsed(last_timer) < interval_time) {
782 return; 801 return;
783 } 802 }
784 last_timer = timer_read(); 803 last_timer = timer_read();
@@ -798,7 +817,9 @@ void rgblight_effect_rainbow_mood(uint8_t interval) {
798 static uint16_t current_hue = 0; 817 static uint16_t current_hue = 0;
799 static uint16_t last_timer = 0; 818 static uint16_t last_timer = 0;
800 819
801 if (timer_elapsed(last_timer) < pgm_read_byte(&RGBLED_RAINBOW_MOOD_INTERVALS[interval])) { 820 uint8_t interval_time = get_interval_time(&RGBLED_RAINBOW_MOOD_INTERVALS[interval], 5, 100);
821
822 if (timer_elapsed(last_timer) < interval_time) {
802 return; 823 return;
803 } 824 }
804 last_timer = timer_read(); 825 last_timer = timer_read();
@@ -820,7 +841,10 @@ void rgblight_effect_rainbow_swirl(uint8_t interval) {
820 static uint16_t last_timer = 0; 841 static uint16_t last_timer = 0;
821 uint16_t hue; 842 uint16_t hue;
822 uint8_t i; 843 uint8_t i;
823 if (timer_elapsed(last_timer) < pgm_read_byte(&RGBLED_RAINBOW_SWIRL_INTERVALS[interval / 2])) { 844
845 uint8_t interval_time = get_interval_time(&RGBLED_RAINBOW_SWIRL_INTERVALS[interval / 2], 1, 100);
846
847 if (timer_elapsed(last_timer) < interval_time) {
824 return; 848 return;
825 } 849 }
826 last_timer = timer_read(); 850 last_timer = timer_read();
@@ -855,7 +879,10 @@ void rgblight_effect_snake(uint8_t interval) {
855 if (interval % 2) { 879 if (interval % 2) {
856 increment = -1; 880 increment = -1;
857 } 881 }
858 if (timer_elapsed(last_timer) < pgm_read_byte(&RGBLED_SNAKE_INTERVALS[interval / 2])) { 882
883 uint8_t interval_time = get_interval_time(&RGBLED_SNAKE_INTERVALS[interval / 2], 1, 200);
884
885 if (timer_elapsed(last_timer) < interval_time) {
859 return; 886 return;
860 } 887 }
861 last_timer = timer_read(); 888 last_timer = timer_read();
@@ -892,7 +919,10 @@ const uint8_t RGBLED_KNIGHT_INTERVALS[] PROGMEM = {127, 63, 31};
892 919
893void rgblight_effect_knight(uint8_t interval) { 920void rgblight_effect_knight(uint8_t interval) {
894 static uint16_t last_timer = 0; 921 static uint16_t last_timer = 0;
895 if (timer_elapsed(last_timer) < pgm_read_byte(&RGBLED_KNIGHT_INTERVALS[interval])) { 922
923 uint8_t interval_time = get_interval_time(&RGBLED_KNIGHT_INTERVALS[interval], 5, 100);
924
925 if (timer_elapsed(last_timer) < interval_time) {
896 return; 926 return;
897 } 927 }
898 last_timer = timer_read(); 928 last_timer = timer_read();
diff --git a/quantum/velocikey.c b/quantum/velocikey.c
new file mode 100644
index 000000000..550c3b70a
--- /dev/null
+++ b/quantum/velocikey.c
@@ -0,0 +1,46 @@
1#include "velocikey.h"
2#include "timer.h"
3#include "eeconfig.h"
4#include "eeprom.h"
5
6#ifndef MIN
7#define MIN(a,b) (((a)<(b))?(a):(b))
8#endif
9#ifndef MAX
10#define MAX(a,b) (((a)>(b))?(a):(b))
11#endif
12
13#define TYPING_SPEED_MAX_VALUE 200
14uint8_t typing_speed = 0;
15
16bool velocikey_enabled(void) {
17 return eeprom_read_byte(EECONFIG_VELOCIKEY) == 1;
18}
19
20void velocikey_toggle(void) {
21 if (velocikey_enabled())
22 eeprom_update_byte(EECONFIG_VELOCIKEY, 0);
23 else
24 eeprom_update_byte(EECONFIG_VELOCIKEY, 1);
25}
26
27void velocikey_accelerate(void) {
28 if (typing_speed < TYPING_SPEED_MAX_VALUE) typing_speed += (TYPING_SPEED_MAX_VALUE / 100);
29}
30
31void velocikey_decelerate(void) {
32 static uint16_t decay_timer = 0;
33
34 if (timer_elapsed(decay_timer) > 500 || decay_timer == 0) {
35 if (typing_speed > 0) typing_speed -= 1;
36 //Decay a little faster at half of max speed
37 if (typing_speed > TYPING_SPEED_MAX_VALUE / 2) typing_speed -= 1;
38 //Decay even faster at 3/4 of max speed
39 if (typing_speed > TYPING_SPEED_MAX_VALUE / 4 * 3) typing_speed -= 2;
40 decay_timer = timer_read();
41 }
42}
43
44uint8_t velocikey_match_speed(uint8_t minValue, uint8_t maxValue) {
45 return MAX(minValue, maxValue - (maxValue - minValue) * ((float)typing_speed / TYPING_SPEED_MAX_VALUE));
46}
diff --git a/quantum/velocikey.h b/quantum/velocikey.h
new file mode 100644
index 000000000..1910f0f4e
--- /dev/null
+++ b/quantum/velocikey.h
@@ -0,0 +1,13 @@
1#ifndef VELOCIKEY_H
2#define VELOCIKEY_H
3
4#include <stdint.h>
5#include <stdbool.h>
6
7bool velocikey_enabled(void);
8void velocikey_toggle(void);
9void velocikey_accelerate(void);
10void velocikey_decelerate(void);
11uint8_t velocikey_match_speed(uint8_t minValue, uint8_t maxValue);
12
13#endif \ No newline at end of file
diff --git a/tmk_core/common/eeconfig.c b/tmk_core/common/eeconfig.c
index ded27e599..9c1e3520e 100644
--- a/tmk_core/common/eeconfig.c
+++ b/tmk_core/common/eeconfig.c
@@ -46,6 +46,7 @@ void eeconfig_init_quantum(void) {
46 eeprom_update_dword(EECONFIG_RGBLIGHT, 0); 46 eeprom_update_dword(EECONFIG_RGBLIGHT, 0);
47 eeprom_update_byte(EECONFIG_STENOMODE, 0); 47 eeprom_update_byte(EECONFIG_STENOMODE, 0);
48 eeprom_update_dword(EECONFIG_HAPTIC, 0); 48 eeprom_update_dword(EECONFIG_HAPTIC, 0);
49 eeprom_update_byte(EECONFIG_VELOCIKEY, 0);
49 50
50 eeconfig_init_kb(); 51 eeconfig_init_kb();
51} 52}
diff --git a/tmk_core/common/eeconfig.h b/tmk_core/common/eeconfig.h
index d576634f5..0ac3dff07 100644
--- a/tmk_core/common/eeconfig.h
+++ b/tmk_core/common/eeconfig.h
@@ -40,6 +40,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
40#define EECONFIG_HANDEDNESS (uint8_t *)14 40#define EECONFIG_HANDEDNESS (uint8_t *)14
41#define EECONFIG_KEYBOARD (uint32_t *)15 41#define EECONFIG_KEYBOARD (uint32_t *)15
42#define EECONFIG_USER (uint32_t *)19 42#define EECONFIG_USER (uint32_t *)19
43#define EECONFIG_VELOCIKEY (uint8_t *)23
43 44
44#define EECONFIG_HAPTIC (uint32_t*)24 45#define EECONFIG_HAPTIC (uint32_t*)24
45 46
diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c
index 849d74aa1..52546866e 100644
--- a/tmk_core/common/keyboard.c
+++ b/tmk_core/common/keyboard.c
@@ -75,6 +75,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
75#ifdef QWIIC_ENABLE 75#ifdef QWIIC_ENABLE
76# include "qwiic.h" 76# include "qwiic.h"
77#endif 77#endif
78#ifdef VELOCIKEY_ENABLE
79 #include "velocikey.h"
80#endif
78 81
79#ifdef MATRIX_HAS_GHOST 82#ifdef MATRIX_HAS_GHOST
80extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS]; 83extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS];
@@ -336,6 +339,10 @@ MATRIX_LOOP_END:
336 midi_task(); 339 midi_task();
337#endif 340#endif
338 341
342#ifdef VELOCIKEY_ENABLE
343 if (velocikey_enabled()) { velocikey_decelerate(); }
344#endif
345
339 // update LED 346 // update LED
340 if (led_status != host_keyboard_leds()) { 347 if (led_status != host_keyboard_leds()) {
341 led_status = host_keyboard_leds(); 348 led_status = host_keyboard_leds();