Expose the timeOut (and rename it)

Fixes #1.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/365/head
Gergely Nagy 8 years ago
parent 7dbb5b39e0
commit 263b12151c

@ -50,13 +50,16 @@ left and the right halves.
The extension provides a `MagicCombo` singleton object, with the following method: The extension provides a `MagicCombo` singleton object, with the following method:
### `.configure(dictionary[, timeout])` ### `.configure(dictionary)`
> Configures the extension to use the supplied dictionary, and restrict it to > Configures the extension to use the supplied dictionary.
> fire at most once every `timeout` cycles.
### `.minInterval`
> Restrict the magic action to fire at most once every `minInterval` cycles.
> Defaults to 10.
> >
> If the timeout is not specified, it defaults to `DEFAULT_TIMEOUT`, which in > Not strictly a method, it is a variable one can assign a new value to.
> turn is 40 cycles.
## Overrideable methods ## Overrideable methods

@ -21,7 +21,7 @@
namespace Akela { namespace Akela {
const MagicCombo::dictionary_t *MagicCombo::dictionary; const MagicCombo::dictionary_t *MagicCombo::dictionary;
uint8_t MagicCombo::timeOut; uint8_t MagicCombo::minInterval = 10;
uint8_t MagicCombo::timer; uint8_t MagicCombo::timer;
MagicCombo::MagicCombo (void) { MagicCombo::MagicCombo (void) {
@ -33,9 +33,8 @@ namespace Akela {
} }
void void
MagicCombo::configure (const MagicCombo::dictionary_t dictionary_[], uint8_t timeOut_) { MagicCombo::configure (const MagicCombo::dictionary_t dictionary_[]) {
dictionary = (dictionary_t *)dictionary_; dictionary = (dictionary_t *)dictionary_;
timeOut = timeOut_;
} }
void void
@ -43,7 +42,7 @@ namespace Akela {
if (!dictionary || postClear) if (!dictionary || postClear)
return; return;
if (timer && timer < timeOut) if (timer && timer < minInterval)
timer++; timer++;
for (byte i = 0;; i++) { for (byte i = 0;; i++) {
@ -57,7 +56,7 @@ namespace Akela {
if (KeyboardHardware.leftHandState.all == combo.leftHand && if (KeyboardHardware.leftHandState.all == combo.leftHand &&
KeyboardHardware.rightHandState.all == combo.rightHand) { KeyboardHardware.rightHandState.all == combo.rightHand) {
if (timer == 0 || timer >= timeOut || timeOut == 0) { if (timer == 0 || timer >= minInterval || minInterval == 0) {
magicComboActions (i, combo.leftHand, combo.rightHand); magicComboActions (i, combo.leftHand, combo.rightHand);
timer = 1; timer = 1;
} }

@ -20,8 +20,6 @@
#include <Akela-Core.h> #include <Akela-Core.h>
#define AKELA_MAGICCOMBO_TIMEOUT DEFAULT_TIMEOUT
namespace Akela { namespace Akela {
class MagicCombo : public KeyboardioPlugin { class MagicCombo : public KeyboardioPlugin {
public: public:
@ -33,12 +31,11 @@ namespace Akela {
virtual void begin (void) final; virtual void begin (void) final;
static void configure (const dictionary_t dictionary[], uint8_t timeout); static void configure (const dictionary_t dictionary[]);
static void configure (const dictionary_t dictionary[]) { configure (dictionary, AKELA_MAGICCOMBO_TIMEOUT); }; static uint8_t minInterval;
private: private:
static const dictionary_t *dictionary; static const dictionary_t *dictionary;
static uint8_t timeOut;
static uint8_t timer; static uint8_t timer;
static void loopHook (bool postClear); static void loopHook (bool postClear);

Loading…
Cancel
Save