writing speed is detected, and the model mayhem sets backlight according to
speed
This commit is contained in:
@ -523,6 +523,49 @@ void sendString(char* string) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate an average value for the speed the keys are pressed in. The speed
|
||||
* value is sent to the keyboard interface, the keyboard decides what to do
|
||||
* with it.
|
||||
* \param updates number of updates since the last call (should be in the range
|
||||
* 0-1)
|
||||
*/
|
||||
void calculateSpeed(uint8_t updates) {
|
||||
static uint8_t callcounter = 0;
|
||||
static uint8_t speed = 0;
|
||||
callcounter++;
|
||||
if (updates > 0) {
|
||||
// a key has been pressed
|
||||
if (speed < 251) {
|
||||
// it can get hotter...
|
||||
if (callcounter < 8) {
|
||||
speed += 4;
|
||||
} else if (callcounter < 16) {
|
||||
speed += 3;
|
||||
} else if (callcounter < 24) {
|
||||
speed += 2;
|
||||
} else {
|
||||
speed += 1;
|
||||
}
|
||||
setSpeed(speed);
|
||||
}
|
||||
callcounter = 0;
|
||||
} else {
|
||||
// no key pressed...
|
||||
if (callcounter == 16) {
|
||||
// ... for a long time, decrease speed value
|
||||
if (speed > 10) {
|
||||
speed -= 10;
|
||||
setSpeed(speed);
|
||||
} else if (speed > 0) {
|
||||
speed = 0;
|
||||
setSpeed(speed);
|
||||
}
|
||||
callcounter = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Main function, containing the main loop that manages timer- and
|
||||
* USB-functionality.
|
||||
@ -531,6 +574,7 @@ void sendString(char* string) {
|
||||
int main(void) {
|
||||
uint8_t updateNeeded = 0;
|
||||
uint8_t idleCounter = 0;
|
||||
uint8_t updates = 0;
|
||||
wdt_enable(WDTO_2S);
|
||||
hardwareInit();
|
||||
usbInit();
|
||||
@ -545,10 +589,15 @@ int main(void) {
|
||||
usbPoll();
|
||||
|
||||
updateNeeded = scankeys(reportBuffer, oldReportBuffer, sizeof(reportBuffer)); // changes?
|
||||
if (updateNeeded) {
|
||||
updates++;
|
||||
}
|
||||
|
||||
// check timer if we need periodic reports
|
||||
if (TIFR & (1 << TOV0)) {
|
||||
TIFR = (1 << TOV0); // reset flag
|
||||
calculateSpeed(updates);
|
||||
updates = 0;
|
||||
if (idleRate != 0) { // do we need periodic reports?
|
||||
if(idleCounter > 4){ // yes, but not yet
|
||||
idleCounter -= 5; // 22ms in units of 4ms
|
||||
|
Reference in New Issue
Block a user