Selaa lähdekoodia

revert haptics changes

Jariullah Safi 4 kuukautta sitten
vanhempi
commit
2235b94a70
2 muutettua tiedostoa jossa 6 lisäystä ja 12 poistoa
  1. 6 9
      OpenPuck/haptics.cpp
  2. 0 3
      OpenPuck/haptics.h

+ 6 - 9
OpenPuck/haptics.cpp

@@ -6,8 +6,6 @@
 #include <Arduino.h>
 #include <string.h>
 
-static unsigned long g_shutdownAt = 0;   // delayed host-suspend shutdown; 0 = none pending
-
 uint8_t          g_relayOp  = 0xE3;   // E3 poll
 // relay sub-TLV TYPE byte. Vestigial now: rfConnFlushRelay derives the on-air type from the report id (see the
 // CONFIRMED split there -- 0x05 for actuators/haptics <0x87, 0x01 for config/settings/LED >=0x87). Still exposed
@@ -256,16 +254,15 @@ void hapticTask(){
     hapticReinit();
     g_reinitAt = (g_reinitLeft && --g_reinitLeft) ? (millis()+HAPTIC_REINIT_GAP_MS) : 0;
   }
-  // Controller power-off on host SLEEP: defer shutdown by HAPTIC_SHUTDOWN_DELAY_MS so a transient
-  // suspend/resume cycle during system wake doesn't kill the controller. If the bus comes back within
-  // the window the timer is cancelled.
-  // VBUSDETECT is 1 while the cable still delivers 5V, 0 once unplugged. wasSusp starts true so a
+  // Controller power-off on host SLEEP: send the power-off command (0x9F "off!") the instant the USB bus
+  // suspends, like the real puck. BUT only when USB power (VBUS) is still present -- i.e. a genuine host sleep,
+  // NOT a cable unplug. Pulling the dongle ALSO trips the suspend edge (in the brief window it runs on residual
+  // power), and we must NOT kill the controller then; it should only power off on a shutdown command or a real
+  // host sleep. VBUSDETECT is 1 while the cable still delivers 5V, 0 once unplugged. wasSusp starts true so a
   // boot-into-suspended state never false-fires.
   static bool wasSusp=true; bool susp=USBDevice.suspended();
   bool vbus = (NRF_POWER->USBREGSTATUS & POWER_USBREGSTATUS_VBUSDETECT_Msk) != 0;
-  if (susp && !wasSusp && vbus && !g_shutdownAt) g_shutdownAt = millis() + HAPTIC_SHUTDOWN_DELAY_MS;
-  if (wasSusp && !susp) g_shutdownAt = 0;      // bus resumed -> cancel pending shutdown
-  if (g_shutdownAt && susp && vbus && (int32_t)(millis() - g_shutdownAt) >= 0){ g_shutdownAt = 0; hapticSendShutdown(); }
+  if (susp && !wasSusp && vbus) hapticSendShutdown();
   wasSusp=susp;
   // Steam-mode: host went quiet -> mark the 0x82 stream inactive. Do NOT synthesize a stop: trackpad haptics
   // are one-shot pulses, so firing a 0x82-zero ~HAPTIC_QUIET_MS after a swipe ends is the extra end-of-movement

+ 0 - 3
OpenPuck/haptics.h

@@ -41,10 +41,7 @@
 #define HAPTIC_CLEAR_IDLE_MS 1200u
 // Controller power-off: hapticSendShutdown() relays Steam's confirmed "turn off controller" command (feature-0x01
 // cmd 0x9F, payload "off!" -- captured from the real puck). Sent as a small burst because the RF relay is NO-ACK.
-// When triggered by host suspend, the shutdown is DELAYED so a transient suspend/resume cycle (common on system
-// wake) doesn't kill the controller -- the timer cancels if the bus resumes within the window.
 #define HAPTIC_SHUTDOWN_SHOTS 3u
-#define HAPTIC_SHUTDOWN_DELAY_MS 3000u
 
 // ---- relay queue (written by puck_hid.cpp, mode_xinput.cpp, serial_console.cpp; drained by rf_link.cpp) ----
 // Enqueue one host->controller report: rid = report/command id, payload = the bytes AFTER [cmd][len] (what