Skip to content

Commit

Permalink
Move velocikey to within rgblight
Browse files Browse the repository at this point in the history
  • Loading branch information
zvecr committed Sep 25, 2023
1 parent a7afa58 commit 3784565
Show file tree
Hide file tree
Showing 16 changed files with 124 additions and 150 deletions.
4 changes: 4 additions & 0 deletions builddefs/common_features.mk
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,10 @@ ifeq ($(strip $(RGBLIGHT_ENABLE)), yes)
ifeq ($(strip $(RGBLIGHT_DRIVER)), apa102)
APA102_DRIVER_REQUIRED := yes
endif

ifeq ($(strip $(VELOCIKEY_ENABLE)), yes)
OPT_DEFS += -DVELOCIKEY_ENABLE
endif
endif

# Deprecated driver names - do not use
Expand Down
1 change: 0 additions & 1 deletion builddefs/generic_features.mk
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ GENERIC_FEATURES = \
SPACE_CADET \
SWAP_HANDS \
TAP_DANCE \
VELOCIKEY \
WPM \
DYNAMIC_TAPPING_TERM \
TRI_LAYER
Expand Down
1 change: 0 additions & 1 deletion docs/_summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@
* [PS/2 Mouse](feature_ps2_mouse.md)
* [Split Keyboard](feature_split_keyboard.md)
* [Stenography](feature_stenography.md)
* [Velocikey](feature_velocikey.md)

* Keyboard Building
* [Easy Maker for One Offs](easy_maker.md)
Expand Down
30 changes: 30 additions & 0 deletions docs/feature_rgblight.md
Original file line number Diff line number Diff line change
Expand Up @@ -552,3 +552,33 @@ In addition to setting the Clipping Range, you can use `RGBLIGHT_LED_MAP` togeth
## Hardware Modification
If your keyboard lacks onboard underglow LEDs, you may often be able to solder on an RGB LED strip yourself. You will need to find an unused pin to wire to the data pin of your LED strip. Some keyboards may break out unused pins from the MCU to make soldering easier. The other two pins, VCC and GND, must also be connected to the appropriate power pins.
## Velocikey
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, there are two steps. First, when compiling your keyboard, you'll need to set `VELOCIKEY_ENABLE=yes` in `rules.mk`, e.g.:
```
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 `VK_TOGG` keycode, which toggles the feature on and off.
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
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.
29 changes: 0 additions & 29 deletions docs/feature_velocikey.md

This file was deleted.

1 change: 0 additions & 1 deletion docs/ja/_summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@
* [分割キーボード](ja/feature_split_keyboard.md)
* [速記](ja/feature_stenography.md)
* [感熱式プリンタ](ja/feature_thermal_printer.md)
* [Velocikey](ja/feature_velocikey.md)

* QMK の開発
* [PR チェックリスト](ja/pr_checklist.md)
Expand Down
34 changes: 0 additions & 34 deletions docs/ja/feature_velocikey.md

This file was deleted.

1 change: 0 additions & 1 deletion docs/zh-cn/_summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@
* [分体式键盘](zh-cn/feature_split_keyboard.md)
* [速记](zh-cn/feature_stenography.md)
* [热敏打印机](zh-cn/feature_thermal_printer.md)
* [Velocikey](zh-cn/feature_velocikey.md)

* QMK开发
* [PR Checklist](zh-cn/pr_checklist.md)
Expand Down
2 changes: 1 addition & 1 deletion quantum/eeconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,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_RGBLIGHT_EXTENDED, 0);
eeprom_update_byte(EECONFIG_VELOCIKEY, 0);
eeprom_update_byte(EECONFIG_UNUSED, 0);
eeprom_update_byte(EECONFIG_UNICODEMODE, 0);
eeprom_update_byte(EECONFIG_STENOMODE, 0);
uint64_t dummy = 0;
Expand Down
2 changes: 1 addition & 1 deletion quantum/eeconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define EECONFIG_HANDEDNESS (uint8_t *)14
#define EECONFIG_KEYBOARD (uint32_t *)15
#define EECONFIG_USER (uint32_t *)19
#define EECONFIG_VELOCIKEY (uint8_t *)23
#define EECONFIG_UNUSED (uint8_t *)23
// Mutually exclusive
#define EECONFIG_LED_MATRIX (uint32_t *)24
#define EECONFIG_RGB_MATRIX (uint64_t *)24
Expand Down
9 changes: 0 additions & 9 deletions quantum/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifdef ST7565_ENABLE
# include "st7565.h"
#endif
#ifdef VELOCIKEY_ENABLE
# include "velocikey.h"
#endif
#ifdef VIA_ENABLE
# include "via.h"
#endif
Expand Down Expand Up @@ -708,12 +705,6 @@ void keyboard_task(void) {
midi_task();
#endif

#ifdef VELOCIKEY_ENABLE
if (velocikey_enabled()) {
velocikey_decelerate();
}
#endif

#ifdef JOYSTICK_ENABLE
joystick_task();
#endif
Expand Down
10 changes: 3 additions & 7 deletions quantum/quantum.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@
# include "process_unicode_common.h"
#endif

#ifdef VELOCIKEY_ENABLE
# include "velocikey.h"
#endif

#ifdef AUDIO_ENABLE
# ifndef GOODBYE_SONG
# define GOODBYE_SONG SONG(GOODBYE_SOUND)
Expand Down Expand Up @@ -288,9 +284,9 @@ bool process_record_quantum(keyrecord_t *record) {
}
#endif

#ifdef VELOCIKEY_ENABLE
if (velocikey_enabled() && record->event.pressed) {
velocikey_accelerate();
#ifdef RGBLIGHT_ENABLE
if (record->event.pressed) {
preprocess_rgblight();
}
#endif

Expand Down
81 changes: 69 additions & 12 deletions quantum/rgblight/rgblight.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
#ifdef EEPROM_ENABLE
# include "eeprom.h"
#endif
#ifdef VELOCIKEY_ENABLE
# include "velocikey.h"
#endif

#ifdef RGBLIGHT_SPLIT
/* for split keyboard */
Expand Down Expand Up @@ -198,19 +195,21 @@ void eeconfig_update_rgblight_current(void) {
}

void eeconfig_update_rgblight_default(void) {
rgblight_config.enable = 1;
rgblight_config.mode = RGBLIGHT_DEFAULT_MODE;
rgblight_config.hue = RGBLIGHT_DEFAULT_HUE;
rgblight_config.sat = RGBLIGHT_DEFAULT_SAT;
rgblight_config.val = RGBLIGHT_DEFAULT_VAL;
rgblight_config.speed = RGBLIGHT_DEFAULT_SPD;
rgblight_config.enable = 1;
rgblight_config.velocikey = 0;
rgblight_config.mode = RGBLIGHT_DEFAULT_MODE;
rgblight_config.hue = RGBLIGHT_DEFAULT_HUE;
rgblight_config.sat = RGBLIGHT_DEFAULT_SAT;
rgblight_config.val = RGBLIGHT_DEFAULT_VAL;
rgblight_config.speed = RGBLIGHT_DEFAULT_SPD;
RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS;
eeconfig_update_rgblight(rgblight_config.raw);
}

void eeconfig_debug_rgblight(void) {
dprintf("rgblight_config EEPROM:\n");
dprintf("rgblight_config.enable = %d\n", rgblight_config.enable);
dprintf("rgblight_config.velocikey = %d\n", rgblight_config.velocikey);
dprintf("rghlight_config.mode = %d\n", rgblight_config.mode);
dprintf("rgblight_config.hue = %d\n", rgblight_config.hue);
dprintf("rgblight_config.sat = %d\n", rgblight_config.sat);
Expand Down Expand Up @@ -689,9 +688,9 @@ void rgblight_sethsv_at(uint8_t hue, uint8_t sat, uint8_t val, uint8_t index) {
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) :
rgblight_velocikey_enabled() ? rgblight_velocikey_match_speed(velocikey_min, velocikey_max) :
# endif
pgm_read_byte(default_interval_address);
pgm_read_byte(default_interval_address);
}

#endif
Expand Down Expand Up @@ -1049,7 +1048,7 @@ static void rgblight_effect_dummy(animation_status_t *anim) {
**/
}

void rgblight_task(void) {
void rgblight_timer_task(void) {
if (rgblight_status.timer_enabled) {
effect_func_t effect_func = rgblight_effect_dummy;
uint16_t interval_time = 2000; // dummy interval
Expand Down Expand Up @@ -1519,3 +1518,61 @@ void rgblight_effect_twinkle(animation_status_t *anim) {
rgblight_set();
}
#endif

void preprocess_rgblight(void) {
#ifdef VELOCIKEY_ENABLE
if (rgblight_velocikey_enabled()) {
rgblight_velocikey_accelerate();
}
#endif
}

void rgblight_task(void) {
#ifdef RGBLIGHT_USE_TIMER
rgblight_timer_task();
#endif

#ifdef VELOCIKEY_ENABLE
if (rgblight_velocikey_enabled()) {
rgblight_velocikey_decelerate();
}
#endif
}

#ifdef VELOCIKEY_ENABLE
# define TYPING_SPEED_MAX_VALUE 200

static uint8_t typing_speed = 0;

bool rgblight_velocikey_enabled(void) {
return rgblight_config.velocikey;
}

void rgblight_velocikey_toggle(void) {
dprintf("rgblight velocikey toggle [EEPROM]: rgblight_config.velocikey = %u\n", !rgblight_config.velocikey);
rgblight_config.velocikey = !rgblight_config.velocikey;
eeconfig_update_rgblight_current();
}

void rgblight_velocikey_accelerate(void) {
if (typing_speed < TYPING_SPEED_MAX_VALUE) typing_speed += (TYPING_SPEED_MAX_VALUE / 100);
}

void rgblight_velocikey_decelerate(void) {
static uint16_t decay_timer = 0;

if (timer_elapsed(decay_timer) > 500 || decay_timer == 0) {
if (typing_speed > 0) typing_speed -= 1;
// Decay a little faster at half of max speed
if (typing_speed > TYPING_SPEED_MAX_VALUE / 2) typing_speed -= 1;
// Decay even faster at 3/4 of max speed
if (typing_speed > TYPING_SPEED_MAX_VALUE / 4 * 3) typing_speed -= 2;
decay_timer = timer_read();
}
}

uint8_t rgblight_velocikey_match_speed(uint8_t minValue, uint8_t maxValue) {
return MAX(minValue, maxValue - (maxValue - minValue) * ((float)typing_speed / TYPING_SPEED_MAX_VALUE));
}

#endif
19 changes: 16 additions & 3 deletions quantum/rgblight/rgblight.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ typedef union {
uint64_t raw;
struct {
bool enable : 1;
uint8_t mode : 7;
bool velocikey : 1;
uint8_t mode : 6;
uint8_t hue : 8;
uint8_t sat : 8;
uint8_t val : 8;
Expand Down Expand Up @@ -385,14 +386,15 @@ void rgblight_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom);
#define EZ_RGB(val) rgblight_show_solid_color((val >> 16) & 0xFF, (val >> 8) & 0xFF, val & 0xFF)
void rgblight_show_solid_color(uint8_t r, uint8_t g, uint8_t b);

#ifdef RGBLIGHT_USE_TIMER
void preprocess_rgblight(void);
void rgblight_task(void);

#ifdef RGBLIGHT_USE_TIMER
void rgblight_timer_init(void);
void rgblight_timer_enable(void);
void rgblight_timer_disable(void);
void rgblight_timer_toggle(void);
#else
# define rgblight_task()
# define rgblight_timer_init()
# define rgblight_timer_enable()
# define rgblight_timer_disable()
Expand Down Expand Up @@ -446,3 +448,14 @@ void rgblight_effect_alternating(animation_status_t *anim);
void rgblight_effect_twinkle(animation_status_t *anim);

#endif

#ifdef VELOCIKEY_ENABLE
bool rgblight_velocikey_enabled(void);
void rgblight_velocikey_toggle(void);
void rgblight_velocikey_accelerate(void);
void rgblight_velocikey_decelerate(void);
uint8_t rgblight_velocikey_match_speed(uint8_t minValue, uint8_t maxValue);

# define velocikey_enabled rgblight_velocikey_enabled
# define velocikey_toggle rgblight_velocikey_toggle
#endif
Loading

0 comments on commit 3784565

Please sign in to comment.