Browse Source

Steam + Y shutdown global (#52)

* Steam+Y for 2 seconds will shutdown from any mode

* readme
Jari 4 months ago
parent
commit
c0a27905ae
2 changed files with 18 additions and 0 deletions
  1. 16 0
      OpenPuck/rf_link.cpp
  2. 2 0
      README.md

+ 16 - 0
OpenPuck/rf_link.cpp

@@ -183,6 +183,22 @@ uint8_t rfConnTx(uint8_t ch, uint8_t s1, const uint8_t* payload, uint8_t plen, u
             }
             // Decode the report into the shared g_in (one source, read by every IController).
             g_in.buttons=bb;
+            // Global power-off chord: Steam + Y held 2 s -> shut the controller down (any mode). Detect on the raw
+            // `bb` (pre-mask), time-based (poll rate varies), fires once per hold, re-arms only after release. While
+            // held, mask Steam+Y out of g_in.buttons so the press doesn't leak to the host -- in EVERY mode except
+            // regular Steam (mode 0 forwards the raw 0x45 to Steam, which owns the Steam button). Runs before
+            // onReport45 below so push modes (Xbox) see the mask too; stream modes read g_in in task() (also masked).
+            { static unsigned long offHoldMs=0; static bool offFired=false;
+              if((bb&(TB_STEAM|TB_Y))==(TB_STEAM|TB_Y)){
+                if(offHoldMs==0) offHoldMs=millis();
+                else if(!offFired && (unsigned long)(millis()-offHoldMs)>=2000u){ offFired=true; hapticSendShutdown(); }
+                if(g_usbMode!=MODE_STEAM){
+                  g_in.buttons &= ~(uint32_t)(TB_STEAM|TB_Y);          // stream modes read g_in
+                  ((uint8_t*)rep)[2] &= ~(uint8_t)TB_Y;               // push modes read btnsOf(rep): TB_Y in rep[2],
+                  ((uint8_t*)rep)[4] &= ~(uint8_t)(TB_STEAM>>16);     // TB_STEAM in rep[4]
+                }
+              } else { offHoldMs=0; offFired=false; }
+            }
             g_in.lx=(int16_t)s16off(rep,8);  g_in.ly=(int16_t)s16off(rep,10);
             g_in.rx=(int16_t)s16off(rep,12); g_in.ry=(int16_t)s16off(rep,14);
             g_in.lt=trigU8(u16off(rep,4));   g_in.rt=trigU8(u16off(rep,6));   // for the Switch digital-trigger threshold

+ 2 - 0
README.md

@@ -37,6 +37,8 @@ Similarly you can hold all 4 back buttons and press Y to switch (teehee) over to
 | WebUSB panel → mode 5 | DualSense + Gyro + Trackpad | PC only |
 | WebUSB panel → mode 6 | DS4/HIDGYRO + Gyro + Trackpad | PC only |
 
+I'm also adding various QOL items as I go as well. For example having to hold the Steam button for like 6 seconds feels like an eternity. If Steam is open you can do Steam +Y for a shutdown. I'm adding Steam + Y for 2 seconds as a shutdown chort in ALL modes now.
+
 ### A note on the Lizard mode:
 The Lizard mode behaves similarly to how the controller behaves when Steam is closed, but this will work even when Steam is open. This has a few advantages
 the biggest one being that you can use inputs when a high privilege application is in the foreground (like the Task Manager, when using Steam if you wanna be able to do that Steam must be run as admin).