Browse Source

Fix start/select binding

Jari 1 tháng trước cách đây
mục cha
commit
e2805335b8
2 tập tin đã thay đổi với 27 bổ sung và 8 xóa
  1. 23 6
      OpenPuck/mode_switch2_pro.cpp
  2. 4 2
      docs/index.html

+ 23 - 6
OpenPuck/mode_switch2_pro.cpp

@@ -69,7 +69,13 @@ static const uint8_t SWITCH2_PRO_CFG_BODY[] = {
 static_assert(sizeof SWITCH2_PRO_CFG_BODY == 259,
 	      "Switch 2 Pro configuration body must remain byte-exact");
 
-static volatile uint8_t g_sw2ActiveReport = 0x09;
+// Report 0x05 is the only input report that carries motion: per SWITCH2_PRO_HID_DESC, 0x09 is
+// 2 vendor bytes + 21 button bits + four 12-bit axes and has no IMU fields at all, while 0x05
+// is the 63-byte vendor blob whose tail sw2Build05 fills with accel/gyro. Defaulting to 0x09
+// made gyro structurally impossible on any host that never sends the 0x03/0x0a report select
+// (buttons still worked, which is what made it look like an IMU problem). An explicit host
+// selection is still honoured either way.
+static volatile uint8_t g_sw2ActiveReport = 0x05;
 static volatile uint8_t g_sw2Features = 0;
 static volatile uint8_t g_sw2FeatureMask = 0;
 static volatile bool g_sw2InputEnabled = false;
@@ -78,7 +84,15 @@ static volatile uint32_t g_sw2Counter32 = 0;
 static int8_t g_sw2LastRumbleBond = -1;
 static uint16_t g_sw2LastRumbleLeft = 0;
 static uint16_t g_sw2LastRumbleRight = 0;
-static const uint8_t def[8] = { 18, 18, 23, 22, 9, 10, 11, 21 };
+// L4, R4, L5, R5, View, Menu, Steam, QAM -> Switch 2 button codes. Mind the naming trap
+// documented in triton.h: TB_VIEW is the START-side button (Switch +) and TB_MENU the
+// SELECT-side one (Switch -), so View maps to Plus and Menu to Minus -- reading the names
+// literally swaps Start and Select on the host.
+static const uint8_t def[8] = { 18, 18, 23, 22, 10, 9, 11, 21 };
+// cfgExt[0] versions this table. A puck that already persisted the reversed Plus/Minus
+// defaults would otherwise keep them forever; bumping the version re-normalises once.
+#define SW2_MAP_FMT_INDEX 0u
+#define SW2_MAP_FMT_VERSION 2u
 static uint8_t g_sw2Map[8];
 static bool g_sw2MapLoaded = false;
 
@@ -87,10 +101,11 @@ static void switch2ProLoadMap()
 	if (g_sw2MapLoaded)
 		return;
 	g_sw2MapLoaded = true;
-	bool normalize = false;
+	const bool stale = cfgExtRead(SW2_MAP_FMT_INDEX) != SW2_MAP_FMT_VERSION;
+	bool normalize = stale;
 	for (uint8_t i = 0; i < 8; i++) {
 		const uint8_t saved = cfgExtRead((uint8_t)(3u + i));
-		if (saved <= 23u) {
+		if (!stale && saved <= 23u) {
 			g_sw2Map[i] = saved;
 		} else {
 			g_sw2Map[i] = def[i];
@@ -98,8 +113,10 @@ static void switch2ProLoadMap()
 			normalize = true;
 		}
 	}
-	if (normalize)
+	if (normalize) {
+		cfgExtWrite(SW2_MAP_FMT_INDEX, SW2_MAP_FMT_VERSION);
 		saveCfg();
+	}
 }
 
 uint8_t switch2ProMapGet(uint8_t index)
@@ -916,7 +933,7 @@ static void sw2DriverReset(uint8_t rhport)
 	g_sw2VendorCommandPending = false;
 	g_sw2VendorInFlight = false;
 	g_sw2InputEnabled = false;
-	g_sw2ActiveReport = 0x09;
+	g_sw2ActiveReport = 0x05;
 	g_sw2Features = 0;
 	g_sw2FeatureMask = 0;
 	g_sw2LastRumbleBond = -1;

+ 4 - 2
docs/index.html

@@ -589,7 +589,7 @@ const TYPE_DEFS = [
   {key:"DS5", name:"DS5", labels:{1:"Cross",2:"Circle",3:"Square",4:"Triangle",5:"L1",6:"R1",7:"L3",8:"R3",9:"Create",10:"Options",11:"PS",19:"L2",20:"R2",...DPAD,16:"Touchpad Click",17:"Mute"}},
 ];
 // Which emulated type a USB mode belongs to (mirror of firmware etypeForMode); -1 = puck mode (no type).
-const SW2_SOURCE_NAMES = ["L4 (back upper-left)","R4 (back upper-right)","L5 (back lower-left)","R5 (back lower-right)","View","Menu","Steam","QAM (3 dots)"];
+const SW2_SOURCE_NAMES = ["L4 (back upper-left)","R4 (back upper-right)","L5 (back lower-left)","R5 (back lower-right)","View (Start side)","Menu (Select side)","Steam","QAM (3 dots)"];
 const SW2_TARGETS = [[1,"A"],[2,"B"],[3,"X"],[4,"Y"],[5,"L"],[6,"R"],[7,"L-Stick"],[8,"R-Stick"],[9,"Minus"],[10,"Plus"],[11,"Home"],[12,"D-pad Up"],[13,"D-pad Down"],[14,"D-pad Left"],[15,"D-pad Right"],[18,"Capture"],[19,"ZL"],[20,"ZR"],[21,"C"],[22,"GR"],[23,"GL"]];
 const sw2MapEls=[];
 (function buildSw2Map(){
@@ -963,7 +963,9 @@ function applyBlob(p){
 
   // Eight Switch 2 Pro physical-source mappings occupy payload p[194..201].
   const sw2MapCap=(p[0]>=23 && p.length>201);
-  const sw2Map=sw2MapCap?p.slice(194,202):[18,18,23,22,9,10,11,21];
+  // Mirrors def[] in mode_switch2_pro.cpp: View is the START-side button (-> Plus) and Menu
+  // the SELECT-side one (-> Minus); see the TB_VIEW/TB_MENU note in triton.h.
+  const sw2Map=sw2MapCap?p.slice(194,202):[18,18,23,22,10,9,11,21];
   // per-slot link status (protocol v8, p.length >= 73)
   const hasSlotsData = p.length >= 73;
   if (hasSlotsData) {