From 0c53e49a50a454b895c3a60a848ddb38fd33e1e5 Mon Sep 17 00:00:00 2001 From: Naxdy Date: Thu, 4 Apr 2024 18:51:10 +0200 Subject: [PATCH] feat(hid): improve rate limiting in SuperHack mode --- src/gcc_hid.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/gcc_hid.rs b/src/gcc_hid.rs index 47e0563..c444a1b 100644 --- a/src/gcc_hid.rs +++ b/src/gcc_hid.rs @@ -361,7 +361,6 @@ pub async fn usb_transfer_task(raw_serial: [u8; 8], driver: Driver<'static, USB> let mut gcc_subscriber = CHANNEL_GCC_STATE.subscriber().unwrap(); let mut last_report_time = Instant::now(); - let mut last_loop_time = Instant::now(); let mut ticker = Ticker::every(Duration::from_micros(8333)); loop { @@ -378,12 +377,10 @@ pub async fn usb_transfer_task(raw_serial: [u8; 8], driver: Driver<'static, USB> InputConsistencyMode::SuperHack => { // In SuperHack mode, we send reports only if the state changes, but // in order to not mess up very fast inputs (like sticks travelling, for example), - // we still need a delay that is higher than the polling rate, but ideally also - // a multiple/divisor of the game's frame rate. - // This doesn't quite hit the 8.33ms every time though, so inputs during lots of - // stick movement might still be a bit off. - Timer::at(last_loop_time + Duration::from_micros(8333)).await; - last_loop_time = Instant::now(); + // we still need to "rate limit" the reports to every 8.33ms at most. + // This does rate limit it to ~8.33ms fairly well, my only + // gripe with it is that I hate it :) + Timer::at(last_report_time + Duration::from_micros(8100)).await; } InputConsistencyMode::ConsistencyHack => { // Ticker better maintains a consistent interval than Timer, so