summaryrefslogtreecommitdiff
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)
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 d5040479e8..d010383018 100644
--- a/common/action.c
+++ b/common/action.c
@@ -47,7 +47,7 @@ static uint8_t waiting_keys_head = 0;
static bool waiting_keys_enqueue(keyevent_t event)
{
debug("waiting_keys["); debug_dec(waiting_keys_head); debug("] = ");
- debug_hex8(event.key.row); debug_hex8(event.key.col); debug("\n"); // TODO event.key.raw
+ debug_hex16(event.key.raw); debug("\n");
if (waiting_keys_head < WAITING_KEYS_BUFFER) {
waiting_keys[waiting_keys_head++] = (keyrecord_t){ .event = event,
.mods = host_get_mods() };
@@ -59,7 +59,7 @@ static void waiting_keys_clear(void)
{
waiting_keys_head = 0;
}
-static bool waiting_keys_has(keypos_t key)
+static bool waiting_keys_has(key_t key)
{
for (uint8_t i = 0; i < waiting_keys_head; i++) {
if KEYEQ(key, waiting_keys[i].event.key) return true;
@@ -71,7 +71,6 @@ static void waiting_keys_process_in_current_layer(void)
// TODO: in case of including layer key in waiting keys
for (uint8_t i = 0; i < waiting_keys_head; i++) {
debug("waiting_keys_process_in_current_layer["); debug_dec(i); debug("]\n");
- // TODO: no need action in waiting_keys? should get_action() in process()?
process(waiting_keys[i].event);
}
waiting_keys_clear();
@@ -80,6 +79,12 @@ static void waiting_keys_process_in_current_layer(void)
void action_exec(keyevent_t event)
{
+ if (!IS_NOEVENT(event)) {
+ debug("event: "); debug_hex16(event.key.raw);
+ debug("[");
+ if (event.pressed) debug("down"); else debug("up");
+ debug("]\n");
+ }
if (IS_TAPPING) {
/* when tap time elapses or waiting key is released */
if ((timer_elapsed(tapping_key.event.time) > TAP_TIME) ||
@@ -136,7 +141,7 @@ void action_exec(keyevent_t event)
static void process(keyevent_t event)
{
- action_t action = keymap_get_action(current_layer, event.key.row, event.key.col);
+ action_t action = keymap_get_action(current_layer, event.key.pos.row, event.key.pos.col);
debug("action: "); debug_hex16(action.code);
if (event.pressed) debug("[down]\n"); else debug("[up]\n");
diff --git a/common/keyboard.c b/common/keyboard.c
index 2e32e91e08..ea4d0ee7e6 100644
--- a/common/keyboard.c
+++ b/common/keyboard.c
@@ -66,7 +66,7 @@ void keyboard_task(void)
for (int c = 0; c < MATRIX_COLS; c++) {
if (matrix_change & (1<<c)) {
action_exec((keyevent_t){
- .key = (keypos_t){ .row = r, .col = c },
+ .key.pos = (keypos_t){ .row = r, .col = c },
.pressed = (matrix_row & (1<<c)),
.time = (timer_read() | 1) /* NOTE: 0 means no event */
});
@@ -80,7 +80,7 @@ void keyboard_task(void)
}
// call to update delaying layer when no real event
action_exec((keyevent_t) {
- .key = (keypos_t){ .row = 255, .col = 255 }, // assume this key doesn't exist
+ .key.pos = (keypos_t){ .row = 255, .col = 255 }, // assume this key doesn't exist
.pressed = false,
.time = 0,
});
diff --git a/common/keyboard.h b/common/keyboard.h
index 907ee1f97e..4518cdddc3 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/>.
extern "C" {
#endif
-// TODO: union {raw = row:col}
typedef struct {
- uint8_t row;
uint8_t col;
+ uint8_t row;
} keypos_t;
+typedef union {
+ uint16_t raw;
+ keypos_t pos;
+} key_t;
+
typedef struct {
- keypos_t key;
+ key_t key;
bool pressed;
uint16_t time;
} keyevent_t;
-#define KEYEQ(keya, keyb) (keya.row == keyb.row && keya.col == keyb.col)
+#define KEYEQ(keya, keyb) (keya.raw == keyb.raw)
#define IS_NOEVENT(event) (event.time == 0)
#define NOEVENT (keyevent_t) { \
.key = (keypos_t){ .row = 255, .col = 255 }, \