Improved timer handling

Instead of calculating the time delta each time we want to check for a
timeout, calculate the projected ending time ahead of time.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/365/head
Gergely Nagy 8 years ago
parent 92205513de
commit 839d5c298b

@ -32,7 +32,7 @@ namespace KaleidoscopePlugins {
const MagicCombo::dictionary_t *MagicCombo::dictionary; const MagicCombo::dictionary_t *MagicCombo::dictionary;
uint16_t MagicCombo::minInterval = 500; uint16_t MagicCombo::minInterval = 500;
uint32_t MagicCombo::startTime; uint32_t MagicCombo::endTime;
MagicCombo::MagicCombo (void) { MagicCombo::MagicCombo (void) {
} }
@ -63,9 +63,9 @@ namespace KaleidoscopePlugins {
if (LEFTHANDSTATE.all == combo.leftHand && if (LEFTHANDSTATE.all == combo.leftHand &&
RIGHTHANDSTATE.all == combo.rightHand) { RIGHTHANDSTATE.all == combo.rightHand) {
if (startTime == 0 || minInterval == 0 || ((millis () - startTime) >= minInterval)) { if (millis () >= endTime) {
magicComboActions (i, combo.leftHand, combo.rightHand); magicComboActions (i, combo.leftHand, combo.rightHand);
startTime = millis (); endTime = millis () + minInterval;
} }
break; break;
} }

@ -36,7 +36,7 @@ namespace KaleidoscopePlugins {
private: private:
static const dictionary_t *dictionary; static const dictionary_t *dictionary;
static uint32_t startTime; static uint32_t endTime;
static void loopHook (bool postClear); static void loopHook (bool postClear);
}; };

Loading…
Cancel
Save