diff options
Diffstat (limited to 'quantum')
| -rw-r--r-- | quantum/quantum.c | 17 | ||||
| -rw-r--r-- | quantum/quantum_keycodes.h | 3 | ||||
| -rw-r--r-- | quantum/rgblight.c | 40 | ||||
| -rw-r--r-- | quantum/velocikey.c | 46 | ||||
| -rw-r--r-- | quantum/velocikey.h | 13 |
5 files changed, 113 insertions, 6 deletions
diff --git a/quantum/quantum.c b/quantum/quantum.c index cb4d5ee80..46d404029 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c | |||
| @@ -47,6 +47,10 @@ extern backlight_config_t backlight_config; | |||
| 47 | #include "process_midi.h" | 47 | #include "process_midi.h" |
| 48 | #endif | 48 | #endif |
| 49 | 49 | ||
| 50 | #ifdef VELOCIKEY_ENABLE | ||
| 51 | #include "velocikey.h" | ||
| 52 | #endif | ||
| 53 | |||
| 50 | #ifdef HAPTIC_ENABLE | 54 | #ifdef HAPTIC_ENABLE |
| 51 | #include "haptic.h" | 55 | #include "haptic.h" |
| 52 | #endif | 56 | #endif |
| @@ -251,6 +255,10 @@ bool process_record_quantum(keyrecord_t *record) { | |||
| 251 | // return false; | 255 | // return false; |
| 252 | // } | 256 | // } |
| 253 | 257 | ||
| 258 | #ifdef VELOCIKEY_ENABLE | ||
| 259 | if (velocikey_enabled() && record->event.pressed) { velocikey_accelerate(); } | ||
| 260 | #endif | ||
| 261 | |||
| 254 | #ifdef TAP_DANCE_ENABLE | 262 | #ifdef TAP_DANCE_ENABLE |
| 255 | preprocess_tap_dance(keycode, record); | 263 | preprocess_tap_dance(keycode, record); |
| 256 | #endif | 264 | #endif |
| @@ -568,7 +576,14 @@ bool process_record_quantum(keyrecord_t *record) { | |||
| 568 | #endif | 576 | #endif |
| 569 | return false; | 577 | return false; |
| 570 | #endif // defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE) | 578 | #endif // defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE) |
| 571 | #ifdef PROTOCOL_LUFA | 579 | #ifdef VELOCIKEY_ENABLE |
| 580 | case VLK_TOG: | ||
| 581 | if (record->event.pressed) { | ||
| 582 | velocikey_toggle(); | ||
| 583 | } | ||
| 584 | return false; | ||
| 585 | #endif | ||
| 586 | #ifdef PROTOCOL_LUFA | ||
| 572 | case OUT_AUTO: | 587 | case OUT_AUTO: |
| 573 | if (record->event.pressed) { | 588 | if (record->event.pressed) { |
| 574 | set_output(OUTPUT_AUTO); | 589 | set_output(OUTPUT_AUTO); |
diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index 00c84cbf5..1ced6ae37 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h | |||
| @@ -422,6 +422,9 @@ enum quantum_keycodes { | |||
| 422 | RGB_MODE_GRADIENT, | 422 | RGB_MODE_GRADIENT, |
| 423 | RGB_MODE_RGBTEST, | 423 | RGB_MODE_RGBTEST, |
| 424 | 424 | ||
| 425 | //Momentum matching toggle | ||
| 426 | VLK_TOG, | ||
| 427 | |||
| 425 | // Left shift, open paren | 428 | // Left shift, open paren |
| 426 | KC_LSPO, | 429 | KC_LSPO, |
| 427 | 430 | ||
diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 45d521786..57de56df7 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c | |||
| @@ -30,6 +30,9 @@ | |||
| 30 | #include "rgblight.h" | 30 | #include "rgblight.h" |
| 31 | #include "debug.h" | 31 | #include "debug.h" |
| 32 | #include "led_tables.h" | 32 | #include "led_tables.h" |
| 33 | #ifdef VELOCIKEY_ENABLE | ||
| 34 | #include "velocikey.h" | ||
| 35 | #endif | ||
| 33 | 36 | ||
| 34 | #define _RGBM_SINGLE_STATIC(sym) RGBLIGHT_MODE_ ## sym, | 37 | #define _RGBM_SINGLE_STATIC(sym) RGBLIGHT_MODE_ ## sym, |
| 35 | #define _RGBM_SINGLE_DYNAMIC(sym) | 38 | #define _RGBM_SINGLE_DYNAMIC(sym) |
| @@ -607,6 +610,19 @@ void rgblight_sethsv_at(uint16_t hue, uint8_t sat, uint8_t val, uint8_t index) { | |||
| 607 | rgblight_setrgb_at(tmp_led.r, tmp_led.g, tmp_led.b, index); | 610 | rgblight_setrgb_at(tmp_led.r, tmp_led.g, tmp_led.b, index); |
| 608 | } | 611 | } |
| 609 | 612 | ||
| 613 | #if defined(RGBLIGHT_EFFECT_BREATHING) || defined(RGBLIGHT_EFFECT_RAINBOW_MOOD) || defined(RGBLIGHT_EFFECT_RAINBOW_SWIRL) \ | ||
| 614 | || defined(RGBLIGHT_EFFECT_SNAKE) || defined(RGBLIGHT_EFFECT_KNIGHT) | ||
| 615 | |||
| 616 | static uint8_t get_interval_time(const uint8_t* default_interval_address, uint8_t velocikey_min, uint8_t velocikey_max) { | ||
| 617 | return | ||
| 618 | #ifdef VELOCIKEY_ENABLE | ||
| 619 | velocikey_enabled() ? velocikey_match_speed(velocikey_min, velocikey_max) : | ||
| 620 | #endif | ||
| 621 | pgm_read_byte(default_interval_address); | ||
| 622 | } | ||
| 623 | |||
| 624 | #endif | ||
| 625 | |||
| 610 | void rgblight_setrgb_range(uint8_t r, uint8_t g, uint8_t b, uint8_t start, uint8_t end) { | 626 | void rgblight_setrgb_range(uint8_t r, uint8_t g, uint8_t b, uint8_t start, uint8_t end) { |
| 611 | if (!rgblight_config.enable || start < 0 || start >= end || end > RGBLED_NUM) { return; } | 627 | if (!rgblight_config.enable || start < 0 || start >= end || end > RGBLED_NUM) { return; } |
| 612 | 628 | ||
| @@ -707,6 +723,7 @@ void rgblight_show_solid_color(uint8_t r, uint8_t g, uint8_t b) { | |||
| 707 | } | 723 | } |
| 708 | 724 | ||
| 709 | void rgblight_task(void) { | 725 | void rgblight_task(void) { |
| 726 | |||
| 710 | if (rgblight_timer_enabled) { | 727 | if (rgblight_timer_enabled) { |
| 711 | // static light mode, do nothing here | 728 | // static light mode, do nothing here |
| 712 | if ( 1 == 0 ) { //dummy | 729 | if ( 1 == 0 ) { //dummy |
| @@ -778,7 +795,9 @@ void rgblight_effect_breathing(uint8_t interval) { | |||
| 778 | static uint16_t last_timer = 0; | 795 | static uint16_t last_timer = 0; |
| 779 | float val; | 796 | float val; |
| 780 | 797 | ||
| 781 | if (timer_elapsed(last_timer) < pgm_read_byte(&RGBLED_BREATHING_INTERVALS[interval])) { | 798 | uint8_t interval_time = get_interval_time(&RGBLED_RAINBOW_SWIRL_INTERVALS[interval / 2], 1, 100); |
| 799 | |||
| 800 | if (timer_elapsed(last_timer) < interval_time) { | ||
| 782 | return; | 801 | return; |
| 783 | } | 802 | } |
| 784 | last_timer = timer_read(); | 803 | last_timer = timer_read(); |
| @@ -798,7 +817,9 @@ void rgblight_effect_rainbow_mood(uint8_t interval) { | |||
| 798 | static uint16_t current_hue = 0; | 817 | static uint16_t current_hue = 0; |
| 799 | static uint16_t last_timer = 0; | 818 | static uint16_t last_timer = 0; |
| 800 | 819 | ||
| 801 | if (timer_elapsed(last_timer) < pgm_read_byte(&RGBLED_RAINBOW_MOOD_INTERVALS[interval])) { | 820 | uint8_t interval_time = get_interval_time(&RGBLED_RAINBOW_MOOD_INTERVALS[interval], 5, 100); |
| 821 | |||
| 822 | if (timer_elapsed(last_timer) < interval_time) { | ||
| 802 | return; | 823 | return; |
| 803 | } | 824 | } |
| 804 | last_timer = timer_read(); | 825 | last_timer = timer_read(); |
| @@ -820,7 +841,10 @@ void rgblight_effect_rainbow_swirl(uint8_t interval) { | |||
| 820 | static uint16_t last_timer = 0; | 841 | static uint16_t last_timer = 0; |
| 821 | uint16_t hue; | 842 | uint16_t hue; |
| 822 | uint8_t i; | 843 | uint8_t i; |
| 823 | if (timer_elapsed(last_timer) < pgm_read_byte(&RGBLED_RAINBOW_SWIRL_INTERVALS[interval / 2])) { | 844 | |
| 845 | uint8_t interval_time = get_interval_time(&RGBLED_RAINBOW_SWIRL_INTERVALS[interval / 2], 1, 100); | ||
| 846 | |||
| 847 | if (timer_elapsed(last_timer) < interval_time) { | ||
| 824 | return; | 848 | return; |
| 825 | } | 849 | } |
| 826 | last_timer = timer_read(); | 850 | last_timer = timer_read(); |
| @@ -855,7 +879,10 @@ void rgblight_effect_snake(uint8_t interval) { | |||
| 855 | if (interval % 2) { | 879 | if (interval % 2) { |
| 856 | increment = -1; | 880 | increment = -1; |
| 857 | } | 881 | } |
| 858 | if (timer_elapsed(last_timer) < pgm_read_byte(&RGBLED_SNAKE_INTERVALS[interval / 2])) { | 882 | |
| 883 | uint8_t interval_time = get_interval_time(&RGBLED_SNAKE_INTERVALS[interval / 2], 1, 200); | ||
| 884 | |||
| 885 | if (timer_elapsed(last_timer) < interval_time) { | ||
| 859 | return; | 886 | return; |
| 860 | } | 887 | } |
| 861 | last_timer = timer_read(); | 888 | last_timer = timer_read(); |
| @@ -892,7 +919,10 @@ const uint8_t RGBLED_KNIGHT_INTERVALS[] PROGMEM = {127, 63, 31}; | |||
| 892 | 919 | ||
| 893 | void rgblight_effect_knight(uint8_t interval) { | 920 | void rgblight_effect_knight(uint8_t interval) { |
| 894 | static uint16_t last_timer = 0; | 921 | static uint16_t last_timer = 0; |
| 895 | if (timer_elapsed(last_timer) < pgm_read_byte(&RGBLED_KNIGHT_INTERVALS[interval])) { | 922 | |
| 923 | uint8_t interval_time = get_interval_time(&RGBLED_KNIGHT_INTERVALS[interval], 5, 100); | ||
| 924 | |||
| 925 | if (timer_elapsed(last_timer) < interval_time) { | ||
| 896 | return; | 926 | return; |
| 897 | } | 927 | } |
| 898 | last_timer = timer_read(); | 928 | last_timer = timer_read(); |
diff --git a/quantum/velocikey.c b/quantum/velocikey.c new file mode 100644 index 000000000..550c3b70a --- /dev/null +++ b/quantum/velocikey.c | |||
| @@ -0,0 +1,46 @@ | |||
| 1 | #include "velocikey.h" | ||
| 2 | #include "timer.h" | ||
| 3 | #include "eeconfig.h" | ||
| 4 | #include "eeprom.h" | ||
| 5 | |||
| 6 | #ifndef MIN | ||
| 7 | #define MIN(a,b) (((a)<(b))?(a):(b)) | ||
| 8 | #endif | ||
| 9 | #ifndef MAX | ||
| 10 | #define MAX(a,b) (((a)>(b))?(a):(b)) | ||
| 11 | #endif | ||
| 12 | |||
| 13 | #define TYPING_SPEED_MAX_VALUE 200 | ||
| 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 | } | ||
diff --git a/quantum/velocikey.h b/quantum/velocikey.h new file mode 100644 index 000000000..1910f0f4e --- /dev/null +++ b/quantum/velocikey.h | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | #ifndef VELOCIKEY_H | ||
| 2 | #define VELOCIKEY_H | ||
| 3 | |||
| 4 | #include <stdint.h> | ||
| 5 | #include <stdbool.h> | ||
| 6 | |||
| 7 | bool velocikey_enabled(void); | ||
| 8 | void velocikey_toggle(void); | ||
| 9 | void velocikey_accelerate(void); | ||
| 10 | void velocikey_decelerate(void); | ||
| 11 | uint8_t velocikey_match_speed(uint8_t minValue, uint8_t maxValue); | ||
| 12 | |||
| 13 | #endif \ No newline at end of file | ||
