Add full motion to cemu hook

This commit is contained in:
german
2020-08-29 17:51:41 -05:00
parent 39319f09d8
commit 4a6fa559c4
4 changed files with 38 additions and 11 deletions

View File

@@ -135,6 +135,8 @@ Client::Client(std::shared_ptr<DeviceStatus> status, const std::string& host, u1
u8 pad_index, u32 client_id)
: status(std::move(status)) {
StartCommunication(host, port, pad_index, client_id);
motion = new InputCommon::MotionInput(0.3f, 0.005f, 0.0f);
motion->SetGyroThreshold(0.0006f);
}
Client::~Client() {
@@ -168,12 +170,22 @@ void Client::OnPadData(Response::PadData data) {
packet_sequence = data.packet_counter;
// TODO: Check how the Switch handles motions and how the CemuhookUDP motion
// directions correspond to the ones of the Switch
Common::Vec3f accel = Common::MakeVec<float>(data.accel.x, data.accel.y, data.accel.z);
Common::Vec3f gyro = Common::MakeVec<float>(data.gyro.pitch, data.gyro.yaw, data.gyro.roll);
const auto now = std::chrono::system_clock::now();
u64 time_difference =
std::chrono::duration_cast<std::chrono::microseconds>(now - last_motion_update).count();
last_motion_update = now;
Common::Vec3f rawgyroscope = {data.gyro.pitch, data.gyro.roll, -data.gyro.yaw};
motion->SetAcceleration({data.accel.x, -data.accel.z, data.accel.y});
motion->SetGyroscope(rawgyroscope / 312.0f);
motion->UpdateRotation(time_difference);
motion->UpdateOrientation(time_difference);
Common::Vec3f gyroscope = motion->GetGyroscope();
Common::Vec3f accelerometer = motion->GetAcceleration();
Common::Vec3f rotation = motion->GetRotations();
std::array<Common::Vec3f, 3> orientation = motion->GetOrientation();
{
std::lock_guard guard(status->update_mutex);
status->motion_status = {accel, gyro};
status->motion_status = {accelerometer, gyroscope, rotation, orientation};
// TODO: add a setting for "click" touch. Click touch refers to a device that differentiates
// between a simple "tap" and a hard press that causes the touch screen to click.

View File

@@ -14,6 +14,7 @@
#include "common/common_types.h"
#include "common/thread.h"
#include "common/vector_math.h"
#include "input_common/motion_input.h"
namespace InputCommon::CemuhookUDP {
@@ -30,7 +31,9 @@ struct Version;
struct DeviceStatus {
std::mutex update_mutex;
std::tuple<Common::Vec3<float>, Common::Vec3<float>> motion_status;
std::tuple<Common::Vec3<float>, Common::Vec3<float>, Common::Vec3<float>,
std::array<Common::Vec3f, 3>>
motion_status;
std::tuple<float, float, bool> touch_status;
// calibration data for scaling the device's touch area to 3ds
@@ -57,6 +60,8 @@ private:
void OnPadData(Response::PadData);
void StartCommunication(const std::string& host, u16 port, u8 pad_index, u32 client_id);
InputCommon::MotionInput* motion = nullptr;
std::chrono::time_point<std::chrono::system_clock> last_motion_update;
std::unique_ptr<Socket> socket;
std::shared_ptr<DeviceStatus> status;
std::thread thread;

View File

@@ -26,10 +26,12 @@ private:
std::shared_ptr<DeviceStatus> status;
};
class UDPMotionDevice final : public Input::MotionDevice {
class UDPMotionDevice final : public Input::RealMotionDevice {
public:
explicit UDPMotionDevice(std::shared_ptr<DeviceStatus> status_) : status(std::move(status_)) {}
std::tuple<Common::Vec3<float>, Common::Vec3<float>> GetStatus() const override {
std::tuple<Common::Vec3<float>, Common::Vec3<float>, Common::Vec3<float>,
std::array<Common::Vec3f, 3>>
GetStatus() const override {
std::lock_guard guard(status->update_mutex);
return status->motion_status;
}
@@ -59,11 +61,11 @@ private:
std::shared_ptr<DeviceStatus> status;
};
class UDPMotionFactory final : public Input::Factory<Input::MotionDevice> {
class UDPMotionFactory final : public Input::Factory<Input::RealMotionDevice> {
public:
explicit UDPMotionFactory(std::shared_ptr<DeviceStatus> status_) : status(std::move(status_)) {}
std::unique_ptr<Input::MotionDevice> Create(const Common::ParamPackage& params) override {
std::unique_ptr<Input::RealMotionDevice> Create(const Common::ParamPackage& params) override {
return std::make_unique<UDPMotionDevice>(status);
}
@@ -80,13 +82,13 @@ State::State() {
motion_factory = std::make_shared<UDPMotionFactory>(status);
touch_factory = std::make_shared<UDPTouchFactory>(status);
Input::RegisterFactory<Input::MotionDevice>("cemuhookudp", motion_factory);
Input::RegisterFactory<Input::RealMotionDevice>("cemuhookudp", motion_factory);
Input::RegisterFactory<Input::TouchDevice>("cemuhookudp", touch_factory);
}
State::~State() {
Input::UnregisterFactory<Input::TouchDevice>("cemuhookudp");
Input::UnregisterFactory<Input::MotionDevice>("cemuhookudp");
Input::UnregisterFactory<Input::RealMotionDevice>("cemuhookudp");
}
std::vector<Common::ParamPackage> State::GetInputDevices() const {

View File

@@ -173,6 +173,14 @@ QString ButtonToText(const Common::ParamPackage& param) {
return {};
}
if (param.Get("engine", "") == "cemuhookudp") {
if (param.Has("pad_index")) {
const QString motion_str = QString::fromStdString(param.Get("pad_index", ""));
return QObject::tr("UDP Motion %1").arg(motion_str);
}
return GetKeyName(param.Get("code", 0));
}
return QObject::tr("[unknown]");
}