diff options
Diffstat (limited to 'src/input_common/udp/client.h')
| -rw-r--r-- | src/input_common/udp/client.h | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/src/input_common/udp/client.h b/src/input_common/udp/client.h index 747e0c0a2..00c8b09f5 100644 --- a/src/input_common/udp/client.h +++ b/src/input_common/udp/client.h | |||
| @@ -21,8 +21,7 @@ | |||
| 21 | 21 | ||
| 22 | namespace InputCommon::CemuhookUDP { | 22 | namespace InputCommon::CemuhookUDP { |
| 23 | 23 | ||
| 24 | constexpr u16 DEFAULT_PORT = 26760; | 24 | constexpr char DEFAULT_SRV[] = "127.0.0.1:26760"; |
| 25 | constexpr char DEFAULT_ADDR[] = "127.0.0.1"; | ||
| 26 | 25 | ||
| 27 | class Socket; | 26 | class Socket; |
| 28 | 27 | ||
| @@ -48,6 +47,9 @@ enum class PadTouch { | |||
| 48 | }; | 47 | }; |
| 49 | 48 | ||
| 50 | struct UDPPadStatus { | 49 | struct UDPPadStatus { |
| 50 | std::string host{"127.0.0.1"}; | ||
| 51 | u16 port{26760}; | ||
| 52 | std::size_t pad_index{}; | ||
| 51 | PadTouch touch{PadTouch::Undefined}; | 53 | PadTouch touch{PadTouch::Undefined}; |
| 52 | PadMotion motion{PadMotion::Undefined}; | 54 | PadMotion motion{PadMotion::Undefined}; |
| 53 | f32 motion_value{0.0f}; | 55 | f32 motion_value{0.0f}; |
| @@ -82,37 +84,41 @@ public: | |||
| 82 | 84 | ||
| 83 | std::vector<Common::ParamPackage> GetInputDevices() const; | 85 | std::vector<Common::ParamPackage> GetInputDevices() const; |
| 84 | 86 | ||
| 85 | bool DeviceConnected(std::size_t pad) const; | 87 | bool DeviceConnected(std::size_t client) const; |
| 86 | void ReloadUDPClient(); | 88 | void ReloadSockets(); |
| 87 | void ReloadSocket(const std::string& host = "127.0.0.1", u16 port = 26760, | ||
| 88 | std::size_t pad_index = 0, u32 client_id = 24872); | ||
| 89 | 89 | ||
| 90 | std::array<Common::SPSCQueue<UDPPadStatus>, 4>& GetPadQueue(); | 90 | Common::SPSCQueue<UDPPadStatus>& GetPadQueue(); |
| 91 | const std::array<Common::SPSCQueue<UDPPadStatus>, 4>& GetPadQueue() const; | 91 | const Common::SPSCQueue<UDPPadStatus>& GetPadQueue() const; |
| 92 | 92 | ||
| 93 | DeviceStatus& GetPadState(std::size_t pad); | 93 | DeviceStatus& GetPadState(const std::string& host, u16 port, std::size_t pad); |
| 94 | const DeviceStatus& GetPadState(std::size_t pad) const; | 94 | const DeviceStatus& GetPadState(const std::string& host, u16 port, std::size_t pad) const; |
| 95 | 95 | ||
| 96 | private: | 96 | private: |
| 97 | struct ClientData { | 97 | struct ClientData { |
| 98 | std::string host{"127.0.0.1"}; | ||
| 99 | u16 port{26760}; | ||
| 100 | std::size_t pad_index{}; | ||
| 98 | std::unique_ptr<Socket> socket; | 101 | std::unique_ptr<Socket> socket; |
| 99 | DeviceStatus status; | 102 | DeviceStatus status; |
| 100 | std::thread thread; | 103 | std::thread thread; |
| 101 | u64 packet_sequence = 0; | 104 | u64 packet_sequence{}; |
| 102 | u8 active = 0; | 105 | s8 active{-1}; |
| 103 | 106 | ||
| 104 | // Realtime values | 107 | // Realtime values |
| 105 | // motion is initalized with PID values for drift correction on joycons | 108 | // motion is initalized with PID values for drift correction on joycons |
| 106 | InputCommon::MotionInput motion{0.3f, 0.005f, 0.0f}; | 109 | InputCommon::MotionInput motion{0.3f, 0.005f, 0.0f}; |
| 107 | std::chrono::time_point<std::chrono::system_clock> last_motion_update; | 110 | std::chrono::time_point<std::chrono::steady_clock> last_motion_update; |
| 108 | }; | 111 | }; |
| 109 | 112 | ||
| 110 | // For shutting down, clear all data, join all threads, release usb | 113 | // For shutting down, clear all data, join all threads, release usb |
| 111 | void Reset(); | 114 | void Reset(); |
| 112 | 115 | ||
| 116 | // Translates configuration to client number | ||
| 117 | std::size_t GetClientNumber(std::string_view host, u16 port, std::size_t pad) const; | ||
| 118 | |||
| 113 | void OnVersion(Response::Version); | 119 | void OnVersion(Response::Version); |
| 114 | void OnPortInfo(Response::PortInfo); | 120 | void OnPortInfo(Response::PortInfo); |
| 115 | void OnPadData(Response::PadData); | 121 | void OnPadData(Response::PadData, std::size_t client); |
| 116 | void StartCommunication(std::size_t client, const std::string& host, u16 port, | 122 | void StartCommunication(std::size_t client, const std::string& host, u16 port, |
| 117 | std::size_t pad_index, u32 client_id); | 123 | std::size_t pad_index, u32 client_id); |
| 118 | void UpdateYuzuSettings(std::size_t client, const Common::Vec3<float>& acc, | 124 | void UpdateYuzuSettings(std::size_t client, const Common::Vec3<float>& acc, |
| @@ -120,8 +126,10 @@ private: | |||
| 120 | 126 | ||
| 121 | bool configuring = false; | 127 | bool configuring = false; |
| 122 | 128 | ||
| 123 | std::array<ClientData, 4> clients; | 129 | // Allocate clients for 8 udp servers |
| 124 | std::array<Common::SPSCQueue<UDPPadStatus>, 4> pad_queue; | 130 | const std::size_t max_udp_clients = 32; |
| 131 | std::array<ClientData, 4 * 8> clients; | ||
| 132 | Common::SPSCQueue<UDPPadStatus> pad_queue; | ||
| 125 | }; | 133 | }; |
| 126 | 134 | ||
| 127 | /// An async job allowing configuration of the touchpad calibration. | 135 | /// An async job allowing configuration of the touchpad calibration. |