forked from mirrors/qmk_firmware
Add timeout option to MODS_ONESHOT #66
This commit is contained in:
parent
d52d554360
commit
35f9f30074
5 changed files with 44 additions and 30 deletions
|
@ -100,40 +100,29 @@ void process_action(keyrecord_t *record)
|
||||||
action.key.mods<<4;
|
action.key.mods<<4;
|
||||||
switch (action.layer_tap.code) {
|
switch (action.layer_tap.code) {
|
||||||
#ifndef NO_ACTION_ONESHOT
|
#ifndef NO_ACTION_ONESHOT
|
||||||
case 0x00:
|
case MODS_ONESHOT:
|
||||||
// Oneshot modifier
|
// Oneshot modifier
|
||||||
if (event.pressed) {
|
if (event.pressed) {
|
||||||
if (tap_count == 0) {
|
if (tap_count == 0) {
|
||||||
dprint("MODS_TAP: Oneshot: add_mods\n");
|
|
||||||
register_mods(mods);
|
register_mods(mods);
|
||||||
}
|
}
|
||||||
else if (tap_count == 1) {
|
else if (tap_count == 1) {
|
||||||
dprint("MODS_TAP: Oneshot: start\n");
|
dprint("MODS_TAP: Oneshot: start\n");
|
||||||
set_oneshot_mods(mods);
|
set_oneshot_mods(mods);
|
||||||
}
|
}
|
||||||
else if (tap_count == TAPPING_TOGGLE) {
|
|
||||||
dprint("MODS_TAP: Oneshot: toggle\n");
|
|
||||||
oneshot_toggle();
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
dprint("MODS_TAP: Oneshot: cancel&add_mods\n");
|
|
||||||
// double tap cancels oneshot and works as normal modifier.
|
|
||||||
clear_oneshot_mods();
|
|
||||||
register_mods(mods);
|
register_mods(mods);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (tap_count == 0) {
|
if (tap_count == 0) {
|
||||||
dprint("MODS_TAP: Oneshot: cancel/del_mods\n");
|
|
||||||
// cancel oneshot on hold
|
|
||||||
clear_oneshot_mods();
|
clear_oneshot_mods();
|
||||||
unregister_mods(mods);
|
unregister_mods(mods);
|
||||||
}
|
}
|
||||||
else if (tap_count == 1) {
|
else if (tap_count == 1) {
|
||||||
// Oneshot
|
// Retain Oneshot mods
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
dprint("MODS_TAP: Oneshot: del_mods\n");
|
clear_oneshot_mods();
|
||||||
// cancel Mods
|
|
||||||
unregister_mods(mods);
|
unregister_mods(mods);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#include "report.h"
|
#include "report.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "action_util.h"
|
#include "action_util.h"
|
||||||
|
#include "timer.h"
|
||||||
|
|
||||||
static inline void add_key_byte(uint8_t code);
|
static inline void add_key_byte(uint8_t code);
|
||||||
static inline void del_key_byte(uint8_t code);
|
static inline void del_key_byte(uint8_t code);
|
||||||
|
@ -35,17 +36,28 @@ static uint8_t weak_mods = 0;
|
||||||
report_keyboard_t *keyboard_report = &(report_keyboard_t){};
|
report_keyboard_t *keyboard_report = &(report_keyboard_t){};
|
||||||
|
|
||||||
#ifndef NO_ACTION_ONESHOT
|
#ifndef NO_ACTION_ONESHOT
|
||||||
static bool oneshot_enabled = true;
|
|
||||||
static int8_t oneshot_mods = 0;
|
static int8_t oneshot_mods = 0;
|
||||||
|
#if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
|
||||||
|
static int16_t oneshot_time = 0;
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
void send_keyboard_report(void) {
|
void send_keyboard_report(void) {
|
||||||
keyboard_report->mods = real_mods;
|
keyboard_report->mods = real_mods;
|
||||||
keyboard_report->mods |= weak_mods;
|
keyboard_report->mods |= weak_mods;
|
||||||
#ifndef NO_ACTION_ONESHOT
|
#ifndef NO_ACTION_ONESHOT
|
||||||
keyboard_report->mods |= oneshot_mods;
|
if (oneshot_mods) {
|
||||||
if (has_anykey()) {
|
#if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
|
||||||
clear_oneshot_mods();
|
if (TIMER_DIFF_16(timer_read(), oneshot_time) >= ONESHOT_TIMEOUT) {
|
||||||
|
dprintf("Oneshot: timeout\n");
|
||||||
|
clear_oneshot_mods();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
keyboard_report->mods |= oneshot_mods;
|
||||||
|
if (has_anykey()) {
|
||||||
|
clear_oneshot_mods();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
host_keyboard_send(keyboard_report);
|
host_keyboard_send(keyboard_report);
|
||||||
|
@ -99,11 +111,20 @@ void clear_weak_mods(void) { weak_mods = 0; }
|
||||||
|
|
||||||
/* Oneshot modifier */
|
/* Oneshot modifier */
|
||||||
#ifndef NO_ACTION_ONESHOT
|
#ifndef NO_ACTION_ONESHOT
|
||||||
void set_oneshot_mods(uint8_t mods) { oneshot_mods = mods; }
|
void set_oneshot_mods(uint8_t mods)
|
||||||
void clear_oneshot_mods(void) { oneshot_mods = 0; }
|
{
|
||||||
void oneshot_toggle(void) { oneshot_enabled = !oneshot_enabled; }
|
oneshot_mods = mods;
|
||||||
void oneshot_enable(void) { oneshot_enabled = true; }
|
#if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
|
||||||
void oneshot_disable(void) { oneshot_enabled = false; }
|
oneshot_time = timer_read();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
void clear_oneshot_mods(void)
|
||||||
|
{
|
||||||
|
oneshot_mods = 0;
|
||||||
|
#if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
|
||||||
|
oneshot_time = 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -516,13 +516,14 @@ This is a feature to assign both toggle layer and momentary switch layer action
|
||||||
ACTION_LAYER_TAP_TOGGLE(1)
|
ACTION_LAYER_TAP_TOGGLE(1)
|
||||||
|
|
||||||
|
|
||||||
### 4.3 One Shot Modifier
|
### 4.3 Oneshot Modifier
|
||||||
This adds oneshot feature to modifier key. 'One Shot Modifier' is one time modifier which has effect only on following just one key.
|
This runs onetime effect swhich modify only on just one following key. It works as normal modifier key when holding down while oneshot modifier when tapping.
|
||||||
It works as normal modifier key when holding but oneshot modifier when tapping.
|
|
||||||
|
|
||||||
ACTION_MODS_ONESHOT(MOD_LSFT)
|
ACTION_MODS_ONESHOT(MOD_LSFT)
|
||||||
|
|
||||||
Say you want to type 'The', you have to push and hold Shift before type 't' then release Shift before type 'h' and 'e' or you'll get 'THe'. With One Shot Modifier you can tap Shift then type 't', 'h' and 'e' normally, you don't need to holding Shift key properly here.
|
Say you want to type 'The', you have to push and hold Shift key before type 't' then release it before type 'h' and 'e', otherwise you'll get 'THe' or 'the' unintentionally. With Oneshot Modifier you can tap Shift then type 't', 'h' and 'e' normally, you don't need to holding Shift key properly here. This mean you can realease Shift before 't' is pressed down.
|
||||||
|
|
||||||
|
Oneshot effect is cancel unless following key is pressed down within `ONESHOT_TIMEOUT` of `config.h`. No timeout when it is `0` or not defined.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -128,6 +128,8 @@ include $(TOP_DIR)/protocol/lufa.mk
|
||||||
include $(TOP_DIR)/common.mk
|
include $(TOP_DIR)/common.mk
|
||||||
include $(TOP_DIR)/rules.mk
|
include $(TOP_DIR)/rules.mk
|
||||||
|
|
||||||
debug-on: EXTRAFLAGS += -DDEBUG
|
debug-on: EXTRAFLAGS += -DDEBUG -DDEBUG_ACTION
|
||||||
#debug-on: EXTRAFLAGS += -DDEBUG -DDEBUG_ACTION
|
|
||||||
debug-on: all
|
debug-on: all
|
||||||
|
|
||||||
|
debug-off: EXTRAFLAGS += -DNO_DEBUG -DNO_PRINT
|
||||||
|
debug-off: all
|
||||||
|
|
|
@ -40,7 +40,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#define TAPPING_TERM 300
|
#define TAPPING_TERM 300
|
||||||
/* tap count needed for toggling a feature */
|
/* tap count needed for toggling a feature */
|
||||||
#define TAPPING_TOGGLE 5
|
#define TAPPING_TOGGLE 5
|
||||||
|
/* Oneshot timeout(ms) */
|
||||||
|
#define ONESHOT_TIMEOUT 300
|
||||||
|
|
||||||
/* Boot Magic salt key: Space */
|
/* Boot Magic salt key: Space */
|
||||||
#define BOOTMAGIC_KEY_SALT KC_FN6
|
#define BOOTMAGIC_KEY_SALT KC_FN6
|
||||||
|
|
Loading…
Reference in a new issue