From 2d3fbc5d0ad70309ede5cdeb9cf84380fd69baae Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Wed, 25 Jul 2018 11:59:44 +1000 Subject: [PATCH 01/50] Draft commit of typing speed RGB control --- quantum/quantum.c | 3 +++ quantum/quantum.h | 2 ++ quantum/rgblight.c | 18 +++++++++++++++--- readme.md | 20 +++++++++++++++++++- 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/quantum/quantum.c b/quantum/quantum.c index 9c6ed3330e5a..1a5d992818bc 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -187,12 +187,15 @@ static uint16_t scs_timer[2] = {0, 0}; */ static bool grave_esc_was_shifted = false; +uint8_t typing_speed = 0; bool process_record_quantum(keyrecord_t *record) { /* This gets the keycode from the key pressed */ keypos_t key = record->event.key; uint16_t keycode; + if (typing_speed < 100) typing_speed += 1; + #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS) /* TODO: Use store_or_get_action() or a similar function. */ if (!disable_action_cache) { diff --git a/quantum/quantum.h b/quantum/quantum.h index 0675a90ac3fa..35822f9a4f36 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h @@ -55,6 +55,8 @@ #include "send_string_keycodes.h" extern uint32_t default_layer_state; +//Used in rgblight.c to match RGB animation to typing speed +extern uint8_t typing_speed; #ifndef NO_ACTION_LAYER extern uint32_t layer_state; diff --git a/quantum/rgblight.c b/quantum/rgblight.c index aa70cbd9ec56..548c84a74e37 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -24,13 +24,15 @@ #include "rgblight.h" #include "debug.h" #include "led_tables.h" +#include "quantum.h" #ifndef RGBLIGHT_LIMIT_VAL #define RGBLIGHT_LIMIT_VAL 255 #endif -#define MIN(a,b) (((a)<(b))?(a):(b)) -#define MAX(a,b) (((a)>(b))?(a):(b)) +//These conflict with a chained include that comes from including quantum.h +// #define MIN(a,b) (((a)<(b))?(a):(b)) +// #define MAX(a,b) (((a)>(b))?(a):(b)) __attribute__ ((weak)) const uint8_t RGBLED_BREATHING_INTERVALS[] PROGMEM = {30, 20, 10, 5}; @@ -628,7 +630,17 @@ 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])) { + + //Improvement: move this code into rgblight_task() so that the typing_speed can be used across all RGB effects, not just swirl + static uint16_t decay_timer = 0; + if (timer_elapsed(decay_timer) > 250 || decay_timer == 0) { + if (typing_speed > 0) typing_speed -= 1; + //Improvement(?): decay by a greater rate depending on how big typing_speed is, so you can't reach max speed just by outpacing the regular decay + decay_timer = timer_read(); + } + + //Improvement: make the usage of typing speed more easily configurable, either with a pre-processor toggle or with real-time key toggles + if (timer_elapsed(last_timer) < MAX(1, 100 - typing_speed)) { return; } last_timer = timer_read(); diff --git a/readme.md b/readme.md index 859e3ed12f15..226ed74add1e 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,22 @@ -# Quantum Mechanical Keyboard Firmware +# Quantum Mechanical Keyboard Firmware - chrislewisdev fork + +## Typing Speed -> RGB Animation Control + +This fork of qmk_firmware contains the code I whipped up to make your keyboard's RGB animation speed match your typing speed. As of writing, this is a "first draft" version, aka the simplest implementation I could think of with the quickest/hackiest code. Beware hard-coding :) + +Regardless, I'm happy to share the code and discuss improvements with anyone who'd like to contribute. I'll do my best to facilitate it in my spare time. + +## Getting Started + +My entire change amounts to several lines in `quantum.h`, `quantum.c` and `rgblight.c`. To see the details it's probably easiest if you look at my first commit to this fork which contains all the changes. + +I've left a couple of "Improvement:" comments around the code to indicate what I think would make it better or more "production"-ready. These could be good places to start for anyone interested in contributing. + +To test it, I've just been using my DZ60 keyboard, building the firmware with `make dz60:default` and flashing with qmk_toolbox. + +Below is the original QMK readme: + +# QMK [![Current Version](https://img.shields.io/github/tag/qmk/qmk_firmware.svg)](https://github.com/qmk/qmk_firmware/tags) [![Build Status](https://travis-ci.org/qmk/qmk_firmware.svg?branch=master)](https://travis-ci.org/qmk/qmk_firmware) From 876cb7a14fee02cb3d59e2f9b133f84118e985d1 Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Wed, 25 Jul 2018 12:08:13 +1000 Subject: [PATCH 02/50] More information in the readme --- readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 226ed74add1e..4f23243287dd 100644 --- a/readme.md +++ b/readme.md @@ -8,11 +8,11 @@ Regardless, I'm happy to share the code and discuss improvements with anyone who ## Getting Started -My entire change amounts to several lines in `quantum.h`, `quantum.c` and `rgblight.c`. To see the details it's probably easiest if you look at my first commit to this fork which contains all the changes. +My entire change amounts to several lines in `quantum.h`, `quantum.c` and `rgblight.c`. To see the details it's probably easiest if you look at [this commit](https://github.com/chrislewisdev/qmk_firmware/commit/2d3fbc5d0ad70309ede5cdeb9cf84380fd69baae) which contains all the changes. I've left a couple of "Improvement:" comments around the code to indicate what I think would make it better or more "production"-ready. These could be good places to start for anyone interested in contributing. -To test it, I've just been using my DZ60 keyboard, building the firmware with `make dz60:default` and flashing with qmk_toolbox. +To test it, I've just been using my DZ60 keyboard, building the firmware with `make dz60:default` and flashing with qmk_toolbox. If you're not familiar with how to do that, it's probably best you consult the [QMK documentation](https://docs.qmk.fm/#/). Below is the original QMK readme: From 5f2b065dad5054b0301ec2fecba47f66818c4fd7 Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Fri, 27 Jul 2018 00:23:44 +1000 Subject: [PATCH 03/50] 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! --- quantum/quantum.c | 2 +- quantum/quantum.h | 1 + quantum/rgblight.c | 36 ++++++++++++++++++++++-------------- quantum/rgblight.h | 3 +++ 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/quantum/quantum.c b/quantum/quantum.c index 1a5d992818bc..30a7beba403d 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -194,7 +194,7 @@ bool process_record_quantum(keyrecord_t *record) { keypos_t key = record->event.key; uint16_t keycode; - if (typing_speed < 100) typing_speed += 1; + if (typing_speed < TYPING_SPEED_MAX_VALUE) typing_speed += 1; #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS) /* TODO: Use store_or_get_action() or a similar function. */ diff --git a/quantum/quantum.h b/quantum/quantum.h index 35822f9a4f36..1837caddbb84 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h @@ -57,6 +57,7 @@ extern uint32_t default_layer_state; //Used in rgblight.c to match RGB animation to typing speed extern uint8_t typing_speed; +#define TYPING_SPEED_MAX_VALUE 100 #ifndef NO_ACTION_LAYER extern uint32_t layer_state; diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 548c84a74e37..fda64855d1d3 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -569,8 +569,25 @@ void rgblight_show_solid_color(uint8_t r, uint8_t g, uint8_t b) { rgblight_setrgb(r, g, b); } +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_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(); + // mode = 1, static light, do nothing here if (rgblight_config.mode >= 2 && rgblight_config.mode <= 5) { // mode = 2 to 5, breathing mode @@ -603,7 +620,7 @@ 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])) { + if (timer_elapsed(last_timer) < typing_speed_matched_interval(1, 100)) { return; } last_timer = timer_read(); @@ -618,7 +635,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) < pgm_read_byte(&RGBLED_RAINBOW_MOOD_INTERVALS[interval])) { + if (timer_elapsed(last_timer) < typing_speed_matched_interval(5, 100)) { return; } last_timer = timer_read(); @@ -631,16 +648,7 @@ void rgblight_effect_rainbow_swirl(uint8_t interval) { uint16_t hue; uint8_t i; - //Improvement: move this code into rgblight_task() so that the typing_speed can be used across all RGB effects, not just swirl - static uint16_t decay_timer = 0; - if (timer_elapsed(decay_timer) > 250 || decay_timer == 0) { - if (typing_speed > 0) typing_speed -= 1; - //Improvement(?): decay by a greater rate depending on how big typing_speed is, so you can't reach max speed just by outpacing the regular decay - decay_timer = timer_read(); - } - - //Improvement: make the usage of typing speed more easily configurable, either with a pre-processor toggle or with real-time key toggles - if (timer_elapsed(last_timer) < MAX(1, 100 - typing_speed)) { + if (timer_elapsed(last_timer) < typing_speed_matched_interval(1, 100)) { return; } last_timer = timer_read(); @@ -669,7 +677,7 @@ 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])) { + if (timer_elapsed(last_timer) < typing_speed_matched_interval(5, 100)) { return; } last_timer = timer_read(); @@ -700,7 +708,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) < pgm_read_byte(&RGBLED_KNIGHT_INTERVALS[interval])) { + if (timer_elapsed(last_timer) < typing_speed_matched_interval(5, 100)) { return; } last_timer = timer_read(); diff --git a/quantum/rgblight.h b/quantum/rgblight.h index 0f7b5ffb569f..ecc1ff60589f 100644 --- a/quantum/rgblight.h +++ b/quantum/rgblight.h @@ -167,4 +167,7 @@ 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 From 676b01312fd9b0b467bc3ac01ba46494b9cd0dbd Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Fri, 27 Jul 2018 10:06:06 +1000 Subject: [PATCH 04/50] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 4f23243287dd..f29e62a983e4 100644 --- a/readme.md +++ b/readme.md @@ -10,7 +10,7 @@ Regardless, I'm happy to share the code and discuss improvements with anyone who My entire change amounts to several lines in `quantum.h`, `quantum.c` and `rgblight.c`. To see the details it's probably easiest if you look at [this commit](https://github.com/chrislewisdev/qmk_firmware/commit/2d3fbc5d0ad70309ede5cdeb9cf84380fd69baae) which contains all the changes. -I've left a couple of "Improvement:" comments around the code to indicate what I think would make it better or more "production"-ready. These could be good places to start for anyone interested in contributing. +I've created GitHub Issues for the most pressing things that need to be addressed before this could be merged into QMK - if you're interested in helping out, please do take a look! To test it, I've just been using my DZ60 keyboard, building the firmware with `make dz60:default` and flashing with qmk_toolbox. If you're not familiar with how to do that, it's probably best you consult the [QMK documentation](https://docs.qmk.fm/#/). From 7cefccd13e04b7ed68c4ab45be6b8e48be22eebb Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Fri, 27 Jul 2018 23:48:07 +1000 Subject: [PATCH 05/50] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index f29e62a983e4..1c98c795d88d 100644 --- a/readme.md +++ b/readme.md @@ -8,7 +8,7 @@ Regardless, I'm happy to share the code and discuss improvements with anyone who ## Getting Started -My entire change amounts to several lines in `quantum.h`, `quantum.c` and `rgblight.c`. To see the details it's probably easiest if you look at [this commit](https://github.com/chrislewisdev/qmk_firmware/commit/2d3fbc5d0ad70309ede5cdeb9cf84380fd69baae) which contains all the changes. +My original change amounts to several lines in `quantum.h`, `quantum.c` and `rgblight.c`. To see the details it's probably easiest if you look at [this commit](https://github.com/chrislewisdev/qmk_firmware/commit/2d3fbc5d0ad70309ede5cdeb9cf84380fd69baae) which contains all the changes. I've created GitHub Issues for the most pressing things that need to be addressed before this could be merged into QMK - if you're interested in helping out, please do take a look! From e783cb06f7f412f8c7fa9aa6acf800b34efb21f3 Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Sat, 28 Jul 2018 15:54:08 +1000 Subject: [PATCH 06/50] 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 --- quantum/quantum.c | 5 +++-- quantum/quantum.h | 3 --- quantum/rgblight.c | 7 +++---- quantum/rgblight.h | 4 ++++ 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/quantum/quantum.c b/quantum/quantum.c index 30a7beba403d..ff59bc0c41d7 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -187,14 +187,15 @@ static uint16_t scs_timer[2] = {0, 0}; */ static bool grave_esc_was_shifted = false; -uint8_t typing_speed = 0; bool process_record_quantum(keyrecord_t *record) { /* This gets the keycode from the key pressed */ keypos_t key = record->event.key; uint16_t keycode; - if (typing_speed < TYPING_SPEED_MAX_VALUE) typing_speed += 1; + #ifdef RGBLIGHT_ENABLE + if (typing_speed < TYPING_SPEED_MAX_VALUE) typing_speed += 1; + #endif #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS) /* TODO: Use store_or_get_action() or a similar function. */ diff --git a/quantum/quantum.h b/quantum/quantum.h index 1837caddbb84..0675a90ac3fa 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h @@ -55,9 +55,6 @@ #include "send_string_keycodes.h" extern uint32_t default_layer_state; -//Used in rgblight.c to match RGB animation to typing speed -extern uint8_t typing_speed; -#define TYPING_SPEED_MAX_VALUE 100 #ifndef NO_ACTION_LAYER extern uint32_t layer_state; diff --git a/quantum/rgblight.c b/quantum/rgblight.c index fda64855d1d3..88a21d0aff73 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -24,15 +24,13 @@ #include "rgblight.h" #include "debug.h" #include "led_tables.h" -#include "quantum.h" #ifndef RGBLIGHT_LIMIT_VAL #define RGBLIGHT_LIMIT_VAL 255 #endif -//These conflict with a chained include that comes from including quantum.h -// #define MIN(a,b) (((a)<(b))?(a):(b)) -// #define MAX(a,b) (((a)>(b))?(a):(b)) +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define MAX(a,b) (((a)>(b))?(a):(b)) __attribute__ ((weak)) const uint8_t RGBLED_BREATHING_INTERVALS[] PROGMEM = {30, 20, 10, 5}; @@ -569,6 +567,7 @@ 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; diff --git a/quantum/rgblight.h b/quantum/rgblight.h index ecc1ff60589f..5b954312992f 100644 --- a/quantum/rgblight.h +++ b/quantum/rgblight.h @@ -89,6 +89,10 @@ 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 100 + typedef union { uint32_t raw; struct { From f5025c41664af3789afdf30074b601a1d85bb808 Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Sat, 28 Jul 2018 16:02:36 +1000 Subject: [PATCH 07/50] Tweaks to the typing speed decay rate --- quantum/quantum.c | 2 +- quantum/rgblight.c | 6 +++++- quantum/rgblight.h | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/quantum/quantum.c b/quantum/quantum.c index ff59bc0c41d7..9c44c07561bf 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -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 += 1; + if (typing_speed < TYPING_SPEED_MAX_VALUE) typing_speed += (TYPING_SPEED_MAX_VALUE / 100); #endif #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS) diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 88a21d0aff73..000d91e9e794 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -573,6 +573,10 @@ void typing_speed_decay_task() { 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(); } } @@ -676,7 +680,7 @@ void rgblight_effect_snake(uint8_t interval) { if (interval % 2) { increment = -1; } - if (timer_elapsed(last_timer) < typing_speed_matched_interval(5, 100)) { + if (timer_elapsed(last_timer) < typing_speed_matched_interval(1, 200)) { return; } last_timer = timer_read(); diff --git a/quantum/rgblight.h b/quantum/rgblight.h index 5b954312992f..b3264dff1f72 100644 --- a/quantum/rgblight.h +++ b/quantum/rgblight.h @@ -91,7 +91,7 @@ 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 100 +#define TYPING_SPEED_MAX_VALUE 200 typedef union { uint32_t raw; From 12fcf80d3da5771a8db76f2a07a8eade3d9c2101 Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Sat, 18 Aug 2018 20:43:39 +1000 Subject: [PATCH 08/50] Renamed to momentum; moved implementation into dedicated files --- common_features.mk | 1 + quantum/momentum.c | 32 ++++++++++++++++++++++++++++++++ quantum/momentum.h | 11 +++++++++++ quantum/quantum.c | 2 +- quantum/rgblight.c | 30 ++++++------------------------ quantum/rgblight.h | 9 ++------- 6 files changed, 53 insertions(+), 32 deletions(-) create mode 100644 quantum/momentum.c create mode 100644 quantum/momentum.h diff --git a/common_features.mk b/common_features.mk index b78f04d2a820..dd215071963c 100644 --- a/common_features.mk +++ b/common_features.mk @@ -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) diff --git a/quantum/momentum.c b/quantum/momentum.c new file mode 100644 index 000000000000..e0fadc991c18 --- /dev/null +++ b/quantum/momentum.c @@ -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)); +} \ No newline at end of file diff --git a/quantum/momentum.h b/quantum/momentum.h new file mode 100644 index 000000000000..7acf139255a7 --- /dev/null +++ b/quantum/momentum.h @@ -0,0 +1,11 @@ +#ifndef MOMENTUM_H +#define MOMENTUM_H + +#include +#include "timer.h" + +void momentum_accelerate(void); +void momentum_decay_task(void); +uint8_t match_momentum(uint8_t minValue, uint8_t maxValue); + +#endif \ No newline at end of file diff --git a/quantum/quantum.c b/quantum/quantum.c index 9c44c07561bf..ea2300ebd086 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -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) diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 000d91e9e794..022fe21f169f 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -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(); diff --git a/quantum/rgblight.h b/quantum/rgblight.h index b3264dff1f72..67bab7eb57bc 100644 --- a/quantum/rgblight.h +++ b/quantum/rgblight.h @@ -80,6 +80,8 @@ #include #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 From 13f7c9e3a1f322ebdd61b6b300a6720bd28153b6 Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Sat, 18 Aug 2018 21:03:02 +1000 Subject: [PATCH 09/50] Groundwork for toggling momentum on/off (currently always on) --- quantum/momentum.c | 5 +++++ quantum/momentum.h | 3 ++- quantum/quantum.c | 2 +- quantum/rgblight.c | 34 ++++++++++++++++++++++++++++------ 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/quantum/momentum.c b/quantum/momentum.c index e0fadc991c18..8b2d8dc06d3f 100644 --- a/quantum/momentum.c +++ b/quantum/momentum.c @@ -1,4 +1,5 @@ #include "momentum.h" +#include "timer.h" #ifndef MIN #define MIN(a,b) (((a)<(b))?(a):(b)) @@ -10,6 +11,10 @@ #define TYPING_SPEED_MAX_VALUE 200 uint8_t typing_speed = 0; +bool momentum_enabled() { + return true; +} + void momentum_accelerate() { if (typing_speed < TYPING_SPEED_MAX_VALUE) typing_speed += (TYPING_SPEED_MAX_VALUE / 100); } diff --git a/quantum/momentum.h b/quantum/momentum.h index 7acf139255a7..d72c043d1515 100644 --- a/quantum/momentum.h +++ b/quantum/momentum.h @@ -2,8 +2,9 @@ #define MOMENTUM_H #include -#include "timer.h" +#include +bool momentum_enabled(void); void momentum_accelerate(void); void momentum_decay_task(void); uint8_t match_momentum(uint8_t minValue, uint8_t maxValue); diff --git a/quantum/quantum.c b/quantum/quantum.c index ea2300ebd086..ae308fad2d4d 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -194,7 +194,7 @@ bool process_record_quantum(keyrecord_t *record) { uint16_t keycode; #ifdef RGBLIGHT_ENABLE - momentum_accelerate(); + if (momentum_enabled()) momentum_accelerate(); #endif #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS) diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 022fe21f169f..2c26c807a3b2 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -571,7 +571,7 @@ void rgblight_task(void) { if (rgblight_timer_enabled) { - momentum_decay_task(); + if (momentum_enabled()) momentum_decay_task(); // mode = 1, static light, do nothing here if (rgblight_config.mode >= 2 && rgblight_config.mode <= 5) { @@ -605,7 +605,11 @@ void rgblight_effect_breathing(uint8_t interval) { static uint16_t last_timer = 0; float val; - if (timer_elapsed(last_timer) < match_momentum(1, 100)) { + uint8_t interval_time = momentum_enabled() + ? match_momentum(1, 100) + : pgm_read_byte(&RGBLED_RAINBOW_SWIRL_INTERVALS[interval / 2]); + + if (timer_elapsed(last_timer) < interval_time) { return; } last_timer = timer_read(); @@ -620,7 +624,11 @@ 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) < match_momentum(5, 100)) { + uint8_t interval_time = momentum_enabled() + ? match_momentum(5, 100) + : pgm_read_byte(&RGBLED_RAINBOW_MOOD_INTERVALS[interval]); + + if (timer_elapsed(last_timer) < interval_time) { return; } last_timer = timer_read(); @@ -633,7 +641,11 @@ void rgblight_effect_rainbow_swirl(uint8_t interval) { uint16_t hue; uint8_t i; - if (timer_elapsed(last_timer) < match_momentum(1, 100)) { + uint8_t interval_time = momentum_enabled() + ? match_momentum(1, 100) + : pgm_read_byte(&RGBLED_RAINBOW_SWIRL_INTERVALS[interval / 2]); + + if (timer_elapsed(last_timer) < interval_time) { return; } last_timer = timer_read(); @@ -662,7 +674,12 @@ void rgblight_effect_snake(uint8_t interval) { if (interval % 2) { increment = -1; } - if (timer_elapsed(last_timer) < match_momentum(1, 200)) { + + uint8_t interval_time = momentum_enabled() + ? match_momentum(1, 200) + : pgm_read_byte(&RGBLED_SNAKE_INTERVALS[interval / 2]); + + if (timer_elapsed(last_timer) < interval_time) { return; } last_timer = timer_read(); @@ -693,7 +710,12 @@ 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) < match_momentum(5, 100)) { + + uint8_t interval_time = momentum_enabled() + ? match_momentum(5, 100) + : pgm_read_byte(&RGBLED_KNIGHT_INTERVALS[interval]); + + if (timer_elapsed(last_timer) < interval_time) { return; } last_timer = timer_read(); From b070efe019ca579a944934ee0bc6ab8dae272541 Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Sat, 18 Aug 2018 21:58:52 +1000 Subject: [PATCH 10/50] Add EEPROM toggle for momentum-matching --- quantum/momentum.c | 11 ++++++++++- quantum/momentum.h | 1 + quantum/quantum.c | 5 +++++ quantum/quantum_keycodes.h | 3 +++ tmk_core/common/eeconfig.c | 1 + tmk_core/common/eeconfig.h | 2 +- 6 files changed, 21 insertions(+), 2 deletions(-) diff --git a/quantum/momentum.c b/quantum/momentum.c index 8b2d8dc06d3f..662f71d51c8d 100644 --- a/quantum/momentum.c +++ b/quantum/momentum.c @@ -1,5 +1,7 @@ #include "momentum.h" #include "timer.h" +#include "eeconfig.h" +#include "eeprom.h" #ifndef MIN #define MIN(a,b) (((a)<(b))?(a):(b)) @@ -12,7 +14,14 @@ uint8_t typing_speed = 0; bool momentum_enabled() { - return true; + return eeprom_read_byte(EECONFIG_MOMENTUM) == 1; +} + +void momentum_toggle() { + if (momentum_enabled()) + eeprom_update_byte(EECONFIG_MOMENTUM, 0); + else + eeprom_update_byte(EECONFIG_MOMENTUM, 1); } void momentum_accelerate() { diff --git a/quantum/momentum.h b/quantum/momentum.h index d72c043d1515..1fe4c58aea31 100644 --- a/quantum/momentum.h +++ b/quantum/momentum.h @@ -5,6 +5,7 @@ #include bool momentum_enabled(void); +void momentum_toggle(void); void momentum_accelerate(void); void momentum_decay_task(void); uint8_t match_momentum(uint8_t minValue, uint8_t maxValue); diff --git a/quantum/quantum.c b/quantum/quantum.c index ae308fad2d4d..5301c8bd752c 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -516,6 +516,11 @@ bool process_record_quantum(keyrecord_t *record) { rgblight_mode(35); } return false; + case MOM_TOG: + if (record->event.pressed) { + momentum_toggle(); + } + return false; #endif // defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE) #ifdef PROTOCOL_LUFA case OUT_AUTO: diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index f2cdb8a3bffa..2391122d9d98 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h @@ -425,6 +425,9 @@ enum quantum_keycodes { RGB_MODE_GRADIENT, RGB_MODE_RGBTEST, + //Momentum matching toggle + MOM_TOG, + // Left shift, open paren KC_LSPO, diff --git a/tmk_core/common/eeconfig.c b/tmk_core/common/eeconfig.c index 3e5987ee3be3..4d76cc0a6940 100644 --- a/tmk_core/common/eeconfig.c +++ b/tmk_core/common/eeconfig.c @@ -22,6 +22,7 @@ void eeconfig_init(void) #endif #if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE) eeprom_update_dword(EECONFIG_RGBLIGHT, 0); + eeprom_update_byte(EECONFIG_MOMENTUM, 0); #endif #ifdef STENO_ENABLE eeprom_update_byte(EECONFIG_STENOMODE, 0); diff --git a/tmk_core/common/eeconfig.h b/tmk_core/common/eeconfig.h index 1397a90c79ff..87cf9b485e59 100644 --- a/tmk_core/common/eeconfig.h +++ b/tmk_core/common/eeconfig.h @@ -37,7 +37,7 @@ along with this program. If not, see . #define EECONFIG_STENOMODE (uint8_t *)13 // EEHANDS for two handed boards #define EECONFIG_HANDEDNESS (uint8_t *)14 - +#define EECONFIG_MOMENTUM (uint8_t *)15 /* debug bit */ #define EECONFIG_DEBUG_ENABLE (1<<0) From b444fa38afc6a3ebb5481d17a7abcd00d70ea8a9 Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Sat, 18 Aug 2018 22:21:16 +1000 Subject: [PATCH 11/50] Moved momentum out of RGBLIGHT_ENABLE toggles so it's more generic --- common_features.mk | 4 ++-- quantum/quantum.c | 10 +++++----- quantum/rgblight.c | 1 + quantum/rgblight.h | 2 -- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/common_features.mk b/common_features.mk index dd215071963c..261d4fc25f45 100644 --- a/common_features.mk +++ b/common_features.mk @@ -105,7 +105,6 @@ 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) @@ -208,7 +207,8 @@ QUANTUM_SRC:= \ $(QUANTUM_DIR)/quantum.c \ $(QUANTUM_DIR)/keymap_common.c \ $(QUANTUM_DIR)/keycode_config.c \ - $(QUANTUM_DIR)/process_keycode/process_leader.c + $(QUANTUM_DIR)/process_keycode/process_leader.c \ + $(QUANTUM_DIR)/momentum.c ifndef CUSTOM_MATRIX ifeq ($(strip $(SPLIT_KEYBOARD)), yes) diff --git a/quantum/quantum.c b/quantum/quantum.c index 5301c8bd752c..64e364a24518 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -42,6 +42,8 @@ extern backlight_config_t backlight_config; #include "process_midi.h" #endif +#include "momentum.h" + #ifdef AUDIO_ENABLE #ifndef GOODBYE_SONG #define GOODBYE_SONG SONG(GOODBYE_SOUND) @@ -193,9 +195,7 @@ bool process_record_quantum(keyrecord_t *record) { keypos_t key = record->event.key; uint16_t keycode; - #ifdef RGBLIGHT_ENABLE - if (momentum_enabled()) momentum_accelerate(); - #endif + if (momentum_enabled()) momentum_accelerate(); #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS) /* TODO: Use store_or_get_action() or a similar function. */ @@ -516,13 +516,13 @@ bool process_record_quantum(keyrecord_t *record) { rgblight_mode(35); } return false; + #endif // defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE) case MOM_TOG: if (record->event.pressed) { momentum_toggle(); } return false; - #endif // defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE) - #ifdef PROTOCOL_LUFA + #ifdef PROTOCOL_LUFA case OUT_AUTO: if (record->event.pressed) { set_output(OUTPUT_AUTO); diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 2c26c807a3b2..4f1bb11c6aa2 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -24,6 +24,7 @@ #include "rgblight.h" #include "debug.h" #include "led_tables.h" +#include "momentum.h" #ifndef RGBLIGHT_LIMIT_VAL #define RGBLIGHT_LIMIT_VAL 255 diff --git a/quantum/rgblight.h b/quantum/rgblight.h index 67bab7eb57bc..0f7b5ffb569f 100644 --- a/quantum/rgblight.h +++ b/quantum/rgblight.h @@ -80,8 +80,6 @@ #include #endif -#include "momentum.h" - extern LED_TYPE led[RGBLED_NUM]; extern const uint8_t RGBLED_BREATHING_INTERVALS[4] PROGMEM; From e7a39d9c12c126b230740ce7b6bc93e0744764f2 Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Sat, 18 Aug 2018 22:26:44 +1000 Subject: [PATCH 12/50] Move momentum decay task out of rgblight_task() --- quantum/rgblight.c | 3 --- tmk_core/protocol/lufa/lufa.c | 2 ++ 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 4f1bb11c6aa2..4136077992c8 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -571,9 +571,6 @@ void rgblight_show_solid_color(uint8_t r, uint8_t g, uint8_t b) { void rgblight_task(void) { if (rgblight_timer_enabled) { - - if (momentum_enabled()) momentum_decay_task(); - // mode = 1, static light, do nothing here if (rgblight_config.mode >= 2 && rgblight_config.mode <= 5) { // mode = 2 to 5, breathing mode diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index cb918d3dce14..b15c7a76c89a 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -1074,6 +1074,8 @@ int main(void) MIDI_Device_USBTask(&USB_MIDI_Interface); #endif + if (momentum_enabled()) momentum_decay_task(); + #if defined(RGBLIGHT_ANIMATIONS) & defined(RGBLIGHT_ENABLE) rgblight_task(); #endif From 7e0ca8df8dc254aaa0e4a784c228d7125ffddf90 Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Sat, 18 Aug 2018 22:44:59 +1000 Subject: [PATCH 13/50] Fix missing momentum.h in lufa.c --- tmk_core/protocol/lufa/lufa.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index b15c7a76c89a..3bfcc40dd619 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -54,6 +54,7 @@ #include "quantum.h" #include #include "outputselect.h" +#include "momentum.h" #ifdef NKRO_ENABLE #include "keycode_config.h" From 97b7a6e84c06be988b5145d7fdd8dfc70e5d6d11 Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Sat, 18 Aug 2018 22:35:59 +1000 Subject: [PATCH 14/50] Experimental LED support (untested) --- quantum/quantum.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/quantum/quantum.c b/quantum/quantum.c index 64e364a24518..dda8ea8a994e 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -1194,7 +1194,10 @@ static inline uint16_t scale_backlight(uint16_t v) { */ ISR(TIMER1_OVF_vect) { - uint16_t interval = (uint16_t) breathing_period * 244 / BREATHING_STEPS; + uint16_t interval = momentum_enabled() + ? match_momentum(1, 10) + : (uint16_t) breathing_period * 244 / BREATHING_STEPS; + // resetting after one period to prevent ugly reset at overflow. breathing_counter = (breathing_counter + 1) % (breathing_period * 244); uint8_t index = breathing_counter / interval % BREATHING_STEPS; From 48a222de4ec8b7728658bf72b8c626a9381ef0aa Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Wed, 25 Jul 2018 11:59:44 +1000 Subject: [PATCH 15/50] Draft commit of typing speed RGB control --- quantum/quantum.c | 3 +++ quantum/quantum.h | 2 ++ quantum/rgblight.c | 18 +++++++++++++++--- readme.md | 20 +++++++++++++++++++- 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/quantum/quantum.c b/quantum/quantum.c index ab47fa48ff48..a9f2b38561f8 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -190,12 +190,15 @@ static uint16_t scs_timer[2] = {0, 0}; */ static bool grave_esc_was_shifted = false; +uint8_t typing_speed = 0; bool process_record_quantum(keyrecord_t *record) { /* This gets the keycode from the key pressed */ keypos_t key = record->event.key; uint16_t keycode; + if (typing_speed < 100) typing_speed += 1; + #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS) /* TODO: Use store_or_get_action() or a similar function. */ if (!disable_action_cache) { diff --git a/quantum/quantum.h b/quantum/quantum.h index 1db9846f0458..5d400e7e42c8 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h @@ -56,6 +56,8 @@ #include "suspend.h" extern uint32_t default_layer_state; +//Used in rgblight.c to match RGB animation to typing speed +extern uint8_t typing_speed; #ifndef NO_ACTION_LAYER extern uint32_t layer_state; diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 4919ae4abfe4..548afd8d94f2 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -24,13 +24,15 @@ #include "rgblight.h" #include "debug.h" #include "led_tables.h" +#include "quantum.h" #ifndef RGBLIGHT_LIMIT_VAL #define RGBLIGHT_LIMIT_VAL 255 #endif -#define MIN(a,b) (((a)<(b))?(a):(b)) -#define MAX(a,b) (((a)>(b))?(a):(b)) +//These conflict with a chained include that comes from including quantum.h +// #define MIN(a,b) (((a)<(b))?(a):(b)) +// #define MAX(a,b) (((a)>(b))?(a):(b)) __attribute__ ((weak)) const uint8_t RGBLED_BREATHING_INTERVALS[] PROGMEM = {30, 20, 10, 5}; @@ -631,7 +633,17 @@ 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])) { + + //Improvement: move this code into rgblight_task() so that the typing_speed can be used across all RGB effects, not just swirl + static uint16_t decay_timer = 0; + if (timer_elapsed(decay_timer) > 250 || decay_timer == 0) { + if (typing_speed > 0) typing_speed -= 1; + //Improvement(?): decay by a greater rate depending on how big typing_speed is, so you can't reach max speed just by outpacing the regular decay + decay_timer = timer_read(); + } + + //Improvement: make the usage of typing speed more easily configurable, either with a pre-processor toggle or with real-time key toggles + if (timer_elapsed(last_timer) < MAX(1, 100 - typing_speed)) { return; } last_timer = timer_read(); diff --git a/readme.md b/readme.md index 6e6cfaa1bd10..55b097f8ace6 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,22 @@ -# Quantum Mechanical Keyboard Firmware +# Quantum Mechanical Keyboard Firmware - chrislewisdev fork + +## Typing Speed -> RGB Animation Control + +This fork of qmk_firmware contains the code I whipped up to make your keyboard's RGB animation speed match your typing speed. As of writing, this is a "first draft" version, aka the simplest implementation I could think of with the quickest/hackiest code. Beware hard-coding :) + +Regardless, I'm happy to share the code and discuss improvements with anyone who'd like to contribute. I'll do my best to facilitate it in my spare time. + +## Getting Started + +My entire change amounts to several lines in `quantum.h`, `quantum.c` and `rgblight.c`. To see the details it's probably easiest if you look at my first commit to this fork which contains all the changes. + +I've left a couple of "Improvement:" comments around the code to indicate what I think would make it better or more "production"-ready. These could be good places to start for anyone interested in contributing. + +To test it, I've just been using my DZ60 keyboard, building the firmware with `make dz60:default` and flashing with qmk_toolbox. + +Below is the original QMK readme: + +# QMK [![Current Version](https://img.shields.io/github/tag/qmk/qmk_firmware.svg)](https://github.com/qmk/qmk_firmware/tags) [![Build Status](https://travis-ci.org/qmk/qmk_firmware.svg?branch=master)](https://travis-ci.org/qmk/qmk_firmware) From c8b160b410c4a804054919407f939b5d14f418dd Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Wed, 25 Jul 2018 12:08:13 +1000 Subject: [PATCH 16/50] More information in the readme --- readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 55b097f8ace6..9b00ba18d0bb 100644 --- a/readme.md +++ b/readme.md @@ -8,11 +8,11 @@ Regardless, I'm happy to share the code and discuss improvements with anyone who ## Getting Started -My entire change amounts to several lines in `quantum.h`, `quantum.c` and `rgblight.c`. To see the details it's probably easiest if you look at my first commit to this fork which contains all the changes. +My entire change amounts to several lines in `quantum.h`, `quantum.c` and `rgblight.c`. To see the details it's probably easiest if you look at [this commit](https://github.com/chrislewisdev/qmk_firmware/commit/2d3fbc5d0ad70309ede5cdeb9cf84380fd69baae) which contains all the changes. I've left a couple of "Improvement:" comments around the code to indicate what I think would make it better or more "production"-ready. These could be good places to start for anyone interested in contributing. -To test it, I've just been using my DZ60 keyboard, building the firmware with `make dz60:default` and flashing with qmk_toolbox. +To test it, I've just been using my DZ60 keyboard, building the firmware with `make dz60:default` and flashing with qmk_toolbox. If you're not familiar with how to do that, it's probably best you consult the [QMK documentation](https://docs.qmk.fm/#/). Below is the original QMK readme: From 4d15b2d785ae3c09e693299140239ce093a26dc6 Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Fri, 27 Jul 2018 00:23:44 +1000 Subject: [PATCH 17/50] 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! --- quantum/quantum.c | 2 +- quantum/quantum.h | 1 + quantum/rgblight.c | 36 ++++++++++++++++++++++-------------- quantum/rgblight.h | 3 +++ 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/quantum/quantum.c b/quantum/quantum.c index a9f2b38561f8..2828a039660c 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -197,7 +197,7 @@ bool process_record_quantum(keyrecord_t *record) { keypos_t key = record->event.key; uint16_t keycode; - if (typing_speed < 100) typing_speed += 1; + if (typing_speed < TYPING_SPEED_MAX_VALUE) typing_speed += 1; #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS) /* TODO: Use store_or_get_action() or a similar function. */ diff --git a/quantum/quantum.h b/quantum/quantum.h index 5d400e7e42c8..a57a0dc0a1bf 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h @@ -58,6 +58,7 @@ extern uint32_t default_layer_state; //Used in rgblight.c to match RGB animation to typing speed extern uint8_t typing_speed; +#define TYPING_SPEED_MAX_VALUE 100 #ifndef NO_ACTION_LAYER extern uint32_t layer_state; diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 548afd8d94f2..9cbaf60851f0 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -570,8 +570,25 @@ void rgblight_show_solid_color(uint8_t r, uint8_t g, uint8_t b) { rgblight_setrgb(r, g, b); } +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_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(); + // mode = 1, static light, do nothing here if (rgblight_config.mode >= 2 && rgblight_config.mode <= 5) { // mode = 2 to 5, breathing mode @@ -606,7 +623,7 @@ 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])) { + if (timer_elapsed(last_timer) < typing_speed_matched_interval(1, 100)) { return; } last_timer = timer_read(); @@ -621,7 +638,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) < pgm_read_byte(&RGBLED_RAINBOW_MOOD_INTERVALS[interval])) { + if (timer_elapsed(last_timer) < typing_speed_matched_interval(5, 100)) { return; } last_timer = timer_read(); @@ -634,16 +651,7 @@ void rgblight_effect_rainbow_swirl(uint8_t interval) { uint16_t hue; uint8_t i; - //Improvement: move this code into rgblight_task() so that the typing_speed can be used across all RGB effects, not just swirl - static uint16_t decay_timer = 0; - if (timer_elapsed(decay_timer) > 250 || decay_timer == 0) { - if (typing_speed > 0) typing_speed -= 1; - //Improvement(?): decay by a greater rate depending on how big typing_speed is, so you can't reach max speed just by outpacing the regular decay - decay_timer = timer_read(); - } - - //Improvement: make the usage of typing speed more easily configurable, either with a pre-processor toggle or with real-time key toggles - if (timer_elapsed(last_timer) < MAX(1, 100 - typing_speed)) { + if (timer_elapsed(last_timer) < typing_speed_matched_interval(1, 100)) { return; } last_timer = timer_read(); @@ -672,7 +680,7 @@ 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])) { + if (timer_elapsed(last_timer) < typing_speed_matched_interval(5, 100)) { return; } last_timer = timer_read(); @@ -703,7 +711,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) < pgm_read_byte(&RGBLED_KNIGHT_INTERVALS[interval])) { + if (timer_elapsed(last_timer) < typing_speed_matched_interval(5, 100)) { return; } last_timer = timer_read(); diff --git a/quantum/rgblight.h b/quantum/rgblight.h index ba010dfae3c4..eccbbf26bb5c 100644 --- a/quantum/rgblight.h +++ b/quantum/rgblight.h @@ -168,4 +168,7 @@ void rgblight_effect_christmas(void); void rgblight_effect_rgbtest(void); void rgblight_effect_alternating(void); +void typing_speed_decay_task(void); +uint8_t typing_speed_matched_interval(uint8_t minValue, uint8_t maxValue); + #endif From 03f757875b3532fd3b90b39bc08b247dda711a3a Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Fri, 27 Jul 2018 10:06:06 +1000 Subject: [PATCH 18/50] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 9b00ba18d0bb..3a8ac989c865 100644 --- a/readme.md +++ b/readme.md @@ -10,7 +10,7 @@ Regardless, I'm happy to share the code and discuss improvements with anyone who My entire change amounts to several lines in `quantum.h`, `quantum.c` and `rgblight.c`. To see the details it's probably easiest if you look at [this commit](https://github.com/chrislewisdev/qmk_firmware/commit/2d3fbc5d0ad70309ede5cdeb9cf84380fd69baae) which contains all the changes. -I've left a couple of "Improvement:" comments around the code to indicate what I think would make it better or more "production"-ready. These could be good places to start for anyone interested in contributing. +I've created GitHub Issues for the most pressing things that need to be addressed before this could be merged into QMK - if you're interested in helping out, please do take a look! To test it, I've just been using my DZ60 keyboard, building the firmware with `make dz60:default` and flashing with qmk_toolbox. If you're not familiar with how to do that, it's probably best you consult the [QMK documentation](https://docs.qmk.fm/#/). From b266a92cca38838ae1512d241dce0d57aa5ff4de Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Fri, 27 Jul 2018 23:48:07 +1000 Subject: [PATCH 19/50] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 3a8ac989c865..8673f66f79df 100644 --- a/readme.md +++ b/readme.md @@ -8,7 +8,7 @@ Regardless, I'm happy to share the code and discuss improvements with anyone who ## Getting Started -My entire change amounts to several lines in `quantum.h`, `quantum.c` and `rgblight.c`. To see the details it's probably easiest if you look at [this commit](https://github.com/chrislewisdev/qmk_firmware/commit/2d3fbc5d0ad70309ede5cdeb9cf84380fd69baae) which contains all the changes. +My original change amounts to several lines in `quantum.h`, `quantum.c` and `rgblight.c`. To see the details it's probably easiest if you look at [this commit](https://github.com/chrislewisdev/qmk_firmware/commit/2d3fbc5d0ad70309ede5cdeb9cf84380fd69baae) which contains all the changes. I've created GitHub Issues for the most pressing things that need to be addressed before this could be merged into QMK - if you're interested in helping out, please do take a look! From e7fd2bc991cbbfca4681f5c24a8cfaeeb820c4f0 Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Sat, 28 Jul 2018 15:54:08 +1000 Subject: [PATCH 20/50] 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 --- quantum/quantum.c | 5 +++-- quantum/quantum.h | 3 --- quantum/rgblight.c | 7 +++---- quantum/rgblight.h | 4 ++++ 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/quantum/quantum.c b/quantum/quantum.c index 2828a039660c..83e0fdfaac1f 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -190,14 +190,15 @@ static uint16_t scs_timer[2] = {0, 0}; */ static bool grave_esc_was_shifted = false; -uint8_t typing_speed = 0; bool process_record_quantum(keyrecord_t *record) { /* This gets the keycode from the key pressed */ keypos_t key = record->event.key; uint16_t keycode; - if (typing_speed < TYPING_SPEED_MAX_VALUE) typing_speed += 1; + #ifdef RGBLIGHT_ENABLE + if (typing_speed < TYPING_SPEED_MAX_VALUE) typing_speed += 1; + #endif #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS) /* TODO: Use store_or_get_action() or a similar function. */ diff --git a/quantum/quantum.h b/quantum/quantum.h index a57a0dc0a1bf..1db9846f0458 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h @@ -56,9 +56,6 @@ #include "suspend.h" extern uint32_t default_layer_state; -//Used in rgblight.c to match RGB animation to typing speed -extern uint8_t typing_speed; -#define TYPING_SPEED_MAX_VALUE 100 #ifndef NO_ACTION_LAYER extern uint32_t layer_state; diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 9cbaf60851f0..302ca4c7c150 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -24,15 +24,13 @@ #include "rgblight.h" #include "debug.h" #include "led_tables.h" -#include "quantum.h" #ifndef RGBLIGHT_LIMIT_VAL #define RGBLIGHT_LIMIT_VAL 255 #endif -//These conflict with a chained include that comes from including quantum.h -// #define MIN(a,b) (((a)<(b))?(a):(b)) -// #define MAX(a,b) (((a)>(b))?(a):(b)) +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define MAX(a,b) (((a)>(b))?(a):(b)) __attribute__ ((weak)) const uint8_t RGBLED_BREATHING_INTERVALS[] PROGMEM = {30, 20, 10, 5}; @@ -570,6 +568,7 @@ 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; diff --git a/quantum/rgblight.h b/quantum/rgblight.h index eccbbf26bb5c..1b8fc4ad455d 100644 --- a/quantum/rgblight.h +++ b/quantum/rgblight.h @@ -89,6 +89,10 @@ 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 100 + typedef union { uint32_t raw; struct { From 08ceae1d908bcbdc7da884606afb8b929ca64e30 Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Sat, 28 Jul 2018 16:02:36 +1000 Subject: [PATCH 21/50] Tweaks to the typing speed decay rate --- quantum/quantum.c | 2 +- quantum/rgblight.c | 6 +++++- quantum/rgblight.h | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/quantum/quantum.c b/quantum/quantum.c index 83e0fdfaac1f..377d3692e49f 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -197,7 +197,7 @@ bool process_record_quantum(keyrecord_t *record) { uint16_t keycode; #ifdef RGBLIGHT_ENABLE - if (typing_speed < TYPING_SPEED_MAX_VALUE) typing_speed += 1; + if (typing_speed < TYPING_SPEED_MAX_VALUE) typing_speed += (TYPING_SPEED_MAX_VALUE / 100); #endif #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS) diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 302ca4c7c150..085fbadd7b76 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -574,6 +574,10 @@ void typing_speed_decay_task() { 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(); } } @@ -679,7 +683,7 @@ void rgblight_effect_snake(uint8_t interval) { if (interval % 2) { increment = -1; } - if (timer_elapsed(last_timer) < typing_speed_matched_interval(5, 100)) { + if (timer_elapsed(last_timer) < typing_speed_matched_interval(1, 200)) { return; } last_timer = timer_read(); diff --git a/quantum/rgblight.h b/quantum/rgblight.h index 1b8fc4ad455d..4b203c79c1a3 100644 --- a/quantum/rgblight.h +++ b/quantum/rgblight.h @@ -91,7 +91,7 @@ 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 100 +#define TYPING_SPEED_MAX_VALUE 200 typedef union { uint32_t raw; From 6604f164acf7bd9d49dec48542e203afe748a0e2 Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Sat, 18 Aug 2018 20:43:39 +1000 Subject: [PATCH 22/50] Renamed to momentum; moved implementation into dedicated files --- common_features.mk | 1 + quantum/momentum.c | 32 ++++++++++++++++++++++++++++++++ quantum/momentum.h | 11 +++++++++++ quantum/quantum.c | 2 +- quantum/rgblight.c | 30 ++++++------------------------ quantum/rgblight.h | 9 ++------- 6 files changed, 53 insertions(+), 32 deletions(-) create mode 100644 quantum/momentum.c create mode 100644 quantum/momentum.h diff --git a/common_features.mk b/common_features.mk index b78f04d2a820..dd215071963c 100644 --- a/common_features.mk +++ b/common_features.mk @@ -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) diff --git a/quantum/momentum.c b/quantum/momentum.c new file mode 100644 index 000000000000..e0fadc991c18 --- /dev/null +++ b/quantum/momentum.c @@ -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)); +} \ No newline at end of file diff --git a/quantum/momentum.h b/quantum/momentum.h new file mode 100644 index 000000000000..7acf139255a7 --- /dev/null +++ b/quantum/momentum.h @@ -0,0 +1,11 @@ +#ifndef MOMENTUM_H +#define MOMENTUM_H + +#include +#include "timer.h" + +void momentum_accelerate(void); +void momentum_decay_task(void); +uint8_t match_momentum(uint8_t minValue, uint8_t maxValue); + +#endif \ No newline at end of file diff --git a/quantum/quantum.c b/quantum/quantum.c index 377d3692e49f..3d47585d456d 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -197,7 +197,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) diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 085fbadd7b76..aa3143dcd3ae 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -568,29 +568,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) { @@ -626,7 +608,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(); @@ -641,7 +623,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(); @@ -654,7 +636,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(); @@ -683,7 +665,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(); @@ -714,7 +696,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(); diff --git a/quantum/rgblight.h b/quantum/rgblight.h index 4b203c79c1a3..5ada9ac4aabf 100644 --- a/quantum/rgblight.h +++ b/quantum/rgblight.h @@ -80,6 +80,8 @@ #include #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 { @@ -172,7 +170,4 @@ void rgblight_effect_christmas(void); void rgblight_effect_rgbtest(void); void rgblight_effect_alternating(void); -void typing_speed_decay_task(void); -uint8_t typing_speed_matched_interval(uint8_t minValue, uint8_t maxValue); - #endif From 4eafbcf008512a669e00367d7ee646524adc86ef Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Sat, 18 Aug 2018 21:03:02 +1000 Subject: [PATCH 23/50] Groundwork for toggling momentum on/off (currently always on) --- quantum/momentum.c | 5 +++++ quantum/momentum.h | 3 ++- quantum/quantum.c | 2 +- quantum/rgblight.c | 34 ++++++++++++++++++++++++++++------ 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/quantum/momentum.c b/quantum/momentum.c index e0fadc991c18..8b2d8dc06d3f 100644 --- a/quantum/momentum.c +++ b/quantum/momentum.c @@ -1,4 +1,5 @@ #include "momentum.h" +#include "timer.h" #ifndef MIN #define MIN(a,b) (((a)<(b))?(a):(b)) @@ -10,6 +11,10 @@ #define TYPING_SPEED_MAX_VALUE 200 uint8_t typing_speed = 0; +bool momentum_enabled() { + return true; +} + void momentum_accelerate() { if (typing_speed < TYPING_SPEED_MAX_VALUE) typing_speed += (TYPING_SPEED_MAX_VALUE / 100); } diff --git a/quantum/momentum.h b/quantum/momentum.h index 7acf139255a7..d72c043d1515 100644 --- a/quantum/momentum.h +++ b/quantum/momentum.h @@ -2,8 +2,9 @@ #define MOMENTUM_H #include -#include "timer.h" +#include +bool momentum_enabled(void); void momentum_accelerate(void); void momentum_decay_task(void); uint8_t match_momentum(uint8_t minValue, uint8_t maxValue); diff --git a/quantum/quantum.c b/quantum/quantum.c index 3d47585d456d..6f5af6f60cca 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -197,7 +197,7 @@ bool process_record_quantum(keyrecord_t *record) { uint16_t keycode; #ifdef RGBLIGHT_ENABLE - momentum_accelerate(); + if (momentum_enabled()) momentum_accelerate(); #endif #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS) diff --git a/quantum/rgblight.c b/quantum/rgblight.c index aa3143dcd3ae..19f65e17b397 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -572,7 +572,7 @@ void rgblight_task(void) { if (rgblight_timer_enabled) { - momentum_decay_task(); + if (momentum_enabled()) momentum_decay_task(); // mode = 1, static light, do nothing here if (rgblight_config.mode >= 2 && rgblight_config.mode <= 5) { @@ -608,7 +608,11 @@ void rgblight_effect_breathing(uint8_t interval) { static uint16_t last_timer = 0; float val; - if (timer_elapsed(last_timer) < match_momentum(1, 100)) { + uint8_t interval_time = momentum_enabled() + ? match_momentum(1, 100) + : pgm_read_byte(&RGBLED_RAINBOW_SWIRL_INTERVALS[interval / 2]); + + if (timer_elapsed(last_timer) < interval_time) { return; } last_timer = timer_read(); @@ -623,7 +627,11 @@ 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) < match_momentum(5, 100)) { + uint8_t interval_time = momentum_enabled() + ? match_momentum(5, 100) + : pgm_read_byte(&RGBLED_RAINBOW_MOOD_INTERVALS[interval]); + + if (timer_elapsed(last_timer) < interval_time) { return; } last_timer = timer_read(); @@ -636,7 +644,11 @@ void rgblight_effect_rainbow_swirl(uint8_t interval) { uint16_t hue; uint8_t i; - if (timer_elapsed(last_timer) < match_momentum(1, 100)) { + uint8_t interval_time = momentum_enabled() + ? match_momentum(1, 100) + : pgm_read_byte(&RGBLED_RAINBOW_SWIRL_INTERVALS[interval / 2]); + + if (timer_elapsed(last_timer) < interval_time) { return; } last_timer = timer_read(); @@ -665,7 +677,12 @@ void rgblight_effect_snake(uint8_t interval) { if (interval % 2) { increment = -1; } - if (timer_elapsed(last_timer) < match_momentum(1, 200)) { + + uint8_t interval_time = momentum_enabled() + ? match_momentum(1, 200) + : pgm_read_byte(&RGBLED_SNAKE_INTERVALS[interval / 2]); + + if (timer_elapsed(last_timer) < interval_time) { return; } last_timer = timer_read(); @@ -696,7 +713,12 @@ 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) < match_momentum(5, 100)) { + + uint8_t interval_time = momentum_enabled() + ? match_momentum(5, 100) + : pgm_read_byte(&RGBLED_KNIGHT_INTERVALS[interval]); + + if (timer_elapsed(last_timer) < interval_time) { return; } last_timer = timer_read(); From 6696088f0e26d36c24f173197a00accc963939e5 Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Sat, 18 Aug 2018 21:58:52 +1000 Subject: [PATCH 24/50] Add EEPROM toggle for momentum-matching --- quantum/momentum.c | 11 ++++++++++- quantum/momentum.h | 1 + quantum/quantum.c | 5 +++++ quantum/quantum_keycodes.h | 3 +++ tmk_core/common/eeconfig.c | 1 + tmk_core/common/eeconfig.h | 2 +- 6 files changed, 21 insertions(+), 2 deletions(-) diff --git a/quantum/momentum.c b/quantum/momentum.c index 8b2d8dc06d3f..662f71d51c8d 100644 --- a/quantum/momentum.c +++ b/quantum/momentum.c @@ -1,5 +1,7 @@ #include "momentum.h" #include "timer.h" +#include "eeconfig.h" +#include "eeprom.h" #ifndef MIN #define MIN(a,b) (((a)<(b))?(a):(b)) @@ -12,7 +14,14 @@ uint8_t typing_speed = 0; bool momentum_enabled() { - return true; + return eeprom_read_byte(EECONFIG_MOMENTUM) == 1; +} + +void momentum_toggle() { + if (momentum_enabled()) + eeprom_update_byte(EECONFIG_MOMENTUM, 0); + else + eeprom_update_byte(EECONFIG_MOMENTUM, 1); } void momentum_accelerate() { diff --git a/quantum/momentum.h b/quantum/momentum.h index d72c043d1515..1fe4c58aea31 100644 --- a/quantum/momentum.h +++ b/quantum/momentum.h @@ -5,6 +5,7 @@ #include bool momentum_enabled(void); +void momentum_toggle(void); void momentum_accelerate(void); void momentum_decay_task(void); uint8_t match_momentum(uint8_t minValue, uint8_t maxValue); diff --git a/quantum/quantum.c b/quantum/quantum.c index 6f5af6f60cca..681b01849f9e 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -519,6 +519,11 @@ bool process_record_quantum(keyrecord_t *record) { rgblight_mode(35); } return false; + case MOM_TOG: + if (record->event.pressed) { + momentum_toggle(); + } + return false; #endif // defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE) #ifdef PROTOCOL_LUFA case OUT_AUTO: diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index f2cdb8a3bffa..2391122d9d98 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h @@ -425,6 +425,9 @@ enum quantum_keycodes { RGB_MODE_GRADIENT, RGB_MODE_RGBTEST, + //Momentum matching toggle + MOM_TOG, + // Left shift, open paren KC_LSPO, diff --git a/tmk_core/common/eeconfig.c b/tmk_core/common/eeconfig.c index 3e5987ee3be3..4d76cc0a6940 100644 --- a/tmk_core/common/eeconfig.c +++ b/tmk_core/common/eeconfig.c @@ -22,6 +22,7 @@ void eeconfig_init(void) #endif #if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE) eeprom_update_dword(EECONFIG_RGBLIGHT, 0); + eeprom_update_byte(EECONFIG_MOMENTUM, 0); #endif #ifdef STENO_ENABLE eeprom_update_byte(EECONFIG_STENOMODE, 0); diff --git a/tmk_core/common/eeconfig.h b/tmk_core/common/eeconfig.h index 1397a90c79ff..87cf9b485e59 100644 --- a/tmk_core/common/eeconfig.h +++ b/tmk_core/common/eeconfig.h @@ -37,7 +37,7 @@ along with this program. If not, see . #define EECONFIG_STENOMODE (uint8_t *)13 // EEHANDS for two handed boards #define EECONFIG_HANDEDNESS (uint8_t *)14 - +#define EECONFIG_MOMENTUM (uint8_t *)15 /* debug bit */ #define EECONFIG_DEBUG_ENABLE (1<<0) From e4da94bda9d3690a3c75690a8b1222d42f716526 Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Sat, 18 Aug 2018 22:21:16 +1000 Subject: [PATCH 25/50] Moved momentum out of RGBLIGHT_ENABLE toggles so it's more generic --- common_features.mk | 4 ++-- quantum/quantum.c | 10 +++++----- quantum/rgblight.c | 1 + quantum/rgblight.h | 2 -- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/common_features.mk b/common_features.mk index dd215071963c..261d4fc25f45 100644 --- a/common_features.mk +++ b/common_features.mk @@ -105,7 +105,6 @@ 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) @@ -208,7 +207,8 @@ QUANTUM_SRC:= \ $(QUANTUM_DIR)/quantum.c \ $(QUANTUM_DIR)/keymap_common.c \ $(QUANTUM_DIR)/keycode_config.c \ - $(QUANTUM_DIR)/process_keycode/process_leader.c + $(QUANTUM_DIR)/process_keycode/process_leader.c \ + $(QUANTUM_DIR)/momentum.c ifndef CUSTOM_MATRIX ifeq ($(strip $(SPLIT_KEYBOARD)), yes) diff --git a/quantum/quantum.c b/quantum/quantum.c index 681b01849f9e..586221fcbda6 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -42,6 +42,8 @@ extern backlight_config_t backlight_config; #include "process_midi.h" #endif +#include "momentum.h" + #ifdef AUDIO_ENABLE #ifndef GOODBYE_SONG #define GOODBYE_SONG SONG(GOODBYE_SOUND) @@ -196,9 +198,7 @@ bool process_record_quantum(keyrecord_t *record) { keypos_t key = record->event.key; uint16_t keycode; - #ifdef RGBLIGHT_ENABLE - if (momentum_enabled()) momentum_accelerate(); - #endif + if (momentum_enabled()) momentum_accelerate(); #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS) /* TODO: Use store_or_get_action() or a similar function. */ @@ -519,13 +519,13 @@ bool process_record_quantum(keyrecord_t *record) { rgblight_mode(35); } return false; + #endif // defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE) case MOM_TOG: if (record->event.pressed) { momentum_toggle(); } return false; - #endif // defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE) - #ifdef PROTOCOL_LUFA + #ifdef PROTOCOL_LUFA case OUT_AUTO: if (record->event.pressed) { set_output(OUTPUT_AUTO); diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 19f65e17b397..071a0fee13d9 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -24,6 +24,7 @@ #include "rgblight.h" #include "debug.h" #include "led_tables.h" +#include "momentum.h" #ifndef RGBLIGHT_LIMIT_VAL #define RGBLIGHT_LIMIT_VAL 255 diff --git a/quantum/rgblight.h b/quantum/rgblight.h index 5ada9ac4aabf..ba010dfae3c4 100644 --- a/quantum/rgblight.h +++ b/quantum/rgblight.h @@ -80,8 +80,6 @@ #include #endif -#include "momentum.h" - extern LED_TYPE led[RGBLED_NUM]; extern const uint8_t RGBLED_BREATHING_INTERVALS[4] PROGMEM; From c1900d541e2744d0d62f3876dc4b321e3119a5f6 Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Sat, 18 Aug 2018 22:26:44 +1000 Subject: [PATCH 26/50] Move momentum decay task out of rgblight_task() --- quantum/rgblight.c | 3 --- tmk_core/protocol/lufa/lufa.c | 2 ++ 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 071a0fee13d9..ccb3110a1e1f 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -572,9 +572,6 @@ void rgblight_show_solid_color(uint8_t r, uint8_t g, uint8_t b) { void rgblight_task(void) { if (rgblight_timer_enabled) { - - if (momentum_enabled()) momentum_decay_task(); - // mode = 1, static light, do nothing here if (rgblight_config.mode >= 2 && rgblight_config.mode <= 5) { // mode = 2 to 5, breathing mode diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index cb918d3dce14..b15c7a76c89a 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -1074,6 +1074,8 @@ int main(void) MIDI_Device_USBTask(&USB_MIDI_Interface); #endif + if (momentum_enabled()) momentum_decay_task(); + #if defined(RGBLIGHT_ANIMATIONS) & defined(RGBLIGHT_ENABLE) rgblight_task(); #endif From ad3fb0dc55a60b5b591e7b74f3d5aee66b5e351e Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Sat, 18 Aug 2018 22:44:59 +1000 Subject: [PATCH 27/50] Fix missing momentum.h in lufa.c --- tmk_core/protocol/lufa/lufa.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index b15c7a76c89a..3bfcc40dd619 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -54,6 +54,7 @@ #include "quantum.h" #include #include "outputselect.h" +#include "momentum.h" #ifdef NKRO_ENABLE #include "keycode_config.h" From 2caa8ad4ff38fa01d8f9bacfef574cb45699a6ef Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Thu, 23 Aug 2018 21:52:46 +1000 Subject: [PATCH 28/50] Added documentation --- docs/feature_momentum.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 docs/feature_momentum.md diff --git a/docs/feature_momentum.md b/docs/feature_momentum.md new file mode 100644 index 000000000000..00ce4bb70f76 --- /dev/null +++ b/docs/feature_momentum.md @@ -0,0 +1,18 @@ +# Momentum + +Momentum 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! + +## Usage +For Momentum to take effect, you need to enable it with the MOM_TOG keycode, which toggles it on and off. + +The following light effects will all be controlled by Momentum when it is enabled: + - RGB Breathing + - RGB Rainbow Mood + - RGB Rainbow Swirl + - RGB Snake + - RGB Knight + + As long as Momentum is enabled, it will control the speed regardless of any other speed setting that your RGB lights are currently on. + + ## Configuration + Momentum 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 `momentum.c` and adjust the values there to achieve the kinds of speeds that you like. \ No newline at end of file From e81aa387fa433055fd4993f7092daf78dd89ad82 Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Thu, 23 Aug 2018 21:59:08 +1000 Subject: [PATCH 29/50] Renamed feature to velocikey --- common_features.mk | 2 +- ...ature_momentum.md => feature_velocikey.md} | 2 +- quantum/momentum.h | 13 ----------- quantum/quantum.c | 8 +++---- quantum/quantum_keycodes.h | 2 +- quantum/rgblight.c | 22 +++++++++---------- quantum/{momentum.c => velocikey.c} | 14 ++++++------ quantum/velocikey.h | 13 +++++++++++ tmk_core/protocol/lufa/lufa.c | 4 ++-- 9 files changed, 40 insertions(+), 40 deletions(-) rename docs/{feature_momentum.md => feature_velocikey.md} (92%) delete mode 100644 quantum/momentum.h rename quantum/{momentum.c => velocikey.c} (81%) create mode 100644 quantum/velocikey.h diff --git a/common_features.mk b/common_features.mk index 261d4fc25f45..250cf61cf504 100644 --- a/common_features.mk +++ b/common_features.mk @@ -208,7 +208,7 @@ QUANTUM_SRC:= \ $(QUANTUM_DIR)/keymap_common.c \ $(QUANTUM_DIR)/keycode_config.c \ $(QUANTUM_DIR)/process_keycode/process_leader.c \ - $(QUANTUM_DIR)/momentum.c + $(QUANTUM_DIR)/velocikey.c ifndef CUSTOM_MATRIX ifeq ($(strip $(SPLIT_KEYBOARD)), yes) diff --git a/docs/feature_momentum.md b/docs/feature_velocikey.md similarity index 92% rename from docs/feature_momentum.md rename to docs/feature_velocikey.md index 00ce4bb70f76..31c0b85cf72c 100644 --- a/docs/feature_momentum.md +++ b/docs/feature_velocikey.md @@ -3,7 +3,7 @@ Momentum 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! ## Usage -For Momentum to take effect, you need to enable it with the MOM_TOG keycode, which toggles it on and off. +For Momentum to take effect, you need to enable it with the VLK_TOG keycode, which toggles it on and off. The following light effects will all be controlled by Momentum when it is enabled: - RGB Breathing diff --git a/quantum/momentum.h b/quantum/momentum.h deleted file mode 100644 index 1fe4c58aea31..000000000000 --- a/quantum/momentum.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef MOMENTUM_H -#define MOMENTUM_H - -#include -#include - -bool momentum_enabled(void); -void momentum_toggle(void); -void momentum_accelerate(void); -void momentum_decay_task(void); -uint8_t match_momentum(uint8_t minValue, uint8_t maxValue); - -#endif \ No newline at end of file diff --git a/quantum/quantum.c b/quantum/quantum.c index 586221fcbda6..32f5f2926718 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -42,7 +42,7 @@ extern backlight_config_t backlight_config; #include "process_midi.h" #endif -#include "momentum.h" +#include "velocikey.h" #ifdef AUDIO_ENABLE #ifndef GOODBYE_SONG @@ -198,7 +198,7 @@ bool process_record_quantum(keyrecord_t *record) { keypos_t key = record->event.key; uint16_t keycode; - if (momentum_enabled()) momentum_accelerate(); + if (velocikey_enabled()) velocikey_accelerate(); #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS) /* TODO: Use store_or_get_action() or a similar function. */ @@ -520,9 +520,9 @@ bool process_record_quantum(keyrecord_t *record) { } return false; #endif // defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE) - case MOM_TOG: + case VLK_TOG: if (record->event.pressed) { - momentum_toggle(); + velocikey_toggle(); } return false; #ifdef PROTOCOL_LUFA diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index 2391122d9d98..f63367f30678 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h @@ -426,7 +426,7 @@ enum quantum_keycodes { RGB_MODE_RGBTEST, //Momentum matching toggle - MOM_TOG, + VLK_TOG, // Left shift, open paren KC_LSPO, diff --git a/quantum/rgblight.c b/quantum/rgblight.c index ccb3110a1e1f..d3eb283f805d 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -24,7 +24,7 @@ #include "rgblight.h" #include "debug.h" #include "led_tables.h" -#include "momentum.h" +#include "velocikey.h" #ifndef RGBLIGHT_LIMIT_VAL #define RGBLIGHT_LIMIT_VAL 255 @@ -606,8 +606,8 @@ void rgblight_effect_breathing(uint8_t interval) { static uint16_t last_timer = 0; float val; - uint8_t interval_time = momentum_enabled() - ? match_momentum(1, 100) + uint8_t interval_time = velocikey_enabled() + ? velocikey_match_speed(1, 100) : pgm_read_byte(&RGBLED_RAINBOW_SWIRL_INTERVALS[interval / 2]); if (timer_elapsed(last_timer) < interval_time) { @@ -625,8 +625,8 @@ void rgblight_effect_rainbow_mood(uint8_t interval) { static uint16_t current_hue = 0; static uint16_t last_timer = 0; - uint8_t interval_time = momentum_enabled() - ? match_momentum(5, 100) + uint8_t interval_time = velocikey_enabled() + ? velocikey_match_speed(5, 100) : pgm_read_byte(&RGBLED_RAINBOW_MOOD_INTERVALS[interval]); if (timer_elapsed(last_timer) < interval_time) { @@ -642,8 +642,8 @@ void rgblight_effect_rainbow_swirl(uint8_t interval) { uint16_t hue; uint8_t i; - uint8_t interval_time = momentum_enabled() - ? match_momentum(1, 100) + uint8_t interval_time = velocikey_enabled() + ? velocikey_match_speed(1, 100) : pgm_read_byte(&RGBLED_RAINBOW_SWIRL_INTERVALS[interval / 2]); if (timer_elapsed(last_timer) < interval_time) { @@ -676,8 +676,8 @@ void rgblight_effect_snake(uint8_t interval) { increment = -1; } - uint8_t interval_time = momentum_enabled() - ? match_momentum(1, 200) + uint8_t interval_time = velocikey_enabled() + ? velocikey_match_speed(1, 200) : pgm_read_byte(&RGBLED_SNAKE_INTERVALS[interval / 2]); if (timer_elapsed(last_timer) < interval_time) { @@ -712,8 +712,8 @@ void rgblight_effect_snake(uint8_t interval) { void rgblight_effect_knight(uint8_t interval) { static uint16_t last_timer = 0; - uint8_t interval_time = momentum_enabled() - ? match_momentum(5, 100) + uint8_t interval_time = velocikey_enabled() + ? velocikey_match_speed(5, 100) : pgm_read_byte(&RGBLED_KNIGHT_INTERVALS[interval]); if (timer_elapsed(last_timer) < interval_time) { diff --git a/quantum/momentum.c b/quantum/velocikey.c similarity index 81% rename from quantum/momentum.c rename to quantum/velocikey.c index 662f71d51c8d..4b81ca95a80c 100644 --- a/quantum/momentum.c +++ b/quantum/velocikey.c @@ -1,4 +1,4 @@ -#include "momentum.h" +#include "velocikey.h" #include "timer.h" #include "eeconfig.h" #include "eeprom.h" @@ -13,22 +13,22 @@ #define TYPING_SPEED_MAX_VALUE 200 uint8_t typing_speed = 0; -bool momentum_enabled() { +bool velocikey_enabled() { return eeprom_read_byte(EECONFIG_MOMENTUM) == 1; } -void momentum_toggle() { - if (momentum_enabled()) +void velocikey_toggle() { + if (velocikey_enabled()) eeprom_update_byte(EECONFIG_MOMENTUM, 0); else eeprom_update_byte(EECONFIG_MOMENTUM, 1); } -void momentum_accelerate() { +void velocikey_accelerate() { if (typing_speed < TYPING_SPEED_MAX_VALUE) typing_speed += (TYPING_SPEED_MAX_VALUE / 100); } -void momentum_decay_task() { +void velocikey_decay_task() { static uint16_t decay_timer = 0; if (timer_elapsed(decay_timer) > 500 || decay_timer == 0) { @@ -41,6 +41,6 @@ void momentum_decay_task() { } } -uint8_t match_momentum(uint8_t minValue, uint8_t maxValue) { +uint8_t velocikey_match_speed(uint8_t minValue, uint8_t maxValue) { return MAX(minValue, maxValue - (maxValue - minValue) * ((float)typing_speed / TYPING_SPEED_MAX_VALUE)); } \ No newline at end of file diff --git a/quantum/velocikey.h b/quantum/velocikey.h new file mode 100644 index 000000000000..c6186d83b38e --- /dev/null +++ b/quantum/velocikey.h @@ -0,0 +1,13 @@ +#ifndef VELOCIKEY_H +#define VELOCIKEY_H + +#include +#include + +bool velocikey_enabled(void); +void velocikey_toggle(void); +void velocikey_accelerate(void); +void velocikey_decay_task(void); +uint8_t velocikey_match_speed(uint8_t minValue, uint8_t maxValue); + +#endif \ No newline at end of file diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index 3bfcc40dd619..fd9595c447f4 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -54,7 +54,7 @@ #include "quantum.h" #include #include "outputselect.h" -#include "momentum.h" +#include "velocikey.h" #ifdef NKRO_ENABLE #include "keycode_config.h" @@ -1075,7 +1075,7 @@ int main(void) MIDI_Device_USBTask(&USB_MIDI_Interface); #endif - if (momentum_enabled()) momentum_decay_task(); + if (velocikey_enabled()) velocikey_decay_task(); #if defined(RGBLIGHT_ANIMATIONS) & defined(RGBLIGHT_ENABLE) rgblight_task(); From fe505b400d1b518df74e3fb801089915e127ca76 Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Thu, 23 Aug 2018 22:09:19 +1000 Subject: [PATCH 30/50] Reverted readme to original state --- readme.md | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/readme.md b/readme.md index 8673f66f79df..c92963ad64f9 100644 --- a/readme.md +++ b/readme.md @@ -1,21 +1,3 @@ -# Quantum Mechanical Keyboard Firmware - chrislewisdev fork - -## Typing Speed -> RGB Animation Control - -This fork of qmk_firmware contains the code I whipped up to make your keyboard's RGB animation speed match your typing speed. As of writing, this is a "first draft" version, aka the simplest implementation I could think of with the quickest/hackiest code. Beware hard-coding :) - -Regardless, I'm happy to share the code and discuss improvements with anyone who'd like to contribute. I'll do my best to facilitate it in my spare time. - -## Getting Started - -My original change amounts to several lines in `quantum.h`, `quantum.c` and `rgblight.c`. To see the details it's probably easiest if you look at [this commit](https://github.com/chrislewisdev/qmk_firmware/commit/2d3fbc5d0ad70309ede5cdeb9cf84380fd69baae) which contains all the changes. - -I've created GitHub Issues for the most pressing things that need to be addressed before this could be merged into QMK - if you're interested in helping out, please do take a look! - -To test it, I've just been using my DZ60 keyboard, building the firmware with `make dz60:default` and flashing with qmk_toolbox. If you're not familiar with how to do that, it's probably best you consult the [QMK documentation](https://docs.qmk.fm/#/). - -Below is the original QMK readme: - # QMK [![Current Version](https://img.shields.io/github/tag/qmk/qmk_firmware.svg)](https://github.com/qmk/qmk_firmware/tags) From a0217f3f6c1bdcdf8d272401f8cb9ac408c4044c Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Thu, 23 Aug 2018 22:10:35 +1000 Subject: [PATCH 31/50] Correct the readme title --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index c92963ad64f9..6e6cfaa1bd10 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ -# QMK +# Quantum Mechanical Keyboard Firmware [![Current Version](https://img.shields.io/github/tag/qmk/qmk_firmware.svg)](https://github.com/qmk/qmk_firmware/tags) [![Build Status](https://travis-ci.org/qmk/qmk_firmware.svg?branch=master)](https://travis-ci.org/qmk/qmk_firmware) From 3062b72f14e524fea8b752b11286c8c479c83599 Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Sun, 26 Aug 2018 11:31:26 +1000 Subject: [PATCH 32/50] Updated feature name in the docs --- docs/feature_velocikey.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/docs/feature_velocikey.md b/docs/feature_velocikey.md index 31c0b85cf72c..870abbcaa484 100644 --- a/docs/feature_velocikey.md +++ b/docs/feature_velocikey.md @@ -1,18 +1,20 @@ -# Momentum +# Velocikey -Momentum 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! +Velocikey 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! ## Usage -For Momentum to take effect, you need to enable it with the VLK_TOG keycode, which toggles it on and off. +For Velocikey to take effect, you need to enable it with the VLK_TOG keycode, which toggles it on and off. -The following light effects will all be controlled by Momentum when it is enabled: +The following light effects will all be controlled by Velocikey when it is enabled: - RGB Breathing - RGB Rainbow Mood - RGB Rainbow Swirl - RGB Snake - RGB Knight - As long as Momentum is enabled, it will control the speed regardless of any other speed setting that your RGB lights are currently on. +Support for LED breathing effects is planned but not available yet. + + As long as Velocikey is enabled, it will control the speed regardless of any other speed setting that your RGB lights are currently on. ## Configuration - Momentum 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 `momentum.c` and adjust the values there to achieve the kinds of speeds that you like. \ No newline at end of file + 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. \ No newline at end of file From 42e839c8df86ad7192fe11eb13c7815a1e4fd49a Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Sun, 26 Aug 2018 11:34:50 +1000 Subject: [PATCH 33/50] Update EECONFIG name --- quantum/velocikey.c | 6 +++--- tmk_core/common/eeconfig.c | 2 +- tmk_core/common/eeconfig.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/quantum/velocikey.c b/quantum/velocikey.c index 4b81ca95a80c..1c542314fdbc 100644 --- a/quantum/velocikey.c +++ b/quantum/velocikey.c @@ -14,14 +14,14 @@ uint8_t typing_speed = 0; bool velocikey_enabled() { - return eeprom_read_byte(EECONFIG_MOMENTUM) == 1; + return eeprom_read_byte(EECONFIG_VELOCIKEY) == 1; } void velocikey_toggle() { if (velocikey_enabled()) - eeprom_update_byte(EECONFIG_MOMENTUM, 0); + eeprom_update_byte(EECONFIG_VELOCIKEY, 0); else - eeprom_update_byte(EECONFIG_MOMENTUM, 1); + eeprom_update_byte(EECONFIG_VELOCIKEY, 1); } void velocikey_accelerate() { diff --git a/tmk_core/common/eeconfig.c b/tmk_core/common/eeconfig.c index 4d76cc0a6940..e74384ac63ce 100644 --- a/tmk_core/common/eeconfig.c +++ b/tmk_core/common/eeconfig.c @@ -22,7 +22,7 @@ void eeconfig_init(void) #endif #if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE) eeprom_update_dword(EECONFIG_RGBLIGHT, 0); - eeprom_update_byte(EECONFIG_MOMENTUM, 0); + eeprom_update_byte(EECONFIG_VELOCIKEY, 0); #endif #ifdef STENO_ENABLE eeprom_update_byte(EECONFIG_STENOMODE, 0); diff --git a/tmk_core/common/eeconfig.h b/tmk_core/common/eeconfig.h index 87cf9b485e59..85c485aa8236 100644 --- a/tmk_core/common/eeconfig.h +++ b/tmk_core/common/eeconfig.h @@ -37,7 +37,7 @@ along with this program. If not, see . #define EECONFIG_STENOMODE (uint8_t *)13 // EEHANDS for two handed boards #define EECONFIG_HANDEDNESS (uint8_t *)14 -#define EECONFIG_MOMENTUM (uint8_t *)15 +#define EECONFIG_VELOCIKEY (uint8_t *)15 /* debug bit */ #define EECONFIG_DEBUG_ENABLE (1<<0) From e07b97f33731863132041c18196728a77d98e2c2 Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Sun, 26 Aug 2018 13:07:37 +1000 Subject: [PATCH 34/50] Add compile-time toggles for velocikey --- common_features.mk | 8 +++++-- quantum/quantum.c | 14 +++++++----- quantum/rgblight.c | 40 ++++++++++++++++++++++------------- tmk_core/protocol/lufa/lufa.c | 2 ++ 4 files changed, 42 insertions(+), 22 deletions(-) diff --git a/common_features.mk b/common_features.mk index 250cf61cf504..f0e302f801a3 100644 --- a/common_features.mk +++ b/common_features.mk @@ -203,12 +203,16 @@ ifeq ($(strip $(HD44780_ENABLE)), yes) OPT_DEFS += -DHD44780_ENABLE endif +ifeq ($(strip $(VELOCIKEY_ENABLE)), yes) + OPT_DEFS += -DVELOCIKEY_ENABLE + SRC += $(QUANTUM_DIR)/velocikey.c +endif + QUANTUM_SRC:= \ $(QUANTUM_DIR)/quantum.c \ $(QUANTUM_DIR)/keymap_common.c \ $(QUANTUM_DIR)/keycode_config.c \ - $(QUANTUM_DIR)/process_keycode/process_leader.c \ - $(QUANTUM_DIR)/velocikey.c + $(QUANTUM_DIR)/process_keycode/process_leader.c ifndef CUSTOM_MATRIX ifeq ($(strip $(SPLIT_KEYBOARD)), yes) diff --git a/quantum/quantum.c b/quantum/quantum.c index 32f5f2926718..8a4344986d50 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -198,7 +198,9 @@ bool process_record_quantum(keyrecord_t *record) { keypos_t key = record->event.key; uint16_t keycode; +#ifdef VELOCIKEY_ENABLE if (velocikey_enabled()) velocikey_accelerate(); +#endif #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS) /* TODO: Use store_or_get_action() or a similar function. */ @@ -520,11 +522,13 @@ bool process_record_quantum(keyrecord_t *record) { } return false; #endif // defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE) - case VLK_TOG: - if (record->event.pressed) { - velocikey_toggle(); - } - return false; + #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) { diff --git a/quantum/rgblight.c b/quantum/rgblight.c index d3eb283f805d..0cb08b14d238 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -606,9 +606,11 @@ void rgblight_effect_breathing(uint8_t interval) { static uint16_t last_timer = 0; float val; - uint8_t interval_time = velocikey_enabled() - ? velocikey_match_speed(1, 100) - : pgm_read_byte(&RGBLED_RAINBOW_SWIRL_INTERVALS[interval / 2]); + uint8_t interval_time = +#ifdef VELOCIKEY_ENABLE + velocikey_enabled() ? velocikey_match_speed(1, 100) : +#endif + pgm_read_byte(&RGBLED_RAINBOW_SWIRL_INTERVALS[interval / 2]); if (timer_elapsed(last_timer) < interval_time) { return; @@ -625,9 +627,11 @@ void rgblight_effect_rainbow_mood(uint8_t interval) { static uint16_t current_hue = 0; static uint16_t last_timer = 0; - uint8_t interval_time = velocikey_enabled() - ? velocikey_match_speed(5, 100) - : pgm_read_byte(&RGBLED_RAINBOW_MOOD_INTERVALS[interval]); + uint8_t interval_time = +#ifdef VELOCIKEY_ENABLE + velocikey_enabled() ? velocikey_match_speed(5, 100) : +#endif + pgm_read_byte(&RGBLED_RAINBOW_MOOD_INTERVALS[interval]); if (timer_elapsed(last_timer) < interval_time) { return; @@ -642,9 +646,11 @@ void rgblight_effect_rainbow_swirl(uint8_t interval) { uint16_t hue; uint8_t i; - uint8_t interval_time = velocikey_enabled() - ? velocikey_match_speed(1, 100) - : pgm_read_byte(&RGBLED_RAINBOW_SWIRL_INTERVALS[interval / 2]); + uint8_t interval_time = +#ifdef VELOCIKEY_ENABLE + velocikey_enabled() ? velocikey_match_speed(1, 100) : +#endif + pgm_read_byte(&RGBLED_RAINBOW_SWIRL_INTERVALS[interval / 2]); if (timer_elapsed(last_timer) < interval_time) { return; @@ -676,9 +682,11 @@ void rgblight_effect_snake(uint8_t interval) { increment = -1; } - uint8_t interval_time = velocikey_enabled() - ? velocikey_match_speed(1, 200) - : pgm_read_byte(&RGBLED_SNAKE_INTERVALS[interval / 2]); + uint8_t interval_time = +#ifdef VELOCIKEY_ENABLE + velocikey_enabled() ? velocikey_match_speed(1, 200) : +#endif + pgm_read_byte(&RGBLED_SNAKE_INTERVALS[interval / 2]); if (timer_elapsed(last_timer) < interval_time) { return; @@ -712,9 +720,11 @@ void rgblight_effect_snake(uint8_t interval) { void rgblight_effect_knight(uint8_t interval) { static uint16_t last_timer = 0; - uint8_t interval_time = velocikey_enabled() - ? velocikey_match_speed(5, 100) - : pgm_read_byte(&RGBLED_KNIGHT_INTERVALS[interval]); + uint8_t interval_time = +#ifdef VELOCIKEY_ENABLE + velocikey_enabled() ? velocikey_match_speed(5, 100) : +#endif + pgm_read_byte(&RGBLED_KNIGHT_INTERVALS[interval]); if (timer_elapsed(last_timer) < interval_time) { return; diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index fd9595c447f4..b93afaaa51a8 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -1075,7 +1075,9 @@ int main(void) MIDI_Device_USBTask(&USB_MIDI_Interface); #endif +#ifdef VELOCIKEY_ENABLE if (velocikey_enabled()) velocikey_decay_task(); +#endif #if defined(RGBLIGHT_ANIMATIONS) & defined(RGBLIGHT_ENABLE) rgblight_task(); From df111a55b9d4929182e16108b1c0ead15b16df97 Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Tue, 11 Sep 2018 09:21:27 +1000 Subject: [PATCH 35/50] Update feature documentation --- docs/feature_velocikey.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/docs/feature_velocikey.md b/docs/feature_velocikey.md index 870abbcaa484..5d98410735bc 100644 --- a/docs/feature_velocikey.md +++ b/docs/feature_velocikey.md @@ -3,7 +3,17 @@ Velocikey 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! ## Usage -For Velocikey to take effect, you need to enable it with the VLK_TOG keycode, which toggles it on and off. +For 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.: + +``` +BOOTMAGIC_ENABLE = no +MOUSEKEY_ENABLE = no +STENO_ENABLE = no +EXTRAKEY_ENABLE = yes +VELOCIKEY_ENABLE = yes +``` + +Then, while using your keyboard, you need to also turn it on with the VLK_TOG keycode, which toggles the feature on and off. The following light effects will all be controlled by Velocikey when it is enabled: - RGB Breathing @@ -17,4 +27,4 @@ Support for LED breathing effects is planned but not available yet. As long as Velocikey is enabled, it will control the speed regardless of any other speed setting that your RGB lights are currently on. ## Configuration - 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. \ No newline at end of file + 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. From 84c03b41e2fd19531075e40067c49d90a75623f6 Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Tue, 11 Sep 2018 22:01:48 +1000 Subject: [PATCH 36/50] Revert "Merge branch 'led-support' into master" This reverts commit e123ff5febf61639b9a9020748e1c2e2313460ff, reversing changes made to df111a55b9d4929182e16108b1c0ead15b16df97. --- common_features.mk | 3 +-- quantum/momentum.c | 46 ---------------------------------------------- quantum/momentum.h | 13 ------------- quantum/quantum.c | 5 +---- readme.md | 20 +------------------- 5 files changed, 3 insertions(+), 84 deletions(-) delete mode 100644 quantum/momentum.c delete mode 100644 quantum/momentum.h diff --git a/common_features.mk b/common_features.mk index 173af4dea534..0cc26109a922 100644 --- a/common_features.mk +++ b/common_features.mk @@ -236,8 +236,7 @@ QUANTUM_SRC:= \ $(QUANTUM_DIR)/quantum.c \ $(QUANTUM_DIR)/keymap_common.c \ $(QUANTUM_DIR)/keycode_config.c \ - $(QUANTUM_DIR)/process_keycode/process_leader.c \ - $(QUANTUM_DIR)/momentum.c + $(QUANTUM_DIR)/process_keycode/process_leader.c ifndef CUSTOM_MATRIX ifeq ($(strip $(SPLIT_KEYBOARD)), yes) diff --git a/quantum/momentum.c b/quantum/momentum.c deleted file mode 100644 index 662f71d51c8d..000000000000 --- a/quantum/momentum.c +++ /dev/null @@ -1,46 +0,0 @@ -#include "momentum.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 momentum_enabled() { - return eeprom_read_byte(EECONFIG_MOMENTUM) == 1; -} - -void momentum_toggle() { - if (momentum_enabled()) - eeprom_update_byte(EECONFIG_MOMENTUM, 0); - else - eeprom_update_byte(EECONFIG_MOMENTUM, 1); -} - -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)); -} \ No newline at end of file diff --git a/quantum/momentum.h b/quantum/momentum.h deleted file mode 100644 index 1fe4c58aea31..000000000000 --- a/quantum/momentum.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef MOMENTUM_H -#define MOMENTUM_H - -#include -#include - -bool momentum_enabled(void); -void momentum_toggle(void); -void momentum_accelerate(void); -void momentum_decay_task(void); -uint8_t match_momentum(uint8_t minValue, uint8_t maxValue); - -#endif \ No newline at end of file diff --git a/quantum/quantum.c b/quantum/quantum.c index 130974c34bc7..8a4344986d50 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -1201,10 +1201,7 @@ static inline uint16_t scale_backlight(uint16_t v) { */ ISR(TIMER1_OVF_vect) { - uint16_t interval = momentum_enabled() - ? match_momentum(1, 10) - : (uint16_t) breathing_period * 244 / BREATHING_STEPS; - + uint16_t interval = (uint16_t) breathing_period * 244 / BREATHING_STEPS; // resetting after one period to prevent ugly reset at overflow. breathing_counter = (breathing_counter + 1) % (breathing_period * 244); uint8_t index = breathing_counter / interval % BREATHING_STEPS; diff --git a/readme.md b/readme.md index 8673f66f79df..6e6cfaa1bd10 100644 --- a/readme.md +++ b/readme.md @@ -1,22 +1,4 @@ -# Quantum Mechanical Keyboard Firmware - chrislewisdev fork - -## Typing Speed -> RGB Animation Control - -This fork of qmk_firmware contains the code I whipped up to make your keyboard's RGB animation speed match your typing speed. As of writing, this is a "first draft" version, aka the simplest implementation I could think of with the quickest/hackiest code. Beware hard-coding :) - -Regardless, I'm happy to share the code and discuss improvements with anyone who'd like to contribute. I'll do my best to facilitate it in my spare time. - -## Getting Started - -My original change amounts to several lines in `quantum.h`, `quantum.c` and `rgblight.c`. To see the details it's probably easiest if you look at [this commit](https://github.com/chrislewisdev/qmk_firmware/commit/2d3fbc5d0ad70309ede5cdeb9cf84380fd69baae) which contains all the changes. - -I've created GitHub Issues for the most pressing things that need to be addressed before this could be merged into QMK - if you're interested in helping out, please do take a look! - -To test it, I've just been using my DZ60 keyboard, building the firmware with `make dz60:default` and flashing with qmk_toolbox. If you're not familiar with how to do that, it's probably best you consult the [QMK documentation](https://docs.qmk.fm/#/). - -Below is the original QMK readme: - -# QMK +# Quantum Mechanical Keyboard Firmware [![Current Version](https://img.shields.io/github/tag/qmk/qmk_firmware.svg)](https://github.com/qmk/qmk_firmware/tags) [![Build Status](https://travis-ci.org/qmk/qmk_firmware.svg?branch=master)](https://travis-ci.org/qmk/qmk_firmware) From 5b323e3c5294e6b776669578ab068df1443233a8 Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Sun, 16 Sep 2018 16:55:23 +1000 Subject: [PATCH 37/50] Move velocikey EECONFIG definition to depend on VELOCIKEY_ENABLE --- tmk_core/common/eeconfig.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tmk_core/common/eeconfig.c b/tmk_core/common/eeconfig.c index 772b99ad3400..f6496800387d 100644 --- a/tmk_core/common/eeconfig.c +++ b/tmk_core/common/eeconfig.c @@ -30,6 +30,8 @@ void eeconfig_init(void) #endif #if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE) eeprom_update_dword(EECONFIG_RGBLIGHT, 0); +#endif +#if defined(VELOCIKEY_ENABLE) eeprom_update_byte(EECONFIG_VELOCIKEY, 0); #endif #ifdef STENO_ENABLE From 6306bad3086659468a150f5f59e6e044c1bb5a8f Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Wed, 26 Sep 2018 22:51:01 +1000 Subject: [PATCH 38/50] Rename decay_task function to decelerate --- quantum/velocikey.c | 2 +- quantum/velocikey.h | 2 +- tmk_core/protocol/lufa/lufa.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/quantum/velocikey.c b/quantum/velocikey.c index 1c542314fdbc..2def26affdd3 100644 --- a/quantum/velocikey.c +++ b/quantum/velocikey.c @@ -28,7 +28,7 @@ void velocikey_accelerate() { if (typing_speed < TYPING_SPEED_MAX_VALUE) typing_speed += (TYPING_SPEED_MAX_VALUE / 100); } -void velocikey_decay_task() { +void velocikey_decelerate() { static uint16_t decay_timer = 0; if (timer_elapsed(decay_timer) > 500 || decay_timer == 0) { diff --git a/quantum/velocikey.h b/quantum/velocikey.h index c6186d83b38e..1910f0f4e96f 100644 --- a/quantum/velocikey.h +++ b/quantum/velocikey.h @@ -7,7 +7,7 @@ bool velocikey_enabled(void); void velocikey_toggle(void); void velocikey_accelerate(void); -void velocikey_decay_task(void); +void velocikey_decelerate(void); uint8_t velocikey_match_speed(uint8_t minValue, uint8_t maxValue); #endif \ No newline at end of file diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index 288f2d86d68f..91aba0a976e2 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -1077,7 +1077,7 @@ int main(void) #endif #ifdef VELOCIKEY_ENABLE - if (velocikey_enabled()) velocikey_decay_task(); + if (velocikey_enabled()) velocikey_decelerate(); #endif #if defined(RGBLIGHT_ANIMATIONS) & defined(RGBLIGHT_ENABLE) From a4e83cce0db6752647b187faa46959f789080817 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Sun, 9 Dec 2018 14:53:16 +1100 Subject: [PATCH 39/50] Apply suggestions from code review Co-Authored-By: chrislewisdev --- quantum/rgblight.c | 4 +++- quantum/velocikey.c | 10 +++++----- tmk_core/common/eeconfig.h | 4 ++-- tmk_core/protocol/lufa/lufa.c | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 3a9fb5a58347..2255b66603c7 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -25,7 +25,9 @@ #include "rgblight.h" #include "debug.h" #include "led_tables.h" -#include "velocikey.h" +#ifdef VELOCIKEY_ENABLE + #include "velocikey.h" +#endif #ifndef RGBLIGHT_LIMIT_VAL #define RGBLIGHT_LIMIT_VAL 255 diff --git a/quantum/velocikey.c b/quantum/velocikey.c index 2def26affdd3..be5a6a02b737 100644 --- a/quantum/velocikey.c +++ b/quantum/velocikey.c @@ -13,22 +13,22 @@ #define TYPING_SPEED_MAX_VALUE 200 uint8_t typing_speed = 0; -bool velocikey_enabled() { +bool velocikey_enabled(void) { return eeprom_read_byte(EECONFIG_VELOCIKEY) == 1; } -void velocikey_toggle() { +void velocikey_toggle(void) { if (velocikey_enabled()) eeprom_update_byte(EECONFIG_VELOCIKEY, 0); else eeprom_update_byte(EECONFIG_VELOCIKEY, 1); } -void velocikey_accelerate() { +void velocikey_accelerate(void) { if (typing_speed < TYPING_SPEED_MAX_VALUE) typing_speed += (TYPING_SPEED_MAX_VALUE / 100); } -void velocikey_decelerate() { +void velocikey_decelerate(void) { static uint16_t decay_timer = 0; if (timer_elapsed(decay_timer) > 500 || decay_timer == 0) { @@ -43,4 +43,4 @@ void velocikey_decelerate() { uint8_t velocikey_match_speed(uint8_t minValue, uint8_t maxValue) { return MAX(minValue, maxValue - (maxValue - minValue) * ((float)typing_speed / TYPING_SPEED_MAX_VALUE)); -} \ No newline at end of file +} diff --git a/tmk_core/common/eeconfig.h b/tmk_core/common/eeconfig.h index b2292578c026..742a712ce3d9 100644 --- a/tmk_core/common/eeconfig.h +++ b/tmk_core/common/eeconfig.h @@ -40,7 +40,7 @@ along with this program. If not, see . // EEHANDS for two handed boards #define EECONFIG_HANDEDNESS (uint8_t *)14 #define EECONFIG_KEYBOARD (uint32_t *)15 -#define EECONFIG_VELOCIKEY (uint8_t *)16 +#define EECONFIG_VELOCIKEY (uint8_t *)23 #define EECONFIG_USER (uint32_t *)19 #else @@ -58,7 +58,7 @@ along with this program. If not, see . // EEHANDS for two handed boards #define EECONFIG_HANDEDNESS (uint8_t *)11 #define EECONFIG_KEYBOARD (uint32_t *)12 -#define EECONFIG_VELOCIKEY (uint8_t *)13 +#define EECONFIG_VELOCIKEY (uint8_t *)16 #define EECONFIG_USER (uint32_t *)14 #endif diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index e11af233d4b9..a27f392e3823 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -1085,7 +1085,7 @@ int main(void) #endif #ifdef VELOCIKEY_ENABLE - if (velocikey_enabled()) velocikey_decelerate(); + if (velocikey_enabled()) { velocikey_decelerate(); } #endif #if defined(RGBLIGHT_ANIMATIONS) & defined(RGBLIGHT_ENABLE) From cd3fbd7b3602ee5464952c85651fc9c8807232bc Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Mon, 10 Dec 2018 18:10:34 +1100 Subject: [PATCH 40/50] Re-order eeconfig definitions --- tmk_core/common/eeconfig.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tmk_core/common/eeconfig.h b/tmk_core/common/eeconfig.h index 742a712ce3d9..65352125c94b 100644 --- a/tmk_core/common/eeconfig.h +++ b/tmk_core/common/eeconfig.h @@ -40,8 +40,8 @@ along with this program. If not, see . // EEHANDS for two handed boards #define EECONFIG_HANDEDNESS (uint8_t *)14 #define EECONFIG_KEYBOARD (uint32_t *)15 -#define EECONFIG_VELOCIKEY (uint8_t *)23 #define EECONFIG_USER (uint32_t *)19 +#define EECONFIG_VELOCIKEY (uint8_t *)23 #else /* STM32F3 uses 16byte block. Reconfigure memory map */ @@ -58,8 +58,8 @@ along with this program. If not, see . // EEHANDS for two handed boards #define EECONFIG_HANDEDNESS (uint8_t *)11 #define EECONFIG_KEYBOARD (uint32_t *)12 -#define EECONFIG_VELOCIKEY (uint8_t *)16 #define EECONFIG_USER (uint32_t *)14 +#define EECONFIG_VELOCIKEY (uint8_t *)16 #endif /* debug bit */ From 7c9713f1b9bcf35b7aac93e93305472682adcf57 Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Mon, 10 Dec 2018 18:10:52 +1100 Subject: [PATCH 41/50] Apply coding conventions --- quantum/quantum.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quantum/quantum.c b/quantum/quantum.c index c517e67959d3..67e889bd2ef5 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -205,7 +205,7 @@ bool process_record_quantum(keyrecord_t *record) { uint16_t keycode; #ifdef VELOCIKEY_ENABLE - if (velocikey_enabled()) velocikey_accelerate(); + if (velocikey_enabled()) { velocikey_accelerate(); } #endif #if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE) From 732e73680078280e33660cf01941a20f19b0fd09 Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Mon, 10 Dec 2018 18:11:04 +1100 Subject: [PATCH 42/50] Apply #ifdef check in lufa.c --- tmk_core/protocol/lufa/lufa.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index a27f392e3823..6df504e57b7c 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -54,9 +54,12 @@ #include "quantum.h" #include #include "outputselect.h" -#include "velocikey.h" #include "rgblight_reconfig.h" +#ifdef VELOCIKEY_ENABLE + #include "velocikey.h" +#endif + #ifdef NKRO_ENABLE #include "keycode_config.h" From 4f0c8502b3fab53479ff4615e49179116d44cf07 Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Sat, 15 Dec 2018 16:42:22 +1100 Subject: [PATCH 43/50] Refactored interval time checks into one functionc --- quantum/rgblight.c | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 2255b66603c7..9f48327ec43f 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -517,6 +517,14 @@ 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); } +static uint8_t get_interval_time(const uint8_t* default_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_address); +} + #ifndef RGBLIGHT_CUSTOM_DRIVER void rgblight_set(void) { if (rgblight_config.enable) { @@ -653,11 +661,7 @@ void rgblight_effect_breathing(uint8_t interval) { static uint16_t last_timer = 0; float val; - uint8_t interval_time = -#ifdef VELOCIKEY_ENABLE - velocikey_enabled() ? velocikey_match_speed(1, 100) : -#endif - 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; @@ -679,11 +683,7 @@ void rgblight_effect_rainbow_mood(uint8_t interval) { static uint16_t current_hue = 0; static uint16_t last_timer = 0; - uint8_t interval_time = -#ifdef VELOCIKEY_ENABLE - velocikey_enabled() ? velocikey_match_speed(5, 100) : -#endif - 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; @@ -708,11 +708,7 @@ void rgblight_effect_rainbow_swirl(uint8_t interval) { uint16_t hue; uint8_t i; - uint8_t interval_time = -#ifdef VELOCIKEY_ENABLE - velocikey_enabled() ? velocikey_match_speed(1, 100) : -#endif - 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; @@ -750,11 +746,7 @@ void rgblight_effect_snake(uint8_t interval) { increment = -1; } - uint8_t interval_time = -#ifdef VELOCIKEY_ENABLE - velocikey_enabled() ? velocikey_match_speed(1, 200) : -#endif - 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; @@ -794,11 +786,7 @@ const uint8_t RGBLED_KNIGHT_INTERVALS[] PROGMEM = {127, 63, 31}; void rgblight_effect_knight(uint8_t interval) { static uint16_t last_timer = 0; - uint8_t interval_time = -#ifdef VELOCIKEY_ENABLE - velocikey_enabled() ? velocikey_match_speed(5, 100) : -#endif - 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; From 00f3afdd91a47501765eb6a370b8e143f6318405 Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Sat, 15 Dec 2018 16:55:20 +1100 Subject: [PATCH 44/50] Small rename --- quantum/rgblight.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 9f48327ec43f..61058b9e89a4 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -517,12 +517,12 @@ 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); } -static uint8_t get_interval_time(const uint8_t* default_address, uint8_t velocikey_min, uint8_t velocikey_max) { +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_address); + pgm_read_byte(default_interval_address); } #ifndef RGBLIGHT_CUSTOM_DRIVER From b58f2a23276c866ef999d1629046612f7df0df7a Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Sat, 15 Dec 2018 17:13:25 +1100 Subject: [PATCH 45/50] Fix unused function error for layouts not using all rgb effects --- quantum/rgblight.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 61058b9e89a4..723c94d888ed 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -517,6 +517,9 @@ 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 @@ -525,6 +528,8 @@ static uint8_t get_interval_time(const uint8_t* default_interval_address, uint8_ pgm_read_byte(default_interval_address); } +#endif + #ifndef RGBLIGHT_CUSTOM_DRIVER void rgblight_set(void) { if (rgblight_config.enable) { From 85195d7e7cbdea2c0f48fa0482dbec028c47e9ee Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Wed, 16 Jan 2019 23:10:07 +1100 Subject: [PATCH 46/50] Only update EEPROM if Velocikey is enabled --- tmk_core/common/eeconfig.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tmk_core/common/eeconfig.c b/tmk_core/common/eeconfig.c index 352d2dfe7214..2e49c85c953f 100644 --- a/tmk_core/common/eeconfig.c +++ b/tmk_core/common/eeconfig.c @@ -44,8 +44,10 @@ void eeconfig_init_quantum(void) { eeprom_update_byte(EECONFIG_BACKLIGHT, 0); eeprom_update_byte(EECONFIG_AUDIO, 0xFF); // On by default eeprom_update_dword(EECONFIG_RGBLIGHT, 0); - eeprom_update_byte(EECONFIG_VELOCIKEY, 0); eeprom_update_byte(EECONFIG_STENOMODE, 0); +#ifdef VELOCIKEY_ENABLE + eeprom_update_byte(EECONFIG_VELOCIKEY, 0); +#endif eeconfig_init_kb(); } From 4bf75c743dd93461034e0bfe1a6f516cff2ec4b8 Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Wed, 23 Jan 2019 16:58:48 +1100 Subject: [PATCH 47/50] Incorporate code review feedback --- quantum/quantum.c | 8 ++++---- tmk_core/common/eeconfig.c | 2 -- tmk_core/common/keyboard.c | 7 +++++++ tmk_core/protocol/lufa/lufa.c | 8 -------- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/quantum/quantum.c b/quantum/quantum.c index d2e95d413266..8c0af251435a 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -212,10 +212,6 @@ bool process_record_quantum(keyrecord_t *record) { keypos_t key = record->event.key; uint16_t keycode; - #ifdef VELOCIKEY_ENABLE - if (velocikey_enabled()) { velocikey_accelerate(); } - #endif - #if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE) /* TODO: Use store_or_get_action() or a similar function. */ if (!disable_action_cache) { @@ -240,6 +236,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 diff --git a/tmk_core/common/eeconfig.c b/tmk_core/common/eeconfig.c index 2e49c85c953f..a215ad88abbf 100644 --- a/tmk_core/common/eeconfig.c +++ b/tmk_core/common/eeconfig.c @@ -45,9 +45,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_STENOMODE, 0); -#ifdef VELOCIKEY_ENABLE eeprom_update_byte(EECONFIG_VELOCIKEY, 0); -#endif eeconfig_init_kb(); } diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c index 6f659b2440a9..03cd54861ad9 100644 --- a/tmk_core/common/keyboard.c +++ b/tmk_core/common/keyboard.c @@ -75,6 +75,9 @@ along with this program. If not, see . #ifdef QWIIC_ENABLE # include "qwiic.h" #endif +#ifdef VELOCIKEY_ENABLE + #include "velocikey.h" +#endif #ifdef MATRIX_HAS_GHOST extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS]; @@ -313,6 +316,10 @@ void keyboard_task(void) midi_task(); #endif +#ifdef VELOCIKEY_ENABLE + if (velocikey_enabled()) { velocikey_decelerate(); } +#endif + // update LED if (led_status != host_keyboard_leds()) { led_status = host_keyboard_leds(); diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index b83c40c639a2..cdabaf16e61d 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -56,10 +56,6 @@ #include "outputselect.h" #include "rgblight_reconfig.h" -#ifdef VELOCIKEY_ENABLE - #include "velocikey.h" -#endif - #ifdef NKRO_ENABLE #include "keycode_config.h" @@ -1090,10 +1086,6 @@ int main(void) MIDI_Device_USBTask(&USB_MIDI_Interface); #endif -#ifdef VELOCIKEY_ENABLE - if (velocikey_enabled()) { velocikey_decelerate(); } -#endif - #if defined(RGBLIGHT_ANIMATIONS) & defined(RGBLIGHT_ENABLE) rgblight_task(); #endif From cc5adf941a33f3b9b6180aa75686d801dae5bdcb Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Wed, 23 Jan 2019 17:22:10 +1100 Subject: [PATCH 48/50] Small adjustment to top-end decay rate --- quantum/velocikey.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quantum/velocikey.c b/quantum/velocikey.c index be5a6a02b737..550c3b70a647 100644 --- a/quantum/velocikey.c +++ b/quantum/velocikey.c @@ -36,7 +36,7 @@ void velocikey_decelerate(void) { //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; + if (typing_speed > TYPING_SPEED_MAX_VALUE / 4 * 3) typing_speed -= 2; decay_timer = timer_read(); } } From f123f054cc6636518cf820e91bf0365c1f9fde6c Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Mon, 18 Feb 2019 16:56:09 +1100 Subject: [PATCH 49/50] Add Velocikey documentation to table of contents --- docs/_summary.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/_summary.md b/docs/_summary.md index 6bc747189663..09ea9e6e7967 100644 --- a/docs/_summary.md +++ b/docs/_summary.md @@ -76,6 +76,7 @@ * [Thermal Printer](feature_thermal_printer.md) * [Unicode](feature_unicode.md) * [Userspace](feature_userspace.md) + * [Velocikey](feature_velocikey.md) * For Makers and Modders * [Hand Wiring Guide](hand_wire.md) From 25712ad8b09a25cf47a3c1d6ebfebe4aac800ab1 Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Wed, 20 Feb 2019 18:10:58 +1100 Subject: [PATCH 50/50] Bring tetris:default keymap size down by disabling audio --- keyboards/tetris/rules.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/keyboards/tetris/rules.mk b/keyboards/tetris/rules.mk index 4741c162bda0..64c434554340 100644 --- a/keyboards/tetris/rules.mk +++ b/keyboards/tetris/rules.mk @@ -52,7 +52,7 @@ COMMAND_ENABLE = no # Commands for debug and configuration SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend NKRO_ENABLE = yes # USB Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality -AUDIO_ENABLE = yes +AUDIO_ENABLE = no RGBLIGHT_ENABLE = yes TAP_DANCE_ENABLE = no