mirror of
https://github.com/MCKero6423/uv-k5-v3-emulator.git
synced 2026-10-02 03:15:36 +00:00
Cut key latency: fire at pointerdown and shorten the tap
Two changes, both aimed only at latency, since that is what the link makes expensive. 1. Send on pointerdown instead of pointerup. Waiting for release left the network idle for the entire click. The duration is unknown at that moment, so the speculative request asks for a short press; holding past LONG_PRESS_AFTER_MS sends a second, deliberately long press, which is how held events stay reachable. 2. TAP_MS 200 -> 60 ms. The server blocks for hold_ms before replying, so this is latency the user pays directly. 200 ms was a guess that gave back most of what change 1 saved. The 60 ms is measured, and the sample size mattered: at 4 trials per value 30 ms looked reliable, but at 12 trials 20 ms registered only 5/12 while 30 ms was 12/12. The nominal 20 ms debounce is not sufficient alone because KEYBOARD_Poll samples each column 8 times wanting 2 matching reads. 60 ms is double the proven floor. Click-to-visible at 400 ms RTT, where one round trip is an unavoidable 400 ms: original (2 requests, on release) 2525 ms (+2125 over the floor) one request, on release 657 ms (+257) current (1 request, on press) 505 ms (+105) Long press still works: a 60 ms press opens the menu (gScreenToDisplay 0 -> 1) while a 900 ms press is treated as held and correctly does not, so the firmware still distinguishes them. Also drops MIN_HOLD_MS, now dead: the browser no longer measures press duration, so there is no measurement to clamp. Its test asserted only that the string appeared, which would have kept passing over dead code.
This commit is contained in:
1 parent
c6d58f5601
commit
20e7577257
2 files changed
+97
-26
No files matched your search
+41
-6
@@ -207,17 +207,14 @@ class TestFrontEndHoldMs(unittest.TestCase):
|
||||
def test_sends_hold_ms(self):
|
||||
self.assertIn("hold_ms", self.body)
|
||||
|
||||
def test_measures_press_duration_in_the_browser(self):
|
||||
self.assertIn("performance.now()", self.body)
|
||||
|
||||
def test_does_not_send_separate_down_and_up_for_taps(self):
|
||||
"""Two requests per key double the latency and break at 400 ms RTT."""
|
||||
self.assertNotIn("send(key, 'down')", self.body)
|
||||
self.assertNotIn("send(key, 'up')", self.body)
|
||||
|
||||
def test_enforces_a_minimum_hold(self):
|
||||
"""A very fast click still has to clear the 20 ms debounce."""
|
||||
self.assertIn("MIN_HOLD_MS", self.body)
|
||||
def test_uses_a_measured_tap_length(self):
|
||||
"""The tap length is a server-side constant, not a browser measurement."""
|
||||
self.assertIn("TAP_MS", self.body)
|
||||
|
||||
|
||||
class TestStreamUsesPump(unittest.TestCase):
|
||||
@@ -471,5 +468,43 @@ class TestStartsPoweredOff(unittest.TestCase):
|
||||
self.assertNotIn("supervisor.power_on()", src)
|
||||
|
||||
|
||||
class TestOptimisticSend(unittest.TestCase):
|
||||
"""The request must leave on pointerdown, not on release.
|
||||
|
||||
Waiting for pointerup spends the whole click duration with the network idle:
|
||||
on a 400 ms link a 120 ms click cost 650 ms click-to-visible instead of 530 ms,
|
||||
because nothing was in flight while the button was down.
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
_, http = make_app()
|
||||
self.body = http.get("/").get_data(as_text=True)
|
||||
|
||||
def test_sends_from_pointerdown(self):
|
||||
# down() must issue the request itself rather than only recording a time.
|
||||
down_fn = self.body.split("function down(key)")[1].split("function up(")[0]
|
||||
self.assertIn("sendKey(", down_fn,
|
||||
"down() must fire the request immediately")
|
||||
|
||||
def test_up_does_not_send_the_press(self):
|
||||
up_fn = self.body.split("function up(key)")[1].split("}")[0]
|
||||
self.assertNotIn("sendKey(", up_fn,
|
||||
"up() must not be where the press is sent")
|
||||
|
||||
def test_long_press_is_still_reachable(self):
|
||||
"""Holding must still produce a held event, or long-press breaks."""
|
||||
self.assertIn("LONG_PRESS_MS", self.body)
|
||||
self.assertIn("LONG_PRESS_AFTER_MS", self.body)
|
||||
|
||||
def test_long_press_threshold_is_past_the_firmware_boundary(self):
|
||||
"""Must exceed 400 ms or the firmware will not call it held."""
|
||||
self.assertGreater(webui.LONG_PRESS_MS, 400)
|
||||
self.assertGreaterEqual(webui.LONG_PRESS_AFTER_MS, 400)
|
||||
|
||||
def test_optimistic_hold_is_a_short_press(self):
|
||||
"""The speculative press must stay under the held threshold."""
|
||||
self.assertLess(webui.TAP_MS, 400)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user