made transient layers not need a back stack

pull/18/head
Jesse Vincent 11 years ago
parent 6b2a2b00d4
commit b9d91aad6f

@ -368,7 +368,7 @@ typedef struct {
#define META_NEXT_KEYMAP_MOMENTARY 0xFF #define META_NEXT_KEYMAP_MOMENTARY 0xFF
#define NextKeymap (Key){ KEY_FLAGS | MOMENTARY, LAYER_1 } #define NextKeymap (Key){ KEY_FLAGS | SWITCH_TO_LAYER | MOMENTARY, LAYER_1 }

@ -21,7 +21,8 @@ byte matrixState[ROWS][COLS];
long counter = 0; long counter = 0;
static const int LAYERS = 2; static const int LAYERS = 2;
int current_keymap = 0; int current_layer = 0;
int previous_keymap = 0;
static const Key keymaps[LAYERS][ROWS][COLS] = { static const Key keymaps[LAYERS][ROWS][COLS] = {
{ {
@ -83,7 +84,7 @@ boolean key_is_not_pressed (byte keyState) {
} }
boolean key_toggled_on(byte keyState) { boolean key_toggled_on(byte keyState) {
if (key_is_pressed(keyState) && ( key_was_not_pressed(keyState))) { if (key_is_pressed(keyState) && key_was_not_pressed(keyState)) {
return true; return true;
} }
else { else {
@ -110,7 +111,7 @@ void reset_matrix() {
} }
} }
void send_key_event() { void send_key_events(int layer) {
//for every newly pressed button, figure out what logical key it is and send a key down event //for every newly pressed button, figure out what logical key it is and send a key down event
// for every newly released button, figure out what logical key it is and send a key up event // for every newly released button, figure out what logical key it is and send a key up event
@ -121,7 +122,7 @@ void send_key_event() {
int x = 0; int x = 0;
int y = 0; int y = 0;
byte switchState = matrixState[row][col]; byte switchState = matrixState[row][col];
Key mappedKey = keymaps[current_keymap][row][col]; Key mappedKey = keymaps[layer][row][col];
if (mappedKey.flags & MOUSE_KEY ) { if (mappedKey.flags & MOUSE_KEY ) {
@ -180,6 +181,9 @@ void setup_matrix() {
} }
void scan_matrix() { void scan_matrix() {
int active_layer = current_layer;
//scan the Keyboard matrix looking for connections //scan the Keyboard matrix looking for connections
for (int row = 0; row < ROWS; row++) { for (int row = 0; row < ROWS; row++) {
digitalWrite(rowPins[row], LOW); digitalWrite(rowPins[row], LOW);
@ -199,26 +203,16 @@ void scan_matrix() {
if ( keymaps[current_keymap][row][col].flags & MOMENTARY ) { if (! (keymaps[current_layer][row][col].flags ^ ( MOMENTARY | SWITCH_TO_LAYER))) { // this logic sucks. there is a better way TODO this
if (key_toggled_on(matrixState[row][col]) ) {
current_keymap++;
}
else if (key_toggled_off(matrixState[row][col]) ) {
current_keymap--;
}
}
// guard against layer overflow if (key_is_pressed(matrixState[row][col])) {
if (current_keymap >= LAYERS) { active_layer = keymaps[current_layer][row][col].rawKey;
current_keymap = 0;
} }
else if (current_keymap < 0) {
current_keymap = LAYERS - 1;
} }
} }
digitalWrite(rowPins[row], HIGH); digitalWrite(rowPins[row], HIGH);
} }
send_key_events(active_layer);
} }
@ -257,7 +251,6 @@ void setup() {
void loop() { void loop() {
scan_matrix(); scan_matrix();
// report_matrix(); // report_matrix();
send_key_event();
reset_matrix(); reset_matrix();
} }

Loading…
Cancel
Save