Kaleidoscope Style Guide conformance

Also updated to work with the newest `EEPROM-Keymap` API.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/389/head
Gergely Nagy 7 years ago
parent f2ee554ce6
commit 8220369f6f

@ -23,47 +23,45 @@
const Key keymaps[][ROWS][COLS] PROGMEM = { const Key keymaps[][ROWS][COLS] PROGMEM = {
[0] = KEYMAP_STACKED [0] = KEYMAP_STACKED
( (M(0), Key_1, Key_2, Key_3, Key_4, Key_5, Key_NoKey,
M(0), Key_1, Key_2, Key_3, Key_4, Key_5, Key_NoKey, Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_Tab,
Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_Tab, Key_PageUp, Key_A, Key_S, Key_D, Key_F, Key_G,
Key_PageUp, Key_A, Key_S, Key_D, Key_F, Key_G, Key_PageDown, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Escape,
Key_PageDown, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Escape,
Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift, Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift,
Key_NoKey, Key_NoKey,
Key_skip, Key_6, Key_7, Key_8, Key_9, Key_0, Key_skip, Key_skip, Key_6, Key_7, Key_8, Key_9, Key_0, Key_skip,
Key_Enter, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals, Key_Enter, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals,
Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote, Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote,
Key_skip, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus, Key_skip, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus,
Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl, Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl,
Key_NoKey Key_NoKey),
),
}; };
const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) { const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) {
if (macroIndex == 0 && key_toggled_off (keyState)) { if (macroIndex == 0 && key_toggled_off(keyState)) {
EEPROMKeymapProgrammer.nextState (); EEPROMKeymapProgrammer.nextState();
} }
return MACRO_NONE; return MACRO_NONE;
} }
void setup () { void setup() {
Serial.begin (9600); Serial.begin(9600);
Kaleidoscope.setup (); USE_PLUGINS(&EEPROMKeymapProgrammer, &EEPROMKeymap, &Macros);
USE_PLUGINS (&EEPROMKeymapProgrammer, &EEPROMKeymap, &Macros); Kaleidoscope.setup();
Layer.getKey = EEPROMKeymap.getKey; Layer.getKey = EEPROMKeymap.getKey;
EEPROMKeymap.reserveSpace (1); EEPROMKeymap.max_layers(1);
EEPROMSettings.seal (); EEPROMSettings.seal();
} }
void loop () { void loop() {
Kaleidoscope.loop (); Kaleidoscope.loop();
} }

@ -18,93 +18,89 @@
#include <Kaleidoscope-EEPROM-Keymap-Programmer.h> #include <Kaleidoscope-EEPROM-Keymap-Programmer.h>
namespace KaleidoscopePlugins { namespace kaleidoscope {
uint16_t EEPROMKeymapProgrammer::updatePosition; uint16_t EEPROMKeymapProgrammer::update_position_;
EEPROMKeymapProgrammer::state_t EEPROMKeymapProgrammer::state; EEPROMKeymapProgrammer::state_t EEPROMKeymapProgrammer::state_;
EEPROMKeymapProgrammer::mode_t EEPROMKeymapProgrammer::mode; EEPROMKeymapProgrammer::mode_t EEPROMKeymapProgrammer::mode;
Key EEPROMKeymapProgrammer::newKey; Key EEPROMKeymapProgrammer::new_key_;
EEPROMKeymapProgrammer::EEPROMKeymapProgrammer (void) { EEPROMKeymapProgrammer::EEPROMKeymapProgrammer(void) {
} }
void void EEPROMKeymapProgrammer::begin(void) {
EEPROMKeymapProgrammer::begin (void) { event_handler_hook_use(eventHandlerHook);
event_handler_hook_use (eventHandlerHook);
} }
void void EEPROMKeymapProgrammer::nextState(void) {
EEPROMKeymapProgrammer::nextState (void) { switch (state_) {
switch (state) { case INACTIVE:
case INACTIVE: state_ = WAIT_FOR_KEY;
state = WAIT_FOR_KEY; break;
break; case WAIT_FOR_KEY:
case WAIT_FOR_KEY: if (mode == CODE)
if (mode == CODE) state_ = WAIT_FOR_CODE;
state = WAIT_FOR_CODE; else
else state_ = WAIT_FOR_SOURCE_KEY;
state = WAIT_FOR_SOURCE_KEY; break;
break; case WAIT_FOR_CODE:
case WAIT_FOR_CODE: case WAIT_FOR_SOURCE_KEY:
case WAIT_FOR_SOURCE_KEY: ::EEPROMKeymap.updateKey(update_position_, new_key_);
::EEPROMKeymap.updateKey (updatePosition, newKey); cancel();
cancel (); break;
break; }
}
} }
void void EEPROMKeymapProgrammer::cancel(void) {
EEPROMKeymapProgrammer::cancel (void) { update_position_ = 0;
updatePosition = 0; new_key_ = Key_NoKey;
newKey = Key_NoKey; state_ = INACTIVE;
state = INACTIVE;
} }
Key Key EEPROMKeymapProgrammer::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state) {
EEPROMKeymapProgrammer::eventHandlerHook (Key mappedKey, byte row, byte col, uint8_t keyState) { if (state_ == INACTIVE)
if (state == INACTIVE) return mapped_key;
return mappedKey;
if (state_ == WAIT_FOR_KEY) {
if (state == WAIT_FOR_KEY) { if (key_toggled_on(key_state)) {
if (key_toggled_on (keyState)) { update_position_ = Layer.top() * ROWS * COLS + row * COLS + col;
updatePosition = Layer.top () * ROWS * COLS + row * COLS + col;
}
if (key_toggled_off (keyState)) {
if ((uint16_t)(Layer.top () * ROWS * COLS + row * COLS + col) == updatePosition)
nextState ();
}
return Key_NoKey;
} }
if (key_toggled_off(key_state)) {
if ((uint16_t)(Layer.top() * ROWS * COLS + row * COLS + col) == update_position_)
nextState();
}
return Key_NoKey;
}
if (state == WAIT_FOR_SOURCE_KEY) { if (state_ == WAIT_FOR_SOURCE_KEY) {
if (key_toggled_on (keyState)) { if (key_toggled_on(key_state)) {
newKey = Layer.getKeyFromPROGMEM (Layer.top (), row, col); new_key_ = Layer.getKeyFromPROGMEM(Layer.top(), row, col);
} }
if (key_toggled_off (keyState)) { if (key_toggled_off(key_state)) {
if (newKey == Layer.getKeyFromPROGMEM (Layer.top (), row, col)) if (new_key_ == Layer.getKeyFromPROGMEM(Layer.top(), row, col))
nextState (); nextState();
}
return Key_NoKey;
} }
return Key_NoKey;
}
// WAIT_FOR_CODE state // WAIT_FOR_CODE state
if (mappedKey < Key_1 || mappedKey > Key_0) if (mapped_key < Key_1 || mapped_key > Key_0)
return mappedKey; return mapped_key;
if (!key_toggled_on (keyState)) if (!key_toggled_on(key_state))
return Key_NoKey; return Key_NoKey;
uint8_t n; uint8_t n;
if (mappedKey.keyCode == Key_0.keyCode) if (mapped_key.keyCode == Key_0.keyCode)
n = 0; n = 0;
else else
n = mappedKey.keyCode - Key_1.keyCode + 1; n = mapped_key.keyCode - Key_1.keyCode + 1;
newKey.raw = newKey.raw * 10 + n; new_key_.raw = new_key_.raw * 10 + n;
return Key_NoKey; return Key_NoKey;
} }
}; }
KaleidoscopePlugins::EEPROMKeymapProgrammer EEPROMKeymapProgrammer; kaleidoscope::EEPROMKeymapProgrammer EEPROMKeymapProgrammer;

@ -21,36 +21,36 @@
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
#include <Kaleidoscope-EEPROM-Keymap.h> #include <Kaleidoscope-EEPROM-Keymap.h>
namespace KaleidoscopePlugins { namespace kaleidoscope {
class EEPROMKeymapProgrammer : public KaleidoscopePlugin { class EEPROMKeymapProgrammer : public KaleidoscopePlugin {
public: public:
typedef enum { typedef enum {
CODE, CODE,
COPY, COPY,
} mode_t; } mode_t;
static mode_t mode; static mode_t mode;
EEPROMKeymapProgrammer (void); EEPROMKeymapProgrammer(void);
virtual void begin (void) final; void begin(void) final;
static void nextState (void); static void nextState(void);
static void cancel (void); static void cancel(void);
private: private:
typedef enum { typedef enum {
INACTIVE, INACTIVE,
WAIT_FOR_KEY, WAIT_FOR_KEY,
WAIT_FOR_CODE, WAIT_FOR_CODE,
WAIT_FOR_SOURCE_KEY, WAIT_FOR_SOURCE_KEY,
} state_t; } state_t;
static state_t state; static state_t state_;
static uint16_t updatePosition; // layer, row, col static uint16_t update_position_; // layer, row, col
static Key newKey; static Key new_key_;
static Key eventHandlerHook (Key mappedKey, byte row, byte col, uint8_t keyState); static Key eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state);
};
}; };
}
extern KaleidoscopePlugins::EEPROMKeymapProgrammer EEPROMKeymapProgrammer; extern kaleidoscope::EEPROMKeymapProgrammer EEPROMKeymapProgrammer;

Loading…
Cancel
Save