Cleanup after linter
This commit is contained in:
parent
18a42d3815
commit
0076a08d04
9 changed files with 95 additions and 164 deletions
|
@ -14,8 +14,7 @@ public:
|
||||||
float modifier_scale_)
|
float modifier_scale_)
|
||||||
: up(std::move(up_)), down(std::move(down_)), left(std::move(left_)),
|
: up(std::move(up_)), down(std::move(down_)), left(std::move(left_)),
|
||||||
right(std::move(right_)), modifier(std::move(modifier_)),
|
right(std::move(right_)), modifier(std::move(modifier_)),
|
||||||
modifier_scale(modifier_scale_) {
|
modifier_scale(modifier_scale_) {}
|
||||||
}
|
|
||||||
|
|
||||||
std::tuple<float, float> GetStatus() const override {
|
std::tuple<float, float> GetStatus() const override {
|
||||||
constexpr float SQRT_HALF = 0.707106781f;
|
constexpr float SQRT_HALF = 0.707106781f;
|
||||||
|
|
|
@ -13,8 +13,7 @@ namespace InputCommon {
|
||||||
class KeyButton final : public Input::ButtonDevice {
|
class KeyButton final : public Input::ButtonDevice {
|
||||||
public:
|
public:
|
||||||
explicit KeyButton(std::shared_ptr<KeyButtonList> key_button_list_)
|
explicit KeyButton(std::shared_ptr<KeyButtonList> key_button_list_)
|
||||||
: key_button_list(std::move(key_button_list_)) {
|
: key_button_list(std::move(key_button_list_)) {}
|
||||||
}
|
|
||||||
|
|
||||||
~KeyButton() override;
|
~KeyButton() override;
|
||||||
|
|
||||||
|
@ -69,9 +68,7 @@ private:
|
||||||
std::list<KeyButtonPair> list;
|
std::list<KeyButtonPair> list;
|
||||||
};
|
};
|
||||||
|
|
||||||
Keyboard::Keyboard()
|
Keyboard::Keyboard() : key_button_list{std::make_shared<KeyButtonList>()} {}
|
||||||
: key_button_list{std::make_shared<KeyButtonList>()} {
|
|
||||||
}
|
|
||||||
|
|
||||||
KeyButton::~KeyButton() {
|
KeyButton::~KeyButton() {
|
||||||
key_button_list->RemoveKeyButton(this);
|
key_button_list->RemoveKeyButton(this);
|
||||||
|
@ -81,7 +78,7 @@ std::unique_ptr<Input::ButtonDevice> Keyboard::Create(const Common::ParamPackage
|
||||||
int key_code = params.Get("code", 0);
|
int key_code = params.Get("code", 0);
|
||||||
std::unique_ptr<KeyButton> button = std::make_unique<KeyButton>(key_button_list);
|
std::unique_ptr<KeyButton> button = std::make_unique<KeyButton>(key_button_list);
|
||||||
key_button_list->AddKeyButton(key_code, button.get());
|
key_button_list->AddKeyButton(key_code, button.get());
|
||||||
return std::move(button);
|
return button;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Keyboard::PressKey(int key_code) {
|
void Keyboard::PressKey(int key_code) {
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <libusb.h>
|
#include <libusb.h>
|
||||||
#include <iostream>
|
|
||||||
#include "common/param_package.h"
|
#include "common/param_package.h"
|
||||||
#include "input_common/analog_from_button.h"
|
#include "input_common/analog_from_button.h"
|
||||||
#include "input_common/gcadapter/gc_poller.h"
|
#include "input_common/gcadapter/gc_poller.h"
|
||||||
|
@ -44,10 +43,7 @@ void Init() {
|
||||||
#ifdef HAVE_SDL2
|
#ifdef HAVE_SDL2
|
||||||
sdl = SDL::Init();
|
sdl = SDL::Init();
|
||||||
#endif
|
#endif
|
||||||
/*
|
|
||||||
|
|
||||||
udp = CemuhookUDP::Init();
|
udp = CemuhookUDP::Init();
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Shutdown() {
|
void Shutdown() {
|
||||||
|
|
|
@ -22,8 +22,7 @@ public:
|
||||||
: update_millisecond(update_millisecond),
|
: update_millisecond(update_millisecond),
|
||||||
update_duration(std::chrono::duration_cast<std::chrono::steady_clock::duration>(
|
update_duration(std::chrono::duration_cast<std::chrono::steady_clock::duration>(
|
||||||
std::chrono::milliseconds(update_millisecond))),
|
std::chrono::milliseconds(update_millisecond))),
|
||||||
sensitivity(sensitivity), motion_emu_thread(&MotionEmuDevice::MotionEmuThread, this) {
|
sensitivity(sensitivity), motion_emu_thread(&MotionEmuDevice::MotionEmuThread, this) {}
|
||||||
}
|
|
||||||
|
|
||||||
~MotionEmuDevice() {
|
~MotionEmuDevice() {
|
||||||
if (motion_emu_thread.joinable()) {
|
if (motion_emu_thread.joinable()) {
|
||||||
|
@ -146,7 +145,7 @@ std::unique_ptr<Input::MotionDevice> MotionEmu::Create(const Common::ParamPackag
|
||||||
// Previously created device is disconnected here. Having two motion devices for 3DS is not
|
// Previously created device is disconnected here. Having two motion devices for 3DS is not
|
||||||
// expected.
|
// expected.
|
||||||
current_device = device_wrapper->device;
|
current_device = device_wrapper->device;
|
||||||
return std::move(device_wrapper);
|
return device_wrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MotionEmu::BeginTilt(int x, int y) {
|
void MotionEmu::BeginTilt(int x, int y) {
|
||||||
|
|
|
@ -49,8 +49,7 @@ static int SDLEventWatcher(void* user_data, SDL_Event* event) {
|
||||||
class SDLJoystick {
|
class SDLJoystick {
|
||||||
public:
|
public:
|
||||||
SDLJoystick(std::string guid_, int port_, SDL_Joystick* joystick)
|
SDLJoystick(std::string guid_, int port_, SDL_Joystick* joystick)
|
||||||
: guid{std::move(guid_)}, port{port_}, sdl_joystick{joystick, &SDL_JoystickClose} {
|
: guid{std::move(guid_)}, port{port_}, sdl_joystick{joystick, &SDL_JoystickClose} {}
|
||||||
}
|
|
||||||
|
|
||||||
void SetButton(int button, bool value) {
|
void SetButton(int button, bool value) {
|
||||||
std::lock_guard lock{mutex};
|
std::lock_guard lock{mutex};
|
||||||
|
@ -98,7 +97,6 @@ public:
|
||||||
std::lock_guard lock{mutex};
|
std::lock_guard lock{mutex};
|
||||||
return (state.hats.at(hat) & direction) != 0;
|
return (state.hats.at(hat) & direction) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The guid of the joystick
|
* The guid of the joystick
|
||||||
*/
|
*/
|
||||||
|
@ -127,7 +125,6 @@ private:
|
||||||
std::unordered_map<int, Sint16> axes;
|
std::unordered_map<int, Sint16> axes;
|
||||||
std::unordered_map<int, Uint8> hats;
|
std::unordered_map<int, Uint8> hats;
|
||||||
} state;
|
} state;
|
||||||
|
|
||||||
std::string guid;
|
std::string guid;
|
||||||
int port;
|
int port;
|
||||||
std::unique_ptr<SDL_Joystick, decltype(&SDL_JoystickClose)> sdl_joystick;
|
std::unique_ptr<SDL_Joystick, decltype(&SDL_JoystickClose)> sdl_joystick;
|
||||||
|
@ -158,8 +155,7 @@ std::shared_ptr<SDLJoystick> SDLState::GetSDLJoystickBySDLID(SDL_JoystickID sdl_
|
||||||
if (map_it != joystick_map.end()) {
|
if (map_it != joystick_map.end()) {
|
||||||
const auto vec_it =
|
const auto vec_it =
|
||||||
std::find_if(map_it->second.begin(), map_it->second.end(),
|
std::find_if(map_it->second.begin(), map_it->second.end(),
|
||||||
[&sdl_joystick](const std::shared_ptr<SDLJoystick>& joystick)
|
[&sdl_joystick](const std::shared_ptr<SDLJoystick>& joystick) {
|
||||||
{
|
|
||||||
return sdl_joystick == joystick->GetSDLJoystick();
|
return sdl_joystick == joystick->GetSDLJoystick();
|
||||||
});
|
});
|
||||||
if (vec_it != map_it->second.end()) {
|
if (vec_it != map_it->second.end()) {
|
||||||
|
@ -170,8 +166,7 @@ std::shared_ptr<SDLJoystick> SDLState::GetSDLJoystickBySDLID(SDL_JoystickID sdl_
|
||||||
|
|
||||||
// Search for a SDLJoystick without a mapped SDL_Joystick...
|
// Search for a SDLJoystick without a mapped SDL_Joystick...
|
||||||
const auto nullptr_it = std::find_if(map_it->second.begin(), map_it->second.end(),
|
const auto nullptr_it = std::find_if(map_it->second.begin(), map_it->second.end(),
|
||||||
[](const std::shared_ptr<SDLJoystick>& joystick)
|
[](const std::shared_ptr<SDLJoystick>& joystick) {
|
||||||
{
|
|
||||||
return !joystick->GetSDLJoystick();
|
return !joystick->GetSDLJoystick();
|
||||||
});
|
});
|
||||||
if (nullptr_it != map_it->second.end()) {
|
if (nullptr_it != map_it->second.end()) {
|
||||||
|
@ -228,8 +223,7 @@ void SDLState::CloseJoystick(SDL_Joystick* sdl_joystick) {
|
||||||
const auto& joystick_guid_list = joystick_map[guid];
|
const auto& joystick_guid_list = joystick_map[guid];
|
||||||
const auto joystick_it =
|
const auto joystick_it =
|
||||||
std::find_if(joystick_guid_list.begin(), joystick_guid_list.end(),
|
std::find_if(joystick_guid_list.begin(), joystick_guid_list.end(),
|
||||||
[&sdl_joystick](const std::shared_ptr<SDLJoystick>& joystick)
|
[&sdl_joystick](const std::shared_ptr<SDLJoystick>& joystick) {
|
||||||
{
|
|
||||||
return joystick->GetSDLJoystick() == sdl_joystick;
|
return joystick->GetSDLJoystick() == sdl_joystick;
|
||||||
});
|
});
|
||||||
joystick = *joystick_it;
|
joystick = *joystick_it;
|
||||||
|
@ -285,8 +279,7 @@ void SDLState::CloseJoysticks() {
|
||||||
class SDLButton final : public Input::ButtonDevice {
|
class SDLButton final : public Input::ButtonDevice {
|
||||||
public:
|
public:
|
||||||
explicit SDLButton(std::shared_ptr<SDLJoystick> joystick_, int button_)
|
explicit SDLButton(std::shared_ptr<SDLJoystick> joystick_, int button_)
|
||||||
: joystick(std::move(joystick_)), button(button_) {
|
: joystick(std::move(joystick_)), button(button_) {}
|
||||||
}
|
|
||||||
|
|
||||||
bool GetStatus() const override {
|
bool GetStatus() const override {
|
||||||
return joystick->GetButton(button);
|
return joystick->GetButton(button);
|
||||||
|
@ -300,8 +293,7 @@ private:
|
||||||
class SDLDirectionButton final : public Input::ButtonDevice {
|
class SDLDirectionButton final : public Input::ButtonDevice {
|
||||||
public:
|
public:
|
||||||
explicit SDLDirectionButton(std::shared_ptr<SDLJoystick> joystick_, int hat_, Uint8 direction_)
|
explicit SDLDirectionButton(std::shared_ptr<SDLJoystick> joystick_, int hat_, Uint8 direction_)
|
||||||
: joystick(std::move(joystick_)), hat(hat_), direction(direction_) {
|
: joystick(std::move(joystick_)), hat(hat_), direction(direction_) {}
|
||||||
}
|
|
||||||
|
|
||||||
bool GetStatus() const override {
|
bool GetStatus() const override {
|
||||||
return joystick->GetHatDirection(hat, direction);
|
return joystick->GetHatDirection(hat, direction);
|
||||||
|
@ -318,8 +310,7 @@ public:
|
||||||
explicit SDLAxisButton(std::shared_ptr<SDLJoystick> joystick_, int axis_, float threshold_,
|
explicit SDLAxisButton(std::shared_ptr<SDLJoystick> joystick_, int axis_, float threshold_,
|
||||||
bool trigger_if_greater_)
|
bool trigger_if_greater_)
|
||||||
: joystick(std::move(joystick_)), axis(axis_), threshold(threshold_),
|
: joystick(std::move(joystick_)), axis(axis_), threshold(threshold_),
|
||||||
trigger_if_greater(trigger_if_greater_) {
|
trigger_if_greater(trigger_if_greater_) {}
|
||||||
}
|
|
||||||
|
|
||||||
bool GetStatus() const override {
|
bool GetStatus() const override {
|
||||||
const float axis_value = joystick->GetAxis(axis);
|
const float axis_value = joystick->GetAxis(axis);
|
||||||
|
@ -339,8 +330,7 @@ private:
|
||||||
class SDLAnalog final : public Input::AnalogDevice {
|
class SDLAnalog final : public Input::AnalogDevice {
|
||||||
public:
|
public:
|
||||||
SDLAnalog(std::shared_ptr<SDLJoystick> joystick_, int axis_x_, int axis_y_, float deadzone_)
|
SDLAnalog(std::shared_ptr<SDLJoystick> joystick_, int axis_x_, int axis_y_, float deadzone_)
|
||||||
: joystick(std::move(joystick_)), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_) {
|
: joystick(std::move(joystick_)), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_) {}
|
||||||
}
|
|
||||||
|
|
||||||
std::tuple<float, float> GetStatus() const override {
|
std::tuple<float, float> GetStatus() const override {
|
||||||
const auto [x, y] = joystick->GetAnalog(axis_x, axis_y);
|
const auto [x, y] = joystick->GetAnalog(axis_x, axis_y);
|
||||||
|
@ -378,9 +368,7 @@ private:
|
||||||
/// A button device factory that creates button devices from SDL joystick
|
/// A button device factory that creates button devices from SDL joystick
|
||||||
class SDLButtonFactory final : public Input::Factory<Input::ButtonDevice> {
|
class SDLButtonFactory final : public Input::Factory<Input::ButtonDevice> {
|
||||||
public:
|
public:
|
||||||
explicit SDLButtonFactory(SDLState& state_)
|
explicit SDLButtonFactory(SDLState& state_) : state(state_) {}
|
||||||
: state(state_) {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a button device from a joystick button
|
* Creates a button device from a joystick button
|
||||||
|
@ -455,9 +443,7 @@ private:
|
||||||
/// An analog device factory that creates analog devices from SDL joystick
|
/// An analog device factory that creates analog devices from SDL joystick
|
||||||
class SDLAnalogFactory final : public Input::Factory<Input::AnalogDevice> {
|
class SDLAnalogFactory final : public Input::Factory<Input::AnalogDevice> {
|
||||||
public:
|
public:
|
||||||
explicit SDLAnalogFactory(SDLState& state_)
|
explicit SDLAnalogFactory(SDLState& state_) : state(state_) {}
|
||||||
: state(state_) {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates analog device from joystick axes
|
* Creates analog device from joystick axes
|
||||||
|
@ -505,8 +491,7 @@ SDLState::SDLState() {
|
||||||
|
|
||||||
initialized = true;
|
initialized = true;
|
||||||
if (start_thread) {
|
if (start_thread) {
|
||||||
poll_thread = std::thread([this]
|
poll_thread = std::thread([this] {
|
||||||
{
|
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
while (initialized) {
|
while (initialized) {
|
||||||
SDL_PumpEvents();
|
SDL_PumpEvents();
|
||||||
|
@ -592,9 +577,7 @@ namespace Polling {
|
||||||
|
|
||||||
class SDLPoller : public InputCommon::Polling::DevicePoller {
|
class SDLPoller : public InputCommon::Polling::DevicePoller {
|
||||||
public:
|
public:
|
||||||
explicit SDLPoller(SDLState& state_)
|
explicit SDLPoller(SDLState& state_) : state(state_) {}
|
||||||
: state(state_) {
|
|
||||||
}
|
|
||||||
|
|
||||||
void Start() override {
|
void Start() override {
|
||||||
state.event_queue.Clear();
|
state.event_queue.Clear();
|
||||||
|
@ -611,9 +594,7 @@ protected:
|
||||||
|
|
||||||
class SDLButtonPoller final : public SDLPoller {
|
class SDLButtonPoller final : public SDLPoller {
|
||||||
public:
|
public:
|
||||||
explicit SDLButtonPoller(SDLState& state_)
|
explicit SDLButtonPoller(SDLState& state_) : SDLPoller(state_) {}
|
||||||
: SDLPoller(state_) {
|
|
||||||
}
|
|
||||||
|
|
||||||
Common::ParamPackage GetNextInput() override {
|
Common::ParamPackage GetNextInput() override {
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
|
@ -622,7 +603,8 @@ public:
|
||||||
case SDL_JOYAXISMOTION:
|
case SDL_JOYAXISMOTION:
|
||||||
if (std::abs(event.jaxis.value / 32767.0) < 0.5) {
|
if (std::abs(event.jaxis.value / 32767.0) < 0.5) {
|
||||||
break;
|
break;
|
||||||
}[[fallthrough]];
|
}
|
||||||
|
[[fallthrough]];
|
||||||
case SDL_JOYBUTTONUP:
|
case SDL_JOYBUTTONUP:
|
||||||
case SDL_JOYHATMOTION:
|
case SDL_JOYHATMOTION:
|
||||||
return SDLEventToButtonParamPackage(state, event);
|
return SDLEventToButtonParamPackage(state, event);
|
||||||
|
@ -634,9 +616,7 @@ public:
|
||||||
|
|
||||||
class SDLAnalogPoller final : public SDLPoller {
|
class SDLAnalogPoller final : public SDLPoller {
|
||||||
public:
|
public:
|
||||||
explicit SDLAnalogPoller(SDLState& state_)
|
explicit SDLAnalogPoller(SDLState& state_) : SDLPoller(state_) {}
|
||||||
: SDLPoller(state_) {
|
|
||||||
}
|
|
||||||
|
|
||||||
void Start() override {
|
void Start() override {
|
||||||
SDLPoller::Start();
|
SDLPoller::Start();
|
||||||
|
|
|
@ -59,8 +59,7 @@ public:
|
||||||
void StartReceive() {
|
void StartReceive() {
|
||||||
socket.async_receive_from(
|
socket.async_receive_from(
|
||||||
boost::asio::buffer(receive_buffer), receive_endpoint,
|
boost::asio::buffer(receive_buffer), receive_endpoint,
|
||||||
[this](const boost::system::error_code& error, std::size_t bytes_transferred)
|
[this](const boost::system::error_code& error, std::size_t bytes_transferred) {
|
||||||
{
|
|
||||||
HandleReceive(error, bytes_transferred);
|
HandleReceive(error, bytes_transferred);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -212,27 +211,21 @@ void Client::StartCommunication(const std::string& host, u16 port, u8 pad_index,
|
||||||
void TestCommunication(const std::string& host, u16 port, u8 pad_index, u32 client_id,
|
void TestCommunication(const std::string& host, u16 port, u8 pad_index, u32 client_id,
|
||||||
std::function<void()> success_callback,
|
std::function<void()> success_callback,
|
||||||
std::function<void()> failure_callback) {
|
std::function<void()> failure_callback) {
|
||||||
std::thread([=]
|
std::thread([=] {
|
||||||
{
|
Common::Event success_event;
|
||||||
Common::Event success_event;
|
SocketCallback callback{[](Response::Version version) {}, [](Response::PortInfo info) {},
|
||||||
SocketCallback callback{[](Response::Version version)
|
[&](Response::PadData data) { success_event.Set(); }};
|
||||||
{
|
Socket socket{host, port, pad_index, client_id, std::move(callback)};
|
||||||
},
|
std::thread worker_thread{SocketLoop, &socket};
|
||||||
[](Response::PortInfo info)
|
bool result = success_event.WaitFor(std::chrono::seconds(8));
|
||||||
{
|
socket.Stop();
|
||||||
},
|
worker_thread.join();
|
||||||
[&](Response::PadData data) { success_event.Set(); }};
|
if (result) {
|
||||||
Socket socket{host, port, pad_index, client_id, std::move(callback)};
|
success_callback();
|
||||||
std::thread worker_thread{SocketLoop, &socket};
|
} else {
|
||||||
bool result = success_event.WaitFor(std::chrono::seconds(8));
|
failure_callback();
|
||||||
socket.Stop();
|
}
|
||||||
worker_thread.join();
|
})
|
||||||
if (result) {
|
|
||||||
success_callback();
|
|
||||||
} else {
|
|
||||||
failure_callback();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.detach();
|
.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,60 +234,53 @@ CalibrationConfigurationJob::CalibrationConfigurationJob(
|
||||||
std::function<void(Status)> status_callback,
|
std::function<void(Status)> status_callback,
|
||||||
std::function<void(u16, u16, u16, u16)> data_callback) {
|
std::function<void(u16, u16, u16, u16)> data_callback) {
|
||||||
|
|
||||||
std::thread([=]
|
std::thread([=] {
|
||||||
{
|
constexpr u16 CALIBRATION_THRESHOLD = 100;
|
||||||
constexpr u16 CALIBRATION_THRESHOLD = 100;
|
|
||||||
|
|
||||||
u16 min_x{UINT16_MAX};
|
u16 min_x{UINT16_MAX};
|
||||||
u16 min_y{UINT16_MAX};
|
u16 min_y{UINT16_MAX};
|
||||||
u16 max_x{};
|
u16 max_x{};
|
||||||
u16 max_y{};
|
u16 max_y{};
|
||||||
|
|
||||||
Status current_status{Status::Initialized};
|
Status current_status{Status::Initialized};
|
||||||
SocketCallback callback{[](Response::Version version)
|
SocketCallback callback{[](Response::Version version) {}, [](Response::PortInfo info) {},
|
||||||
{
|
[&](Response::PadData data) {
|
||||||
},
|
if (current_status == Status::Initialized) {
|
||||||
[](Response::PortInfo info)
|
// Receiving data means the communication is ready now
|
||||||
{
|
current_status = Status::Ready;
|
||||||
},
|
status_callback(current_status);
|
||||||
[&](Response::PadData data)
|
}
|
||||||
{
|
if (!data.touch_1.is_active) {
|
||||||
if (current_status == Status::Initialized) {
|
return;
|
||||||
// Receiving data means the communication is ready now
|
}
|
||||||
current_status = Status::Ready;
|
LOG_DEBUG(Input, "Current touch: {} {}", data.touch_1.x,
|
||||||
status_callback(current_status);
|
data.touch_1.y);
|
||||||
}
|
min_x = std::min(min_x, static_cast<u16>(data.touch_1.x));
|
||||||
if (!data.touch_1.is_active) {
|
min_y = std::min(min_y, static_cast<u16>(data.touch_1.y));
|
||||||
return;
|
if (current_status == Status::Ready) {
|
||||||
}
|
// First touch - min data (min_x/min_y)
|
||||||
LOG_DEBUG(Input, "Current touch: {} {}", data.touch_1.x,
|
current_status = Status::Stage1Completed;
|
||||||
data.touch_1.y);
|
status_callback(current_status);
|
||||||
min_x = std::min(min_x, static_cast<u16>(data.touch_1.x));
|
}
|
||||||
min_y = std::min(min_y, static_cast<u16>(data.touch_1.y));
|
if (data.touch_1.x - min_x > CALIBRATION_THRESHOLD &&
|
||||||
if (current_status == Status::Ready) {
|
data.touch_1.y - min_y > CALIBRATION_THRESHOLD) {
|
||||||
// First touch - min data (min_x/min_y)
|
// Set the current position as max value and finishes
|
||||||
current_status = Status::Stage1Completed;
|
// configuration
|
||||||
status_callback(current_status);
|
max_x = data.touch_1.x;
|
||||||
}
|
max_y = data.touch_1.y;
|
||||||
if (data.touch_1.x - min_x > CALIBRATION_THRESHOLD &&
|
current_status = Status::Completed;
|
||||||
data.touch_1.y - min_y > CALIBRATION_THRESHOLD) {
|
data_callback(min_x, min_y, max_x, max_y);
|
||||||
// Set the current position as max value and finishes
|
status_callback(current_status);
|
||||||
// configuration
|
|
||||||
max_x = data.touch_1.x;
|
|
||||||
max_y = data.touch_1.y;
|
|
||||||
current_status = Status::Completed;
|
|
||||||
data_callback(min_x, min_y, max_x, max_y);
|
|
||||||
status_callback(current_status);
|
|
||||||
|
|
||||||
complete_event.Set();
|
complete_event.Set();
|
||||||
}
|
}
|
||||||
}};
|
}};
|
||||||
Socket socket{host, port, pad_index, client_id, std::move(callback)};
|
Socket socket{host, port, pad_index, client_id, std::move(callback)};
|
||||||
std::thread worker_thread{SocketLoop, &socket};
|
std::thread worker_thread{SocketLoop, &socket};
|
||||||
complete_event.Wait();
|
complete_event.Wait();
|
||||||
socket.Stop();
|
socket.Stop();
|
||||||
worker_thread.join();
|
worker_thread.join();
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,6 @@ struct DeviceStatus {
|
||||||
u16 max_x{};
|
u16 max_x{};
|
||||||
u16 max_y{};
|
u16 max_y{};
|
||||||
};
|
};
|
||||||
|
|
||||||
std::optional<CalibrationData> touch_calibration;
|
std::optional<CalibrationData> touch_calibration;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -73,7 +72,6 @@ public:
|
||||||
Stage1Completed,
|
Stage1Completed,
|
||||||
Completed,
|
Completed,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs and starts the job with the specified parameter.
|
* Constructs and starts the job with the specified parameter.
|
||||||
*
|
*
|
||||||
|
|
|
@ -35,7 +35,6 @@ struct Header {
|
||||||
///> the data
|
///> the data
|
||||||
Type type{};
|
Type type{};
|
||||||
};
|
};
|
||||||
|
|
||||||
static_assert(sizeof(Header) == 20, "UDP Message Header struct has wrong size");
|
static_assert(sizeof(Header) == 20, "UDP Message Header struct has wrong size");
|
||||||
static_assert(std::is_trivially_copyable_v<Header>, "UDP Message Header is not trivially copyable");
|
static_assert(std::is_trivially_copyable_v<Header>, "UDP Message Header is not trivially copyable");
|
||||||
|
|
||||||
|
@ -55,9 +54,7 @@ constexpr Type GetMessageType();
|
||||||
|
|
||||||
namespace Request {
|
namespace Request {
|
||||||
|
|
||||||
struct Version {
|
struct Version {};
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Requests the server to send information about what controllers are plugged into the ports
|
* Requests the server to send information about what controllers are plugged into the ports
|
||||||
* In citra's case, we only have one controller, so for simplicity's sake, we can just send a
|
* In citra's case, we only have one controller, so for simplicity's sake, we can just send a
|
||||||
|
@ -65,14 +62,12 @@ struct Version {
|
||||||
* nice to make this configurable
|
* nice to make this configurable
|
||||||
*/
|
*/
|
||||||
constexpr u32 MAX_PORTS = 4;
|
constexpr u32 MAX_PORTS = 4;
|
||||||
|
|
||||||
struct PortInfo {
|
struct PortInfo {
|
||||||
u32_le pad_count{}; ///> Number of ports to request data for
|
u32_le pad_count{}; ///> Number of ports to request data for
|
||||||
std::array<u8, MAX_PORTS> port;
|
std::array<u8, MAX_PORTS> port;
|
||||||
};
|
};
|
||||||
|
|
||||||
static_assert(std::is_trivially_copyable_v<PortInfo>,
|
static_assert(std::is_trivially_copyable_v<PortInfo>,
|
||||||
"UDP Request PortInfo is not trivially copyable");
|
"UDP Request PortInfo is not trivially copyable");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request the latest pad information from the server. If the server hasn't received this message
|
* Request the latest pad information from the server. If the server hasn't received this message
|
||||||
|
@ -85,7 +80,6 @@ struct PadData {
|
||||||
Id,
|
Id,
|
||||||
Mac,
|
Mac,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Determines which method will be used as a look up for the controller
|
/// Determines which method will be used as a look up for the controller
|
||||||
Flags flags{};
|
Flags flags{};
|
||||||
/// Index of the port of the controller to retrieve data about
|
/// Index of the port of the controller to retrieve data about
|
||||||
|
@ -93,10 +87,9 @@ struct PadData {
|
||||||
/// Mac address of the controller to retrieve data about
|
/// Mac address of the controller to retrieve data about
|
||||||
MacAddress mac;
|
MacAddress mac;
|
||||||
};
|
};
|
||||||
|
|
||||||
static_assert(sizeof(PadData) == 8, "UDP Request PadData struct has wrong size");
|
static_assert(sizeof(PadData) == 8, "UDP Request PadData struct has wrong size");
|
||||||
static_assert(std::is_trivially_copyable_v<PadData>,
|
static_assert(std::is_trivially_copyable_v<PadData>,
|
||||||
"UDP Request PadData is not trivially copyable");
|
"UDP Request PadData is not trivially copyable");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a message with the proper header data that can be sent to the server.
|
* Creates a message with the proper header data that can be sent to the server.
|
||||||
|
@ -121,10 +114,9 @@ namespace Response {
|
||||||
struct Version {
|
struct Version {
|
||||||
u16_le version{};
|
u16_le version{};
|
||||||
};
|
};
|
||||||
|
|
||||||
static_assert(sizeof(Version) == 2, "UDP Response Version struct has wrong size");
|
static_assert(sizeof(Version) == 2, "UDP Response Version struct has wrong size");
|
||||||
static_assert(std::is_trivially_copyable_v<Version>,
|
static_assert(std::is_trivially_copyable_v<Version>,
|
||||||
"UDP Response Version is not trivially copyable");
|
"UDP Response Version is not trivially copyable");
|
||||||
|
|
||||||
struct PortInfo {
|
struct PortInfo {
|
||||||
u8 id{};
|
u8 id{};
|
||||||
|
@ -135,10 +127,9 @@ struct PortInfo {
|
||||||
u8 battery{};
|
u8 battery{};
|
||||||
u8 is_pad_active{};
|
u8 is_pad_active{};
|
||||||
};
|
};
|
||||||
|
|
||||||
static_assert(sizeof(PortInfo) == 12, "UDP Response PortInfo struct has wrong size");
|
static_assert(sizeof(PortInfo) == 12, "UDP Response PortInfo struct has wrong size");
|
||||||
static_assert(std::is_trivially_copyable_v<PortInfo>,
|
static_assert(std::is_trivially_copyable_v<PortInfo>,
|
||||||
"UDP Response PortInfo is not trivially copyable");
|
"UDP Response PortInfo is not trivially copyable");
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
#pragma pack(push, 1)
|
||||||
struct PadData {
|
struct PadData {
|
||||||
|
@ -215,16 +206,16 @@ struct PadData {
|
||||||
|
|
||||||
static_assert(sizeof(PadData) == 80, "UDP Response PadData struct has wrong size ");
|
static_assert(sizeof(PadData) == 80, "UDP Response PadData struct has wrong size ");
|
||||||
static_assert(std::is_trivially_copyable_v<PadData>,
|
static_assert(std::is_trivially_copyable_v<PadData>,
|
||||||
"UDP Response PadData is not trivially copyable");
|
"UDP Response PadData is not trivially copyable");
|
||||||
|
|
||||||
static_assert(sizeof(Message<PadData>) == MAX_PACKET_SIZE,
|
static_assert(sizeof(Message<PadData>) == MAX_PACKET_SIZE,
|
||||||
"UDP MAX_PACKET_SIZE is no longer larger than Message<PadData>");
|
"UDP MAX_PACKET_SIZE is no longer larger than Message<PadData>");
|
||||||
|
|
||||||
static_assert(sizeof(PadData::AnalogButton) == 12,
|
static_assert(sizeof(PadData::AnalogButton) == 12,
|
||||||
"UDP Response AnalogButton struct has wrong size ");
|
"UDP Response AnalogButton struct has wrong size ");
|
||||||
static_assert(sizeof(PadData::TouchPad) == 6, "UDP Response TouchPad struct has wrong size ");
|
static_assert(sizeof(PadData::TouchPad) == 6, "UDP Response TouchPad struct has wrong size ");
|
||||||
static_assert(sizeof(PadData::Accelerometer) == 12,
|
static_assert(sizeof(PadData::Accelerometer) == 12,
|
||||||
"UDP Response Accelerometer struct has wrong size ");
|
"UDP Response Accelerometer struct has wrong size ");
|
||||||
static_assert(sizeof(PadData::Gyroscope) == 12, "UDP Response Gyroscope struct has wrong size ");
|
static_assert(sizeof(PadData::Gyroscope) == 12, "UDP Response Gyroscope struct has wrong size ");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -241,27 +232,22 @@ template <>
|
||||||
constexpr Type GetMessageType<Request::Version>() {
|
constexpr Type GetMessageType<Request::Version>() {
|
||||||
return Type::Version;
|
return Type::Version;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
constexpr Type GetMessageType<Request::PortInfo>() {
|
constexpr Type GetMessageType<Request::PortInfo>() {
|
||||||
return Type::PortInfo;
|
return Type::PortInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
constexpr Type GetMessageType<Request::PadData>() {
|
constexpr Type GetMessageType<Request::PadData>() {
|
||||||
return Type::PadData;
|
return Type::PadData;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
constexpr Type GetMessageType<Response::Version>() {
|
constexpr Type GetMessageType<Response::Version>() {
|
||||||
return Type::Version;
|
return Type::Version;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
constexpr Type GetMessageType<Response::PortInfo>() {
|
constexpr Type GetMessageType<Response::PortInfo>() {
|
||||||
return Type::PortInfo;
|
return Type::PortInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
constexpr Type GetMessageType<Response::PadData>() {
|
constexpr Type GetMessageType<Response::PadData>() {
|
||||||
return Type::PadData;
|
return Type::PadData;
|
||||||
|
|
|
@ -16,10 +16,7 @@ namespace InputCommon::CemuhookUDP {
|
||||||
|
|
||||||
class UDPTouchDevice final : public Input::TouchDevice {
|
class UDPTouchDevice final : public Input::TouchDevice {
|
||||||
public:
|
public:
|
||||||
explicit UDPTouchDevice(std::shared_ptr<DeviceStatus> status_)
|
explicit UDPTouchDevice(std::shared_ptr<DeviceStatus> status_) : status(std::move(status_)) {}
|
||||||
: status(std::move(status_)) {
|
|
||||||
}
|
|
||||||
|
|
||||||
std::tuple<float, float, bool> GetStatus() const override {
|
std::tuple<float, float, bool> GetStatus() const override {
|
||||||
std::lock_guard guard(status->update_mutex);
|
std::lock_guard guard(status->update_mutex);
|
||||||
return status->touch_status;
|
return status->touch_status;
|
||||||
|
@ -31,10 +28,7 @@ private:
|
||||||
|
|
||||||
class UDPMotionDevice final : public Input::MotionDevice {
|
class UDPMotionDevice final : public Input::MotionDevice {
|
||||||
public:
|
public:
|
||||||
explicit UDPMotionDevice(std::shared_ptr<DeviceStatus> status_)
|
explicit UDPMotionDevice(std::shared_ptr<DeviceStatus> status_) : status(std::move(status_)) {}
|
||||||
: status(std::move(status_)) {
|
|
||||||
}
|
|
||||||
|
|
||||||
std::tuple<Common::Vec3<float>, Common::Vec3<float>> GetStatus() const override {
|
std::tuple<Common::Vec3<float>, Common::Vec3<float>> GetStatus() const override {
|
||||||
std::lock_guard guard(status->update_mutex);
|
std::lock_guard guard(status->update_mutex);
|
||||||
return status->motion_status;
|
return status->motion_status;
|
||||||
|
@ -46,9 +40,7 @@ private:
|
||||||
|
|
||||||
class UDPTouchFactory final : public Input::Factory<Input::TouchDevice> {
|
class UDPTouchFactory final : public Input::Factory<Input::TouchDevice> {
|
||||||
public:
|
public:
|
||||||
explicit UDPTouchFactory(std::shared_ptr<DeviceStatus> status_)
|
explicit UDPTouchFactory(std::shared_ptr<DeviceStatus> status_) : status(std::move(status_)) {}
|
||||||
: status(std::move(status_)) {
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_ptr<Input::TouchDevice> Create(const Common::ParamPackage& params) override {
|
std::unique_ptr<Input::TouchDevice> Create(const Common::ParamPackage& params) override {
|
||||||
{
|
{
|
||||||
|
@ -69,9 +61,7 @@ private:
|
||||||
|
|
||||||
class UDPMotionFactory final : public Input::Factory<Input::MotionDevice> {
|
class UDPMotionFactory final : public Input::Factory<Input::MotionDevice> {
|
||||||
public:
|
public:
|
||||||
explicit UDPMotionFactory(std::shared_ptr<DeviceStatus> status_)
|
explicit UDPMotionFactory(std::shared_ptr<DeviceStatus> status_) : status(std::move(status_)) {}
|
||||||
: status(std::move(status_)) {
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_ptr<Input::MotionDevice> Create(const Common::ParamPackage& params) override {
|
std::unique_ptr<Input::MotionDevice> Create(const Common::ParamPackage& params) override {
|
||||||
return std::make_unique<UDPMotionDevice>(status);
|
return std::make_unique<UDPMotionDevice>(status);
|
||||||
|
|
Loading…
Reference in a new issue