From 92bfb0ea79e24a8bc83e7ffbc85a709bad95ebc2 Mon Sep 17 00:00:00 2001 From: Jari Date: Tue, 23 Jun 2026 15:45:48 -0400 Subject: [PATCH] restore back button mounting --- OpenPuck/gamepad_util.cpp | 6 ++++++ OpenPuck/gamepad_util.h | 4 ++++ OpenPuck/mode_switch_hori.cpp | 4 ++++ OpenPuck/mode_switch_pro.cpp | 4 ++++ OpenPuck/mode_xinput.cpp | 17 +++++++++++++++++ OpenPuck/serial_console.cpp | 4 ++-- OpenPuck/triton.h | 4 ++++ docs/index.html | 8 ++++---- 8 files changed, 45 insertions(+), 6 deletions(-) diff --git a/OpenPuck/gamepad_util.cpp b/OpenPuck/gamepad_util.cpp index fc237b0..d1426f6 100644 --- a/OpenPuck/gamepad_util.cpp +++ b/OpenPuck/gamepad_util.cpp @@ -158,6 +158,12 @@ static void psOrBackCode(uint32_t *b, uint8_t c) case 17: *b |= TB_MUTE; break; + case 19: + *b |= TB_L2; // left trigger (L2) + break; + case 20: + *b |= TB_R2; // right trigger (R2) + break; default: break; } diff --git a/OpenPuck/gamepad_util.h b/OpenPuck/gamepad_util.h index 6463270..a314148 100644 --- a/OpenPuck/gamepad_util.h +++ b/OpenPuck/gamepad_util.h @@ -78,6 +78,10 @@ static inline uint32_t tritonFromCode(uint8_t c) return TB_TOUCH; case 17: return TB_MUTE; + case 19: + return TB_L2; // left trigger (LT / L2 / ZL) + case 20: + return TB_R2; // right trigger (RT / R2 / ZR) default: return 0; } diff --git a/OpenPuck/mode_switch_hori.cpp b/OpenPuck/mode_switch_hori.cpp index c74e9c0..b1ba503 100644 --- a/OpenPuck/mode_switch_hori.cpp +++ b/OpenPuck/mode_switch_hori.cpp @@ -61,6 +61,10 @@ static uint16_t codeToSwitch(uint8_t c, uint16_t fA, uint16_t fB, uint16_t fX, return 0x1000; case 18: return 0x2000; // Capture / Screenshot (Switch-only target) + case 19: + return 0x40; // ZL (left trigger) + case 20: + return 0x80; // ZR (right trigger) default: return 0; } diff --git a/OpenPuck/mode_switch_pro.cpp b/OpenPuck/mode_switch_pro.cpp index 13976bc..e475b52 100644 --- a/OpenPuck/mode_switch_pro.cpp +++ b/OpenPuck/mode_switch_pro.cpp @@ -133,6 +133,10 @@ static uint32_t codeToJc(uint8_t c, uint32_t fA, uint32_t fB, uint32_t fX, return JC_BTN_HOME; case 18: return JC_BTN_CAPTURE; // Capture / Screenshot (Switch-only target) + case 19: + return JC_BTN_ZL; // left trigger + case 20: + return JC_BTN_ZR; // right trigger case 12: return JC_BTN_UP; case 13: diff --git a/OpenPuck/mode_xinput.cpp b/OpenPuck/mode_xinput.cpp index 0b1e2a2..934eff7 100644 --- a/OpenPuck/mode_xinput.cpp +++ b/OpenPuck/mode_xinput.cpp @@ -352,6 +352,23 @@ static void rfXboxGamepad(uint8_t slot, const uint8_t *r) uint8_t lt = trigU8(u16off(r, 4)), rt = trigU8(u16off( r, 6)); // triggers u16 (half-scale) -> full-range u8 + // Trigger remaps (codes 19=LT, 20=RT): XInput triggers are analog bytes, not buttons, so a back paddle / + // QAM mapped to a trigger pulls it full. QAM arrives as TB_L2/TB_R2 (folded into b via tritonFromCode); + // back paddles are matched by their configured code. + if (b & TB_L2) + lt = 0xFF; + if (b & TB_R2) + rt = 0xFF; + const uint8_t bc[4] = { g_back[0], g_back[1], g_back[2], g_back[3] }; + const uint32_t bm[4] = { TB_L4, TB_R4, TB_L5, TB_R5 }; + for (int i = 0; i < 4; i++) { + if (!(b & bm[i])) + continue; + if (bc[i] == 19) + lt = 0xFF; + else if (bc[i] == 20) + rt = 0xFF; + } xinputSend(slot, btn, lt, rt, (int16_t)s16off(r, 8), (int16_t)s16off(r, 10), // L stick X/Y (int16_t)s16off(r, 12), diff --git a/OpenPuck/serial_console.cpp b/OpenPuck/serial_console.cpp index a14c8f7..9589764 100644 --- a/OpenPuck/serial_console.cpp +++ b/OpenPuck/serial_console.cpp @@ -235,7 +235,7 @@ void serialConsolePoll() applyActiveType(); saveCfg(); Serial.printf( - "# back[%d] (%s) -> code %u [type %u] [0=none 1=A 2=B 3=X 4=Y 5=LB 6=RB 7=L3 8=R3 9=Back 10=QAM 11=Guide 12=Dup 13=Ddown 14=Dleft 15=Dright 16=TouchClick 17=Mute 18=Capture(Switch)]\n", + "# back[%d] (%s) -> code %u [type %u] [0=none 1=A 2=B 3=X 4=Y 5=LB 6=RB 7=L3 8=R3 9=Back 10=QAM 11=Guide 12=Dup 13=Ddown 14=Dleft 15=Dright 16=TouchClick 17=Mute 18=Capture(Switch) 19=LT/L2/ZL 20=RT/R2/ZR]\n", i, (const char *[]){ "L4", "R4", "L5", @@ -254,7 +254,7 @@ void serialConsolePoll() applyActiveType(); saveCfg(); Serial.printf( - "# QAM -> code %u [type %u] [0=default 1=A 2=B 3=X 4=Y 5=LB 6=RB 7=L3 8=R3 9=Back 10=QAM 11=Guide 12=Dup 13=Ddown 14=Dleft 15=Dright 16=TouchClick 17=Mute 18=Capture(Switch)]\n", + "# QAM -> code %u [type %u] [0=default 1=A 2=B 3=X 4=Y 5=LB 6=RB 7=L3 8=R3 9=Back 10=QAM 11=Guide 12=Dup 13=Ddown 14=Dleft 15=Dright 16=TouchClick 17=Mute 18=Capture(Switch) 19=LT/L2/ZL 20=RT/R2/ZR]\n", code, g_etype); } else Serial.println( diff --git a/OpenPuck/triton.h b/OpenPuck/triton.h index 8885383..9aee3a5 100644 --- a/OpenPuck/triton.h +++ b/OpenPuck/triton.h @@ -32,6 +32,10 @@ #define TB_RPADC 0x400000u #define TB_LPADT 0x2000000u #define TB_LPADC 0x4000000u +// Trigger full-pull / click bits (the controller sets these at a full ZL/ZR pull; also the target of a back- +// paddle / QAM remap to LT/RT). psShouldersByte / the Switch builders already read these as L2/R2 / ZL/ZR. +#define TB_R2 0x800000u +#define TB_L2 0x8000000u // Virtual PS targets, settable ONLY via a back-paddle/QAM remap (psOrBackCode / tritonFromCode), never by the // controller itself. They live on bits 30/31 -- the only bits the SC2 0x45 report does NOT use (see PROTOCOL.md diff --git a/docs/index.html b/docs/index.html index 53b0531..bdb8cd7 100644 --- a/docs/index.html +++ b/docs/index.html @@ -193,10 +193,10 @@ function log(m){ const l=$("#log"); l.textContent=(new Date().toLocaleTimeString // (k: 0..3 back paddles, 4 QAM, 5 A/B-swap, 6 trackpad-haptics). Blob v9 reads them back at p[75 + et*7 + ...]. const DPAD = {12:"D-pad Up",13:"D-pad Down",14:"D-pad Left",15:"D-pad Right"}; const TYPE_DEFS = [ - {key:"XBOX", name:"Xbox", labels:{1:"A",2:"B",3:"X",4:"Y",5:"LB",6:"RB",7:"L3",8:"R3",9:"Back",10:"Start",11:"Guide",...DPAD}}, - {key:"SWITCH", name:"Switch", labels:{1:"A",2:"B",3:"X",4:"Y",5:"L",6:"R",7:"L-Stick",8:"R-Stick",9:"Minus",10:"Plus",11:"Home",...DPAD,18:"Capture / Screenshot"}}, - {key:"DS4", name:"DS4", labels:{1:"Cross",2:"Circle",3:"Square",4:"Triangle",5:"L1",6:"R1",7:"L3",8:"R3",9:"Create",10:"Options",11:"PS",...DPAD,16:"Touchpad Click"}}, - {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",...DPAD,16:"Touchpad Click",17:"Mute"}}, + {key:"XBOX", name:"Xbox", labels:{1:"A",2:"B",3:"X",4:"Y",5:"LB",6:"RB",7:"L3",8:"R3",9:"Back",10:"Start",11:"Guide",19:"LT",20:"RT",...DPAD}}, + {key:"SWITCH", name:"Switch", labels:{1:"A",2:"B",3:"X",4:"Y",5:"L",6:"R",7:"L-Stick",8:"R-Stick",9:"Minus",10:"Plus",11:"Home",19:"ZL",20:"ZR",...DPAD,18:"Capture / Screenshot"}}, + {key:"DS4", name:"DS4", 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"}}, + {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). function etypeForMode(m){ switch(m){case 1:return 0; case 2:case 4:return 1; case 6:case 8:return 2; case 5:case 7:return 3; default:return -1;} } -- knotmirror 0.0.1