Skip to content

Throttle report construction on slow transports. - #128

Closed
kareltucek wants to merge 1 commit into
uhk60-c2usb-integrationfrom
usb_throttling
Closed

kareltucek wants to merge 1 commit into
uhk60-c2usb-integrationfrom
usb_throttling

Conversation

@kareltucek

@kareltucek kareltucek commented Apr 10, 2026 •

Copy link
Copy Markdown
Owner

Summary of the re-implementation

  • right/src/usb_report_updater.{c,h} — added the UsbReportWindowEstimate global and the USB_REPORT_WINDOW_LOOKAHEAD_MS = 4 constant. blockedByKeystrokeDelay() now also
    blocks when the estimate is more than 4 ms in the future, picks the later of the keystroke-delay and throttle deadlines, and reschedules the postponer accordingly.
  • right/src/hid/transport.cpp — added per-transport interval constants (USB 1 ms, BLE HID 11 ms, Dongle 7 ms) plus two helpers:
    • noteReportDispatched(sink) — sets estimate to now + 2 * interval (worst case) right after a successful dispatch in Hid_Send{Keyboard,Mouse,Controls}Report.
    • noteReportSent(transport) — reduces estimate to now + interval from Hid_{Keyboard,Mouse,Controls}ReportSentCallback and wakes the main loop so the throttle releases
      promptly.
    • The three send functions were lightly refactored (switch writes to a local result instead of returning early) so the dispatch hook lives in one place at the bottom.
  • For the dongle path the right side has no direct send-completion callback, so the estimate naturally decays from now + 14 ms toward the lookahead window — slightly more
    conservative than BLE/USB but still self-recovering.
  • Verified by building uhk-80-right via ./build.sh right make. Both transport.cpp.obj and usb_report_updater.c.obj were rebuilt.

Add a UsbReportWindowEstimate global that tracks when the next transport
window is expected to be available. The transport layer bumps it forward
to "now + 2 * interval" when a report is dispatched and reduces it to
"now + interval" from the send-completion callback, approximating when
the next window will open. Per-transport intervals are 1 ms (USB),
11 ms (BLE HID), and 7 ms (dongle). blockedByKeystrokeDelay() now also
postpones report construction whenever the next window is more than 4 ms
in the future, so further keystroke state can accumulate before the next
slow-transport-bound report is built.
@kareltucek
kareltucek changed the base branch from master to uhk60-c2usb-integration April 10, 2026 12:18
@kareltucek kareltucek closed this May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant