diff options
Diffstat (limited to '')
| -rw-r--r-- | src/input_common/udp/client.cpp | 26 | ||||
| -rw-r--r-- | src/input_common/udp/client.h | 6 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_motion_touch.cpp | 8 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_motion_touch.h | 2 |
4 files changed, 23 insertions, 19 deletions
diff --git a/src/input_common/udp/client.cpp b/src/input_common/udp/client.cpp index c4afa4174..df73f9ff7 100644 --- a/src/input_common/udp/client.cpp +++ b/src/input_common/udp/client.cpp | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #include <chrono> | 5 | #include <chrono> |
| 6 | #include <cstring> | 6 | #include <cstring> |
| 7 | #include <functional> | 7 | #include <functional> |
| 8 | #include <random> | ||
| 8 | #include <thread> | 9 | #include <thread> |
| 9 | #include <boost/asio.hpp> | 10 | #include <boost/asio.hpp> |
| 10 | #include "common/logging/log.h" | 11 | #include "common/logging/log.h" |
| @@ -26,10 +27,10 @@ class Socket { | |||
| 26 | public: | 27 | public: |
| 27 | using clock = std::chrono::system_clock; | 28 | using clock = std::chrono::system_clock; |
| 28 | 29 | ||
| 29 | explicit Socket(const std::string& host, u16 port, std::size_t pad_index_, u32 client_id_, | 30 | explicit Socket(const std::string& host, u16 port, std::size_t pad_index_, |
| 30 | SocketCallback callback_) | 31 | SocketCallback callback_) |
| 31 | : callback(std::move(callback_)), timer(io_service), | 32 | : callback(std::move(callback_)), timer(io_service), |
| 32 | socket(io_service, udp::endpoint(udp::v4(), 0)), client_id(client_id_), | 33 | socket(io_service, udp::endpoint(udp::v4(), 0)), client_id(GenerateRandomClientId()), |
| 33 | pad_index(pad_index_) { | 34 | pad_index(pad_index_) { |
| 34 | boost::system::error_code ec{}; | 35 | boost::system::error_code ec{}; |
| 35 | auto ipv4 = boost::asio::ip::make_address_v4(host, ec); | 36 | auto ipv4 = boost::asio::ip::make_address_v4(host, ec); |
| @@ -63,6 +64,11 @@ public: | |||
| 63 | } | 64 | } |
| 64 | 65 | ||
| 65 | private: | 66 | private: |
| 67 | u32 GenerateRandomClientId() const { | ||
| 68 | std::random_device device; | ||
| 69 | return device(); | ||
| 70 | } | ||
| 71 | |||
| 66 | void HandleReceive(const boost::system::error_code&, std::size_t bytes_transferred) { | 72 | void HandleReceive(const boost::system::error_code&, std::size_t bytes_transferred) { |
| 67 | if (auto type = Response::Validate(receive_buffer.data(), bytes_transferred)) { | 73 | if (auto type = Response::Validate(receive_buffer.data(), bytes_transferred)) { |
| 68 | switch (*type) { | 74 | switch (*type) { |
| @@ -115,7 +121,7 @@ private: | |||
| 115 | boost::asio::basic_waitable_timer<clock> timer; | 121 | boost::asio::basic_waitable_timer<clock> timer; |
| 116 | udp::socket socket; | 122 | udp::socket socket; |
| 117 | 123 | ||
| 118 | u32 client_id{}; | 124 | const u32 client_id; |
| 119 | std::size_t pad_index{}; | 125 | std::size_t pad_index{}; |
| 120 | 126 | ||
| 121 | static constexpr std::size_t PORT_INFO_SIZE = sizeof(Message<Request::PortInfo>); | 127 | static constexpr std::size_t PORT_INFO_SIZE = sizeof(Message<Request::PortInfo>); |
| @@ -203,7 +209,7 @@ void Client::ReloadSockets() { | |||
| 203 | LOG_ERROR(Input, "Duplicated UDP servers found"); | 209 | LOG_ERROR(Input, "Duplicated UDP servers found"); |
| 204 | continue; | 210 | continue; |
| 205 | } | 211 | } |
| 206 | StartCommunication(client++, udp_input_address, udp_input_port, pad, 24872); | 212 | StartCommunication(client++, udp_input_address, udp_input_port, pad); |
| 207 | } | 213 | } |
| 208 | } | 214 | } |
| 209 | } | 215 | } |
| @@ -277,7 +283,7 @@ void Client::OnPadData(Response::PadData data, std::size_t client) { | |||
| 277 | } | 283 | } |
| 278 | 284 | ||
| 279 | void Client::StartCommunication(std::size_t client, const std::string& host, u16 port, | 285 | void Client::StartCommunication(std::size_t client, const std::string& host, u16 port, |
| 280 | std::size_t pad_index, u32 client_id) { | 286 | std::size_t pad_index) { |
| 281 | SocketCallback callback{[this](Response::Version version) { OnVersion(version); }, | 287 | SocketCallback callback{[this](Response::Version version) { OnVersion(version); }, |
| 282 | [this](Response::PortInfo info) { OnPortInfo(info); }, | 288 | [this](Response::PortInfo info) { OnPortInfo(info); }, |
| 283 | [this, client](Response::PadData data) { OnPadData(data, client); }}; | 289 | [this, client](Response::PadData data) { OnPadData(data, client); }}; |
| @@ -287,7 +293,7 @@ void Client::StartCommunication(std::size_t client, const std::string& host, u16 | |||
| 287 | clients[client].port = port; | 293 | clients[client].port = port; |
| 288 | clients[client].pad_index = pad_index; | 294 | clients[client].pad_index = pad_index; |
| 289 | clients[client].active = 0; | 295 | clients[client].active = 0; |
| 290 | clients[client].socket = std::make_unique<Socket>(host, port, pad_index, client_id, callback); | 296 | clients[client].socket = std::make_unique<Socket>(host, port, pad_index, callback); |
| 291 | clients[client].thread = std::thread{SocketLoop, clients[client].socket.get()}; | 297 | clients[client].thread = std::thread{SocketLoop, clients[client].socket.get()}; |
| 292 | // Set motion parameters | 298 | // Set motion parameters |
| 293 | // SetGyroThreshold value should be dependent on GyroscopeZeroDriftMode | 299 | // SetGyroThreshold value should be dependent on GyroscopeZeroDriftMode |
| @@ -416,7 +422,7 @@ const Common::SPSCQueue<UDPPadStatus>& Client::GetPadQueue() const { | |||
| 416 | return pad_queue; | 422 | return pad_queue; |
| 417 | } | 423 | } |
| 418 | 424 | ||
| 419 | void TestCommunication(const std::string& host, u16 port, std::size_t pad_index, u32 client_id, | 425 | void TestCommunication(const std::string& host, u16 port, std::size_t pad_index, |
| 420 | const std::function<void()>& success_callback, | 426 | const std::function<void()>& success_callback, |
| 421 | const std::function<void()>& failure_callback) { | 427 | const std::function<void()>& failure_callback) { |
| 422 | std::thread([=] { | 428 | std::thread([=] { |
| @@ -426,7 +432,7 @@ void TestCommunication(const std::string& host, u16 port, std::size_t pad_index, | |||
| 426 | .port_info = [](Response::PortInfo) {}, | 432 | .port_info = [](Response::PortInfo) {}, |
| 427 | .pad_data = [&](Response::PadData) { success_event.Set(); }, | 433 | .pad_data = [&](Response::PadData) { success_event.Set(); }, |
| 428 | }; | 434 | }; |
| 429 | Socket socket{host, port, pad_index, client_id, std::move(callback)}; | 435 | Socket socket{host, port, pad_index, std::move(callback)}; |
| 430 | std::thread worker_thread{SocketLoop, &socket}; | 436 | std::thread worker_thread{SocketLoop, &socket}; |
| 431 | const bool result = success_event.WaitFor(std::chrono::seconds(5)); | 437 | const bool result = success_event.WaitFor(std::chrono::seconds(5)); |
| 432 | socket.Stop(); | 438 | socket.Stop(); |
| @@ -440,7 +446,7 @@ void TestCommunication(const std::string& host, u16 port, std::size_t pad_index, | |||
| 440 | } | 446 | } |
| 441 | 447 | ||
| 442 | CalibrationConfigurationJob::CalibrationConfigurationJob( | 448 | CalibrationConfigurationJob::CalibrationConfigurationJob( |
| 443 | const std::string& host, u16 port, std::size_t pad_index, u32 client_id, | 449 | const std::string& host, u16 port, std::size_t pad_index, |
| 444 | std::function<void(Status)> status_callback, | 450 | std::function<void(Status)> status_callback, |
| 445 | std::function<void(u16, u16, u16, u16)> data_callback) { | 451 | std::function<void(u16, u16, u16, u16)> data_callback) { |
| 446 | 452 | ||
| @@ -485,7 +491,7 @@ CalibrationConfigurationJob::CalibrationConfigurationJob( | |||
| 485 | complete_event.Set(); | 491 | complete_event.Set(); |
| 486 | } | 492 | } |
| 487 | }}; | 493 | }}; |
| 488 | Socket socket{host, port, pad_index, client_id, std::move(callback)}; | 494 | Socket socket{host, port, pad_index, std::move(callback)}; |
| 489 | std::thread worker_thread{SocketLoop, &socket}; | 495 | std::thread worker_thread{SocketLoop, &socket}; |
| 490 | complete_event.Wait(); | 496 | complete_event.Wait(); |
| 491 | socket.Stop(); | 497 | socket.Stop(); |
diff --git a/src/input_common/udp/client.h b/src/input_common/udp/client.h index a523f6124..e9e438e88 100644 --- a/src/input_common/udp/client.h +++ b/src/input_common/udp/client.h | |||
| @@ -126,7 +126,7 @@ private: | |||
| 126 | void OnPortInfo(Response::PortInfo); | 126 | void OnPortInfo(Response::PortInfo); |
| 127 | void OnPadData(Response::PadData, std::size_t client); | 127 | void OnPadData(Response::PadData, std::size_t client); |
| 128 | void StartCommunication(std::size_t client, const std::string& host, u16 port, | 128 | void StartCommunication(std::size_t client, const std::string& host, u16 port, |
| 129 | std::size_t pad_index, u32 client_id); | 129 | std::size_t pad_index); |
| 130 | void UpdateYuzuSettings(std::size_t client, const Common::Vec3<float>& acc, | 130 | void UpdateYuzuSettings(std::size_t client, const Common::Vec3<float>& acc, |
| 131 | const Common::Vec3<float>& gyro); | 131 | const Common::Vec3<float>& gyro); |
| 132 | 132 | ||
| @@ -165,7 +165,7 @@ public: | |||
| 165 | * @param data_callback Called when calibration data is ready | 165 | * @param data_callback Called when calibration data is ready |
| 166 | */ | 166 | */ |
| 167 | explicit CalibrationConfigurationJob(const std::string& host, u16 port, std::size_t pad_index, | 167 | explicit CalibrationConfigurationJob(const std::string& host, u16 port, std::size_t pad_index, |
| 168 | u32 client_id, std::function<void(Status)> status_callback, | 168 | std::function<void(Status)> status_callback, |
| 169 | std::function<void(u16, u16, u16, u16)> data_callback); | 169 | std::function<void(u16, u16, u16, u16)> data_callback); |
| 170 | ~CalibrationConfigurationJob(); | 170 | ~CalibrationConfigurationJob(); |
| 171 | void Stop(); | 171 | void Stop(); |
| @@ -174,7 +174,7 @@ private: | |||
| 174 | Common::Event complete_event; | 174 | Common::Event complete_event; |
| 175 | }; | 175 | }; |
| 176 | 176 | ||
| 177 | void TestCommunication(const std::string& host, u16 port, std::size_t pad_index, u32 client_id, | 177 | void TestCommunication(const std::string& host, u16 port, std::size_t pad_index, |
| 178 | const std::function<void()>& success_callback, | 178 | const std::function<void()>& success_callback, |
| 179 | const std::function<void()>& failure_callback); | 179 | const std::function<void()>& failure_callback); |
| 180 | 180 | ||
diff --git a/src/yuzu/configuration/configure_motion_touch.cpp b/src/yuzu/configuration/configure_motion_touch.cpp index 1f2b792e4..52fdf7265 100644 --- a/src/yuzu/configuration/configure_motion_touch.cpp +++ b/src/yuzu/configuration/configure_motion_touch.cpp | |||
| @@ -24,7 +24,7 @@ | |||
| 24 | 24 | ||
| 25 | CalibrationConfigurationDialog::CalibrationConfigurationDialog(QWidget* parent, | 25 | CalibrationConfigurationDialog::CalibrationConfigurationDialog(QWidget* parent, |
| 26 | const std::string& host, u16 port, | 26 | const std::string& host, u16 port, |
| 27 | u8 pad_index, u16 client_id) | 27 | u8 pad_index) |
| 28 | : QDialog(parent) { | 28 | : QDialog(parent) { |
| 29 | layout = new QVBoxLayout; | 29 | layout = new QVBoxLayout; |
| 30 | status_label = new QLabel(tr("Communicating with the server...")); | 30 | status_label = new QLabel(tr("Communicating with the server...")); |
| @@ -41,7 +41,7 @@ CalibrationConfigurationDialog::CalibrationConfigurationDialog(QWidget* parent, | |||
| 41 | 41 | ||
| 42 | using namespace InputCommon::CemuhookUDP; | 42 | using namespace InputCommon::CemuhookUDP; |
| 43 | job = std::make_unique<CalibrationConfigurationJob>( | 43 | job = std::make_unique<CalibrationConfigurationJob>( |
| 44 | host, port, pad_index, client_id, | 44 | host, port, pad_index, |
| 45 | [this](CalibrationConfigurationJob::Status status) { | 45 | [this](CalibrationConfigurationJob::Status status) { |
| 46 | QString text; | 46 | QString text; |
| 47 | switch (status) { | 47 | switch (status) { |
| @@ -218,7 +218,6 @@ void ConfigureMotionTouch::OnCemuhookUDPTest() { | |||
| 218 | udp_test_in_progress = true; | 218 | udp_test_in_progress = true; |
| 219 | InputCommon::CemuhookUDP::TestCommunication( | 219 | InputCommon::CemuhookUDP::TestCommunication( |
| 220 | ui->udp_server->text().toStdString(), static_cast<u16>(ui->udp_port->text().toInt()), 0, | 220 | ui->udp_server->text().toStdString(), static_cast<u16>(ui->udp_port->text().toInt()), 0, |
| 221 | 24872, | ||
| 222 | [this] { | 221 | [this] { |
| 223 | LOG_INFO(Frontend, "UDP input test success"); | 222 | LOG_INFO(Frontend, "UDP input test success"); |
| 224 | QMetaObject::invokeMethod(this, "ShowUDPTestResult", Q_ARG(bool, true)); | 223 | QMetaObject::invokeMethod(this, "ShowUDPTestResult", Q_ARG(bool, true)); |
| @@ -233,8 +232,7 @@ void ConfigureMotionTouch::OnConfigureTouchCalibration() { | |||
| 233 | ui->touch_calibration_config->setEnabled(false); | 232 | ui->touch_calibration_config->setEnabled(false); |
| 234 | ui->touch_calibration_config->setText(tr("Configuring")); | 233 | ui->touch_calibration_config->setText(tr("Configuring")); |
| 235 | CalibrationConfigurationDialog dialog(this, ui->udp_server->text().toStdString(), | 234 | CalibrationConfigurationDialog dialog(this, ui->udp_server->text().toStdString(), |
| 236 | static_cast<u16>(ui->udp_port->text().toUInt()), 0, | 235 | static_cast<u16>(ui->udp_port->text().toUInt()), 0); |
| 237 | 24872); | ||
| 238 | dialog.exec(); | 236 | dialog.exec(); |
| 239 | if (dialog.completed) { | 237 | if (dialog.completed) { |
| 240 | min_x = dialog.min_x; | 238 | min_x = dialog.min_x; |
diff --git a/src/yuzu/configuration/configure_motion_touch.h b/src/yuzu/configuration/configure_motion_touch.h index 15d61e8ba..d76bc8154 100644 --- a/src/yuzu/configuration/configure_motion_touch.h +++ b/src/yuzu/configuration/configure_motion_touch.h | |||
| @@ -30,7 +30,7 @@ class CalibrationConfigurationDialog : public QDialog { | |||
| 30 | Q_OBJECT | 30 | Q_OBJECT |
| 31 | public: | 31 | public: |
| 32 | explicit CalibrationConfigurationDialog(QWidget* parent, const std::string& host, u16 port, | 32 | explicit CalibrationConfigurationDialog(QWidget* parent, const std::string& host, u16 port, |
| 33 | u8 pad_index, u16 client_id); | 33 | u8 pad_index); |
| 34 | ~CalibrationConfigurationDialog() override; | 34 | ~CalibrationConfigurationDialog() override; |
| 35 | 35 | ||
| 36 | private: | 36 | private: |