Add NES Controller support for Switch parser#206
Open
mattintech wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The NES Controllers (sold for Nintendo Switch Online) report as
controller_type0x09 (Left) and 0x0a (Right) in the device info subcommand reply. These types were unhandled inuni_hid_parser_switch.c, which caused:"Switch: Invalid controller_type: 0x0009"log messageGuru Meditation Error: IntegerDivideByZerocrash inparse_imu()→mult_frac()— NES controllers have no IMU, so the gyro calibration divisors are zeroChanges
SWITCH_CONTROLLER_TYPE_NES_L(0x09) andSWITCH_CONTROLLER_TYPE_NES_R(0x0a) to theswitch_controller_typesenumparse_report_30_pro_controller(same button layout as SNES/Pro, minus analog sticks and IMU)parse_imu()call against zero calibration divisors so controllers without IMU don't crashmult_frac()to prevent divide-by-zero from any future unrecognized controller typeTesting
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.