aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2013-01-17 15:00:41 +0900
committertmk <nobody@nowhere>2013-01-17 15:02:34 +0900
commitee7ce433357a1c1bbcaba54525fc5b5b5404aa82 (patch)
tree287fd6ef79a45680bcdb5ebf98524d9d1428e087
parent567b2ae5259634a5293afbc6a710a19d7c45dcda (diff)
downloadqmk_firmware-ee7ce433357a1c1bbcaba54525fc5b5b5404aa82.tar.gz
qmk_firmware-ee7ce433357a1c1bbcaba54525fc5b5b5404aa82.zip
Refactor struct keyevent_t.
-rw-r--r--common/action.c13
-rw-r--r--common/keyboard.c4
-rw-r--r--common/keyboard.h12
3 files changed, 19 insertions, 10 deletions
diff --git a/common/action.c b/common/action.c
index d5040479e..d01038301 100644
--- a/common/action.c
+++ b/common/action.c
@@ -47,7 +47,7 @@ static uint8_t waiting_keys_head = 0;
47static bool waiting_keys_enqueue(keyevent_t event) 47static bool waiting_keys_enqueue(keyevent_t event)
48{ 48{
49 debug("waiting_keys["); debug_dec(waiting_keys_head); debug("] = "); 49 debug("waiting_keys["); debug_dec(waiting_keys_head); debug("] = ");
50 debug_hex8(event.key.row); debug_hex8(event.key.col); debug("\n"); // TODO event.key.raw 50 debug_hex16(event.key.raw); debug("\n");
51 if (waiting_keys_head < WAITING_KEYS_BUFFER) { 51 if (waiting_keys_head < WAITING_KEYS_BUFFER) {
52 waiting_keys[waiting_keys_head++] = (keyrecord_t){ .event = event, 52 waiting_keys[waiting_keys_head++] = (keyrecord_t){ .event = event,
53 .mods = host_get_mods() }; 53 .mods = host_get_mods() };
@@ -59,7 +59,7 @@ static void waiting_keys_clear(void)
59{ 59{
60 waiting_keys_head = 0; 60 waiting_keys_head = 0;
61} 61}
62static bool waiting_keys_has(keypos_t key) 62static bool waiting_keys_has(key_t key)
63{ 63{
64 for (uint8_t i = 0; i < waiting_keys_head; i++) { 64 for (uint8_t i = 0; i < waiting_keys_head; i++) {
65 if KEYEQ(key, waiting_keys[i].event.key) return true; 65 if KEYEQ(key, waiting_keys[i].event.key) return true;
@@ -71,7 +71,6 @@ static void waiting_keys_process_in_current_layer(void)
71 // TODO: in case of including layer key in waiting keys 71 // TODO: in case of including layer key in waiting keys
72 for (uint8_t i = 0; i < waiting_keys_head; i++) { 72 for (uint8_t i = 0; i < waiting_keys_head; i++) {
73 debug("waiting_keys_process_in_current_layer["); debug_dec(i); debug("]\n"); 73 debug("waiting_keys_process_in_current_layer["); debug_dec(i); debug("]\n");
74 // TODO: no need action in waiting_keys? should get_action() in process()?
75 process(waiting_keys[i].event); 74 process(waiting_keys[i].event);
76 } 75 }
77 waiting_keys_clear(); 76 waiting_keys_clear();
@@ -80,6 +79,12 @@ static void waiting_keys_process_in_current_layer(void)
80 79
81void action_exec(keyevent_t event) 80void action_exec(keyevent_t event)
82{ 81{
82 if (!IS_NOEVENT(event)) {
83 debug("event: "); debug_hex16(event.key.raw);
84 debug("[");
85 if (event.pressed) debug("down"); else debug("up");
86 debug("]\n");
87 }
83 if (IS_TAPPING) { 88 if (IS_TAPPING) {
84 /* when tap time elapses or waiting key is released */ 89 /* when tap time elapses or waiting key is released */
85 if ((timer_elapsed(tapping_key.event.time) > TAP_TIME) || 90 if ((timer_elapsed(tapping_key.event.time) > TAP_TIME) ||
@@ -136,7 +141,7 @@ void action_exec(keyevent_t event)
136 141
137static void process(keyevent_t event) 142static void process(keyevent_t event)
138{ 143{
139 action_t action = keymap_get_action(current_layer, event.key.row, event.key.col); 144 action_t action = keymap_get_action(current_layer, event.key.pos.row, event.key.pos.col);
140 debug("action: "); debug_hex16(action.code); 145 debug("action: "); debug_hex16(action.code);
141 if (event.pressed) debug("[down]\n"); else debug("[up]\n"); 146 if (event.pressed) debug("[down]\n"); else debug("[up]\n");
142 147
diff --git a/common/keyboard.c b/common/keyboard.c
index 2e32e91e0..ea4d0ee7e 100644
--- a/common/keyboard.c
+++ b/common/keyboard.c
@@ -66,7 +66,7 @@ void keyboard_task(void)
66 for (int c = 0; c < MATRIX_COLS; c++) { 66 for (int c = 0; c < MATRIX_COLS; c++) {
67 if (matrix_change & (1<<c)) { 67 if (matrix_change & (1<<c)) {
68 action_exec((keyevent_t){ 68 action_exec((keyevent_t){
69 .key = (keypos_t){ .row = r, .col = c }, 69 .key.pos = (keypos_t){ .row = r, .col = c },
70 .pressed = (matrix_row & (1<<c)), 70 .pressed = (matrix_row & (1<<c)),
71 .time = (timer_read() | 1) /* NOTE: 0 means no event */ 71 .time = (timer_read() | 1) /* NOTE: 0 means no event */
72 }); 72 });
@@ -80,7 +80,7 @@ void keyboard_task(void)
80 } 80 }
81 // call to update delaying layer when no real event 81 // call to update delaying layer when no real event
82 action_exec((keyevent_t) { 82 action_exec((keyevent_t) {
83 .key = (keypos_t){ .row = 255, .col = 255 }, // assume this key doesn't exist 83 .key.pos = (keypos_t){ .row = 255, .col = 255 }, // assume this key doesn't exist
84 .pressed = false, 84 .pressed = false,
85 .time = 0, 85 .time = 0,
86 }); 86 });
diff --git a/common/keyboard.h b/common/keyboard.h
index 907ee1f97..4518cdddc 100644
--- a/common/keyboard.h
+++ b/common/keyboard.h
@@ -26,19 +26,23 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
26extern "C" { 26extern "C" {
27#endif 27#endif
28 28
29// TODO: union {raw = row:col}
30typedef struct { 29typedef struct {
31 uint8_t row;
32 uint8_t col; 30 uint8_t col;
31 uint8_t row;
33} keypos_t; 32} keypos_t;
34 33
34typedef union {
35 uint16_t raw;
36 keypos_t pos;
37} key_t;
38
35typedef struct { 39typedef struct {
36 keypos_t key; 40 key_t key;
37 bool pressed; 41 bool pressed;
38 uint16_t time; 42 uint16_t time;
39} keyevent_t; 43} keyevent_t;
40 44
41#define KEYEQ(keya, keyb) (keya.row == keyb.row && keya.col == keyb.col) 45#define KEYEQ(keya, keyb) (keya.raw == keyb.raw)
42#define IS_NOEVENT(event) (event.time == 0) 46#define IS_NOEVENT(event) (event.time == 0)
43#define NOEVENT (keyevent_t) { \ 47#define NOEVENT (keyevent_t) { \
44 .key = (keypos_t){ .row = 255, .col = 255 }, \ 48 .key = (keypos_t){ .row = 255, .col = 255 }, \