Skip to content

Commit

Permalink
Merge branch 'led-support' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
chrislewisdev authored Sep 11, 2018
2 parents df111a5 + 97b7a6e commit e123ff5
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 3 deletions.
3 changes: 2 additions & 1 deletion common_features.mk
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ QUANTUM_SRC:= \
$(QUANTUM_DIR)/quantum.c \
$(QUANTUM_DIR)/keymap_common.c \
$(QUANTUM_DIR)/keycode_config.c \
$(QUANTUM_DIR)/process_keycode/process_leader.c
$(QUANTUM_DIR)/process_keycode/process_leader.c \
$(QUANTUM_DIR)/momentum.c

ifndef CUSTOM_MATRIX
ifeq ($(strip $(SPLIT_KEYBOARD)), yes)
Expand Down
46 changes: 46 additions & 0 deletions quantum/momentum.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "momentum.h"
#include "timer.h"
#include "eeconfig.h"
#include "eeprom.h"

#ifndef MIN
#define MIN(a,b) (((a)<(b))?(a):(b))
#endif
#ifndef MAX
#define MAX(a,b) (((a)>(b))?(a):(b))
#endif

#define TYPING_SPEED_MAX_VALUE 200
uint8_t typing_speed = 0;

bool momentum_enabled() {
return eeprom_read_byte(EECONFIG_MOMENTUM) == 1;
}

void momentum_toggle() {
if (momentum_enabled())
eeprom_update_byte(EECONFIG_MOMENTUM, 0);
else
eeprom_update_byte(EECONFIG_MOMENTUM, 1);
}

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

void momentum_decay_task() {
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 -= 3;
decay_timer = timer_read();
}
}

uint8_t match_momentum(uint8_t minValue, uint8_t maxValue) {
return MAX(minValue, maxValue - (maxValue - minValue) * ((float)typing_speed / TYPING_SPEED_MAX_VALUE));
}
13 changes: 13 additions & 0 deletions quantum/momentum.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef MOMENTUM_H
#define MOMENTUM_H

#include <stdint.h>
#include <stdbool.h>

bool momentum_enabled(void);
void momentum_toggle(void);
void momentum_accelerate(void);
void momentum_decay_task(void);
uint8_t match_momentum(uint8_t minValue, uint8_t maxValue);

#endif
5 changes: 4 additions & 1 deletion quantum/quantum.c
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,10 @@ static inline uint16_t scale_backlight(uint16_t v) {
*/
ISR(TIMER1_OVF_vect)
{
uint16_t interval = (uint16_t) breathing_period * 244 / BREATHING_STEPS;
uint16_t interval = momentum_enabled()
? match_momentum(1, 10)
: (uint16_t) breathing_period * 244 / BREATHING_STEPS;

// resetting after one period to prevent ugly reset at overflow.
breathing_counter = (breathing_counter + 1) % (breathing_period * 244);
uint8_t index = breathing_counter / interval % BREATHING_STEPS;
Expand Down
20 changes: 19 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -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 original 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 [this commit](https://github.com/chrislewisdev/qmk_firmware/commit/2d3fbc5d0ad70309ede5cdeb9cf84380fd69baae) which contains all the changes.

I've created GitHub Issues for the most pressing things that need to be addressed before this could be merged into QMK - if you're interested in helping out, please do take a look!

To test it, I've just been using my DZ60 keyboard, building the firmware with `make dz60:default` and flashing with qmk_toolbox. If you're not familiar with how to do that, it's probably best you consult the [QMK documentation](https://docs.qmk.fm/#/).

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)
Expand Down

0 comments on commit e123ff5

Please sign in to comment.