diff options
| author | 2019-11-03 07:04:28 +0100 | |
|---|---|---|
| committer | 2020-01-23 20:55:26 +0100 | |
| commit | 0fe11746fcb37de2465cdbbe74be6ad4a59228e5 (patch) | |
| tree | df1f0c06411a69f801e969db6892ade90dec6460 /src/input_common/udp/client.cpp | |
| parent | Input: UDP Client to provide motion and touch controls (diff) | |
| download | yuzu-0fe11746fcb37de2465cdbbe74be6ad4a59228e5.tar.gz yuzu-0fe11746fcb37de2465cdbbe74be6ad4a59228e5.tar.xz yuzu-0fe11746fcb37de2465cdbbe74be6ad4a59228e5.zip | |
Address review comments
Diffstat (limited to 'src/input_common/udp/client.cpp')
| -rw-r--r-- | src/input_common/udp/client.cpp | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/input_common/udp/client.cpp b/src/input_common/udp/client.cpp index c31236c7c..3c51f72a0 100644 --- a/src/input_common/udp/client.cpp +++ b/src/input_common/udp/client.cpp | |||
| @@ -88,15 +88,15 @@ private: | |||
| 88 | void HandleSend(const boost::system::error_code& error) { | 88 | void HandleSend(const boost::system::error_code& error) { |
| 89 | // Send a request for getting port info for the pad | 89 | // Send a request for getting port info for the pad |
| 90 | Request::PortInfo port_info{1, {pad_index, 0, 0, 0}}; | 90 | Request::PortInfo port_info{1, {pad_index, 0, 0, 0}}; |
| 91 | auto port_message = Request::Create(port_info, client_id); | 91 | const auto port_message = Request::Create(port_info, client_id); |
| 92 | std::memcpy(&send_buffer1, &port_message, PORT_INFO_SIZE); | 92 | std::memcpy(&send_buffer1, &port_message, PORT_INFO_SIZE); |
| 93 | std::size_t len = socket.send_to(boost::asio::buffer(send_buffer1), send_endpoint); | 93 | socket.send_to(boost::asio::buffer(send_buffer1), send_endpoint); |
| 94 | 94 | ||
| 95 | // Send a request for getting pad data for the pad | 95 | // Send a request for getting pad data for the pad |
| 96 | Request::PadData pad_data{Request::PadData::Flags::Id, pad_index, EMPTY_MAC_ADDRESS}; | 96 | Request::PadData pad_data{Request::PadData::Flags::Id, pad_index, EMPTY_MAC_ADDRESS}; |
| 97 | auto pad_message = Request::Create(pad_data, client_id); | 97 | const auto pad_message = Request::Create(pad_data, client_id); |
| 98 | std::memcpy(send_buffer2.data(), &pad_message, PAD_DATA_SIZE); | 98 | std::memcpy(send_buffer2.data(), &pad_message, PAD_DATA_SIZE); |
| 99 | std::size_t len2 = socket.send_to(boost::asio::buffer(send_buffer2), send_endpoint); | 99 | socket.send_to(boost::asio::buffer(send_buffer2), send_endpoint); |
| 100 | StartSend(timer.expiry()); | 100 | StartSend(timer.expiry()); |
| 101 | } | 101 | } |
| 102 | 102 | ||
| @@ -105,8 +105,8 @@ private: | |||
| 105 | boost::asio::basic_waitable_timer<clock> timer; | 105 | boost::asio::basic_waitable_timer<clock> timer; |
| 106 | udp::socket socket; | 106 | udp::socket socket; |
| 107 | 107 | ||
| 108 | u32 client_id; | 108 | u32 client_id{}; |
| 109 | u8 pad_index; | 109 | u8 pad_index{}; |
| 110 | 110 | ||
| 111 | static constexpr std::size_t PORT_INFO_SIZE = sizeof(Message<Request::PortInfo>); | 111 | static constexpr std::size_t PORT_INFO_SIZE = sizeof(Message<Request::PortInfo>); |
| 112 | static constexpr std::size_t PAD_DATA_SIZE = sizeof(Message<Request::PadData>); | 112 | static constexpr std::size_t PAD_DATA_SIZE = sizeof(Message<Request::PadData>); |
| @@ -170,16 +170,16 @@ void Client::OnPadData(Response::PadData data) { | |||
| 170 | 170 | ||
| 171 | // TODO: add a setting for "click" touch. Click touch refers to a device that differentiates | 171 | // TODO: add a setting for "click" touch. Click touch refers to a device that differentiates |
| 172 | // between a simple "tap" and a hard press that causes the touch screen to click. | 172 | // between a simple "tap" and a hard press that causes the touch screen to click. |
| 173 | bool is_active = data.touch_1.is_active != 0; | 173 | const bool is_active = data.touch_1.is_active != 0; |
| 174 | 174 | ||
| 175 | float x = 0; | 175 | float x = 0; |
| 176 | float y = 0; | 176 | float y = 0; |
| 177 | 177 | ||
| 178 | if (is_active && status->touch_calibration) { | 178 | if (is_active && status->touch_calibration) { |
| 179 | u16 min_x = status->touch_calibration->min_x; | 179 | const u16 min_x = status->touch_calibration->min_x; |
| 180 | u16 max_x = status->touch_calibration->max_x; | 180 | const u16 max_x = status->touch_calibration->max_x; |
| 181 | u16 min_y = status->touch_calibration->min_y; | 181 | const u16 min_y = status->touch_calibration->min_y; |
| 182 | u16 max_y = status->touch_calibration->max_y; | 182 | const u16 max_y = status->touch_calibration->max_y; |
| 183 | 183 | ||
| 184 | x = (std::clamp(static_cast<u16>(data.touch_1.x), min_x, max_x) - min_x) / | 184 | x = (std::clamp(static_cast<u16>(data.touch_1.x), min_x, max_x) - min_x) / |
| 185 | static_cast<float>(max_x - min_x); | 185 | static_cast<float>(max_x - min_x); |
| @@ -229,7 +229,7 @@ CalibrationConfigurationJob::CalibrationConfigurationJob( | |||
| 229 | constexpr u16 CALIBRATION_THRESHOLD = 100; | 229 | constexpr u16 CALIBRATION_THRESHOLD = 100; |
| 230 | 230 | ||
| 231 | u16 min_x{UINT16_MAX}, min_y{UINT16_MAX}; | 231 | u16 min_x{UINT16_MAX}, min_y{UINT16_MAX}; |
| 232 | u16 max_x, max_y; | 232 | u16 max_x{}, max_y{}; |
| 233 | 233 | ||
| 234 | Status current_status{Status::Initialized}; | 234 | Status current_status{Status::Initialized}; |
| 235 | SocketCallback callback{[](Response::Version version) {}, [](Response::PortInfo info) {}, | 235 | SocketCallback callback{[](Response::Version version) {}, [](Response::PortInfo info) {}, |