diff options
| author | Chris Lewis <chris@chrislewisdev.com> | 2019-02-22 02:22:46 +1100 |
|---|---|---|
| committer | MechMerlin <30334081+mechmerlin@users.noreply.github.com> | 2019-02-21 07:22:46 -0800 |
| commit | c1c5922aae7b60b7c7d13d3769350eed9dda17ab (patch) | |
| tree | 7c3805d9b949ef2d802bd3df4e9238662a5cdc0b /quantum/velocikey.c | |
| parent | 9f1d781fcb7129a07e671a46461e501e3f1ae59d (diff) | |
| download | qmk_firmware-c1c5922aae7b60b7c7d13d3769350eed9dda17ab.tar.gz qmk_firmware-c1c5922aae7b60b7c7d13d3769350eed9dda17ab.zip | |
Velocikey: Match RGB animation speed to typing speed (#3754)
* Draft commit of typing speed RGB control
* More information in the readme
* Support all RGB animation modes (Fixes #1)
* Added support for all RGB light modes to use typing speed
Except christmas lights because that is seizure-inducing at high speeds!
* Introduced a value range specific to each RGB mode
Because some modes are a little too much when running at full speed!
* Update readme.md
* Update readme.md
* Re-arrange typing_speed definitions (Fixes #5) (#6)
* Re-arrange variable definitions to avoid including quantum.h from rgblight.c
* Fix a compilation error when trying to run make test:all
* Tweaks to the typing speed decay rate
* Renamed to momentum; moved implementation into dedicated files
* Groundwork for toggling momentum on/off (currently always on)
* Add EEPROM toggle for momentum-matching
* Moved momentum out of RGBLIGHT_ENABLE toggles so it's more generic
* Move momentum decay task out of rgblight_task()
* Fix missing momentum.h in lufa.c
* Experimental LED support (untested)
* Draft commit of typing speed RGB control
* More information in the readme
* Support all RGB animation modes (Fixes #1)
* Added support for all RGB light modes to use typing speed
Except christmas lights because that is seizure-inducing at high speeds!
* Introduced a value range specific to each RGB mode
Because some modes are a little too much when running at full speed!
* Update readme.md
* Update readme.md
* Re-arrange typing_speed definitions (Fixes #5) (#6)
* Re-arrange variable definitions to avoid including quantum.h from rgblight.c
* Fix a compilation error when trying to run make test:all
* Tweaks to the typing speed decay rate
* Renamed to momentum; moved implementation into dedicated files
* Groundwork for toggling momentum on/off (currently always on)
* Add EEPROM toggle for momentum-matching
* Moved momentum out of RGBLIGHT_ENABLE toggles so it's more generic
* Move momentum decay task out of rgblight_task()
* Fix missing momentum.h in lufa.c
* Added documentation
* Renamed feature to velocikey
* Reverted readme to original state
* Correct the readme title
* Updated feature name in the docs
* Update EECONFIG name
* Add compile-time toggles for velocikey
* Update feature documentation
* Revert "Merge branch 'led-support' into master"
This reverts commit e123ff5febf61639b9a9020748e1c2e2313460ff, reversing
changes made to df111a55b9d4929182e16108b1c0ead15b16df97.
* Move velocikey EECONFIG definition to depend on VELOCIKEY_ENABLE
* Rename decay_task function to decelerate
* Apply suggestions from code review
Co-Authored-By: chrislewisdev <chris@chrislewisdev.com>
* Re-order eeconfig definitions
* Apply coding conventions
* Apply #ifdef check in lufa.c
* Refactored interval time checks into one functionc
* Small rename
* Fix unused function error for layouts not using all rgb effects
* Only update EEPROM if Velocikey is enabled
* Incorporate code review feedback
* Small adjustment to top-end decay rate
* Add Velocikey documentation to table of contents
* Bring tetris:default keymap size down by disabling audio
Diffstat (limited to 'quantum/velocikey.c')
| -rw-r--r-- | quantum/velocikey.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/quantum/velocikey.c b/quantum/velocikey.c new file mode 100644 index 000000000..550c3b70a --- /dev/null +++ b/quantum/velocikey.c | |||
| @@ -0,0 +1,46 @@ | |||
| 1 | #include "velocikey.h" | ||
| 2 | #include "timer.h" | ||
| 3 | #include "eeconfig.h" | ||
| 4 | #include "eeprom.h" | ||
| 5 | |||
| 6 | #ifndef MIN | ||
| 7 | #define MIN(a,b) (((a)<(b))?(a):(b)) | ||
| 8 | #endif | ||
| 9 | #ifndef MAX | ||
| 10 | #define MAX(a,b) (((a)>(b))?(a):(b)) | ||
| 11 | #endif | ||
| 12 | |||
| 13 | #define TYPING_SPEED_MAX_VALUE 200 | ||
| 14 | uint8_t typing_speed = 0; | ||
| 15 | |||
| 16 | bool velocikey_enabled(void) { | ||
| 17 | return eeprom_read_byte(EECONFIG_VELOCIKEY) == 1; | ||
| 18 | } | ||
| 19 | |||
| 20 | void velocikey_toggle(void) { | ||
| 21 | if (velocikey_enabled()) | ||
| 22 | eeprom_update_byte(EECONFIG_VELOCIKEY, 0); | ||
| 23 | else | ||
| 24 | eeprom_update_byte(EECONFIG_VELOCIKEY, 1); | ||
| 25 | } | ||
| 26 | |||
| 27 | void velocikey_accelerate(void) { | ||
| 28 | if (typing_speed < TYPING_SPEED_MAX_VALUE) typing_speed += (TYPING_SPEED_MAX_VALUE / 100); | ||
| 29 | } | ||
| 30 | |||
| 31 | void velocikey_decelerate(void) { | ||
| 32 | static uint16_t decay_timer = 0; | ||
| 33 | |||
| 34 | if (timer_elapsed(decay_timer) > 500 || decay_timer == 0) { | ||
| 35 | if (typing_speed > 0) typing_speed -= 1; | ||
| 36 | //Decay a little faster at half of max speed | ||
| 37 | if (typing_speed > TYPING_SPEED_MAX_VALUE / 2) typing_speed -= 1; | ||
| 38 | //Decay even faster at 3/4 of max speed | ||
| 39 | if (typing_speed > TYPING_SPEED_MAX_VALUE / 4 * 3) typing_speed -= 2; | ||
| 40 | decay_timer = timer_read(); | ||
| 41 | } | ||
| 42 | } | ||
| 43 | |||
| 44 | uint8_t velocikey_match_speed(uint8_t minValue, uint8_t maxValue) { | ||
| 45 | return MAX(minValue, maxValue - (maxValue - minValue) * ((float)typing_speed / TYPING_SPEED_MAX_VALUE)); | ||
| 46 | } | ||
