@@ -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,8 @@ 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 .pair_delay = 10
160
143
161
144
self ._current_conn = ""
162
145
@@ -264,6 +247,25 @@ def stop_advertising(self):
264
247
except Exception as e :
265
248
print (e )
266
249
250
+ def is_tapped (self , matrix , key ):
251
+ """Check if the key is tapped (press & release quickly)"""
252
+ n = len (matrix )
253
+ if n == 0 :
254
+ n = matrix .wait (self .tap_delay - matrix .ms (matrix .time () - matrix .get_keydown_time (key )))
255
+ target = key | 0x80
256
+ if n == 1 :
257
+ if target == matrix .view (0 ):
258
+ return True
259
+ else :
260
+ n = matrix .wait (
261
+ 200 - matrix .ms (matrix .time () - matrix .get_keydown_time (key ))
262
+ )
263
+ if n == 2 and target == matrix .view (1 ):
264
+ # Fast typing: A down, B down, A up, B up
265
+ return True
266
+
267
+ return False
268
+
267
269
def change_bt (self , n ):
268
270
if self .ble .connected :
269
271
for c in self .ble .connections :
@@ -396,7 +398,7 @@ def run(self):
396
398
key = matrix .view (0 )
397
399
if key < 0x80 and key in self .pair_keys :
398
400
n = matrix .wait (
399
- 10 - ms (matrix .time () - matrix .get_keydown_time (key ))
401
+ self . pair_delay - ms (matrix .time () - matrix .get_keydown_time (key ))
400
402
)
401
403
402
404
if n >= 2 :
@@ -438,7 +440,7 @@ def run(self):
438
440
self .press (* keycodes )
439
441
elif kind < ACT_USAGE :
440
442
# MODS_TAP
441
- if is_tapped (matrix , key ):
443
+ if self . is_tapped (matrix , key ):
442
444
log ("TAP" )
443
445
keycode = action_code & 0xFF
444
446
keys [key ] = keycode
@@ -462,7 +464,7 @@ def run(self):
462
464
keycodes = mods_to_keycodes (mods )
463
465
self .press (* keycodes )
464
466
self .layer_mask |= mask
465
- elif is_tapped (matrix , key ):
467
+ elif self . is_tapped (matrix , key ):
466
468
log ("TAP" )
467
469
keycode = action_code & 0xFF
468
470
if keycode == OP_TAP_TOGGLE :
0 commit comments