@@ -82,7 +82,6 @@ def reset_into_bootloader():
82
82
microcontroller .reset ()
83
83
84
84
85
-
86
85
class Device :
87
86
def __init__ (self , kbd ):
88
87
self .kbd = kbd
@@ -248,21 +247,38 @@ def stop_advertising(self):
248
247
except Exception as e :
249
248
print (e )
250
249
251
- def is_tap_key (self , matrix , key ):
250
+ def is_tapping_key (self , key ):
252
251
"""Check if the key is tapped (press & release quickly)"""
252
+ matrix = self .matrix
253
253
n = len (matrix )
254
254
if n == 0 :
255
- n = matrix .wait (self .tap_delay - matrix .ms (matrix .time () - matrix .get_keydown_time (key )))
255
+ n = matrix .wait (
256
+ self .tap_delay - matrix .ms (matrix .time () - matrix .get_keydown_time (key ))
257
+ )
256
258
target = key | 0x80
257
- if n == 1 :
258
- if target == matrix .view (0 ):
259
+ if n >= 1 :
260
+ new_key = matrix .view (0 )
261
+ if new_key == target :
259
262
return True
260
- else :
263
+ if new_key >= 0x80 :
264
+ # Fast Typing - B is a tap-key
265
+ # A↓ B↓ A↑ B↑
266
+ # --+-------+-------+-------+------> t
267
+ # | dt1 |
268
+ # dt1 < tap_delay
269
+ return True
270
+
271
+ if n == 1 :
261
272
n = matrix .wait (
262
- self .fast_type_thresh - matrix .ms (matrix .time () - matrix .get_keydown_time (key ))
273
+ self .fast_type_thresh
274
+ - matrix .ms (matrix .time () - matrix .get_keydown_time (new_key ))
263
275
)
264
- if n == 2 and target == matrix .view (1 ):
265
- # Fast typing: A down, B down, A up, B up
276
+ if n >= 2 and target == matrix .view (1 ):
277
+ # Fast Typing - B is a tap-key
278
+ # B↓ C↓ B↑ C↑
279
+ # --+-------+-------+-------+------> t
280
+ # | dt1 | dt2 |
281
+ # dt1 < tap_delay && dt2 < fast_type_thresh
266
282
return True
267
283
268
284
return False
@@ -399,7 +415,8 @@ def run(self):
399
415
key = matrix .view (0 )
400
416
if key < 0x80 and key in self .pair_keys :
401
417
n = matrix .wait (
402
- self .pair_delay - ms (matrix .time () - matrix .get_keydown_time (key ))
418
+ self .pair_delay
419
+ - ms (matrix .time () - matrix .get_keydown_time (key ))
403
420
)
404
421
405
422
if n >= 2 :
@@ -441,7 +458,7 @@ def run(self):
441
458
self .press (* keycodes )
442
459
elif kind < ACT_USAGE :
443
460
# MODS_TAP
444
- if self .is_tap_key ( matrix , key ):
461
+ if self .is_tapping_key ( key ):
445
462
log ("TAP" )
446
463
keycode = action_code & 0xFF
447
464
keys [key ] = keycode
@@ -465,7 +482,7 @@ def run(self):
465
482
keycodes = mods_to_keycodes (mods )
466
483
self .press (* keycodes )
467
484
self .layer_mask |= mask
468
- elif self .is_tap_key ( matrix , key ):
485
+ elif self .is_tapping_key ( key ):
469
486
log ("TAP" )
470
487
keycode = action_code & 0xFF
471
488
if keycode == OP_TAP_TOGGLE :
0 commit comments