From 2d3fbc5d0ad70309ede5cdeb9cf84380fd69baae Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Wed, 25 Jul 2018 11:59:44 +1000 Subject: [PATCH] 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 9c6ed3330e..1a5d992818 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 0675a90ac3..35822f9a4f 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 aa70cbd9ec..548c84a74e 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 859e3ed12f..226ed74add 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)