Use timers instead of loop counters

Loop counters are not reliable timer substitutes, use proper timers instead.

Fixes #5.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/389/head
Gergely Nagy 8 years ago
parent bae049583d
commit 74070edcf1

@ -22,8 +22,8 @@ using namespace Akela::Ranges;
namespace Akela {
// --- state ---
uint16_t TapDance::timer;
uint8_t TapDance::timeOut = 5;
uint32_t TapDance::startTime;
uint16_t TapDance::timeOut = 200;
uint8_t TapDance::tapCount[32];
uint32_t TapDance::pressedState;
uint32_t TapDance::triggeredState;
@ -47,7 +47,7 @@ namespace Akela {
tapDanceAction (idx, lastTapDanceRow, lastTapDanceCol, tapCount[idx], Interrupt);
bitWrite (triggeredState, idx, 1);
timer = 0;
startTime = millis ();
if (bitRead (pressedState, idx))
return;
@ -59,6 +59,8 @@ namespace Akela {
TapDance::timeout (void) {
uint8_t idx = lastTapDanceKey.raw - TD_FIRST;
startTime = 0;
tapDanceAction (idx, lastTapDanceRow, lastTapDanceCol, tapCount[idx], Timeout);
bitWrite (triggeredState, idx, 1);
@ -74,7 +76,7 @@ namespace Akela {
TapDance::release (uint8_t tapDanceIndex) {
tapDanceAction (tapDanceIndex, lastTapDanceRow, lastTapDanceCol, tapCount[tapDanceIndex], Release);
timer = 0;
startTime = 0;
tapCount[tapDanceIndex] = 0;
lastTapDanceKey.raw = Key_NoKey.raw;
@ -88,7 +90,7 @@ namespace Akela {
uint8_t idx = lastTapDanceKey.raw - TD_FIRST;
tapCount[idx]++;
timer = 0;
startTime = millis ();
tapDanceAction (idx, lastTapDanceRow, lastTapDanceCol, tapCount[idx], Tap);
@ -211,10 +213,7 @@ namespace Akela {
if (!isActive ())
return;
if (timer < timeOut)
timer++;
if (timer >= timeOut)
if (startTime && (millis () - startTime) >= timeOut)
timeout();
}
};

@ -42,12 +42,12 @@ namespace Akela {
TapDance (void);
virtual void begin (void) final;
static uint8_t timeOut;
static uint16_t timeOut;
void actionKeys (uint8_t tapCount, ActionType tapDanceAction, uint8_t maxKeys, const Key tapKeys[]);
private:
static uint16_t timer;
static uint32_t startTime;
static uint8_t tapCount[32];
static uint32_t pressedState;
static uint32_t triggeredState;

Loading…
Cancel
Save