Draft commit of typing speed RGB control

pull/3754/head
Chris Lewis 7 years ago
parent 6d1536db1d
commit 48a222de4e

@ -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) {

@ -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;

@ -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();

@ -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)

Loading…
Cancel
Save