Sfoglia il codice sorgente

fix compile issue and other logic errors

Jariullah Safi 4 mesi fa
parent
commit
51c583f529
2 ha cambiato i file con 8 aggiunte e 2 eliminazioni
  1. 1 1
      OpenPuck/mode_lizard.cpp
  2. 7 1
      OpenPuck/puck_hid.cpp

+ 1 - 1
OpenPuck/mode_lizard.cpp

@@ -56,7 +56,7 @@ void rfLizard(const uint8_t* r, Adafruit_USBD_HID* mdev, Adafruit_USBD_HID* kdev
     if (!nL5 && prevL5){ uint8_t cc=0x00; if(mdev->ready()) mdev->sendReport(0x03,&cc,1); }  // release
     if (!nR5 && prevR5){ uint8_t cc=0x00; if(mdev->ready()) mdev->sendReport(0x03,&cc,1); }
     prevL5=nL5; prevR5=nR5;
-    if(sh && (b & TB_X)){ mod=KEYBOARD_MODIFIER_LEFT_GUI|KEYBOARD_MODIFIER_LEFTCTRL; kc[0]=HID_KEY_O; kc[1]=0; kc[2]=0; kc[3]=0; kc[4]=0; kc[5]=0; nk=1; }
+    if(sh && (b & TB_X)){ mod=KEYBOARD_MODIFIER_LEFTGUI|KEYBOARD_MODIFIER_LEFTCTRL; kc[0]=HID_KEY_O; kc[1]=0; kc[2]=0; kc[3]=0; kc[4]=0; kc[5]=0; nk=1; }
   }
   static uint8_t pmod=0, pkc[6]={0,0,0,0,0,0};
   bool chg=(mod!=pmod); for(int i=0;i<6;i++) if(kc[i]!=pkc[i]) chg=true;

+ 7 - 1
OpenPuck/puck_hid.cpp

@@ -270,8 +270,14 @@ static void wakeNudgeTask(){
 // connected. Without it Steam shows disconnected even though 0x45 input is streaming.
 void SteamPuckController::task(){
   wakeNudgeTask();
-  { static bool wasSusp=false; bool susp=USBDevice.suspended();   // stamp the suspended->active edge for the post-resume mute
+  { static bool wasSusp=false; bool susp=USBDevice.suspended();
     if(wasSusp && !susp) g_resumeMs=millis();
+    // Delayed shutdown on host sleep: arm 3s timer on suspend edge, cancel on resume. Prevents transient
+    // suspend/resume cycles during system wake from killing the controller.
+    static unsigned long shutAt=0;
+    if(susp && !wasSusp) shutAt=millis()+3000u;
+    if(!susp && wasSusp) shutAt=0;
+    if(susp && shutAt && (int32_t)(millis()-shutAt)>=0){ shutAt=0; hapticSendShutdown(); }
     wasSusp=susp; }
   if (USBDevice.suspended()) return;   // no periodic 0x79/0x7B while the host sleeps -- those sends can wake it too
   static bool usbConn=false; static unsigned long last79=0, last7B=0, connEdgeMs=0;