summaryrefslogtreecommitdiff
path: root/tmk_core/common
diff options
context:
space:
mode:
authorJoe Wasson <jwasson+github@gmail.com>2016-07-28 01:24:06 -0700
committerJoe Wasson <jwasson+github@gmail.com>2016-08-20 17:46:53 -0700
commit8090f6b499fd87ddeb7a191f7bc3dace9d03be23 (patch)
treed0769eecb8f2b236732b8d713d06cb66833535d7 /tmk_core/common
parentdd378601608849679ead6e2cccb74f7f29c131dc (diff)
downloadqmk_firmware-8090f6b499fd87ddeb7a191f7bc3dace9d03be23.tar.gz
qmk_firmware-8090f6b499fd87ddeb7a191f7bc3dace9d03be23.zip
Improve one-hand support by adding more actions and tap keys.
Diffstat (limited to 'tmk_core/common')
-rw-r--r--tmk_core/common/action.c57
-rw-r--r--tmk_core/common/action_code.h28
2 files changed, 77 insertions, 8 deletions
diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c
index 0413b1a997..08ef22eb97 100644
--- a/tmk_core/common/action.c
+++ b/tmk_core/common/action.c
@@ -465,14 +465,55 @@ void process_action(keyrecord_t *record, action_t action)
break;
#endif
case ACT_COMMAND:
- switch (action.command.id) {
+ break;
#ifdef ONEHAND_ENABLE
- case CMD_SWAP_HANDS:
+ case ACT_SWAP_HANDS:
+ switch (action.swap.code) {
+ case OP_SH_TOGGLE:
+ if (event.pressed) {
+ swap_hands = !swap_hands;
+ }
+ break;
+ case OP_SH_ON_OFF:
swap_hands = event.pressed;
break;
-#endif
+ case OP_SH_OFF_ON:
+ swap_hands = !event.pressed;
+ break;
+ case OP_SH_ON:
+ if (!event.pressed) {
+ swap_hands = true;
+ }
+ break;
+ case OP_SH_OFF:
+ if (!event.pressed) {
+ swap_hands = false;
+ }
+ break;
+ #ifndef NO_ACTION_TAPPING
+ case OP_SH_TAP_TOGGLE:
+ /* tap toggle */
+ if (tap_count > 0) {
+ if (!event.pressed) {
+ swap_hands = !swap_hands;
+ }
+ } else {
+ swap_hands = event.pressed;
+ }
+ break;
+ default:
+ if (tap_count > 0) {
+ if (event.pressed) {
+ register_code(action.swap.code);
+ } else {
+ unregister_code(action.swap.code);
+ }
+ } else {
+ swap_hands = event.pressed;
+ }
+ #endif
}
- break;
+#endif
#ifndef NO_ACTION_FUNCTION
case ACT_FUNCTION:
action_function(record, action.func.id, action.func.opt);
@@ -685,6 +726,13 @@ bool is_tap_key(keypos_t key)
return true;
}
return false;
+ case ACT_SWAP_HANDS:
+ switch (action.swap.code) {
+ case 0x00 ... 0xdf:
+ case OP_SH_TAP_TOGGLE:
+ return true;
+ }
+ return false;
case ACT_MACRO:
case ACT_FUNCTION:
if (action.func.opt & FUNC_TAP) { return true; }
@@ -725,6 +773,7 @@ void debug_action(action_t action)
case ACT_MACRO: dprint("ACT_MACRO"); break;
case ACT_COMMAND: dprint("ACT_COMMAND"); break;
case ACT_FUNCTION: dprint("ACT_FUNCTION"); break;
+ case ACT_SWAP_HANDS: dprint("ACT_SWAP_HANDS"); break;
default: dprint("UNKNOWN"); break;
}
dprintf("[%X:%02X]", action.kind.param>>8, action.kind.param&0xff);
diff --git a/tmk_core/common/action_code.h b/tmk_core/common/action_code.h
index 95d2cbf3e4..33da35f35f 100644
--- a/tmk_core/common/action_code.h
+++ b/tmk_core/common/action_code.h
@@ -108,6 +108,8 @@ enum action_kind_id {
/* Other Keys */
ACT_USAGE = 0b0100,
ACT_MOUSEKEY = 0b0101,
+ /* One-hand Support */
+ ACT_SWAP_HANDS = 0b0110,
/* Layer Actions */
ACT_LAYER = 0b1000,
ACT_LAYER_TAP = 0b1010, /* Layer 0-15 */
@@ -178,6 +180,11 @@ typedef union {
uint8_t opt :4;
uint8_t kind :4;
} func;
+ struct action_swap {
+ uint8_t code :8;
+ uint8_t opt :4;
+ uint8_t kind :4;
+ } swap;
} action_t;
@@ -296,9 +303,6 @@ enum backlight_opt {
BACKLIGHT_LEVEL = 4,
};
-enum command_id {
- CMD_SWAP_HANDS = 0x14,
-};
/* Macro */
#define ACTION_MACRO(id) ACTION(ACT_MACRO, (id))
#define ACTION_MACRO_TAP(id) ACTION(ACT_MACRO, FUNC_TAP<<8 | (id))
@@ -319,6 +323,22 @@ enum function_opts {
#define ACTION_FUNCTION_TAP(id) ACTION(ACT_FUNCTION, FUNC_TAP<<8 | (id))
#define ACTION_FUNCTION_OPT(id, opt) ACTION(ACT_FUNCTION, (opt)<<8 | (id))
/* OneHand Support */
-#define ACTION_SWAP_HANDS() ACTION_COMMAND(CMD_SWAP_HANDS, 0)
+enum swap_hands_pram_tap_op {
+ OP_SH_TOGGLE = 0xF0,
+ OP_SH_TAP_TOGGLE,
+ OP_SH_ON_OFF,
+ OP_SH_OFF_ON,
+ OP_SH_OFF,
+ OP_SH_ON,
+};
+
+#define ACTION_SWAP_HANDS() ACTION_SWAP_HANDS_ON_OFF()
+#define ACTION_SWAP_HANDS_TOGGLE() ACTION(ACT_SWAP_HANDS, OP_SH_TOGGLE)
+#define ACTION_SWAP_HANDS_TAP_TOGGLE() ACTION(ACT_SWAP_HANDS, OP_SH_TAP_TOGGLE)
+#define ACTION_SWAP_HANDS_TAP_KEY(key) ACTION(ACT_SWAP_HANDS, key)
+#define ACTION_SWAP_HANDS_ON_OFF() ACTION(ACT_SWAP_HANDS, OP_SH_ON_OFF)
+#define ACTION_SWAP_HANDS_OFF_ON() ACTION(ACT_SWAP_HANDS, OP_SH_OFF_ON)
+#define ACTION_SWAP_HANDS_ON() ACTION(ACT_SWAP_HANDS, OP_SH_ON)
+#define ACTION_SWAP_HANDS_OFF() ACTION(ACT_SWAP_HANDS, OP_SH_OFF)
#endif /* ACTION_CODE_H */