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:
### `.configure(dictionary[, timeout])`
### `.configure(dictionary)`
> Configures the extension to use the supplied dictionary, and restrict it to
> fire at most once every `timeout` cycles.
> Configures the extension to use the supplied dictionary.
### `.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
> turn is 40 cycles.
> Not strictly a method, it is a variable one can assign a new value to.
## Overrideable methods

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

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

Loading…
Cancel
Save