diff options
Diffstat (limited to 'src/input_common/udp/client.h')
| -rw-r--r-- | src/input_common/udp/client.h | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/src/input_common/udp/client.h b/src/input_common/udp/client.h new file mode 100644 index 000000000..5177f46be --- /dev/null +++ b/src/input_common/udp/client.h | |||
| @@ -0,0 +1,96 @@ | |||
| 1 | // Copyright 2018 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <functional> | ||
| 8 | #include <memory> | ||
| 9 | #include <mutex> | ||
| 10 | #include <optional> | ||
| 11 | #include <string> | ||
| 12 | #include <thread> | ||
| 13 | #include <tuple> | ||
| 14 | #include <vector> | ||
| 15 | #include "common/common_types.h" | ||
| 16 | #include "common/thread.h" | ||
| 17 | #include "common/vector_math.h" | ||
| 18 | |||
| 19 | namespace InputCommon::CemuhookUDP { | ||
| 20 | |||
| 21 | static constexpr u16 DEFAULT_PORT = 26760; | ||
| 22 | static constexpr const char* DEFAULT_ADDR = "127.0.0.1"; | ||
| 23 | |||
| 24 | class Socket; | ||
| 25 | |||
| 26 | namespace Response { | ||
| 27 | struct PadData; | ||
| 28 | struct PortInfo; | ||
| 29 | struct Version; | ||
| 30 | } // namespace Response | ||
| 31 | |||
| 32 | struct DeviceStatus { | ||
| 33 | std::mutex update_mutex; | ||
| 34 | std::tuple<Common::Vec3<float>, Common::Vec3<float>> motion_status; | ||
| 35 | std::tuple<float, float, bool> touch_status; | ||
| 36 | |||
| 37 | // calibration data for scaling the device's touch area to 3ds | ||
| 38 | struct CalibrationData { | ||
| 39 | u16 min_x; | ||
| 40 | u16 min_y; | ||
| 41 | u16 max_x; | ||
| 42 | u16 max_y; | ||
| 43 | }; | ||
| 44 | std::optional<CalibrationData> touch_calibration; | ||
| 45 | }; | ||
| 46 | |||
| 47 | class Client { | ||
| 48 | public: | ||
| 49 | explicit Client(std::shared_ptr<DeviceStatus> status, const std::string& host = DEFAULT_ADDR, | ||
| 50 | u16 port = DEFAULT_PORT, u8 pad_index = 0, u32 client_id = 24872); | ||
| 51 | ~Client(); | ||
| 52 | void ReloadSocket(const std::string& host = "127.0.0.1", u16 port = 26760, u8 pad_index = 0, | ||
| 53 | u32 client_id = 24872); | ||
| 54 | |||
| 55 | private: | ||
| 56 | void OnVersion(Response::Version); | ||
| 57 | void OnPortInfo(Response::PortInfo); | ||
| 58 | void OnPadData(Response::PadData); | ||
| 59 | void StartCommunication(const std::string& host, u16 port, u8 pad_index, u32 client_id); | ||
| 60 | |||
| 61 | std::unique_ptr<Socket> socket; | ||
| 62 | std::shared_ptr<DeviceStatus> status; | ||
| 63 | std::thread thread; | ||
| 64 | u64 packet_sequence = 0; | ||
| 65 | }; | ||
| 66 | |||
| 67 | /// An async job allowing configuration of the touchpad calibration. | ||
| 68 | class CalibrationConfigurationJob { | ||
| 69 | public: | ||
| 70 | enum class Status { | ||
| 71 | Initialized, | ||
| 72 | Ready, | ||
| 73 | Stage1Completed, | ||
| 74 | Completed, | ||
| 75 | }; | ||
| 76 | /** | ||
| 77 | * Constructs and starts the job with the specified parameter. | ||
| 78 | * | ||
| 79 | * @param status_callback Callback for job status updates | ||
| 80 | * @param data_callback Called when calibration data is ready | ||
| 81 | */ | ||
| 82 | explicit CalibrationConfigurationJob(const std::string& host, u16 port, u8 pad_index, | ||
| 83 | u32 client_id, std::function<void(Status)> status_callback, | ||
| 84 | std::function<void(u16, u16, u16, u16)> data_callback); | ||
| 85 | ~CalibrationConfigurationJob(); | ||
| 86 | void Stop(); | ||
| 87 | |||
| 88 | private: | ||
| 89 | Common::Event complete_event; | ||
| 90 | }; | ||
| 91 | |||
| 92 | void TestCommunication(const std::string& host, u16 port, u8 pad_index, u32 client_id, | ||
| 93 | std::function<void()> success_callback, | ||
| 94 | std::function<void()> failure_callback); | ||
| 95 | |||
| 96 | } // namespace InputCommon::CemuhookUDP | ||