Просмотр исходного кода

Tighten charge-state slot validation

Co-authored-by: safijari <5191844+safijari@users.noreply.github.com>
copilot-swe-agent[bot] 1 неделя назад
Родитель
Сommit
4ca9079e0a
4 измененных файлов с 8 добавлено и 8 удалено
  1. 4 4
      OpenPuck/haptics.cpp
  2. 2 2
      OpenPuck/haptics.h
  3. 1 1
      OpenPuck/rf_link.cpp
  4. 1 1
      OpenPuck/serial_console.cpp

+ 4 - 4
OpenPuck/haptics.cpp

@@ -31,7 +31,7 @@ uint8_t g_lizKeep = 1;
 // console "SO" toggles.
 uint8_t g_suspendOff = 1;
 uint8_t g_chargeOff = 0;
-static bool g_chargeOffSent[NSLOT] = { false, false, false, false };
+static bool g_chargeOffSent[NSLOT] = { 0 };
 // 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;
@@ -68,9 +68,9 @@ void hapticSendShutdown(uint8_t slot)
 	puckNotePowerOff(slot);
 }
 
-void hapticOnChargeState(uint8_t slot, uint8_t state)
+void hapticOnChargeState(int slot, uint8_t state)
 {
-	if (slot >= NSLOT)
+	if (slot < 0 || slot >= NSLOT)
 		return;
 	bool charging = state == 2 || state == 4;
 	if (!charging) {
@@ -79,7 +79,7 @@ void hapticOnChargeState(uint8_t slot, uint8_t state)
 	}
 	if (g_chargeOff && !g_chargeOffSent[slot]) {
 		g_chargeOffSent[slot] = true;
-		hapticSendShutdown(slot);
+		hapticSendShutdown((uint8_t)slot);
 	}
 }
 

+ 2 - 2
OpenPuck/haptics.h

@@ -99,9 +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.
+// Power a controller off on charge-state 2 (charging) or 4 (charge complete).
 extern uint8_t g_chargeOff;
-void hapticOnChargeState(uint8_t slot, uint8_t state);
+void hapticOnChargeState(int 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;

+ 1 - 1
OpenPuck/rf_link.cpp

@@ -3792,7 +3792,7 @@ uint8_t rfConnTx(uint8_t ch, uint8_t s1, const uint8_t *payload, uint8_t plen,
 							g_battery[g_curSlot] =
 								rep[2];
 							hapticOnChargeState(
-								(uint8_t)g_curSlot,
+								g_curSlot,
 								rep[1]);
 						}
 						if (g_active)

+ 1 - 1
OpenPuck/serial_console.cpp

@@ -13,7 +13,7 @@
 #include <stdlib.h>
 #include <string.h>
 
-// CDC commands: l=listen, s=stop, cN=channel, p<hex>=prefix, a<8hex>=base addr, b=bonds, etc.
+// CDC commands: SO=power off on suspend, CO=power off when charging; l=listen, s=stop, etc.
 // Command order matters: else-if chain, FIRST matching letter wins. 'C' and 'H' appear twice; the second
 // occurrence is unreachable.
 void serialConsolePoll()