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

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

Loading…
Cancel
Save