diff options
| author | tmk <nobody@nowhere> | 2012-10-12 11:00:52 +0900 |
|---|---|---|
| committer | tmk <nobody@nowhere> | 2012-10-17 15:55:37 +0900 |
| commit | f7a445e537243f886d9cb022bede18859c9bfd12 (patch) | |
| tree | 59d9ddf0a131e1a25fb4e7397408f3052001457e /common | |
| parent | 1677b021d7bff6af7763532b038612363b61dada (diff) | |
| download | qmk_firmware-f7a445e537243f886d9cb022bede18859c9bfd12.tar.gz qmk_firmware-f7a445e537243f886d9cb022bede18859c9bfd12.zip | |
Fix use of default_layer
Diffstat (limited to 'common')
| -rw-r--r-- | common/keyboard.c | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/common/keyboard.c b/common/keyboard.c index 7a17a9e38..be01e5540 100644 --- a/common/keyboard.c +++ b/common/keyboard.c | |||
| @@ -46,8 +46,13 @@ typedef enum keykind { | |||
| 46 | typedef enum { IDLE, DELAYING, WAITING, PRESSING } kbdstate_t; | 46 | typedef enum { IDLE, DELAYING, WAITING, PRESSING } kbdstate_t; |
| 47 | 47 | ||
| 48 | 48 | ||
| 49 | uint8_t current_layer = 0; | 49 | #ifdef KEYMAP_DEFAULT_LAYER |
| 50 | uint8_t default_layer = KEYMAP_DEFAULT_LAYER; | ||
| 51 | uint8_t current_layer = KEYMAP_DEFAULT_LAYER; | ||
| 52 | #else | ||
| 50 | uint8_t default_layer = 0; | 53 | uint8_t default_layer = 0; |
| 54 | uint8_t current_layer = 0; | ||
| 55 | #endif | ||
| 51 | 56 | ||
| 52 | /* keyboard internal states */ | 57 | /* keyboard internal states */ |
| 53 | static kbdstate_t kbdstate = IDLE; | 58 | static kbdstate_t kbdstate = IDLE; |
| @@ -120,12 +125,13 @@ static void layer_switch_on(uint8_t code) | |||
| 120 | { | 125 | { |
| 121 | if (!IS_FN(code)) return; | 126 | if (!IS_FN(code)) return; |
| 122 | fn_state_bits |= FN_BIT(code); | 127 | fn_state_bits |= FN_BIT(code); |
| 123 | if (current_layer != keymap_fn_layer(FN_INDEX(code))) { | 128 | uint8_t new_layer = (fn_state_bits ? keymap_fn_layer(biton(fn_state_bits)) : default_layer); |
| 124 | clear_keyboard_but_mods(); | 129 | if (current_layer != new_layer) { |
| 125 | |||
| 126 | debug("Layer Switch(on): "); debug_hex(current_layer); | 130 | debug("Layer Switch(on): "); debug_hex(current_layer); |
| 127 | current_layer = keymap_fn_layer(FN_INDEX(code)); | 131 | debug(" -> "); debug_hex(new_layer); debug("\n"); |
| 128 | debug(" -> "); debug_hex(current_layer); debug("\n"); | 132 | |
| 133 | clear_keyboard_but_mods(); | ||
| 134 | current_layer = new_layer; | ||
| 129 | } | 135 | } |
| 130 | } | 136 | } |
| 131 | 137 | ||
| @@ -133,12 +139,13 @@ static bool layer_switch_off(uint8_t code) | |||
| 133 | { | 139 | { |
| 134 | if (!IS_FN(code)) return false; | 140 | if (!IS_FN(code)) return false; |
| 135 | fn_state_bits &= ~FN_BIT(code); | 141 | fn_state_bits &= ~FN_BIT(code); |
| 136 | if (current_layer != keymap_fn_layer(biton(fn_state_bits))) { | 142 | uint8_t new_layer = (fn_state_bits ? keymap_fn_layer(biton(fn_state_bits)) : default_layer); |
| 137 | clear_keyboard_but_mods(); | 143 | if (current_layer != new_layer) { |
| 138 | |||
| 139 | debug("Layer Switch(off): "); debug_hex(current_layer); | 144 | debug("Layer Switch(off): "); debug_hex(current_layer); |
| 140 | current_layer = keymap_fn_layer(biton(fn_state_bits)); | 145 | debug(" -> "); debug_hex(new_layer); debug("\n"); |
| 141 | debug(" -> "); debug_hex(current_layer); debug("\n"); | 146 | |
| 147 | clear_keyboard_but_mods(); | ||
| 148 | current_layer = new_layer; | ||
| 142 | return true; | 149 | return true; |
| 143 | } | 150 | } |
| 144 | return false; | 151 | return false; |
| @@ -606,8 +613,9 @@ void keyboard_task(void) | |||
| 606 | is_matrix_on |= matrix_get_row(r); | 613 | is_matrix_on |= matrix_get_row(r); |
| 607 | } | 614 | } |
| 608 | if (!is_matrix_on) { | 615 | if (!is_matrix_on) { |
| 609 | debug("FAIL SAFE: clear all keys.\n"); | 616 | debug("FAIL SAFE: clear all keys(default layer).\n"); |
| 610 | clear_keyboard(); | 617 | clear_keyboard(); |
| 618 | current_layer = default_layer; | ||
| 611 | } | 619 | } |
| 612 | } | 620 | } |
| 613 | 621 | ||
