diff options
| author | tmk <nobody@nowhere> | 2013-02-15 15:27:19 +0900 |
|---|---|---|
| committer | tmk <nobody@nowhere> | 2013-02-15 15:27:19 +0900 |
| commit | 2b811352a1497e28b946a49f9f31dc15dbda420b (patch) | |
| tree | 98b2502fd231d4916270b76632242a15bb27781d | |
| parent | 0c1d98bd3c0b0ea4f109d2515521f1fcbccf3d3f (diff) | |
| download | qmk_firmware-2b811352a1497e28b946a49f9f31dc15dbda420b.tar.gz qmk_firmware-2b811352a1497e28b946a49f9f31dc15dbda420b.zip | |
Fix switch_default_layer command
| -rw-r--r-- | common/command.c | 22 | ||||
| -rw-r--r-- | common/layer_stack.c | 18 | ||||
| -rw-r--r-- | common/layer_stack.h | 1 |
3 files changed, 26 insertions, 15 deletions
diff --git a/common/command.c b/common/command.c index 4c874b109..c5b9f0431 100644 --- a/common/command.c +++ b/common/command.c | |||
| @@ -27,6 +27,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 27 | #include "keyboard.h" | 27 | #include "keyboard.h" |
| 28 | #include "bootloader.h" | 28 | #include "bootloader.h" |
| 29 | #include "command.h" | 29 | #include "command.h" |
| 30 | #include "layer_stack.h" | ||
| 31 | |||
| 30 | #ifdef MOUSEKEY_ENABLE | 32 | #ifdef MOUSEKEY_ENABLE |
| 31 | #include "mousekey.h" | 33 | #include "mousekey.h" |
| 32 | #endif | 34 | #endif |
| @@ -53,7 +55,7 @@ static void mousekey_console_help(void); | |||
| 53 | #endif | 55 | #endif |
| 54 | 56 | ||
| 55 | static uint8_t numkey2num(uint8_t code); | 57 | static uint8_t numkey2num(uint8_t code); |
| 56 | static void switch_layer(uint8_t layer); | 58 | static void switch_default_layer(uint8_t layer); |
| 57 | 59 | ||
| 58 | 60 | ||
| 59 | typedef enum { ONESHOT, CONSOLE, MOUSEKEY } cmdstate_t; | 61 | typedef enum { ONESHOT, CONSOLE, MOUSEKEY } cmdstate_t; |
| @@ -264,16 +266,13 @@ static bool command_common(uint8_t code) | |||
| 264 | case KC_ESC: | 266 | case KC_ESC: |
| 265 | case KC_GRV: | 267 | case KC_GRV: |
| 266 | case KC_0: | 268 | case KC_0: |
| 267 | clear_keyboard(); | 269 | switch_default_layer(0); |
| 268 | switch_layer(0); | ||
| 269 | break; | 270 | break; |
| 270 | case KC_1 ... KC_9: | 271 | case KC_1 ... KC_9: |
| 271 | clear_keyboard(); | 272 | switch_default_layer((code - KC_1) + 1); |
| 272 | switch_layer((code - KC_1) + 1); | ||
| 273 | break; | 273 | break; |
| 274 | case KC_F1 ... KC_F12: | 274 | case KC_F1 ... KC_F12: |
| 275 | clear_keyboard(); | 275 | switch_default_layer((code - KC_F1) + 1); |
| 276 | switch_layer((code - KC_F1) + 1); | ||
| 277 | break; | 276 | break; |
| 278 | default: | 277 | default: |
| 279 | print("?"); | 278 | print("?"); |
| @@ -542,11 +541,14 @@ static uint8_t numkey2num(uint8_t code) | |||
| 542 | return 0; | 541 | return 0; |
| 543 | } | 542 | } |
| 544 | 543 | ||
| 545 | static void switch_layer(uint8_t layer) | 544 | static void switch_default_layer(uint8_t layer) |
| 546 | { | 545 | { |
| 547 | print_val_hex8(current_layer); | 546 | print_val_hex8(current_layer); |
| 548 | print_val_hex8(default_layer); | 547 | print_val_hex8(default_layer); |
| 549 | default_layer = layer; | ||
| 550 | current_layer = 0; | ||
| 551 | print("switch to "); print_val_hex8(layer); | 548 | print("switch to "); print_val_hex8(layer); |
| 549 | |||
| 550 | default_layer = layer; | ||
| 551 | current_layer = 0; /* 0 means default_layer */ | ||
| 552 | layer_stack_clear(); | ||
| 553 | clear_keyboard(); | ||
| 552 | } | 554 | } |
diff --git a/common/layer_stack.c b/common/layer_stack.c index 07c84870c..0076bf779 100644 --- a/common/layer_stack.c +++ b/common/layer_stack.c | |||
| @@ -9,13 +9,23 @@ static uint8_t top_layer = 0; | |||
| 9 | /* [0] always works as sentinel and not used for store.*/ | 9 | /* [0] always works as sentinel and not used for store.*/ |
| 10 | static layer_item_t layer_stack[LAYER_STACK_SIZE] = {}; | 10 | static layer_item_t layer_stack[LAYER_STACK_SIZE] = {}; |
| 11 | 11 | ||
| 12 | |||
| 13 | void layer_stack_clear(void) | ||
| 14 | { | ||
| 15 | for (uint8_t i = 0; i < LAYER_STACK_SIZE; i++) { | ||
| 16 | layer_stack[i] = (layer_item_t){ .layer = 0, | ||
| 17 | .next = 0, | ||
| 18 | .used = false }; | ||
| 19 | } | ||
| 20 | } | ||
| 21 | |||
| 12 | bool layer_stack_push(uint8_t layer) | 22 | bool layer_stack_push(uint8_t layer) |
| 13 | { | 23 | { |
| 14 | for (uint8_t i = 1; i < LAYER_STACK_SIZE; i++) { | 24 | for (uint8_t i = 1; i < LAYER_STACK_SIZE; i++) { |
| 15 | if (!layer_stack[i].used) { | 25 | if (!layer_stack[i].used) { |
| 16 | layer_stack[i] = (layer_item_t){ .layer = layer, | 26 | layer_stack[i] = (layer_item_t){ .layer = layer, |
| 17 | .next = top_layer, | 27 | .next = top_layer, |
| 18 | .used = true }; | 28 | .used = true }; |
| 19 | top_layer = i; | 29 | top_layer = i; |
| 20 | return true; | 30 | return true; |
| 21 | } | 31 | } |
| @@ -73,14 +83,12 @@ void layer_stack_debug(void) | |||
| 73 | layer_item_t item = layer_stack[top_layer]; | 83 | layer_item_t item = layer_stack[top_layer]; |
| 74 | while (item.used) { | 84 | while (item.used) { |
| 75 | debug_dec(item.layer); | 85 | debug_dec(item.layer); |
| 76 | debug("["); debug_dec(item.next); debug("]"); | 86 | debug("["); debug_dec(item.next); debug("] "); |
| 77 | item = layer_stack[item.next]; | 87 | item = layer_stack[item.next]; |
| 78 | } | 88 | } |
| 79 | debug("\n"); | 89 | debug("\n"); |
| 80 | } | 90 | } |
| 81 | 91 | ||
| 82 | |||
| 83 | |||
| 84 | action_t layer_stack_get_action(key_t key) | 92 | action_t layer_stack_get_action(key_t key) |
| 85 | { | 93 | { |
| 86 | action_t action; | 94 | action_t action; |
diff --git a/common/layer_stack.h b/common/layer_stack.h index c88eaffc4..25bf37a5b 100644 --- a/common/layer_stack.h +++ b/common/layer_stack.h | |||
| @@ -32,6 +32,7 @@ typedef struct { | |||
| 32 | } layer_item_t; | 32 | } layer_item_t; |
| 33 | 33 | ||
| 34 | 34 | ||
| 35 | void layer_stack_clear(void); | ||
| 35 | bool layer_stack_push(uint8_t layer); | 36 | bool layer_stack_push(uint8_t layer); |
| 36 | bool layer_stack_pop(void); | 37 | bool layer_stack_pop(void); |
| 37 | bool layer_stack_remove(uint8_t layer); | 38 | bool layer_stack_remove(uint8_t layer); |
