浏览代码

remove lizard delay

Jariullah Safi 4 月之前
父节点
当前提交
43573d83eb
共有 3 个文件被更改,包括 16 次插入 和 9 次删除
  1. 1 1
      ARCHITECTURE.md
  2. 12 6
      OpenPuck/puck_hid.cpp
  3. 3 2
      OpenPuck/puck_hid.h

+ 1 - 1
ARCHITECTURE.md

@@ -74,7 +74,7 @@ just points at the `OpenPuck` directory). Modules are layered low → high:
 | `gamepad_util.{h,cpp}` | Cross-mode helpers for building host reports: stick rescaling, Steam-trackpad → touch mapping, PlayStation-layout button packers. |
 | `haptics.{h,cpp}` | Host→controller haptic relay queue + the watchdogs that stop a latched buzz; the OUTPUT-report capture ring. |
 | **`controllers.{h,cpp}`** | The `IController` abstraction + the `mode → singleton` registry. |
-| `puck_hid.{h,cpp}` | **Steam/Lizard** personality: the puck HID slot interfaces, the feature command channel (bond read/write, attributes), the auto-lizard decision, and the USB connection presentation. |
+| `puck_hid.{h,cpp}` | **Steam/Lizard** personality: the puck HID slot interfaces, the feature command channel (bond read/write, attributes), the seamless auto-lizard decision, and the USB connection presentation. |
 | `mode_lizard.{h,cpp}` | The lizard keyboard+mouse mapping (rides on the puck interface; not a standalone controller). |
 | `mode_xinput.{h,cpp}` | **Xbox** personality: a custom TinyUSB XInput class driver + right-pad mouse + rumble relay. |
 | `mode_switch_hori.{h,cpp}` | **Switch HORIPAD** personality (console-friendly, no handshake). |

+ 12 - 6
OpenPuck/puck_hid.cpp

@@ -45,20 +45,26 @@ static Adafruit_USBD_HID hid[NSLOT];
 
 // ===================== seamless LIZARD decision =====================
 // Steam, while running, re-sends settings report 0x87 (lizard-off) every ~3s as a heartbeat (captured on HW),
-// and ANY OUTPUT report likewise stamps g_steamAliveMs. When the heartbeat stops we fall back to lizard.
+// and ANY OUTPUT report likewise stamps g_steamAliveMs. When the heartbeat stops we fall back to lizard, so the
+// controller drives desktop keyboard+mouse whenever Steam isn't running. MODE_LIZARD forces lizard always.
 static unsigned long g_steamAliveMs = 0;   // millis of last Steam OUTPUT/settings write; 0 at boot => lizard until Steam appears
-#define LIZARD_WD_MS 7000u                  // fall back to lizard this long after the heartbeat stops (>2x the 3s cadence)
+// Fall back to lizard this long after Steam's ~3s settings heartbeat stops. This CANNOT go below ~3s: the only
+// "Steam closed" signal is the absence of that beat, so a shorter window would flip to lizard in the gaps
+// while Steam is still running (lizard mid-game). 4s is just above the cadence -> near-minimal switch delay
+// while Steam quits. The heartbeat rides USB (reliable, unlike the RF link), so a dropped beat is a non-issue;
+// no need for the old 7s (>2x) padding.
+#define LIZARD_WD_MS 4000u
 static bool g_autoLizard = true;            // master switch; false => Steam mode always forwards 0x45
+// Single source of truth, shared by the USB input path AND the haptic relay gate: if we ever relay a 0x82 to
+// the controller while presenting lizard (Steam isn't reading 0x45 back), Steam loops the same haptic -> buzz.
+static inline bool steamDrivingGamepad(){ return g_steamAliveMs && (millis()-g_steamAliveMs < LIZARD_WD_MS); }
+static inline bool lizardActive(){ return modeIsPuck(g_usbMode) && (g_usbMode==MODE_LIZARD || (g_autoLizard && !steamDrivingGamepad())); }
 // Right after the host resumes from suspend, MUTE input forwarding briefly. Otherwise the controller's input
 // in that instant (a trackpad click/trigger, or residual button state from the wake gesture) gets forwarded
 // as a real click/keypress into the just-woken desktop -- which was activating the highlighted Start tile
 // (Edge) and closing the Start menu on every wake. Set when task() sees the suspended->active transition.
 static unsigned long g_resumeMs = 0;
 #define POST_RESUME_MUTE_MS 1500u
-// Single source of truth, shared by the USB input path AND the haptic relay gate: if we ever relay a 0x82 to
-// the controller while presenting lizard (Steam isn't reading 0x45 back), Steam loops the same haptic -> buzz.
-static inline bool steamDrivingGamepad(){ return g_steamAliveMs && (millis()-g_steamAliveMs < LIZARD_WD_MS); }
-static inline bool lizardActive(){ return modeIsPuck(g_usbMode) && (g_usbMode==MODE_LIZARD || (g_autoLizard && !steamDrivingGamepad())); }
 
 // ===================== puck feature command channel =====================
 // `slot` is the interface index (interface N == bond slot N).

+ 3 - 2
OpenPuck/puck_hid.h

@@ -6,8 +6,9 @@
 //     uses to read attributes/serials and read/write/clear bond slots, plus the host->controller haptic relay
 //     ride-along on OUTPUT reports 0x80-0x86 and feature passthrough (report 0x01).
 //   - the seamless LIZARD decision: when Steam is driving the gamepad (recent OUTPUT/heartbeat) we forward the
-//     gamepad report 0x45; when Steam is closed we present keyboard+mouse on the SAME interface. lizardActive()
-//     is the single source of truth, shared with the haptic gate so we never buzz while Steam isn't reading.
+//     gamepad report 0x45; when Steam is closed we present keyboard+mouse on the SAME interface. MODE_LIZARD
+//     forces lizard always. lizardActive() is the single source of truth, shared with the haptic gate so we
+//     never relay haptics while presenting lizard (Steam isn't reading 0x45 back -> would buzz-loop).
 //   - the USB connection-state presentation (reports 0x79 / 0x7B) Steam reads to mark the controller connected.
 #pragma once
 #include "controllers.h"