diff options
| author | 2022-12-20 20:27:34 -0600 | |
|---|---|---|
| committer | 2023-01-19 18:05:21 -0600 | |
| commit | f09a023292e659af46d551b9b134d94d000a57c7 (patch) | |
| tree | f34ef390cac9f32f7d807614505601635ac62e28 /src/input_common/helpers/joycon_protocol/poller.h | |
| parent | input_common: Use calibration from joycon (diff) | |
| download | yuzu-f09a023292e659af46d551b9b134d94d000a57c7.tar.gz yuzu-f09a023292e659af46d551b9b134d94d000a57c7.tar.xz yuzu-f09a023292e659af46d551b9b134d94d000a57c7.zip | |
input_common: Add support for joycon input reports
Diffstat (limited to 'src/input_common/helpers/joycon_protocol/poller.h')
| -rw-r--r-- | src/input_common/helpers/joycon_protocol/poller.h | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/src/input_common/helpers/joycon_protocol/poller.h b/src/input_common/helpers/joycon_protocol/poller.h new file mode 100644 index 000000000..fff681d0a --- /dev/null +++ b/src/input_common/helpers/joycon_protocol/poller.h | |||
| @@ -0,0 +1,77 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | // Based on dkms-hid-nintendo implementation, CTCaer joycon toolkit and dekuNukem reverse | ||
| 5 | // engineering https://github.com/nicman23/dkms-hid-nintendo/blob/master/src/hid-nintendo.c | ||
| 6 | // https://github.com/CTCaer/jc_toolkit | ||
| 7 | // https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering | ||
| 8 | |||
| 9 | #pragma once | ||
| 10 | |||
| 11 | #include <functional> | ||
| 12 | #include <span> | ||
| 13 | |||
| 14 | #include "input_common/helpers/joycon_protocol/joycon_types.h" | ||
| 15 | |||
| 16 | namespace InputCommon::Joycon { | ||
| 17 | |||
| 18 | // Handles input packages and triggers the corresponding input events | ||
| 19 | class JoyconPoller { | ||
| 20 | public: | ||
| 21 | JoyconPoller(ControllerType device_type_, JoyStickCalibration left_stick_calibration_, | ||
| 22 | JoyStickCalibration right_stick_calibration_, | ||
| 23 | MotionCalibration motion_calibration_); | ||
| 24 | |||
| 25 | void SetCallbacks(const Joycon::JoyconCallbacks& callbacks_); | ||
| 26 | |||
| 27 | /// Handles data from passive packages | ||
| 28 | void ReadPassiveMode(std::span<u8> buffer); | ||
| 29 | |||
| 30 | /// Handles data from active packages | ||
| 31 | void ReadActiveMode(std::span<u8> buffer, const MotionStatus& motion_status); | ||
| 32 | |||
| 33 | /// Handles data from nfc or ir packages | ||
| 34 | void ReadNfcIRMode(std::span<u8> buffer, const MotionStatus& motion_status); | ||
| 35 | |||
| 36 | void UpdateColor(const Color& color); | ||
| 37 | |||
| 38 | private: | ||
| 39 | void UpdateActiveLeftPadInput(const InputReportActive& input, | ||
| 40 | const MotionStatus& motion_status); | ||
| 41 | void UpdateActiveRightPadInput(const InputReportActive& input, | ||
| 42 | const MotionStatus& motion_status); | ||
| 43 | void UpdateActiveProPadInput(const InputReportActive& input, const MotionStatus& motion_status); | ||
| 44 | |||
| 45 | void UpdatePasiveLeftPadInput(const InputReportPassive& buffer); | ||
| 46 | void UpdatePasiveRightPadInput(const InputReportPassive& buffer); | ||
| 47 | void UpdatePasiveProPadInput(const InputReportPassive& buffer); | ||
| 48 | |||
| 49 | /// Returns a calibrated joystick axis from raw axis data | ||
| 50 | f32 GetAxisValue(u16 raw_value, Joycon::JoyStickAxisCalibration calibration) const; | ||
| 51 | |||
| 52 | /// Returns a calibrated accelerometer axis from raw motion data | ||
| 53 | f32 GetAccelerometerValue(s16 raw, const MotionSensorCalibration& cal, | ||
| 54 | AccelerometerSensitivity sensitivity) const; | ||
| 55 | |||
| 56 | /// Returns a calibrated gyro axis from raw motion data | ||
| 57 | f32 GetGyroValue(s16 raw_value, const MotionSensorCalibration& cal, | ||
| 58 | GyroSensitivity sensitivity) const; | ||
| 59 | |||
| 60 | /// Returns a raw motion value from a buffer | ||
| 61 | s16 GetRawIMUValues(size_t sensor, size_t axis, const InputReportActive& input) const; | ||
| 62 | |||
| 63 | /// Returns motion data from a buffer | ||
| 64 | MotionData GetMotionInput(const InputReportActive& input, | ||
| 65 | const MotionStatus& motion_status) const; | ||
| 66 | |||
| 67 | ControllerType device_type{}; | ||
| 68 | |||
| 69 | // Device calibration | ||
| 70 | JoyStickCalibration left_stick_calibration{}; | ||
| 71 | JoyStickCalibration right_stick_calibration{}; | ||
| 72 | MotionCalibration motion_calibration{}; | ||
| 73 | |||
| 74 | Joycon::JoyconCallbacks callbacks{}; | ||
| 75 | }; | ||
| 76 | |||
| 77 | } // namespace InputCommon::Joycon | ||