forked from qmk/qmk_firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'led-support' into master
- Loading branch information
Showing
5 changed files
with
84 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters