- Dual-Core Architecture: Dedicated 1000Hz USB gaming pipeline on Core 1 and BLE/Wi-Fi/Web telemetry on Core 0. - Multi-Input BLE Host: Parsers for Xbox Wireless, Google Stadia, 8BitDo (Ultimate/Pro2/SN30), and Generic HOGP gamepads. - Multi-Console USB Emulation: Nintendo Switch, PC DirectInput, PS3, PS4, Xbox 360 (libxsm3 cryptographic challenge-response), Original Xbox, and Couch Mouse/Keyboard. - Onboard Web Portal & Captive Portal: Real-time SVG gamepad visualizer, stick deadzone calibration, button combo remapping, and Wi-Fi manager. - Low-Latency Radio Management: Interactive SoftAP toggle to drop to 0-latency gaming mode. - Dual OTA Firmware Flashing: Browser-based wireless firmware updater and automated Python OTA script. - Strict Build Quality: Clean build under -Wall -Wextra with zero warnings or errors. - Versioning & Licensing: Semantic Versioning v1.0.0 and GNU GPLv3 with Commercial Restrictions.
116 lines
4.2 KiB
C
116 lines
4.2 KiB
C
#include "parser_stadia.h"
|
|
|
|
bool parser_stadia_parse(const uint8_t *report, size_t len, controller_state_t *out_state)
|
|
{
|
|
if (!report || !out_state || len < 7) {
|
|
return false;
|
|
}
|
|
|
|
const uint8_t *data = report;
|
|
|
|
/*
|
|
* Stadia BLE reports over GATT notification are 10 bytes and do NOT include
|
|
* a Report ID:
|
|
* Byte 0 is the D-PAD hat switch (0x00=Up, 0x01=Up-Right, 0x02=Right,
|
|
* 0x03=Down-Right, 0x04=Down, 0x05=Down-Left, 0x06=Left, 0x07=Up-Left, 0x08=Neutral).
|
|
*
|
|
* Note: 0x03 is Down+Right! We must never assume data[0] == 0x03 is a Report ID
|
|
* on standard BLE reports (len == 10). Only transports like USB HID that prepend
|
|
* Report ID 0x03 produce len >= 11 where data[1] is the Hat switch and data[4] is LX.
|
|
*/
|
|
if (len >= 11 && data[0] == 0x03 && (data[1] & 0x0F) <= 8 && data[4] >= 40 && data[4] <= 215) {
|
|
data++;
|
|
len--;
|
|
}
|
|
|
|
if (len < 7) {
|
|
return false;
|
|
}
|
|
|
|
controller_state_reset(out_state);
|
|
|
|
/*
|
|
* Verified Google Stadia Controller HID Report Layout:
|
|
* Byte 0: D-PAD (Hat switch)
|
|
* 0x00=Up, 0x01=Up+Right, 0x02=Right, 0x03=Down+Right,
|
|
* 0x04=Down, 0x05=Down+Left, 0x06=Left, 0x07=Up+Left,
|
|
* 0x08=Neutral / Centered
|
|
* Byte 1: Buttons Low
|
|
* 0x01: Capture / Screenshot
|
|
* 0x02: Google Assistant
|
|
* 0x04: L2 digital trigger
|
|
* 0x08: R2 digital trigger
|
|
* 0x10: Stadia Logo (System / Home)
|
|
* 0x20: Menu (Start / Hamburger)
|
|
* 0x40: Options (Select / ...)
|
|
* 0x80: R3 (Right Stick Click)
|
|
* Byte 2: Buttons High
|
|
* 0x01: L3 (Left Stick Click)
|
|
* 0x02: R1 (Right Bumper)
|
|
* 0x04: L1 (Left Bumper)
|
|
* 0x08: Y
|
|
* 0x10: X
|
|
* 0x20: B
|
|
* 0x40: A
|
|
* Byte 3: Left Stick X (0..255, 128 center)
|
|
* Byte 4: Left Stick Y (0..255, 128 center)
|
|
* Byte 5: Right Stick X (0..255, 128 center)
|
|
* Byte 6: Right Stick Y (0..255, 128 center)
|
|
* Byte 7: Left Trigger Analog (0..255) (if present)
|
|
* Byte 8: Right Trigger Analog (0..255) (if present)
|
|
*/
|
|
|
|
/* --- 1. D-Pad / Hat Switch (Byte 0) --- */
|
|
parse_hat_switch_8way(data[0], out_state);
|
|
|
|
/* --- 2. Buttons Byte 1 (data[1]) --- */
|
|
uint8_t b1 = data[1];
|
|
out_state->btn_share = (b1 & 0x01) ? 1 : 0; /* Capture */
|
|
if (b1 & 0x02) out_state->btn_share = 1; /* Assistant -> map to Share */
|
|
out_state->btn_lt = (b1 & 0x04) ? 1 : 0; /* L2 Digital */
|
|
out_state->btn_rt = (b1 & 0x08) ? 1 : 0; /* R2 Digital */
|
|
out_state->btn_system = (b1 & 0x10) ? 1 : 0; /* Stadia Logo */
|
|
out_state->btn_start = (b1 & 0x20) ? 1 : 0; /* Menu */
|
|
out_state->btn_select = (b1 & 0x40) ? 1 : 0; /* Options */
|
|
out_state->btn_r3 = (b1 & 0x80) ? 1 : 0; /* R3 */
|
|
|
|
/* --- 3. Buttons Byte 2 (data[2]) --- */
|
|
uint8_t b2 = data[2];
|
|
out_state->btn_l3 = (b2 & 0x01) ? 1 : 0; /* L3 */
|
|
out_state->btn_rb = (b2 & 0x02) ? 1 : 0; /* R1 */
|
|
out_state->btn_lb = (b2 & 0x04) ? 1 : 0; /* L1 */
|
|
out_state->btn_y = (b2 & 0x08) ? 1 : 0; /* Y */
|
|
out_state->btn_x = (b2 & 0x10) ? 1 : 0; /* X */
|
|
out_state->btn_b = (b2 & 0x20) ? 1 : 0; /* B */
|
|
out_state->btn_a = (b2 & 0x40) ? 1 : 0; /* A */
|
|
|
|
/* --- 4. Analog Sticks (data[3..6]) --- */
|
|
uint8_t raw_lx = data[3];
|
|
uint8_t raw_ly = data[4];
|
|
uint8_t raw_rx = data[5];
|
|
uint8_t raw_ry = data[6];
|
|
|
|
/* Convert 0..255 (128 centered) to normalized -32768..32767 with overflow protection */
|
|
out_state->lx = scale_axis_8bit(raw_lx, false);
|
|
out_state->ly = scale_axis_8bit(raw_ly, true);
|
|
out_state->rx = scale_axis_8bit(raw_rx, false);
|
|
out_state->ry = scale_axis_8bit(raw_ry, true);
|
|
|
|
/* --- 5. Analog Triggers (data[7..8]) --- */
|
|
if (len >= 8) {
|
|
out_state->lt = data[7];
|
|
if (out_state->lt > 30) out_state->btn_lt = 1;
|
|
} else {
|
|
out_state->lt = out_state->btn_lt ? 255 : 0;
|
|
}
|
|
|
|
if (len >= 9) {
|
|
out_state->rt = data[8];
|
|
if (out_state->rt > 30) out_state->btn_rt = 1;
|
|
} else {
|
|
out_state->rt = out_state->btn_rt ? 255 : 0;
|
|
}
|
|
|
|
return true;
|
|
}
|