2021-12-30 05:17:34 +01:00
|
|
|
// Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2017-11-17 20:59:54 +01:00
|
|
|
|
2017-11-07 06:11:08 +01:00
|
|
|
#include "drashna.h"
|
|
|
|
|
2018-05-02 17:39:46 +02:00
|
|
|
userspace_config_t userspace_config;
|
|
|
|
|
2019-07-23 05:22:33 +02:00
|
|
|
bool mod_key_press_timer(uint16_t code, uint16_t mod_code, bool pressed) {
|
2019-05-07 07:34:09 +02:00
|
|
|
static uint16_t this_timer;
|
2019-07-23 05:22:33 +02:00
|
|
|
if (pressed) {
|
|
|
|
this_timer = timer_read();
|
2019-05-07 07:34:09 +02:00
|
|
|
} else {
|
2019-07-23 05:22:33 +02:00
|
|
|
if (timer_elapsed(this_timer) < TAPPING_TERM) {
|
2019-05-07 07:34:09 +02:00
|
|
|
tap_code(code);
|
|
|
|
} else {
|
|
|
|
register_code(mod_code);
|
|
|
|
tap_code(code);
|
|
|
|
unregister_code(mod_code);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2018-07-17 03:04:32 +02:00
|
|
|
}
|
|
|
|
|
2019-07-23 05:22:33 +02:00
|
|
|
bool mod_key_press(uint16_t code, uint16_t mod_code, bool pressed, uint16_t this_timer) {
|
|
|
|
if (pressed) {
|
|
|
|
this_timer = timer_read();
|
2019-05-07 07:34:09 +02:00
|
|
|
} else {
|
2019-07-23 05:22:33 +02:00
|
|
|
if (timer_elapsed(this_timer) < TAPPING_TERM) {
|
2019-05-07 07:34:09 +02:00
|
|
|
tap_code(code);
|
|
|
|
} else {
|
|
|
|
register_code(mod_code);
|
|
|
|
tap_code(code);
|
|
|
|
unregister_code(mod_code);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2018-07-17 03:04:32 +02:00
|
|
|
}
|
2017-11-17 20:59:54 +01:00
|
|
|
|
2019-10-16 22:11:22 +02:00
|
|
|
bool hasAllBitsInMask(uint8_t value, uint8_t mask) {
|
|
|
|
value &= 0xF;
|
|
|
|
mask &= 0xF;
|
|
|
|
|
|
|
|
return (value & mask) == mask;
|
|
|
|
}
|
2021-08-21 22:34:44 +02:00
|
|
|
|
2021-12-30 05:17:34 +01:00
|
|
|
void tap_code16_nomods(uint8_t kc) {
|
|
|
|
uint8_t temp_mod = get_mods();
|
|
|
|
clear_mods();
|
|
|
|
clear_oneshot_mods();
|
|
|
|
tap_code16(kc);
|
|
|
|
set_mods(temp_mod);
|
2021-11-10 15:10:00 +01:00
|
|
|
}
|