Update missing function
This commit is contained in:
@@ -41,7 +41,7 @@ struct InputSubsystem::Impl {
|
||||
sdl = SDL::Init();
|
||||
#endif
|
||||
|
||||
auto udp = std::make_shared<InputCommon::CemuhookUDP::Client>();
|
||||
udp = std::make_shared<InputCommon::CemuhookUDP::Client>();
|
||||
udpmotion = std::make_shared<UDPMotionFactory>(udp);
|
||||
Input::RegisterFactory<Input::RealMotionDevice>("cemuhookudp", udpmotion);
|
||||
udptouch = std::make_shared<UDPTouchFactory>(udp);
|
||||
@@ -80,8 +80,8 @@ struct InputSubsystem::Impl {
|
||||
auto sdl_devices = sdl->GetInputDevices();
|
||||
devices.insert(devices.end(), sdl_devices.begin(), sdl_devices.end());
|
||||
#endif
|
||||
//auto udp_devices = udp->GetInputDevices();
|
||||
//devices.insert(devices.end(), udp_devices.begin(), udp_devices.end());
|
||||
auto udp_devices = udp->GetInputDevices();
|
||||
devices.insert(devices.end(), udp_devices.begin(), udp_devices.end());
|
||||
return devices;
|
||||
}
|
||||
|
||||
@@ -128,6 +128,7 @@ struct InputSubsystem::Impl {
|
||||
std::shared_ptr<GCAnalogFactory> gcanalog;
|
||||
std::shared_ptr<UDPMotionFactory> udpmotion;
|
||||
std::shared_ptr<UDPTouchFactory> udptouch;
|
||||
std::shared_ptr<InputCommon::CemuhookUDP::Client> udp;
|
||||
};
|
||||
|
||||
InputSubsystem::InputSubsystem() : impl{std::make_unique<Impl>()} {}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <thread>
|
||||
#include <boost/asio.hpp>
|
||||
#include "common/logging/log.h"
|
||||
#include "core/settings.h"
|
||||
#include "input_common/udp/client.h"
|
||||
#include "input_common/udp/protocol.h"
|
||||
|
||||
@@ -133,7 +134,8 @@ Client::Client() {
|
||||
LOG_INFO(Input, "Udp Initialization started");
|
||||
for (std::size_t client = 0; client < clients.size(); client++) {
|
||||
u8 pad = client % 4;
|
||||
StartCommunication(client, DEFAULT_ADDR, DEFAULT_PORT, pad, 24872);
|
||||
StartCommunication(client, Settings::values.udp_input_address,
|
||||
Settings::values.udp_input_port, pad, 24872);
|
||||
// Set motion parameters
|
||||
// SetGyroThreshold value should be dependent on GyroscopeZeroDriftMode
|
||||
// Real HW values are unkown, 0.0006 is an aproximate to Standard
|
||||
@@ -145,6 +147,37 @@ Client::~Client() {
|
||||
Reset();
|
||||
}
|
||||
|
||||
std::vector<Common::ParamPackage> Client::GetInputDevices() const {
|
||||
std::vector<Common::ParamPackage> devices;
|
||||
for (std::size_t client = 0; client < clients.size(); client++) {
|
||||
if (!DeviceConnected(client)) {
|
||||
continue;
|
||||
}
|
||||
std::string name = fmt::format("UDP Controller{} {} {}", clients[client].active,
|
||||
clients[client].active == 1, client);
|
||||
devices.emplace_back(Common::ParamPackage{
|
||||
{"class", "cemuhookudp"},
|
||||
{"display", std::move(name)},
|
||||
{"port", std::to_string(client)},
|
||||
});
|
||||
}
|
||||
return devices;
|
||||
}
|
||||
|
||||
bool Client::DeviceConnected(std::size_t pad) const {
|
||||
// Use last timestamp to detect if the socket has stopped sending data
|
||||
const auto now = std::chrono::system_clock::now();
|
||||
u64 time_difference =
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(now - clients[pad].last_motion_update)
|
||||
.count();
|
||||
return time_difference < 1000 && clients[pad].active == 1;
|
||||
}
|
||||
|
||||
void Client::ReloadUDPClient() {
|
||||
for (std::size_t client = 0; client < clients.size(); client++) {
|
||||
ReloadSocket(Settings::values.udp_input_address, Settings::values.udp_input_port, client);
|
||||
}
|
||||
}
|
||||
void Client::ReloadSocket(const std::string& host, u16 port, u8 pad_index, u32 client_id) {
|
||||
// client number must be determined from host / port and pad index
|
||||
std::size_t client = pad_index;
|
||||
@@ -172,6 +205,7 @@ void Client::OnPadData(Response::PadData data) {
|
||||
clients[client].packet_sequence, data.packet_counter);
|
||||
return;
|
||||
}
|
||||
clients[client].active = data.info.is_pad_active;
|
||||
clients[client].packet_sequence = data.packet_counter;
|
||||
const auto now = std::chrono::system_clock::now();
|
||||
u64 time_difference = std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
@@ -239,8 +273,8 @@ void Client::Reset() {
|
||||
}
|
||||
}
|
||||
|
||||
void Client::UpdateYuzuSettings(std::size_t client, Common::Vec3<float> acc,
|
||||
Common::Vec3<float> gyro, bool touch) {
|
||||
void Client::UpdateYuzuSettings(std::size_t client, const Common::Vec3<float>& acc,
|
||||
const Common::Vec3<float>& gyro, bool touch) {
|
||||
if (configuring) {
|
||||
UDPPadStatus pad;
|
||||
if (touch) {
|
||||
@@ -276,11 +310,11 @@ void Client::EndConfiguration() {
|
||||
configuring = false;
|
||||
}
|
||||
|
||||
DeviceStatus& Client::GetPadState(std::string ip, std::size_t port, std::size_t pad) {
|
||||
DeviceStatus& Client::GetPadState(std::size_t pad) {
|
||||
return clients[pad].status;
|
||||
}
|
||||
|
||||
const DeviceStatus& Client::GetPadState(std::string ip, std::size_t port, std::size_t pad) const {
|
||||
const DeviceStatus& Client::GetPadState(std::size_t pad) const {
|
||||
return clients[pad].status;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#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"
|
||||
@@ -31,9 +32,9 @@ struct Version;
|
||||
} // namespace Response
|
||||
|
||||
enum class PadMotion {
|
||||
GyrX,
|
||||
GyrY,
|
||||
GyrZ,
|
||||
GyroX,
|
||||
GyroY,
|
||||
GyroZ,
|
||||
AccX,
|
||||
AccY,
|
||||
AccZ,
|
||||
@@ -70,30 +71,36 @@ struct DeviceStatus {
|
||||
|
||||
class Client {
|
||||
public:
|
||||
/// Initialize the UDP client capture and read sequence
|
||||
// Initialize the UDP client capture and read sequence
|
||||
Client();
|
||||
|
||||
/// Close and relase the client
|
||||
// Close and release the client
|
||||
~Client();
|
||||
/// Used for polling
|
||||
|
||||
// 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::string ip, std::size_t port, std::size_t pad);
|
||||
const DeviceStatus& GetPadState(std::string ip, std::size_t port, std::size_t pad) const;
|
||||
DeviceStatus& GetPadState(std::size_t pad);
|
||||
const DeviceStatus& GetPadState(std::size_t pad) const;
|
||||
|
||||
private:
|
||||
struct Clients {
|
||||
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
|
||||
@@ -101,21 +108,20 @@ private:
|
||||
std::chrono::time_point<std::chrono::system_clock> last_motion_update;
|
||||
};
|
||||
|
||||
/// For shutting down, clear all data, join all threads, release usb
|
||||
// For shutting down, clear all data, join all threads, release usb
|
||||
void Reset();
|
||||
|
||||
// void UpdateOrientation(Joycon& jc, u64 time, std::size_t iteration);
|
||||
void OnVersion(Response::Version);
|
||||
void OnPortInfo(Response::PortInfo);
|
||||
void OnPadData(Response::PadData);
|
||||
void StartCommunication(std::size_t client, const std::string& host, u16 port, u8 pad_index,
|
||||
u32 client_id);
|
||||
void UpdateYuzuSettings(std::size_t client, Common::Vec3<float> acc, Common::Vec3<float> gyro,
|
||||
bool touch);
|
||||
void UpdateYuzuSettings(std::size_t client, const Common::Vec3<float>& acc,
|
||||
const Common::Vec3<float>& gyro, bool touch);
|
||||
|
||||
bool configuring = false;
|
||||
|
||||
std::array<Clients, 4> clients;
|
||||
std::array<ClientData, 4> clients;
|
||||
std::array<Common::SPSCQueue<UDPPadStatus>, 4> pad_queue;
|
||||
};
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
namespace InputCommon {
|
||||
|
||||
class UDPMotion final : public Input::RealMotionDevice {
|
||||
class UDPMotion final : public Input::MotionDevice {
|
||||
public:
|
||||
UDPMotion(std::string ip_, int port_, int pad_, InputCommon::CemuhookUDP::Client* client_)
|
||||
: ip(ip_), port(port_), pad(pad_), client(client_) {}
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
std::tuple<Common::Vec3<float>, Common::Vec3<float>, Common::Vec3<float>,
|
||||
std::array<Common::Vec3f, 3>>
|
||||
GetStatus() const override {
|
||||
return client->GetPadState(ip, port, pad).motion_status;
|
||||
return client->GetPadState(pad).motion_status;
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -41,8 +41,7 @@ UDPMotionFactory::UDPMotionFactory(std::shared_ptr<InputCommon::CemuhookUDP::Cli
|
||||
* @param params contains parameters for creating the device:
|
||||
* - "port": the nth jcpad on the adapter
|
||||
*/
|
||||
std::unique_ptr<Input::RealMotionDevice> UDPMotionFactory::Create(
|
||||
const Common::ParamPackage& params) {
|
||||
std::unique_ptr<Input::MotionDevice> UDPMotionFactory::Create(const Common::ParamPackage& params) {
|
||||
const std::string ip = params.Get("ip", "127.0.0.1");
|
||||
const int port = params.Get("port", 26760);
|
||||
const int pad = params.Get("pad_index", 0);
|
||||
@@ -84,10 +83,10 @@ Common::ParamPackage UDPMotionFactory::GetNextInput() {
|
||||
class UDPTouch final : public Input::TouchDevice {
|
||||
public:
|
||||
UDPTouch(std::string ip_, int port_, int pad_, InputCommon::CemuhookUDP::Client* client_)
|
||||
: ip(ip_), port(port_), pad(pad_), client(client_) {}
|
||||
: ip(std::move(ip_)), port(port_), pad(pad_), client(client_) {}
|
||||
|
||||
std::tuple<float, float, bool> GetStatus() const override {
|
||||
return client->GetPadState(ip, port, pad).touch_status;
|
||||
return client->GetPadState(pad).touch_status;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -11,11 +11,11 @@
|
||||
namespace InputCommon {
|
||||
|
||||
/// A motion device factory that creates motion devices from udp clients
|
||||
class UDPMotionFactory final : public Input::Factory<Input::RealMotionDevice> {
|
||||
class UDPMotionFactory final : public Input::Factory<Input::MotionDevice> {
|
||||
public:
|
||||
explicit UDPMotionFactory(std::shared_ptr<InputCommon::CemuhookUDP::Client> client_);
|
||||
|
||||
std::unique_ptr<Input::RealMotionDevice> Create(const Common::ParamPackage& params) override;
|
||||
std::unique_ptr<Input::MotionDevice> Create(const Common::ParamPackage& params) override;
|
||||
|
||||
Common::ParamPackage GetNextInput();
|
||||
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
#include "core/hle/service/hid/hid.h"
|
||||
#include "core/hle/service/sm/sm.h"
|
||||
#include "input_common/gcadapter/gc_poller.h"
|
||||
#include "input_common/udp/udp.h"
|
||||
#include "input_common/main.h"
|
||||
#include "input_common/udp/udp.h"
|
||||
#include "ui_configure_input_player.h"
|
||||
#include "yuzu/configuration/config.h"
|
||||
#include "yuzu/configuration/configure_input_player.h"
|
||||
|
||||
Reference in New Issue
Block a user