From ac3690f2057fb93ce18f156ff5ffd720a6d6f60c Mon Sep 17 00:00:00 2001 From: fearlessTobi Date: Sat, 24 Aug 2019 15:57:49 +0200 Subject: Input: UDP Client to provide motion and touch controls An implementation of the cemuhook motion/touch protocol, this adds the ability for users to connect several different devices to citra to send direct motion and touch data to citra. Co-Authored-By: jroweboy --- src/input_common/udp/client.h | 96 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 src/input_common/udp/client.h (limited to 'src/input_common/udp/client.h') 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 @@ +// Copyright 2018 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include "common/common_types.h" +#include "common/thread.h" +#include "common/vector_math.h" + +namespace InputCommon::CemuhookUDP { + +static constexpr u16 DEFAULT_PORT = 26760; +static constexpr const char* DEFAULT_ADDR = "127.0.0.1"; + +class Socket; + +namespace Response { +struct PadData; +struct PortInfo; +struct Version; +} // namespace Response + +struct DeviceStatus { + std::mutex update_mutex; + std::tuple, Common::Vec3> motion_status; + std::tuple touch_status; + + // calibration data for scaling the device's touch area to 3ds + struct CalibrationData { + u16 min_x; + u16 min_y; + u16 max_x; + u16 max_y; + }; + std::optional touch_calibration; +}; + +class Client { +public: + explicit Client(std::shared_ptr status, const std::string& host = DEFAULT_ADDR, + u16 port = DEFAULT_PORT, u8 pad_index = 0, u32 client_id = 24872); + ~Client(); + void ReloadSocket(const std::string& host = "127.0.0.1", u16 port = 26760, u8 pad_index = 0, + u32 client_id = 24872); + +private: + 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); + + std::unique_ptr socket; + std::shared_ptr status; + std::thread thread; + u64 packet_sequence = 0; +}; + +/// An async job allowing configuration of the touchpad calibration. +class CalibrationConfigurationJob { +public: + enum class Status { + Initialized, + Ready, + Stage1Completed, + Completed, + }; + /** + * Constructs and starts the job with the specified parameter. + * + * @param status_callback Callback for job status updates + * @param data_callback Called when calibration data is ready + */ + explicit CalibrationConfigurationJob(const std::string& host, u16 port, u8 pad_index, + u32 client_id, std::function status_callback, + std::function data_callback); + ~CalibrationConfigurationJob(); + void Stop(); + +private: + Common::Event complete_event; +}; + +void TestCommunication(const std::string& host, u16 port, u8 pad_index, u32 client_id, + std::function success_callback, + std::function failure_callback); + +} // namespace InputCommon::CemuhookUDP -- cgit v1.2.3