diff options
Diffstat (limited to 'src/input_common')
| -rw-r--r-- | src/input_common/main.cpp | 2 | ||||
| -rw-r--r-- | src/input_common/udp/client.cpp | 143 | ||||
| -rw-r--r-- | src/input_common/udp/client.h | 40 | ||||
| -rw-r--r-- | src/input_common/udp/udp.cpp | 64 |
4 files changed, 149 insertions, 100 deletions
diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp index 880ea73b8..7c4e7dd3b 100644 --- a/src/input_common/main.cpp +++ b/src/input_common/main.cpp | |||
| @@ -286,7 +286,7 @@ void InputSubsystem::ReloadInputDevices() { | |||
| 286 | if (!impl->udp) { | 286 | if (!impl->udp) { |
| 287 | return; | 287 | return; |
| 288 | } | 288 | } |
| 289 | impl->udp->ReloadUDPClient(); | 289 | impl->udp->ReloadSockets(); |
| 290 | } | 290 | } |
| 291 | 291 | ||
| 292 | std::vector<std::unique_ptr<Polling::DevicePoller>> InputSubsystem::GetPollers( | 292 | std::vector<std::unique_ptr<Polling::DevicePoller>> InputSubsystem::GetPollers( |
diff --git a/src/input_common/udp/client.cpp b/src/input_common/udp/client.cpp index c0bb90048..17a9225d7 100644 --- a/src/input_common/udp/client.cpp +++ b/src/input_common/udp/client.cpp | |||
| @@ -136,15 +136,7 @@ static void SocketLoop(Socket* socket) { | |||
| 136 | 136 | ||
| 137 | Client::Client() { | 137 | Client::Client() { |
| 138 | LOG_INFO(Input, "Udp Initialization started"); | 138 | LOG_INFO(Input, "Udp Initialization started"); |
| 139 | for (std::size_t client = 0; client < clients.size(); client++) { | 139 | ReloadSockets(); |
| 140 | const auto pad = client % 4; | ||
| 141 | StartCommunication(client, Settings::values.udp_input_address, | ||
| 142 | Settings::values.udp_input_port, pad, 24872); | ||
| 143 | // Set motion parameters | ||
| 144 | // SetGyroThreshold value should be dependent on GyroscopeZeroDriftMode | ||
| 145 | // Real HW values are unknown, 0.0001 is an approximate to Standard | ||
| 146 | clients[client].motion.SetGyroThreshold(0.0001f); | ||
| 147 | } | ||
| 148 | } | 140 | } |
| 149 | 141 | ||
| 150 | Client::~Client() { | 142 | Client::~Client() { |
| @@ -167,26 +159,61 @@ std::vector<Common::ParamPackage> Client::GetInputDevices() const { | |||
| 167 | return devices; | 159 | return devices; |
| 168 | } | 160 | } |
| 169 | 161 | ||
| 170 | bool Client::DeviceConnected(std::size_t pad) const { | 162 | bool Client::DeviceConnected(std::size_t client) const { |
| 171 | // Use last timestamp to detect if the socket has stopped sending data | 163 | // Use last timestamp to detect if the socket has stopped sending data |
| 172 | const auto now = std::chrono::system_clock::now(); | 164 | const auto now = std::chrono::steady_clock::now(); |
| 173 | const auto time_difference = static_cast<u64>( | 165 | const auto time_difference = |
| 174 | std::chrono::duration_cast<std::chrono::milliseconds>(now - clients[pad].last_motion_update) | 166 | static_cast<u64>(std::chrono::duration_cast<std::chrono::milliseconds>( |
| 175 | .count()); | 167 | now - clients[client].last_motion_update) |
| 176 | return time_difference < 1000 && clients[pad].active == 1; | 168 | .count()); |
| 169 | return time_difference < 1000 && clients[client].active == 1; | ||
| 177 | } | 170 | } |
| 178 | 171 | ||
| 179 | void Client::ReloadUDPClient() { | 172 | void Client::ReloadSockets() { |
| 180 | for (std::size_t client = 0; client < clients.size(); client++) { | 173 | Reset(); |
| 181 | ReloadSocket(Settings::values.udp_input_address, Settings::values.udp_input_port, client); | 174 | |
| 175 | std::stringstream servers_ss(Settings::values.udp_input_servers); | ||
| 176 | std::string server_token; | ||
| 177 | std::size_t client = 0; | ||
| 178 | while (std::getline(servers_ss, server_token, ',')) { | ||
| 179 | if (client == max_udp_clients) { | ||
| 180 | break; | ||
| 181 | } | ||
| 182 | std::stringstream server_ss(server_token); | ||
| 183 | std::string token; | ||
| 184 | std::getline(server_ss, token, ':'); | ||
| 185 | std::string udp_input_address = token; | ||
| 186 | std::getline(server_ss, token, ':'); | ||
| 187 | char* temp; | ||
| 188 | const u16 udp_input_port = static_cast<u16>(std::strtol(token.c_str(), &temp, 0)); | ||
| 189 | if (*temp != '\0') { | ||
| 190 | LOG_ERROR(Input, "Port number is not valid {}", token); | ||
| 191 | continue; | ||
| 192 | } | ||
| 193 | |||
| 194 | for (std::size_t pad = 0; pad < 4; ++pad) { | ||
| 195 | const std::size_t client_number = | ||
| 196 | GetClientNumber(udp_input_address, udp_input_port, pad); | ||
| 197 | if (client_number != max_udp_clients) { | ||
| 198 | LOG_ERROR(Input, "Duplicated UDP servers found"); | ||
| 199 | continue; | ||
| 200 | } | ||
| 201 | StartCommunication(client++, udp_input_address, udp_input_port, pad, 24872); | ||
| 202 | } | ||
| 182 | } | 203 | } |
| 183 | } | 204 | } |
| 184 | void Client::ReloadSocket(const std::string& host, u16 port, std::size_t pad_index, u32 client_id) { | 205 | |
| 185 | // client number must be determined from host / port and pad index | 206 | std::size_t Client::GetClientNumber(std::string_view host, u16 port, std::size_t pad) const { |
| 186 | const std::size_t client = pad_index; | 207 | for (std::size_t client = 0; client < clients.size(); client++) { |
| 187 | clients[client].socket->Stop(); | 208 | if (clients[client].active == -1) { |
| 188 | clients[client].thread.join(); | 209 | continue; |
| 189 | StartCommunication(client, host, port, pad_index, client_id); | 210 | } |
| 211 | if (clients[client].host == host && clients[client].port == port && | ||
| 212 | clients[client].pad_index == pad) { | ||
| 213 | return client; | ||
| 214 | } | ||
| 215 | } | ||
| 216 | return max_udp_clients; | ||
| 190 | } | 217 | } |
| 191 | 218 | ||
| 192 | void Client::OnVersion([[maybe_unused]] Response::Version data) { | 219 | void Client::OnVersion([[maybe_unused]] Response::Version data) { |
| @@ -197,9 +224,7 @@ void Client::OnPortInfo([[maybe_unused]] Response::PortInfo data) { | |||
| 197 | LOG_TRACE(Input, "PortInfo packet received: {}", data.model); | 224 | LOG_TRACE(Input, "PortInfo packet received: {}", data.model); |
| 198 | } | 225 | } |
| 199 | 226 | ||
| 200 | void Client::OnPadData(Response::PadData data) { | 227 | void Client::OnPadData(Response::PadData data, std::size_t client) { |
| 201 | // Client number must be determined from host / port and pad index | ||
| 202 | const std::size_t client = data.info.id; | ||
| 203 | LOG_TRACE(Input, "PadData packet received"); | 228 | LOG_TRACE(Input, "PadData packet received"); |
| 204 | if (data.packet_counter == clients[client].packet_sequence) { | 229 | if (data.packet_counter == clients[client].packet_sequence) { |
| 205 | LOG_WARNING( | 230 | LOG_WARNING( |
| @@ -208,9 +233,9 @@ void Client::OnPadData(Response::PadData data) { | |||
| 208 | clients[client].packet_sequence, data.packet_counter); | 233 | clients[client].packet_sequence, data.packet_counter); |
| 209 | return; | 234 | return; |
| 210 | } | 235 | } |
| 211 | clients[client].active = data.info.is_pad_active; | 236 | clients[client].active = static_cast<s8>(data.info.is_pad_active); |
| 212 | clients[client].packet_sequence = data.packet_counter; | 237 | clients[client].packet_sequence = data.packet_counter; |
| 213 | const auto now = std::chrono::system_clock::now(); | 238 | const auto now = std::chrono::steady_clock::now(); |
| 214 | const auto time_difference = | 239 | const auto time_difference = |
| 215 | static_cast<u64>(std::chrono::duration_cast<std::chrono::microseconds>( | 240 | static_cast<u64>(std::chrono::duration_cast<std::chrono::microseconds>( |
| 216 | now - clients[client].last_motion_update) | 241 | now - clients[client].last_motion_update) |
| @@ -264,16 +289,28 @@ void Client::StartCommunication(std::size_t client, const std::string& host, u16 | |||
| 264 | std::size_t pad_index, u32 client_id) { | 289 | std::size_t pad_index, u32 client_id) { |
| 265 | SocketCallback callback{[this](Response::Version version) { OnVersion(version); }, | 290 | SocketCallback callback{[this](Response::Version version) { OnVersion(version); }, |
| 266 | [this](Response::PortInfo info) { OnPortInfo(info); }, | 291 | [this](Response::PortInfo info) { OnPortInfo(info); }, |
| 267 | [this](Response::PadData data) { OnPadData(data); }}; | 292 | [this, client](Response::PadData data) { OnPadData(data, client); }}; |
| 268 | LOG_INFO(Input, "Starting communication with UDP input server on {}:{}", host, port); | 293 | LOG_INFO(Input, "Starting communication with UDP input server on {}:{}:{}", host, port, |
| 294 | pad_index); | ||
| 295 | clients[client].host = host; | ||
| 296 | clients[client].port = port; | ||
| 297 | clients[client].pad_index = pad_index; | ||
| 298 | clients[client].active = 0; | ||
| 269 | clients[client].socket = std::make_unique<Socket>(host, port, pad_index, client_id, callback); | 299 | clients[client].socket = std::make_unique<Socket>(host, port, pad_index, client_id, callback); |
| 270 | clients[client].thread = std::thread{SocketLoop, clients[client].socket.get()}; | 300 | clients[client].thread = std::thread{SocketLoop, clients[client].socket.get()}; |
| 301 | // Set motion parameters | ||
| 302 | // SetGyroThreshold value should be dependent on GyroscopeZeroDriftMode | ||
| 303 | // Real HW values are unknown, 0.0001 is an approximate to Standard | ||
| 304 | clients[client].motion.SetGyroThreshold(0.0001f); | ||
| 271 | } | 305 | } |
| 272 | 306 | ||
| 273 | void Client::Reset() { | 307 | void Client::Reset() { |
| 274 | for (auto& client : clients) { | 308 | for (auto& client : clients) { |
| 275 | client.socket->Stop(); | 309 | if (client.thread.joinable()) { |
| 276 | client.thread.join(); | 310 | client.active = -1; |
| 311 | client.socket->Stop(); | ||
| 312 | client.thread.join(); | ||
| 313 | } | ||
| 277 | } | 314 | } |
| 278 | } | 315 | } |
| 279 | 316 | ||
| @@ -283,52 +320,60 @@ void Client::UpdateYuzuSettings(std::size_t client, const Common::Vec3<float>& a | |||
| 283 | LOG_DEBUG(Input, "UDP Controller {}: gyro=({}, {}, {}), accel=({}, {}, {}), touch={}", | 320 | LOG_DEBUG(Input, "UDP Controller {}: gyro=({}, {}, {}), accel=({}, {}, {}), touch={}", |
| 284 | client, gyro[0], gyro[1], gyro[2], acc[0], acc[1], acc[2], touch); | 321 | client, gyro[0], gyro[1], gyro[2], acc[0], acc[1], acc[2], touch); |
| 285 | } | 322 | } |
| 286 | UDPPadStatus pad; | 323 | UDPPadStatus pad{ |
| 324 | .host = clients[client].host, | ||
| 325 | .port = clients[client].port, | ||
| 326 | .pad_index = clients[client].pad_index, | ||
| 327 | }; | ||
| 287 | if (touch) { | 328 | if (touch) { |
| 288 | pad.touch = PadTouch::Click; | 329 | pad.touch = PadTouch::Click; |
| 289 | pad_queue[client].Push(pad); | 330 | pad_queue.Push(pad); |
| 290 | } | 331 | } |
| 291 | for (size_t i = 0; i < 3; ++i) { | 332 | for (size_t i = 0; i < 3; ++i) { |
| 292 | if (gyro[i] > 5.0f || gyro[i] < -5.0f) { | 333 | if (gyro[i] > 5.0f || gyro[i] < -5.0f) { |
| 293 | pad.motion = static_cast<PadMotion>(i); | 334 | pad.motion = static_cast<PadMotion>(i); |
| 294 | pad.motion_value = gyro[i]; | 335 | pad.motion_value = gyro[i]; |
| 295 | pad_queue[client].Push(pad); | 336 | pad_queue.Push(pad); |
| 296 | } | 337 | } |
| 297 | if (acc[i] > 1.75f || acc[i] < -1.75f) { | 338 | if (acc[i] > 1.75f || acc[i] < -1.75f) { |
| 298 | pad.motion = static_cast<PadMotion>(i + 3); | 339 | pad.motion = static_cast<PadMotion>(i + 3); |
| 299 | pad.motion_value = acc[i]; | 340 | pad.motion_value = acc[i]; |
| 300 | pad_queue[client].Push(pad); | 341 | pad_queue.Push(pad); |
| 301 | } | 342 | } |
| 302 | } | 343 | } |
| 303 | } | 344 | } |
| 304 | 345 | ||
| 305 | void Client::BeginConfiguration() { | 346 | void Client::BeginConfiguration() { |
| 306 | for (auto& pq : pad_queue) { | 347 | pad_queue.Clear(); |
| 307 | pq.Clear(); | ||
| 308 | } | ||
| 309 | configuring = true; | 348 | configuring = true; |
| 310 | } | 349 | } |
| 311 | 350 | ||
| 312 | void Client::EndConfiguration() { | 351 | void Client::EndConfiguration() { |
| 313 | for (auto& pq : pad_queue) { | 352 | pad_queue.Clear(); |
| 314 | pq.Clear(); | ||
| 315 | } | ||
| 316 | configuring = false; | 353 | configuring = false; |
| 317 | } | 354 | } |
| 318 | 355 | ||
| 319 | DeviceStatus& Client::GetPadState(std::size_t pad) { | 356 | DeviceStatus& Client::GetPadState(const std::string& host, u16 port, std::size_t pad) { |
| 320 | return clients[pad].status; | 357 | const std::size_t client_number = GetClientNumber(host, port, pad); |
| 358 | if (client_number == max_udp_clients) { | ||
| 359 | return clients[0].status; | ||
| 360 | } | ||
| 361 | return clients[client_number].status; | ||
| 321 | } | 362 | } |
| 322 | 363 | ||
| 323 | const DeviceStatus& Client::GetPadState(std::size_t pad) const { | 364 | const DeviceStatus& Client::GetPadState(const std::string& host, u16 port, std::size_t pad) const { |
| 324 | return clients[pad].status; | 365 | const std::size_t client_number = GetClientNumber(host, port, pad); |
| 366 | if (client_number == max_udp_clients) { | ||
| 367 | return clients[0].status; | ||
| 368 | } | ||
| 369 | return clients[client_number].status; | ||
| 325 | } | 370 | } |
| 326 | 371 | ||
| 327 | std::array<Common::SPSCQueue<UDPPadStatus>, 4>& Client::GetPadQueue() { | 372 | Common::SPSCQueue<UDPPadStatus>& Client::GetPadQueue() { |
| 328 | return pad_queue; | 373 | return pad_queue; |
| 329 | } | 374 | } |
| 330 | 375 | ||
| 331 | const std::array<Common::SPSCQueue<UDPPadStatus>, 4>& Client::GetPadQueue() const { | 376 | const Common::SPSCQueue<UDPPadStatus>& Client::GetPadQueue() const { |
| 332 | return pad_queue; | 377 | return pad_queue; |
| 333 | } | 378 | } |
| 334 | 379 | ||
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. |
diff --git a/src/input_common/udp/udp.cpp b/src/input_common/udp/udp.cpp index 71a76a7aa..8686a059c 100644 --- a/src/input_common/udp/udp.cpp +++ b/src/input_common/udp/udp.cpp | |||
| @@ -13,17 +13,17 @@ namespace InputCommon { | |||
| 13 | 13 | ||
| 14 | class UDPMotion final : public Input::MotionDevice { | 14 | class UDPMotion final : public Input::MotionDevice { |
| 15 | public: | 15 | public: |
| 16 | explicit UDPMotion(std::string ip_, int port_, u32 pad_, CemuhookUDP::Client* client_) | 16 | explicit UDPMotion(std::string ip_, u16 port_, u16 pad_, CemuhookUDP::Client* client_) |
| 17 | : ip(std::move(ip_)), port(port_), pad(pad_), client(client_) {} | 17 | : ip(std::move(ip_)), port(port_), pad(pad_), client(client_) {} |
| 18 | 18 | ||
| 19 | Input::MotionStatus GetStatus() const override { | 19 | Input::MotionStatus GetStatus() const override { |
| 20 | return client->GetPadState(pad).motion_status; | 20 | return client->GetPadState(ip, port, pad).motion_status; |
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | private: | 23 | private: |
| 24 | const std::string ip; | 24 | const std::string ip; |
| 25 | const int port; | 25 | const u16 port; |
| 26 | const u32 pad; | 26 | const u16 pad; |
| 27 | CemuhookUDP::Client* client; | 27 | CemuhookUDP::Client* client; |
| 28 | mutable std::mutex mutex; | 28 | mutable std::mutex mutex; |
| 29 | }; | 29 | }; |
| @@ -39,8 +39,8 @@ UDPMotionFactory::UDPMotionFactory(std::shared_ptr<CemuhookUDP::Client> client_) | |||
| 39 | */ | 39 | */ |
| 40 | std::unique_ptr<Input::MotionDevice> UDPMotionFactory::Create(const Common::ParamPackage& params) { | 40 | std::unique_ptr<Input::MotionDevice> UDPMotionFactory::Create(const Common::ParamPackage& params) { |
| 41 | auto ip = params.Get("ip", "127.0.0.1"); | 41 | auto ip = params.Get("ip", "127.0.0.1"); |
| 42 | const auto port = params.Get("port", 26760); | 42 | const auto port = static_cast<u16>(params.Get("port", 26760)); |
| 43 | const auto pad = static_cast<u32>(params.Get("pad_index", 0)); | 43 | const auto pad = static_cast<u16>(params.Get("pad_index", 0)); |
| 44 | 44 | ||
| 45 | return std::make_unique<UDPMotion>(std::move(ip), port, pad, client.get()); | 45 | return std::make_unique<UDPMotion>(std::move(ip), port, pad, client.get()); |
| 46 | } | 46 | } |
| @@ -59,35 +59,33 @@ Common::ParamPackage UDPMotionFactory::GetNextInput() { | |||
| 59 | Common::ParamPackage params; | 59 | Common::ParamPackage params; |
| 60 | CemuhookUDP::UDPPadStatus pad; | 60 | CemuhookUDP::UDPPadStatus pad; |
| 61 | auto& queue = client->GetPadQueue(); | 61 | auto& queue = client->GetPadQueue(); |
| 62 | for (std::size_t pad_number = 0; pad_number < queue.size(); ++pad_number) { | 62 | while (queue.Pop(pad)) { |
| 63 | while (queue[pad_number].Pop(pad)) { | 63 | if (pad.motion == CemuhookUDP::PadMotion::Undefined || std::abs(pad.motion_value) < 1) { |
| 64 | if (pad.motion == CemuhookUDP::PadMotion::Undefined || std::abs(pad.motion_value) < 1) { | 64 | continue; |
| 65 | continue; | ||
| 66 | } | ||
| 67 | params.Set("engine", "cemuhookudp"); | ||
| 68 | params.Set("ip", "127.0.0.1"); | ||
| 69 | params.Set("port", 26760); | ||
| 70 | params.Set("pad_index", static_cast<int>(pad_number)); | ||
| 71 | params.Set("motion", static_cast<u16>(pad.motion)); | ||
| 72 | return params; | ||
| 73 | } | 65 | } |
| 66 | params.Set("engine", "cemuhookudp"); | ||
| 67 | params.Set("ip", pad.host); | ||
| 68 | params.Set("port", static_cast<u16>(pad.port)); | ||
| 69 | params.Set("pad_index", static_cast<u16>(pad.pad_index)); | ||
| 70 | params.Set("motion", static_cast<u16>(pad.motion)); | ||
| 71 | return params; | ||
| 74 | } | 72 | } |
| 75 | return params; | 73 | return params; |
| 76 | } | 74 | } |
| 77 | 75 | ||
| 78 | class UDPTouch final : public Input::TouchDevice { | 76 | class UDPTouch final : public Input::TouchDevice { |
| 79 | public: | 77 | public: |
| 80 | explicit UDPTouch(std::string ip_, int port_, u32 pad_, CemuhookUDP::Client* client_) | 78 | explicit UDPTouch(std::string ip_, u16 port_, u16 pad_, CemuhookUDP::Client* client_) |
| 81 | : ip(std::move(ip_)), port(port_), pad(pad_), client(client_) {} | 79 | : ip(std::move(ip_)), port(port_), pad(pad_), client(client_) {} |
| 82 | 80 | ||
| 83 | std::tuple<float, float, bool> GetStatus() const override { | 81 | std::tuple<float, float, bool> GetStatus() const override { |
| 84 | return client->GetPadState(pad).touch_status; | 82 | return client->GetPadState(ip, port, pad).touch_status; |
| 85 | } | 83 | } |
| 86 | 84 | ||
| 87 | private: | 85 | private: |
| 88 | const std::string ip; | 86 | const std::string ip; |
| 89 | const int port; | 87 | const u16 port; |
| 90 | const u32 pad; | 88 | const u16 pad; |
| 91 | CemuhookUDP::Client* client; | 89 | CemuhookUDP::Client* client; |
| 92 | mutable std::mutex mutex; | 90 | mutable std::mutex mutex; |
| 93 | }; | 91 | }; |
| @@ -103,8 +101,8 @@ UDPTouchFactory::UDPTouchFactory(std::shared_ptr<CemuhookUDP::Client> client_) | |||
| 103 | */ | 101 | */ |
| 104 | std::unique_ptr<Input::TouchDevice> UDPTouchFactory::Create(const Common::ParamPackage& params) { | 102 | std::unique_ptr<Input::TouchDevice> UDPTouchFactory::Create(const Common::ParamPackage& params) { |
| 105 | auto ip = params.Get("ip", "127.0.0.1"); | 103 | auto ip = params.Get("ip", "127.0.0.1"); |
| 106 | const auto port = params.Get("port", 26760); | 104 | const auto port = static_cast<u16>(params.Get("port", 26760)); |
| 107 | const auto pad = static_cast<u32>(params.Get("pad_index", 0)); | 105 | const auto pad = static_cast<u16>(params.Get("pad_index", 0)); |
| 108 | 106 | ||
| 109 | return std::make_unique<UDPTouch>(std::move(ip), port, pad, client.get()); | 107 | return std::make_unique<UDPTouch>(std::move(ip), port, pad, client.get()); |
| 110 | } | 108 | } |
| @@ -123,18 +121,16 @@ Common::ParamPackage UDPTouchFactory::GetNextInput() { | |||
| 123 | Common::ParamPackage params; | 121 | Common::ParamPackage params; |
| 124 | CemuhookUDP::UDPPadStatus pad; | 122 | CemuhookUDP::UDPPadStatus pad; |
| 125 | auto& queue = client->GetPadQueue(); | 123 | auto& queue = client->GetPadQueue(); |
| 126 | for (std::size_t pad_number = 0; pad_number < queue.size(); ++pad_number) { | 124 | while (queue.Pop(pad)) { |
| 127 | while (queue[pad_number].Pop(pad)) { | 125 | if (pad.touch == CemuhookUDP::PadTouch::Undefined) { |
| 128 | if (pad.touch == CemuhookUDP::PadTouch::Undefined) { | 126 | continue; |
| 129 | continue; | ||
| 130 | } | ||
| 131 | params.Set("engine", "cemuhookudp"); | ||
| 132 | params.Set("ip", "127.0.0.1"); | ||
| 133 | params.Set("port", 26760); | ||
| 134 | params.Set("pad_index", static_cast<int>(pad_number)); | ||
| 135 | params.Set("touch", static_cast<u16>(pad.touch)); | ||
| 136 | return params; | ||
| 137 | } | 127 | } |
| 128 | params.Set("engine", "cemuhookudp"); | ||
| 129 | params.Set("ip", pad.host); | ||
| 130 | params.Set("port", static_cast<u16>(pad.port)); | ||
| 131 | params.Set("pad_index", static_cast<u16>(pad.pad_index)); | ||
| 132 | params.Set("touch", static_cast<u16>(pad.touch)); | ||
| 133 | return params; | ||
| 138 | } | 134 | } |
| 139 | return params; | 135 | return params; |
| 140 | } | 136 | } |