Support copying a key from PROGMEM to EEPROM

Fixes #2.

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

@ -20,8 +20,9 @@
namespace KaleidoscopePlugins {
uint16_t EEPROMKeymapProgrammer::updatePosition;
Key EEPROMKeymapProgrammer::newKey;
EEPROMKeymapProgrammer::state_t EEPROMKeymapProgrammer::state;
EEPROMKeymapProgrammer::mode_t EEPROMKeymapProgrammer::programmerMode;
Key EEPROMKeymapProgrammer::newKey;
EEPROMKeymapProgrammer::EEPROMKeymapProgrammer (void) {
}
@ -31,6 +32,11 @@ namespace KaleidoscopePlugins {
event_handler_hook_use (eventHandlerHook);
}
void
EEPROMKeymapProgrammer::mode (mode_t programmerMode_) {
programmerMode = programmerMode_;
}
void
EEPROMKeymapProgrammer::nextState (void) {
switch (state) {
@ -38,9 +44,13 @@ namespace KaleidoscopePlugins {
state = WAIT_FOR_KEY;
break;
case WAIT_FOR_KEY:
state = WAIT_FOR_CODE;
if (programmerMode == CODE)
state = WAIT_FOR_CODE;
else
state = WAIT_FOR_SOURCE_KEY;
break;
case WAIT_FOR_CODE:
case WAIT_FOR_SOURCE_KEY:
::EEPROMKeymap.updateKey (updatePosition, newKey);
cancel ();
break;
@ -70,6 +80,17 @@ namespace KaleidoscopePlugins {
return Key_NoKey;
}
if (state == WAIT_FOR_SOURCE_KEY) {
if (key_toggled_on (keyState)) {
newKey = Layer.getKeyFromPROGMEM (Layer.top (), row, col);
}
if (key_toggled_off (keyState)) {
if (newKey == Layer.getKeyFromPROGMEM (Layer.top (), row, col))
nextState ();
}
return Key_NoKey;
}
// WAIT_FOR_CODE state
if (mappedKey < KEY_1 || mappedKey > KEY_0)

@ -24,23 +24,32 @@
namespace KaleidoscopePlugins {
class EEPROMKeymapProgrammer : public KaleidoscopePlugin {
public:
typedef enum {
CODE,
COPY,
} mode_t;
EEPROMKeymapProgrammer (void);
virtual void begin (void) final;
static void mode (mode_t programmerMode);
static void nextState (void);
static void cancel (void);
private:
static uint16_t updatePosition; // layer, row, col
static Key newKey;
static mode_t programmerMode;
typedef enum {
INACTIVE,
WAIT_FOR_KEY,
WAIT_FOR_CODE,
WAIT_FOR_SOURCE_KEY,
} state_t;
static state_t state;
static uint16_t updatePosition; // layer, row, col
static Key newKey;
static Key eventHandlerHook (Key mappedKey, byte row, byte col, uint8_t keyState);
};
};

Loading…
Cancel
Save