Skip to content

Add NES Controller support for Switch parser#206

Open
mattintech wants to merge 1 commit into
ricardoquesada:mainfrom
mattintech:fix/nes-online-controller-support
Open

Add NES Controller support for Switch parser#206
mattintech wants to merge 1 commit into
ricardoquesada:mainfrom
mattintech:fix/nes-online-controller-support

Conversation

@mattintech
Copy link
Copy Markdown

Summary

The NES Controllers (sold for Nintendo Switch Online) report as controller_type 0x09 (Left) and 0x0a (Right) in the device info subcommand reply. These types were unhandled in uni_hid_parser_switch.c, which caused:

  1. "Switch: Invalid controller_type: 0x0009" log message
  2. A Guru Meditation Error: IntegerDivideByZero crash in parse_imu()mult_frac() — NES controllers have no IMU, so the gyro calibration divisors are zero

Changes

  • Add SWITCH_CONTROLLER_TYPE_NES_L (0x09) and SWITCH_CONTROLLER_TYPE_NES_R (0x0a) to the switch_controller_types enum
  • Route NES controllers through parse_report_30_pro_controller (same button layout as SNES/Pro, minus analog sticks and IMU)
  • Guard parse_imu() call against zero calibration divisors so controllers without IMU don't crash
  • Add defensive zero-check in mult_frac() to prevent divide-by-zero from any future unrecognized controller type

Testing

Tested with both NES Controller (Left) and NES Controller (Right) on ESP32-WROOM-32. All buttons (A, B, D-pad, Start, Select, L, R) register correctly. No crash on connect.

The NES Controllers (sold for Switch Online) report as controller_type
0x09 (Left) and 0x0a (Right). These were unhandled, causing an
"Invalid controller_type" log message followed by a crash in
parse_imu() due to a divide-by-zero — NES controllers have no IMU,
so the gyro calibration divisors are zero.

- Add SWITCH_CONTROLLER_TYPE_NES_L (0x09) and NES_R (0x0a) to the
  controller type enum
- Route NES controllers through parse_report_30_pro_controller (same
  button layout as SNES/Pro minus analog sticks and IMU)
- Guard parse_imu() call against zero calibration divisors
- Add defensive zero-check in mult_frac() to prevent any future
  divide-by-zero from unknown controller types

Tested with both NES Controller (Left) and NES Controller (Right)
on ESP32-WROOM-32 running Bluepad32 v4.2.0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant