diff options
Diffstat (limited to 'src/input_common/udp')
| -rw-r--r-- | src/input_common/udp/client.cpp | 78 | ||||
| -rw-r--r-- | src/input_common/udp/client.h | 18 | ||||
| -rw-r--r-- | src/input_common/udp/udp.cpp | 28 |
3 files changed, 66 insertions, 58 deletions
diff --git a/src/input_common/udp/client.cpp b/src/input_common/udp/client.cpp index 9d0b9f31d..7039d6fc3 100644 --- a/src/input_common/udp/client.cpp +++ b/src/input_common/udp/client.cpp | |||
| @@ -26,11 +26,11 @@ class Socket { | |||
| 26 | public: | 26 | public: |
| 27 | using clock = std::chrono::system_clock; | 27 | using clock = std::chrono::system_clock; |
| 28 | 28 | ||
| 29 | explicit Socket(const std::string& host, u16 port, u8 pad_index, u32 client_id, | 29 | explicit Socket(const std::string& host, u16 port, std::size_t pad_index_, u32 client_id_, |
| 30 | SocketCallback callback) | 30 | SocketCallback callback_) |
| 31 | : callback(std::move(callback)), timer(io_service), | 31 | : callback(std::move(callback_)), timer(io_service), |
| 32 | socket(io_service, udp::endpoint(udp::v4(), 0)), client_id(client_id), | 32 | socket(io_service, udp::endpoint(udp::v4(), 0)), client_id(client_id_), |
| 33 | pad_index(pad_index) { | 33 | pad_index(pad_index_) { |
| 34 | boost::system::error_code ec{}; | 34 | boost::system::error_code ec{}; |
| 35 | auto ipv4 = boost::asio::ip::make_address_v4(host, ec); | 35 | auto ipv4 = boost::asio::ip::make_address_v4(host, ec); |
| 36 | if (ec.value() != boost::system::errc::success) { | 36 | if (ec.value() != boost::system::errc::success) { |
| @@ -93,13 +93,17 @@ private: | |||
| 93 | void HandleSend(const boost::system::error_code& error) { | 93 | void HandleSend(const boost::system::error_code& error) { |
| 94 | boost::system::error_code _ignored{}; | 94 | boost::system::error_code _ignored{}; |
| 95 | // Send a request for getting port info for the pad | 95 | // Send a request for getting port info for the pad |
| 96 | Request::PortInfo port_info{1, {pad_index, 0, 0, 0}}; | 96 | const Request::PortInfo port_info{1, {static_cast<u8>(pad_index), 0, 0, 0}}; |
| 97 | const auto port_message = Request::Create(port_info, client_id); | 97 | const auto port_message = Request::Create(port_info, client_id); |
| 98 | std::memcpy(&send_buffer1, &port_message, PORT_INFO_SIZE); | 98 | std::memcpy(&send_buffer1, &port_message, PORT_INFO_SIZE); |
| 99 | socket.send_to(boost::asio::buffer(send_buffer1), send_endpoint, {}, _ignored); | 99 | socket.send_to(boost::asio::buffer(send_buffer1), send_endpoint, {}, _ignored); |
| 100 | 100 | ||
| 101 | // Send a request for getting pad data for the pad | 101 | // Send a request for getting pad data for the pad |
| 102 | Request::PadData pad_data{Request::PadData::Flags::Id, pad_index, EMPTY_MAC_ADDRESS}; | 102 | const Request::PadData pad_data{ |
| 103 | Request::PadData::Flags::Id, | ||
| 104 | static_cast<u8>(pad_index), | ||
| 105 | EMPTY_MAC_ADDRESS, | ||
| 106 | }; | ||
| 103 | const auto pad_message = Request::Create(pad_data, client_id); | 107 | const auto pad_message = Request::Create(pad_data, client_id); |
| 104 | std::memcpy(send_buffer2.data(), &pad_message, PAD_DATA_SIZE); | 108 | std::memcpy(send_buffer2.data(), &pad_message, PAD_DATA_SIZE); |
| 105 | socket.send_to(boost::asio::buffer(send_buffer2), send_endpoint, {}, _ignored); | 109 | socket.send_to(boost::asio::buffer(send_buffer2), send_endpoint, {}, _ignored); |
| @@ -112,7 +116,7 @@ private: | |||
| 112 | udp::socket socket; | 116 | udp::socket socket; |
| 113 | 117 | ||
| 114 | u32 client_id{}; | 118 | u32 client_id{}; |
| 115 | u8 pad_index{}; | 119 | std::size_t pad_index{}; |
| 116 | 120 | ||
| 117 | static constexpr std::size_t PORT_INFO_SIZE = sizeof(Message<Request::PortInfo>); | 121 | static constexpr std::size_t PORT_INFO_SIZE = sizeof(Message<Request::PortInfo>); |
| 118 | static constexpr std::size_t PAD_DATA_SIZE = sizeof(Message<Request::PadData>); | 122 | static constexpr std::size_t PAD_DATA_SIZE = sizeof(Message<Request::PadData>); |
| @@ -133,7 +137,7 @@ static void SocketLoop(Socket* socket) { | |||
| 133 | Client::Client() { | 137 | Client::Client() { |
| 134 | LOG_INFO(Input, "Udp Initialization started"); | 138 | LOG_INFO(Input, "Udp Initialization started"); |
| 135 | for (std::size_t client = 0; client < clients.size(); client++) { | 139 | for (std::size_t client = 0; client < clients.size(); client++) { |
| 136 | u8 pad = client % 4; | 140 | const auto pad = client % 4; |
| 137 | StartCommunication(client, Settings::values.udp_input_address, | 141 | StartCommunication(client, Settings::values.udp_input_address, |
| 138 | Settings::values.udp_input_port, pad, 24872); | 142 | Settings::values.udp_input_port, pad, 24872); |
| 139 | // Set motion parameters | 143 | // Set motion parameters |
| @@ -166,9 +170,9 @@ std::vector<Common::ParamPackage> Client::GetInputDevices() const { | |||
| 166 | bool Client::DeviceConnected(std::size_t pad) const { | 170 | bool Client::DeviceConnected(std::size_t pad) const { |
| 167 | // Use last timestamp to detect if the socket has stopped sending data | 171 | // Use last timestamp to detect if the socket has stopped sending data |
| 168 | const auto now = std::chrono::system_clock::now(); | 172 | const auto now = std::chrono::system_clock::now(); |
| 169 | u64 time_difference = | 173 | const auto time_difference = static_cast<u64>( |
| 170 | std::chrono::duration_cast<std::chrono::milliseconds>(now - clients[pad].last_motion_update) | 174 | std::chrono::duration_cast<std::chrono::milliseconds>(now - clients[pad].last_motion_update) |
| 171 | .count(); | 175 | .count()); |
| 172 | return time_difference < 1000 && clients[pad].active == 1; | 176 | return time_difference < 1000 && clients[pad].active == 1; |
| 173 | } | 177 | } |
| 174 | 178 | ||
| @@ -177,9 +181,9 @@ void Client::ReloadUDPClient() { | |||
| 177 | ReloadSocket(Settings::values.udp_input_address, Settings::values.udp_input_port, client); | 181 | ReloadSocket(Settings::values.udp_input_address, Settings::values.udp_input_port, client); |
| 178 | } | 182 | } |
| 179 | } | 183 | } |
| 180 | void Client::ReloadSocket(const std::string& host, u16 port, u8 pad_index, u32 client_id) { | 184 | void Client::ReloadSocket(const std::string& host, u16 port, std::size_t pad_index, u32 client_id) { |
| 181 | // client number must be determined from host / port and pad index | 185 | // client number must be determined from host / port and pad index |
| 182 | std::size_t client = pad_index; | 186 | const std::size_t client = pad_index; |
| 183 | clients[client].socket->Stop(); | 187 | clients[client].socket->Stop(); |
| 184 | clients[client].thread.join(); | 188 | clients[client].thread.join(); |
| 185 | StartCommunication(client, host, port, pad_index, client_id); | 189 | StartCommunication(client, host, port, pad_index, client_id); |
| @@ -194,8 +198,8 @@ void Client::OnPortInfo(Response::PortInfo data) { | |||
| 194 | } | 198 | } |
| 195 | 199 | ||
| 196 | void Client::OnPadData(Response::PadData data) { | 200 | void Client::OnPadData(Response::PadData data) { |
| 197 | // client number must be determined from host / port and pad index | 201 | // Client number must be determined from host / port and pad index |
| 198 | std::size_t client = data.info.id; | 202 | const std::size_t client = data.info.id; |
| 199 | LOG_TRACE(Input, "PadData packet received"); | 203 | LOG_TRACE(Input, "PadData packet received"); |
| 200 | if (data.packet_counter == clients[client].packet_sequence) { | 204 | if (data.packet_counter == clients[client].packet_sequence) { |
| 201 | LOG_WARNING( | 205 | LOG_WARNING( |
| @@ -207,11 +211,12 @@ void Client::OnPadData(Response::PadData data) { | |||
| 207 | clients[client].active = data.info.is_pad_active; | 211 | clients[client].active = data.info.is_pad_active; |
| 208 | clients[client].packet_sequence = data.packet_counter; | 212 | clients[client].packet_sequence = data.packet_counter; |
| 209 | const auto now = std::chrono::system_clock::now(); | 213 | const auto now = std::chrono::system_clock::now(); |
| 210 | u64 time_difference = std::chrono::duration_cast<std::chrono::microseconds>( | 214 | const auto time_difference = |
| 211 | now - clients[client].last_motion_update) | 215 | static_cast<u64>(std::chrono::duration_cast<std::chrono::microseconds>( |
| 212 | .count(); | 216 | now - clients[client].last_motion_update) |
| 217 | .count()); | ||
| 213 | clients[client].last_motion_update = now; | 218 | clients[client].last_motion_update = now; |
| 214 | Common::Vec3f raw_gyroscope = {data.gyro.pitch, data.gyro.roll, -data.gyro.yaw}; | 219 | const Common::Vec3f raw_gyroscope = {data.gyro.pitch, data.gyro.roll, -data.gyro.yaw}; |
| 215 | clients[client].motion.SetAcceleration({data.accel.x, -data.accel.z, data.accel.y}); | 220 | clients[client].motion.SetAcceleration({data.accel.x, -data.accel.z, data.accel.y}); |
| 216 | // Gyroscope values are not it the correct scale from better joy. | 221 | // Gyroscope values are not it the correct scale from better joy. |
| 217 | // Dividing by 312 allows us to make one full turn = 1 turn | 222 | // Dividing by 312 allows us to make one full turn = 1 turn |
| @@ -237,9 +242,11 @@ void Client::OnPadData(Response::PadData data) { | |||
| 237 | const u16 min_y = clients[client].status.touch_calibration->min_y; | 242 | const u16 min_y = clients[client].status.touch_calibration->min_y; |
| 238 | const u16 max_y = clients[client].status.touch_calibration->max_y; | 243 | const u16 max_y = clients[client].status.touch_calibration->max_y; |
| 239 | 244 | ||
| 240 | x = (std::clamp(static_cast<u16>(data.touch_1.x), min_x, max_x) - min_x) / | 245 | x = static_cast<float>(std::clamp(static_cast<u16>(data.touch_1.x), min_x, max_x) - |
| 246 | min_x) / | ||
| 241 | static_cast<float>(max_x - min_x); | 247 | static_cast<float>(max_x - min_x); |
| 242 | y = (std::clamp(static_cast<u16>(data.touch_1.y), min_y, max_y) - min_y) / | 248 | y = static_cast<float>(std::clamp(static_cast<u16>(data.touch_1.y), min_y, max_y) - |
| 249 | min_y) / | ||
| 243 | static_cast<float>(max_y - min_y); | 250 | static_cast<float>(max_y - min_y); |
| 244 | } | 251 | } |
| 245 | 252 | ||
| @@ -253,8 +260,8 @@ void Client::OnPadData(Response::PadData data) { | |||
| 253 | } | 260 | } |
| 254 | } | 261 | } |
| 255 | 262 | ||
| 256 | void Client::StartCommunication(std::size_t client, const std::string& host, u16 port, u8 pad_index, | 263 | void Client::StartCommunication(std::size_t client, const std::string& host, u16 port, |
| 257 | u32 client_id) { | 264 | std::size_t pad_index, u32 client_id) { |
| 258 | SocketCallback callback{[this](Response::Version version) { OnVersion(version); }, | 265 | SocketCallback callback{[this](Response::Version version) { OnVersion(version); }, |
| 259 | [this](Response::PortInfo info) { OnPortInfo(info); }, | 266 | [this](Response::PortInfo info) { OnPortInfo(info); }, |
| 260 | [this](Response::PadData data) { OnPadData(data); }}; | 267 | [this](Response::PadData data) { OnPadData(data); }}; |
| @@ -264,9 +271,9 @@ void Client::StartCommunication(std::size_t client, const std::string& host, u16 | |||
| 264 | } | 271 | } |
| 265 | 272 | ||
| 266 | void Client::Reset() { | 273 | void Client::Reset() { |
| 267 | for (std::size_t client = 0; client < clients.size(); client++) { | 274 | for (auto& client : clients) { |
| 268 | clients[client].socket->Stop(); | 275 | client.socket->Stop(); |
| 269 | clients[client].thread.join(); | 276 | client.thread.join(); |
| 270 | } | 277 | } |
| 271 | } | 278 | } |
| 272 | 279 | ||
| @@ -325,16 +332,19 @@ const std::array<Common::SPSCQueue<UDPPadStatus>, 4>& Client::GetPadQueue() cons | |||
| 325 | return pad_queue; | 332 | return pad_queue; |
| 326 | } | 333 | } |
| 327 | 334 | ||
| 328 | void TestCommunication(const std::string& host, u16 port, u8 pad_index, u32 client_id, | 335 | void TestCommunication(const std::string& host, u16 port, std::size_t pad_index, u32 client_id, |
| 329 | std::function<void()> success_callback, | 336 | const std::function<void()>& success_callback, |
| 330 | std::function<void()> failure_callback) { | 337 | const std::function<void()>& failure_callback) { |
| 331 | std::thread([=] { | 338 | std::thread([=] { |
| 332 | Common::Event success_event; | 339 | Common::Event success_event; |
| 333 | SocketCallback callback{[](Response::Version version) {}, [](Response::PortInfo info) {}, | 340 | SocketCallback callback{ |
| 334 | [&](Response::PadData data) { success_event.Set(); }}; | 341 | .version = [](Response::Version) {}, |
| 342 | .port_info = [](Response::PortInfo) {}, | ||
| 343 | .pad_data = [&](Response::PadData) { success_event.Set(); }, | ||
| 344 | }; | ||
| 335 | Socket socket{host, port, pad_index, client_id, std::move(callback)}; | 345 | Socket socket{host, port, pad_index, client_id, std::move(callback)}; |
| 336 | std::thread worker_thread{SocketLoop, &socket}; | 346 | std::thread worker_thread{SocketLoop, &socket}; |
| 337 | bool result = success_event.WaitFor(std::chrono::seconds(8)); | 347 | const bool result = success_event.WaitFor(std::chrono::seconds(8)); |
| 338 | socket.Stop(); | 348 | socket.Stop(); |
| 339 | worker_thread.join(); | 349 | worker_thread.join(); |
| 340 | if (result) { | 350 | if (result) { |
| @@ -346,7 +356,7 @@ void TestCommunication(const std::string& host, u16 port, u8 pad_index, u32 clie | |||
| 346 | } | 356 | } |
| 347 | 357 | ||
| 348 | CalibrationConfigurationJob::CalibrationConfigurationJob( | 358 | CalibrationConfigurationJob::CalibrationConfigurationJob( |
| 349 | const std::string& host, u16 port, u8 pad_index, u32 client_id, | 359 | const std::string& host, u16 port, std::size_t pad_index, u32 client_id, |
| 350 | std::function<void(Status)> status_callback, | 360 | std::function<void(Status)> status_callback, |
| 351 | std::function<void(u16, u16, u16, u16)> data_callback) { | 361 | std::function<void(u16, u16, u16, u16)> data_callback) { |
| 352 | 362 | ||
| @@ -366,7 +376,7 @@ CalibrationConfigurationJob::CalibrationConfigurationJob( | |||
| 366 | current_status = Status::Ready; | 376 | current_status = Status::Ready; |
| 367 | status_callback(current_status); | 377 | status_callback(current_status); |
| 368 | } | 378 | } |
| 369 | if (!data.touch_1.is_active) { | 379 | if (data.touch_1.is_active == 0) { |
| 370 | return; | 380 | return; |
| 371 | } | 381 | } |
| 372 | LOG_DEBUG(Input, "Current touch: {} {}", data.touch_1.x, | 382 | LOG_DEBUG(Input, "Current touch: {} {}", data.touch_1.x, |
diff --git a/src/input_common/udp/client.h b/src/input_common/udp/client.h index 523dc6a7a..747e0c0a2 100644 --- a/src/input_common/udp/client.h +++ b/src/input_common/udp/client.h | |||
| @@ -84,8 +84,8 @@ public: | |||
| 84 | 84 | ||
| 85 | bool DeviceConnected(std::size_t pad) const; | 85 | bool DeviceConnected(std::size_t pad) const; |
| 86 | void ReloadUDPClient(); | 86 | void ReloadUDPClient(); |
| 87 | 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, |
| 88 | u32 client_id = 24872); | 88 | std::size_t pad_index = 0, u32 client_id = 24872); |
| 89 | 89 | ||
| 90 | std::array<Common::SPSCQueue<UDPPadStatus>, 4>& GetPadQueue(); | 90 | std::array<Common::SPSCQueue<UDPPadStatus>, 4>& GetPadQueue(); |
| 91 | const std::array<Common::SPSCQueue<UDPPadStatus>, 4>& GetPadQueue() const; | 91 | const std::array<Common::SPSCQueue<UDPPadStatus>, 4>& GetPadQueue() const; |
| @@ -99,7 +99,7 @@ private: | |||
| 99 | DeviceStatus status; | 99 | DeviceStatus status; |
| 100 | std::thread thread; | 100 | std::thread thread; |
| 101 | u64 packet_sequence = 0; | 101 | u64 packet_sequence = 0; |
| 102 | u8 active; | 102 | u8 active = 0; |
| 103 | 103 | ||
| 104 | // Realtime values | 104 | // Realtime values |
| 105 | // motion is initalized with PID values for drift correction on joycons | 105 | // motion is initalized with PID values for drift correction on joycons |
| @@ -113,8 +113,8 @@ private: | |||
| 113 | void OnVersion(Response::Version); | 113 | void OnVersion(Response::Version); |
| 114 | void OnPortInfo(Response::PortInfo); | 114 | void OnPortInfo(Response::PortInfo); |
| 115 | void OnPadData(Response::PadData); | 115 | void OnPadData(Response::PadData); |
| 116 | void StartCommunication(std::size_t client, const std::string& host, u16 port, u8 pad_index, | 116 | void StartCommunication(std::size_t client, const std::string& host, u16 port, |
| 117 | u32 client_id); | 117 | std::size_t pad_index, u32 client_id); |
| 118 | void UpdateYuzuSettings(std::size_t client, const Common::Vec3<float>& acc, | 118 | void UpdateYuzuSettings(std::size_t client, const Common::Vec3<float>& acc, |
| 119 | const Common::Vec3<float>& gyro, bool touch); | 119 | const Common::Vec3<float>& gyro, bool touch); |
| 120 | 120 | ||
| @@ -139,7 +139,7 @@ public: | |||
| 139 | * @param status_callback Callback for job status updates | 139 | * @param status_callback Callback for job status updates |
| 140 | * @param data_callback Called when calibration data is ready | 140 | * @param data_callback Called when calibration data is ready |
| 141 | */ | 141 | */ |
| 142 | explicit CalibrationConfigurationJob(const std::string& host, u16 port, u8 pad_index, | 142 | explicit CalibrationConfigurationJob(const std::string& host, u16 port, std::size_t pad_index, |
| 143 | u32 client_id, std::function<void(Status)> status_callback, | 143 | u32 client_id, std::function<void(Status)> status_callback, |
| 144 | std::function<void(u16, u16, u16, u16)> data_callback); | 144 | std::function<void(u16, u16, u16, u16)> data_callback); |
| 145 | ~CalibrationConfigurationJob(); | 145 | ~CalibrationConfigurationJob(); |
| @@ -149,8 +149,8 @@ private: | |||
| 149 | Common::Event complete_event; | 149 | Common::Event complete_event; |
| 150 | }; | 150 | }; |
| 151 | 151 | ||
| 152 | void TestCommunication(const std::string& host, u16 port, u8 pad_index, u32 client_id, | 152 | void TestCommunication(const std::string& host, u16 port, std::size_t pad_index, u32 client_id, |
| 153 | std::function<void()> success_callback, | 153 | const std::function<void()>& success_callback, |
| 154 | std::function<void()> failure_callback); | 154 | const std::function<void()>& failure_callback); |
| 155 | 155 | ||
| 156 | } // namespace InputCommon::CemuhookUDP | 156 | } // namespace InputCommon::CemuhookUDP |
diff --git a/src/input_common/udp/udp.cpp b/src/input_common/udp/udp.cpp index eba077a36..71a76a7aa 100644 --- a/src/input_common/udp/udp.cpp +++ b/src/input_common/udp/udp.cpp | |||
| @@ -2,8 +2,6 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <atomic> | ||
| 6 | #include <list> | ||
| 7 | #include <mutex> | 5 | #include <mutex> |
| 8 | #include <utility> | 6 | #include <utility> |
| 9 | #include "common/assert.h" | 7 | #include "common/assert.h" |
| @@ -15,8 +13,8 @@ namespace InputCommon { | |||
| 15 | 13 | ||
| 16 | class UDPMotion final : public Input::MotionDevice { | 14 | class UDPMotion final : public Input::MotionDevice { |
| 17 | public: | 15 | public: |
| 18 | UDPMotion(std::string ip_, int port_, int pad_, CemuhookUDP::Client* client_) | 16 | explicit UDPMotion(std::string ip_, int port_, u32 pad_, CemuhookUDP::Client* client_) |
| 19 | : ip(ip_), port(port_), pad(pad_), client(client_) {} | 17 | : ip(std::move(ip_)), port(port_), pad(pad_), client(client_) {} |
| 20 | 18 | ||
| 21 | Input::MotionStatus GetStatus() const override { | 19 | Input::MotionStatus GetStatus() const override { |
| 22 | return client->GetPadState(pad).motion_status; | 20 | return client->GetPadState(pad).motion_status; |
| @@ -25,7 +23,7 @@ public: | |||
| 25 | private: | 23 | private: |
| 26 | const std::string ip; | 24 | const std::string ip; |
| 27 | const int port; | 25 | const int port; |
| 28 | const int pad; | 26 | const u32 pad; |
| 29 | CemuhookUDP::Client* client; | 27 | CemuhookUDP::Client* client; |
| 30 | mutable std::mutex mutex; | 28 | mutable std::mutex mutex; |
| 31 | }; | 29 | }; |
| @@ -40,11 +38,11 @@ UDPMotionFactory::UDPMotionFactory(std::shared_ptr<CemuhookUDP::Client> client_) | |||
| 40 | * - "port": the nth jcpad on the adapter | 38 | * - "port": the nth jcpad on the adapter |
| 41 | */ | 39 | */ |
| 42 | std::unique_ptr<Input::MotionDevice> UDPMotionFactory::Create(const Common::ParamPackage& params) { | 40 | std::unique_ptr<Input::MotionDevice> UDPMotionFactory::Create(const Common::ParamPackage& params) { |
| 43 | const std::string ip = params.Get("ip", "127.0.0.1"); | 41 | auto ip = params.Get("ip", "127.0.0.1"); |
| 44 | const int port = params.Get("port", 26760); | 42 | const auto port = params.Get("port", 26760); |
| 45 | const int pad = params.Get("pad_index", 0); | 43 | const auto pad = static_cast<u32>(params.Get("pad_index", 0)); |
| 46 | 44 | ||
| 47 | return std::make_unique<UDPMotion>(ip, port, pad, client.get()); | 45 | return std::make_unique<UDPMotion>(std::move(ip), port, pad, client.get()); |
| 48 | } | 46 | } |
| 49 | 47 | ||
| 50 | void UDPMotionFactory::BeginConfiguration() { | 48 | void UDPMotionFactory::BeginConfiguration() { |
| @@ -79,7 +77,7 @@ Common::ParamPackage UDPMotionFactory::GetNextInput() { | |||
| 79 | 77 | ||
| 80 | class UDPTouch final : public Input::TouchDevice { | 78 | class UDPTouch final : public Input::TouchDevice { |
| 81 | public: | 79 | public: |
| 82 | UDPTouch(std::string ip_, int port_, int pad_, CemuhookUDP::Client* client_) | 80 | explicit UDPTouch(std::string ip_, int port_, u32 pad_, CemuhookUDP::Client* client_) |
| 83 | : ip(std::move(ip_)), port(port_), pad(pad_), client(client_) {} | 81 | : ip(std::move(ip_)), port(port_), pad(pad_), client(client_) {} |
| 84 | 82 | ||
| 85 | std::tuple<float, float, bool> GetStatus() const override { | 83 | std::tuple<float, float, bool> GetStatus() const override { |
| @@ -89,7 +87,7 @@ public: | |||
| 89 | private: | 87 | private: |
| 90 | const std::string ip; | 88 | const std::string ip; |
| 91 | const int port; | 89 | const int port; |
| 92 | const int pad; | 90 | const u32 pad; |
| 93 | CemuhookUDP::Client* client; | 91 | CemuhookUDP::Client* client; |
| 94 | mutable std::mutex mutex; | 92 | mutable std::mutex mutex; |
| 95 | }; | 93 | }; |
| @@ -104,11 +102,11 @@ UDPTouchFactory::UDPTouchFactory(std::shared_ptr<CemuhookUDP::Client> client_) | |||
| 104 | * - "port": the nth jcpad on the adapter | 102 | * - "port": the nth jcpad on the adapter |
| 105 | */ | 103 | */ |
| 106 | std::unique_ptr<Input::TouchDevice> UDPTouchFactory::Create(const Common::ParamPackage& params) { | 104 | std::unique_ptr<Input::TouchDevice> UDPTouchFactory::Create(const Common::ParamPackage& params) { |
| 107 | const std::string ip = params.Get("ip", "127.0.0.1"); | 105 | auto ip = params.Get("ip", "127.0.0.1"); |
| 108 | const int port = params.Get("port", 26760); | 106 | const auto port = params.Get("port", 26760); |
| 109 | const int pad = params.Get("pad_index", 0); | 107 | const auto pad = static_cast<u32>(params.Get("pad_index", 0)); |
| 110 | 108 | ||
| 111 | return std::make_unique<UDPTouch>(ip, port, pad, client.get()); | 109 | return std::make_unique<UDPTouch>(std::move(ip), port, pad, client.get()); |
| 112 | } | 110 | } |
| 113 | 111 | ||
| 114 | void UDPTouchFactory::BeginConfiguration() { | 112 | void UDPTouchFactory::BeginConfiguration() { |