@@ -82,25 +82,6 @@ def reset_into_bootloader():
82
82
microcontroller .reset ()
83
83
84
84
85
- def is_tapped (matrix , key ):
86
- """Check if the key is tapped (press & release quickly)"""
87
- n = len (matrix )
88
- if n == 0 :
89
- n = matrix .wait (500 - matrix .ms (matrix .time () - matrix .get_keydown_time (key )))
90
- target = key | 0x80
91
- if n == 1 :
92
- if target == matrix .view (0 ):
93
- return True
94
- else :
95
- n = matrix .wait (
96
- 200 - matrix .ms (matrix .time () - matrix .get_keydown_time (key ))
97
- )
98
- if n == 2 and target == matrix .view (1 ):
99
- # Fast typing: A down, B down, A up, B up
100
- return True
101
-
102
- return False
103
-
104
85
105
86
class Device :
106
87
def __init__ (self , kbd ):
@@ -157,6 +138,9 @@ def __init__(self, keymap=KEYMAP, pairs=(), verbose=True):
157
138
self .uid = microcontroller .cpu .uid * 2
158
139
self .usb_status = 0
159
140
self .leds = None
141
+ self .tap_delay = 500
142
+ self .fast_type_thresh = 200
143
+ self .pair_delay = 10
160
144
161
145
self ._current_conn = ""
162
146
@@ -264,6 +248,25 @@ def stop_advertising(self):
264
248
except Exception as e :
265
249
print (e )
266
250
251
+ def is_tap_key (self , matrix , key ):
252
+ """Check if the key is tapped (press & release quickly)"""
253
+ n = len (matrix )
254
+ if n == 0 :
255
+ n = matrix .wait (self .tap_delay - matrix .ms (matrix .time () - matrix .get_keydown_time (key )))
256
+ target = key | 0x80
257
+ if n == 1 :
258
+ if target == matrix .view (0 ):
259
+ return True
260
+ else :
261
+ n = matrix .wait (
262
+ self .fast_type_thresh - matrix .ms (matrix .time () - matrix .get_keydown_time (key ))
263
+ )
264
+ if n == 2 and target == matrix .view (1 ):
265
+ # Fast typing: A down, B down, A up, B up
266
+ return True
267
+
268
+ return False
269
+
267
270
def change_bt (self , n ):
268
271
if self .ble .connected :
269
272
for c in self .ble .connections :
@@ -396,7 +399,7 @@ def run(self):
396
399
key = matrix .view (0 )
397
400
if key < 0x80 and key in self .pair_keys :
398
401
n = matrix .wait (
399
- 10 - ms (matrix .time () - matrix .get_keydown_time (key ))
402
+ self . pair_delay - ms (matrix .time () - matrix .get_keydown_time (key ))
400
403
)
401
404
402
405
if n >= 2 :
@@ -438,7 +441,7 @@ def run(self):
438
441
self .press (* keycodes )
439
442
elif kind < ACT_USAGE :
440
443
# MODS_TAP
441
- if is_tapped (matrix , key ):
444
+ if self . is_tap_key (matrix , key ):
442
445
log ("TAP" )
443
446
keycode = action_code & 0xFF
444
447
keys [key ] = keycode
@@ -462,7 +465,7 @@ def run(self):
462
465
keycodes = mods_to_keycodes (mods )
463
466
self .press (* keycodes )
464
467
self .layer_mask |= mask
465
- elif is_tapped (matrix , key ):
468
+ elif self . is_tap_key (matrix , key ):
466
469
log ("TAP" )
467
470
keycode = action_code & 0xFF
468
471
if keycode == OP_TAP_TOGGLE :
0 commit comments