diff options
Diffstat (limited to 'src/input_common/udp/client.h')
| -rw-r--r-- | src/input_common/udp/client.h | 74 |
1 files changed, 67 insertions, 7 deletions
diff --git a/src/input_common/udp/client.h b/src/input_common/udp/client.h index a73283ae8..523dc6a7a 100644 --- a/src/input_common/udp/client.h +++ b/src/input_common/udp/client.h | |||
| @@ -12,9 +12,12 @@ | |||
| 12 | #include <thread> | 12 | #include <thread> |
| 13 | #include <tuple> | 13 | #include <tuple> |
| 14 | #include "common/common_types.h" | 14 | #include "common/common_types.h" |
| 15 | #include "common/param_package.h" | ||
| 15 | #include "common/thread.h" | 16 | #include "common/thread.h" |
| 17 | #include "common/threadsafe_queue.h" | ||
| 16 | #include "common/vector_math.h" | 18 | #include "common/vector_math.h" |
| 17 | #include "core/frontend/input.h" | 19 | #include "core/frontend/input.h" |
| 20 | #include "input_common/motion_input.h" | ||
| 18 | 21 | ||
| 19 | namespace InputCommon::CemuhookUDP { | 22 | namespace InputCommon::CemuhookUDP { |
| 20 | 23 | ||
| @@ -29,6 +32,27 @@ struct PortInfo; | |||
| 29 | struct Version; | 32 | struct Version; |
| 30 | } // namespace Response | 33 | } // namespace Response |
| 31 | 34 | ||
| 35 | enum class PadMotion { | ||
| 36 | GyroX, | ||
| 37 | GyroY, | ||
| 38 | GyroZ, | ||
| 39 | AccX, | ||
| 40 | AccY, | ||
| 41 | AccZ, | ||
| 42 | Undefined, | ||
| 43 | }; | ||
| 44 | |||
| 45 | enum class PadTouch { | ||
| 46 | Click, | ||
| 47 | Undefined, | ||
| 48 | }; | ||
| 49 | |||
| 50 | struct UDPPadStatus { | ||
| 51 | PadTouch touch{PadTouch::Undefined}; | ||
| 52 | PadMotion motion{PadMotion::Undefined}; | ||
| 53 | f32 motion_value{0.0f}; | ||
| 54 | }; | ||
| 55 | |||
| 32 | struct DeviceStatus { | 56 | struct DeviceStatus { |
| 33 | std::mutex update_mutex; | 57 | std::mutex update_mutex; |
| 34 | Input::MotionStatus motion_status; | 58 | Input::MotionStatus motion_status; |
| @@ -46,22 +70,58 @@ struct DeviceStatus { | |||
| 46 | 70 | ||
| 47 | class Client { | 71 | class Client { |
| 48 | public: | 72 | public: |
| 49 | explicit Client(std::shared_ptr<DeviceStatus> status, const std::string& host = DEFAULT_ADDR, | 73 | // Initialize the UDP client capture and read sequence |
| 50 | u16 port = DEFAULT_PORT, u8 pad_index = 0, u32 client_id = 24872); | 74 | Client(); |
| 75 | |||
| 76 | // Close and release the client | ||
| 51 | ~Client(); | 77 | ~Client(); |
| 78 | |||
| 79 | // Used for polling | ||
| 80 | void BeginConfiguration(); | ||
| 81 | void EndConfiguration(); | ||
| 82 | |||
| 83 | std::vector<Common::ParamPackage> GetInputDevices() const; | ||
| 84 | |||
| 85 | bool DeviceConnected(std::size_t pad) const; | ||
| 86 | void ReloadUDPClient(); | ||
| 52 | void ReloadSocket(const std::string& host = "127.0.0.1", u16 port = 26760, u8 pad_index = 0, | 87 | void ReloadSocket(const std::string& host = "127.0.0.1", u16 port = 26760, u8 pad_index = 0, |
| 53 | u32 client_id = 24872); | 88 | u32 client_id = 24872); |
| 54 | 89 | ||
| 90 | std::array<Common::SPSCQueue<UDPPadStatus>, 4>& GetPadQueue(); | ||
| 91 | const std::array<Common::SPSCQueue<UDPPadStatus>, 4>& GetPadQueue() const; | ||
| 92 | |||
| 93 | DeviceStatus& GetPadState(std::size_t pad); | ||
| 94 | const DeviceStatus& GetPadState(std::size_t pad) const; | ||
| 95 | |||
| 55 | private: | 96 | private: |
| 97 | struct ClientData { | ||
| 98 | std::unique_ptr<Socket> socket; | ||
| 99 | DeviceStatus status; | ||
| 100 | std::thread thread; | ||
| 101 | u64 packet_sequence = 0; | ||
| 102 | u8 active; | ||
| 103 | |||
| 104 | // Realtime values | ||
| 105 | // motion is initalized with PID values for drift correction on joycons | ||
| 106 | InputCommon::MotionInput motion{0.3f, 0.005f, 0.0f}; | ||
| 107 | std::chrono::time_point<std::chrono::system_clock> last_motion_update; | ||
| 108 | }; | ||
| 109 | |||
| 110 | // For shutting down, clear all data, join all threads, release usb | ||
| 111 | void Reset(); | ||
| 112 | |||
| 56 | void OnVersion(Response::Version); | 113 | void OnVersion(Response::Version); |
| 57 | void OnPortInfo(Response::PortInfo); | 114 | void OnPortInfo(Response::PortInfo); |
| 58 | void OnPadData(Response::PadData); | 115 | void OnPadData(Response::PadData); |
| 59 | void StartCommunication(const std::string& host, u16 port, u8 pad_index, u32 client_id); | 116 | void StartCommunication(std::size_t client, const std::string& host, u16 port, u8 pad_index, |
| 117 | u32 client_id); | ||
| 118 | void UpdateYuzuSettings(std::size_t client, const Common::Vec3<float>& acc, | ||
| 119 | const Common::Vec3<float>& gyro, bool touch); | ||
| 120 | |||
| 121 | bool configuring = false; | ||
| 60 | 122 | ||
| 61 | std::unique_ptr<Socket> socket; | 123 | std::array<ClientData, 4> clients; |
| 62 | std::shared_ptr<DeviceStatus> status; | 124 | std::array<Common::SPSCQueue<UDPPadStatus>, 4> pad_queue; |
| 63 | std::thread thread; | ||
| 64 | u64 packet_sequence = 0; | ||
| 65 | }; | 125 | }; |
| 66 | 126 | ||
| 67 | /// An async job allowing configuration of the touchpad calibration. | 127 | /// An async job allowing configuration of the touchpad calibration. |