diff options
author | german <german@thesoftwareartisans.com> | 2020-09-05 04:35:42 +0200 |
---|---|---|
committer | german <german@thesoftwareartisans.com> | 2020-09-05 04:48:13 +0200 |
commit | 6ee8eab670acfed494ade355d77a32c57f7c9585 (patch) | |
tree | ca91a7ca7ac7861ae48c5456870eee425fc8c209 /src/input_common/udp/client.h | |
parent | Remove RealMotionDevice (diff) | |
download | yuzu-6ee8eab670acfed494ade355d77a32c57f7c9585.tar yuzu-6ee8eab670acfed494ade355d77a32c57f7c9585.tar.gz yuzu-6ee8eab670acfed494ade355d77a32c57f7c9585.tar.bz2 yuzu-6ee8eab670acfed494ade355d77a32c57f7c9585.tar.lz yuzu-6ee8eab670acfed494ade355d77a32c57f7c9585.tar.xz yuzu-6ee8eab670acfed494ade355d77a32c57f7c9585.tar.zst yuzu-6ee8eab670acfed494ade355d77a32c57f7c9585.zip |
Diffstat (limited to '')
-rw-r--r-- | src/input_common/udp/client.h | 74 |
1 files changed, 67 insertions, 7 deletions
diff --git a/src/input_common/udp/client.h b/src/input_common/udp/client.h index a73283ae8..523dc6a7a 100644 --- a/src/input_common/udp/client.h +++ b/src/input_common/udp/client.h @@ -12,9 +12,12 @@ #include <thread> #include <tuple> #include "common/common_types.h" +#include "common/param_package.h" #include "common/thread.h" +#include "common/threadsafe_queue.h" #include "common/vector_math.h" #include "core/frontend/input.h" +#include "input_common/motion_input.h" namespace InputCommon::CemuhookUDP { @@ -29,6 +32,27 @@ struct PortInfo; struct Version; } // namespace Response +enum class PadMotion { + GyroX, + GyroY, + GyroZ, + AccX, + AccY, + AccZ, + Undefined, +}; + +enum class PadTouch { + Click, + Undefined, +}; + +struct UDPPadStatus { + PadTouch touch{PadTouch::Undefined}; + PadMotion motion{PadMotion::Undefined}; + f32 motion_value{0.0f}; +}; + struct DeviceStatus { std::mutex update_mutex; Input::MotionStatus motion_status; @@ -46,22 +70,58 @@ struct DeviceStatus { class Client { public: - explicit Client(std::shared_ptr<DeviceStatus> status, const std::string& host = DEFAULT_ADDR, - u16 port = DEFAULT_PORT, u8 pad_index = 0, u32 client_id = 24872); + // Initialize the UDP client capture and read sequence + Client(); + + // Close and release the client ~Client(); + + // Used for polling + void BeginConfiguration(); + void EndConfiguration(); + + std::vector<Common::ParamPackage> GetInputDevices() const; + + bool DeviceConnected(std::size_t pad) const; + void ReloadUDPClient(); void ReloadSocket(const std::string& host = "127.0.0.1", u16 port = 26760, u8 pad_index = 0, u32 client_id = 24872); + std::array<Common::SPSCQueue<UDPPadStatus>, 4>& GetPadQueue(); + const std::array<Common::SPSCQueue<UDPPadStatus>, 4>& GetPadQueue() const; + + DeviceStatus& GetPadState(std::size_t pad); + const DeviceStatus& GetPadState(std::size_t pad) const; + private: + struct ClientData { + std::unique_ptr<Socket> socket; + DeviceStatus status; + std::thread thread; + u64 packet_sequence = 0; + u8 active; + + // Realtime values + // motion is initalized with PID values for drift correction on joycons + InputCommon::MotionInput motion{0.3f, 0.005f, 0.0f}; + std::chrono::time_point<std::chrono::system_clock> last_motion_update; + }; + + // For shutting down, clear all data, join all threads, release usb + void Reset(); + void OnVersion(Response::Version); void OnPortInfo(Response::PortInfo); void OnPadData(Response::PadData); - void StartCommunication(const std::string& host, u16 port, u8 pad_index, u32 client_id); + void StartCommunication(std::size_t client, const std::string& host, u16 port, u8 pad_index, + u32 client_id); + void UpdateYuzuSettings(std::size_t client, const Common::Vec3<float>& acc, + const Common::Vec3<float>& gyro, bool touch); + + bool configuring = false; - std::unique_ptr<Socket> socket; - std::shared_ptr<DeviceStatus> status; - std::thread thread; - u64 packet_sequence = 0; + std::array<ClientData, 4> clients; + std::array<Common::SPSCQueue<UDPPadStatus>, 4> pad_queue; }; /// An async job allowing configuration of the touchpad calibration. |