浏览代码

Implement charging-triggered shutdown core

Co-authored-by: safijari <5191844+safijari@users.noreply.github.com>
copilot-swe-agent[bot] 1 周之前
父节点
当前提交
215efcba08
共有 4 个文件被更改,包括 28 次插入 和 1 次删除
  1. 5 1
      OpenPuck/config.cpp
  2. 17 0
      OpenPuck/haptics.cpp
  3. 3 0
      OpenPuck/haptics.h
  4. 3 0
      OpenPuck/rf_link.cpp

+ 5 - 1
OpenPuck/config.cpp

@@ -112,6 +112,7 @@ struct Cfg {
 	// pre-tail file) -> compiled default (on)
 	uint8_t suspendOff;
 	uint8_t ext[CFG_EXT_STORAGE_BYTES];
+	uint8_t chargeOff;
 }; // rsvd0 = ex-padSmooth, now the one-shot debug-CDC arm
 
 // Shortest cfg.bin we still accept: the layout as of CFG_MAGIC 0xCF, i.e. everything before the appended tail.
@@ -155,7 +156,8 @@ void saveCfg()
 		  {},
 		  g_rumbleStyle,
 		  g_suspendOff,
-		  {} };
+		  {},
+		  g_chargeOff };
 	memcpy(c.ext, g_cfgExt, sizeof c.ext);
 	for (int i = 0; i < ET_COUNT; i++) {
 		c.type[i] = g_type[i];
@@ -265,6 +267,8 @@ void loadCfg()
 			// suspend power-off enable (0xFF = a cfg.bin predating this tail field -> keep the on default)
 			if (c.suspendOff <= 1)
 				g_suspendOff = c.suspendOff;
+			if (c.chargeOff <= 1)
+				g_chargeOff = c.chargeOff;
 
 			// The poll RX window is now FIXED (g_rxWin is const) -- any persisted rxWin10 is ignored.
 		}

+ 17 - 0
OpenPuck/haptics.cpp

@@ -30,6 +30,8 @@ uint8_t g_lizKeep = 1;
 // Power the controllers off when host sleep persists (see haptics.h for the wake trade-off). Persisted;
 // console "SO" toggles.
 uint8_t g_suspendOff = 1;
+uint8_t g_chargeOff = 0;
+static bool g_chargeOffSent[NSLOT] = { false, false, false, false };
 // Host-rumble shaping (persisted in cfg.bin; console "RS<pct>" / "RY<n>").
 uint16_t g_rumbleScale = RUMBLE_SCALE_PCT;
 uint8_t g_rumbleStyle = RUMBLE_STYLE_NORMAL;
@@ -66,6 +68,21 @@ void hapticSendShutdown(uint8_t slot)
 	puckNotePowerOff(slot);
 }
 
+void hapticOnChargeState(uint8_t slot, uint8_t state)
+{
+	if (slot >= NSLOT)
+		return;
+	bool charging = state == 2 || state == 4;
+	if (!charging) {
+		g_chargeOffSent[slot] = false;
+		return;
+	}
+	if (g_chargeOff && !g_chargeOffSent[slot]) {
+		g_chargeOffSent[slot] = true;
+		hapticSendShutdown(slot);
+	}
+}
+
 // millis of last translated host rumble (0x80), per-slot (4 XInput interfaces each have their own stream)
 static unsigned long g_rumble80Ms[NSLOT] = { 0 };
 

+ 3 - 0
OpenPuck/haptics.h

@@ -99,6 +99,9 @@ extern uint8_t
 // physical gesture; the power-off fires once per suspend so the returning controller is not shut off again.
 // Turn this OFF (console "SO") if a controller must stay awake through host sleep. Persisted.
 extern uint8_t g_suspendOff;
+// Power a controller off when its battery report says it is charging or fully charged.
+extern uint8_t g_chargeOff;
+void hapticOnChargeState(uint8_t slot, uint8_t state);
 // Master enable for the puck->controller haptic relay (Steam 0x80-0x86 rumble/pad-feedback). Console "HR"
 // toggles it to isolate the drag-smoothness cost of relaying Steam's trackpad haptics. See haptics.cpp.
 extern bool g_hapticRelay;

+ 3 - 0
OpenPuck/rf_link.cpp

@@ -3791,6 +3791,9 @@ uint8_t rfConnTx(uint8_t ch, uint8_t s1, const uint8_t *payload, uint8_t plen,
 								rep[1];
 							g_battery[g_curSlot] =
 								rep[2];
+							hapticOnChargeState(
+								(uint8_t)g_curSlot,
+								rep[1]);
 						}
 						if (g_active)
 							g_active->onAuxReport(