2022-04-23 03:59:50 -05:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2021-09-20 16:41:15 -05:00
|
|
|
|
|
|
|
#include "common/common_types.h"
|
|
|
|
#include "common/input.h"
|
|
|
|
|
|
|
|
#include "input_common/input_engine.h"
|
|
|
|
#include "input_common/input_poller.h"
|
|
|
|
|
|
|
|
namespace InputCommon {
|
|
|
|
|
2021-10-30 22:23:10 -05:00
|
|
|
class DummyInput final : public Common::Input::InputDevice {
|
2021-09-20 16:41:15 -05:00
|
|
|
public:
|
2021-12-13 19:37:45 -06:00
|
|
|
explicit DummyInput() = default;
|
2021-09-20 16:41:15 -05:00
|
|
|
};
|
|
|
|
|
2021-10-30 22:23:10 -05:00
|
|
|
class InputFromButton final : public Common::Input::InputDevice {
|
2021-09-20 16:41:15 -05:00
|
|
|
public:
|
2021-10-31 10:41:44 -05:00
|
|
|
explicit InputFromButton(PadIdentifier identifier_, int button_, bool toggle_, bool inverted_,
|
2021-09-20 16:41:15 -05:00
|
|
|
InputEngine* input_engine_)
|
|
|
|
: identifier(identifier_), button(button_), toggle(toggle_), inverted(inverted_),
|
|
|
|
input_engine(input_engine_) {
|
|
|
|
UpdateCallback engine_callback{[this]() { OnChange(); }};
|
|
|
|
const InputIdentifier input_identifier{
|
|
|
|
.identifier = identifier,
|
|
|
|
.type = EngineInputType::Button,
|
|
|
|
.index = button,
|
|
|
|
.callback = engine_callback,
|
|
|
|
};
|
|
|
|
last_button_value = false;
|
|
|
|
callback_key = input_engine->SetCallback(input_identifier);
|
|
|
|
}
|
|
|
|
|
2021-12-13 19:37:45 -06:00
|
|
|
~InputFromButton() override {
|
2021-09-20 16:41:15 -05:00
|
|
|
input_engine->DeleteCallback(callback_key);
|
|
|
|
}
|
|
|
|
|
2021-10-30 22:23:10 -05:00
|
|
|
Common::Input::ButtonStatus GetStatus() const {
|
2021-09-20 16:41:15 -05:00
|
|
|
return {
|
|
|
|
.value = input_engine->GetButton(identifier, button),
|
|
|
|
.inverted = inverted,
|
|
|
|
.toggle = toggle,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-12-13 19:37:45 -06:00
|
|
|
void ForceUpdate() override {
|
2021-10-30 22:23:10 -05:00
|
|
|
const Common::Input::CallbackStatus status{
|
|
|
|
.type = Common::Input::InputType::Button,
|
2021-10-24 20:28:54 -05:00
|
|
|
.button_status = GetStatus(),
|
|
|
|
};
|
|
|
|
|
|
|
|
last_button_value = status.button_status.value;
|
|
|
|
TriggerOnChange(status);
|
|
|
|
}
|
|
|
|
|
2021-09-20 16:41:15 -05:00
|
|
|
void OnChange() {
|
2021-10-30 22:23:10 -05:00
|
|
|
const Common::Input::CallbackStatus status{
|
|
|
|
.type = Common::Input::InputType::Button,
|
2021-09-20 16:41:15 -05:00
|
|
|
.button_status = GetStatus(),
|
|
|
|
};
|
|
|
|
|
|
|
|
if (status.button_status.value != last_button_value) {
|
|
|
|
last_button_value = status.button_status.value;
|
|
|
|
TriggerOnChange(status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const PadIdentifier identifier;
|
2021-10-31 10:41:44 -05:00
|
|
|
const int button;
|
2021-09-20 16:41:15 -05:00
|
|
|
const bool toggle;
|
|
|
|
const bool inverted;
|
|
|
|
int callback_key;
|
|
|
|
bool last_button_value;
|
|
|
|
InputEngine* input_engine;
|
|
|
|
};
|
|
|
|
|
2021-10-30 22:23:10 -05:00
|
|
|
class InputFromHatButton final : public Common::Input::InputDevice {
|
2021-09-20 16:41:15 -05:00
|
|
|
public:
|
2021-10-31 10:41:44 -05:00
|
|
|
explicit InputFromHatButton(PadIdentifier identifier_, int button_, u8 direction_, bool toggle_,
|
2021-09-20 16:41:15 -05:00
|
|
|
bool inverted_, InputEngine* input_engine_)
|
|
|
|
: identifier(identifier_), button(button_), direction(direction_), toggle(toggle_),
|
|
|
|
inverted(inverted_), input_engine(input_engine_) {
|
|
|
|
UpdateCallback engine_callback{[this]() { OnChange(); }};
|
|
|
|
const InputIdentifier input_identifier{
|
|
|
|
.identifier = identifier,
|
|
|
|
.type = EngineInputType::HatButton,
|
|
|
|
.index = button,
|
|
|
|
.callback = engine_callback,
|
|
|
|
};
|
|
|
|
last_button_value = false;
|
|
|
|
callback_key = input_engine->SetCallback(input_identifier);
|
|
|
|
}
|
|
|
|
|
2021-12-13 19:37:45 -06:00
|
|
|
~InputFromHatButton() override {
|
2021-09-20 16:41:15 -05:00
|
|
|
input_engine->DeleteCallback(callback_key);
|
|
|
|
}
|
|
|
|
|
2021-10-30 22:23:10 -05:00
|
|
|
Common::Input::ButtonStatus GetStatus() const {
|
2021-09-20 16:41:15 -05:00
|
|
|
return {
|
|
|
|
.value = input_engine->GetHatButton(identifier, button, direction),
|
|
|
|
.inverted = inverted,
|
|
|
|
.toggle = toggle,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-12-13 19:37:45 -06:00
|
|
|
void ForceUpdate() override {
|
2021-10-30 22:23:10 -05:00
|
|
|
const Common::Input::CallbackStatus status{
|
|
|
|
.type = Common::Input::InputType::Button,
|
2021-10-24 20:28:54 -05:00
|
|
|
.button_status = GetStatus(),
|
|
|
|
};
|
|
|
|
|
|
|
|
last_button_value = status.button_status.value;
|
|
|
|
TriggerOnChange(status);
|
|
|
|
}
|
|
|
|
|
2021-09-20 16:41:15 -05:00
|
|
|
void OnChange() {
|
2021-10-30 22:23:10 -05:00
|
|
|
const Common::Input::CallbackStatus status{
|
|
|
|
.type = Common::Input::InputType::Button,
|
2021-09-20 16:41:15 -05:00
|
|
|
.button_status = GetStatus(),
|
|
|
|
};
|
|
|
|
|
|
|
|
if (status.button_status.value != last_button_value) {
|
|
|
|
last_button_value = status.button_status.value;
|
|
|
|
TriggerOnChange(status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const PadIdentifier identifier;
|
2021-10-31 10:41:44 -05:00
|
|
|
const int button;
|
2021-09-20 16:41:15 -05:00
|
|
|
const u8 direction;
|
|
|
|
const bool toggle;
|
|
|
|
const bool inverted;
|
|
|
|
int callback_key;
|
|
|
|
bool last_button_value;
|
|
|
|
InputEngine* input_engine;
|
|
|
|
};
|
|
|
|
|
2021-10-30 22:23:10 -05:00
|
|
|
class InputFromStick final : public Common::Input::InputDevice {
|
2021-09-20 16:41:15 -05:00
|
|
|
public:
|
2021-10-31 10:41:44 -05:00
|
|
|
explicit InputFromStick(PadIdentifier identifier_, int axis_x_, int axis_y_,
|
2021-10-30 22:23:10 -05:00
|
|
|
Common::Input::AnalogProperties properties_x_,
|
|
|
|
Common::Input::AnalogProperties properties_y_,
|
|
|
|
InputEngine* input_engine_)
|
2021-09-20 16:41:15 -05:00
|
|
|
: identifier(identifier_), axis_x(axis_x_), axis_y(axis_y_), properties_x(properties_x_),
|
2021-11-21 12:59:51 -06:00
|
|
|
properties_y(properties_y_),
|
|
|
|
input_engine(input_engine_), invert_axis_y{input_engine_->GetEngineName() == "sdl"} {
|
2021-09-20 16:41:15 -05:00
|
|
|
UpdateCallback engine_callback{[this]() { OnChange(); }};
|
|
|
|
const InputIdentifier x_input_identifier{
|
|
|
|
.identifier = identifier,
|
|
|
|
.type = EngineInputType::Analog,
|
|
|
|
.index = axis_x,
|
|
|
|
.callback = engine_callback,
|
|
|
|
};
|
|
|
|
const InputIdentifier y_input_identifier{
|
|
|
|
.identifier = identifier,
|
|
|
|
.type = EngineInputType::Analog,
|
|
|
|
.index = axis_y,
|
|
|
|
.callback = engine_callback,
|
|
|
|
};
|
|
|
|
last_axis_x_value = 0.0f;
|
|
|
|
last_axis_y_value = 0.0f;
|
|
|
|
callback_key_x = input_engine->SetCallback(x_input_identifier);
|
|
|
|
callback_key_y = input_engine->SetCallback(y_input_identifier);
|
|
|
|
}
|
|
|
|
|
2021-12-13 19:37:45 -06:00
|
|
|
~InputFromStick() override {
|
2021-09-20 16:41:15 -05:00
|
|
|
input_engine->DeleteCallback(callback_key_x);
|
|
|
|
input_engine->DeleteCallback(callback_key_y);
|
|
|
|
}
|
|
|
|
|
2021-10-30 22:23:10 -05:00
|
|
|
Common::Input::StickStatus GetStatus() const {
|
|
|
|
Common::Input::StickStatus status;
|
2021-09-20 16:41:15 -05:00
|
|
|
status.x = {
|
|
|
|
.raw_value = input_engine->GetAxis(identifier, axis_x),
|
|
|
|
.properties = properties_x,
|
|
|
|
};
|
|
|
|
status.y = {
|
|
|
|
.raw_value = input_engine->GetAxis(identifier, axis_y),
|
|
|
|
.properties = properties_y,
|
|
|
|
};
|
2022-02-06 18:46:54 -06:00
|
|
|
// This is a workaround to keep compatibility with old yuzu versions. Vertical axis is
|
2021-11-21 12:59:51 -06:00
|
|
|
// inverted on SDL compared to Nintendo
|
|
|
|
if (invert_axis_y) {
|
|
|
|
status.y.raw_value = -status.y.raw_value;
|
|
|
|
}
|
2021-09-20 16:41:15 -05:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2021-12-13 19:37:45 -06:00
|
|
|
void ForceUpdate() override {
|
2021-10-30 22:23:10 -05:00
|
|
|
const Common::Input::CallbackStatus status{
|
|
|
|
.type = Common::Input::InputType::Stick,
|
2021-10-24 23:23:54 -05:00
|
|
|
.stick_status = GetStatus(),
|
|
|
|
};
|
|
|
|
|
|
|
|
last_axis_x_value = status.stick_status.x.raw_value;
|
|
|
|
last_axis_y_value = status.stick_status.y.raw_value;
|
|
|
|
TriggerOnChange(status);
|
|
|
|
}
|
|
|
|
|
2021-09-20 16:41:15 -05:00
|
|
|
void OnChange() {
|
2021-10-30 22:23:10 -05:00
|
|
|
const Common::Input::CallbackStatus status{
|
|
|
|
.type = Common::Input::InputType::Stick,
|
2021-09-20 16:41:15 -05:00
|
|
|
.stick_status = GetStatus(),
|
|
|
|
};
|
|
|
|
|
|
|
|
if (status.stick_status.x.raw_value != last_axis_x_value ||
|
|
|
|
status.stick_status.y.raw_value != last_axis_y_value) {
|
|
|
|
last_axis_x_value = status.stick_status.x.raw_value;
|
|
|
|
last_axis_y_value = status.stick_status.y.raw_value;
|
|
|
|
TriggerOnChange(status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const PadIdentifier identifier;
|
2021-10-31 10:41:44 -05:00
|
|
|
const int axis_x;
|
|
|
|
const int axis_y;
|
2021-10-30 22:23:10 -05:00
|
|
|
const Common::Input::AnalogProperties properties_x;
|
|
|
|
const Common::Input::AnalogProperties properties_y;
|
2021-09-20 16:41:15 -05:00
|
|
|
int callback_key_x;
|
|
|
|
int callback_key_y;
|
|
|
|
float last_axis_x_value;
|
|
|
|
float last_axis_y_value;
|
|
|
|
InputEngine* input_engine;
|
2021-11-21 12:59:51 -06:00
|
|
|
const bool invert_axis_y;
|
2021-09-20 16:41:15 -05:00
|
|
|
};
|
|
|
|
|
2021-10-30 22:23:10 -05:00
|
|
|
class InputFromTouch final : public Common::Input::InputDevice {
|
2021-09-20 16:41:15 -05:00
|
|
|
public:
|
2021-10-31 10:41:44 -05:00
|
|
|
explicit InputFromTouch(PadIdentifier identifier_, int touch_id_, int button_, bool toggle_,
|
|
|
|
bool inverted_, int axis_x_, int axis_y_,
|
2021-10-30 22:23:10 -05:00
|
|
|
Common::Input::AnalogProperties properties_x_,
|
|
|
|
Common::Input::AnalogProperties properties_y_,
|
|
|
|
InputEngine* input_engine_)
|
2021-09-20 16:41:15 -05:00
|
|
|
: identifier(identifier_), touch_id(touch_id_), button(button_), toggle(toggle_),
|
|
|
|
inverted(inverted_), axis_x(axis_x_), axis_y(axis_y_), properties_x(properties_x_),
|
|
|
|
properties_y(properties_y_), input_engine(input_engine_) {
|
|
|
|
UpdateCallback engine_callback{[this]() { OnChange(); }};
|
|
|
|
const InputIdentifier button_input_identifier{
|
|
|
|
.identifier = identifier,
|
|
|
|
.type = EngineInputType::Button,
|
|
|
|
.index = button,
|
|
|
|
.callback = engine_callback,
|
|
|
|
};
|
|
|
|
const InputIdentifier x_input_identifier{
|
|
|
|
.identifier = identifier,
|
|
|
|
.type = EngineInputType::Analog,
|
|
|
|
.index = axis_x,
|
|
|
|
.callback = engine_callback,
|
|
|
|
};
|
|
|
|
const InputIdentifier y_input_identifier{
|
|
|
|
.identifier = identifier,
|
|
|
|
.type = EngineInputType::Analog,
|
|
|
|
.index = axis_y,
|
|
|
|
.callback = engine_callback,
|
|
|
|
};
|
|
|
|
last_axis_x_value = 0.0f;
|
|
|
|
last_axis_y_value = 0.0f;
|
|
|
|
last_button_value = false;
|
|
|
|
callback_key_button = input_engine->SetCallback(button_input_identifier);
|
|
|
|
callback_key_x = input_engine->SetCallback(x_input_identifier);
|
|
|
|
callback_key_y = input_engine->SetCallback(y_input_identifier);
|
|
|
|
}
|
|
|
|
|
2021-12-13 19:37:45 -06:00
|
|
|
~InputFromTouch() override {
|
2021-09-20 16:41:15 -05:00
|
|
|
input_engine->DeleteCallback(callback_key_button);
|
|
|
|
input_engine->DeleteCallback(callback_key_x);
|
|
|
|
input_engine->DeleteCallback(callback_key_y);
|
|
|
|
}
|
|
|
|
|
2021-10-30 22:23:10 -05:00
|
|
|
Common::Input::TouchStatus GetStatus() const {
|
|
|
|
Common::Input::TouchStatus status;
|
2021-09-20 16:41:15 -05:00
|
|
|
status.id = touch_id;
|
|
|
|
status.pressed = {
|
|
|
|
.value = input_engine->GetButton(identifier, button),
|
|
|
|
.inverted = inverted,
|
|
|
|
.toggle = toggle,
|
|
|
|
};
|
|
|
|
status.x = {
|
|
|
|
.raw_value = input_engine->GetAxis(identifier, axis_x),
|
|
|
|
.properties = properties_x,
|
|
|
|
};
|
|
|
|
status.y = {
|
|
|
|
.raw_value = input_engine->GetAxis(identifier, axis_y),
|
|
|
|
.properties = properties_y,
|
|
|
|
};
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnChange() {
|
2021-10-30 22:23:10 -05:00
|
|
|
const Common::Input::CallbackStatus status{
|
|
|
|
.type = Common::Input::InputType::Touch,
|
2021-09-20 16:41:15 -05:00
|
|
|
.touch_status = GetStatus(),
|
|
|
|
};
|
|
|
|
|
|
|
|
if (status.touch_status.x.raw_value != last_axis_x_value ||
|
|
|
|
status.touch_status.y.raw_value != last_axis_y_value ||
|
|
|
|
status.touch_status.pressed.value != last_button_value) {
|
|
|
|
last_axis_x_value = status.touch_status.x.raw_value;
|
|
|
|
last_axis_y_value = status.touch_status.y.raw_value;
|
|
|
|
last_button_value = status.touch_status.pressed.value;
|
|
|
|
TriggerOnChange(status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const PadIdentifier identifier;
|
2021-10-31 10:41:44 -05:00
|
|
|
const int touch_id;
|
|
|
|
const int button;
|
2021-09-20 16:41:15 -05:00
|
|
|
const bool toggle;
|
|
|
|
const bool inverted;
|
2021-10-31 10:41:44 -05:00
|
|
|
const int axis_x;
|
|
|
|
const int axis_y;
|
2021-10-30 22:23:10 -05:00
|
|
|
const Common::Input::AnalogProperties properties_x;
|
|
|
|
const Common::Input::AnalogProperties properties_y;
|
2021-09-20 16:41:15 -05:00
|
|
|
int callback_key_button;
|
|
|
|
int callback_key_x;
|
|
|
|
int callback_key_y;
|
|
|
|
bool last_button_value;
|
|
|
|
float last_axis_x_value;
|
|
|
|
float last_axis_y_value;
|
|
|
|
InputEngine* input_engine;
|
|
|
|
};
|
|
|
|
|
2021-10-30 22:23:10 -05:00
|
|
|
class InputFromTrigger final : public Common::Input::InputDevice {
|
2021-09-20 16:41:15 -05:00
|
|
|
public:
|
2021-10-31 10:41:44 -05:00
|
|
|
explicit InputFromTrigger(PadIdentifier identifier_, int button_, bool toggle_, bool inverted_,
|
|
|
|
int axis_, Common::Input::AnalogProperties properties_,
|
2021-09-20 16:41:15 -05:00
|
|
|
InputEngine* input_engine_)
|
|
|
|
: identifier(identifier_), button(button_), toggle(toggle_), inverted(inverted_),
|
|
|
|
axis(axis_), properties(properties_), input_engine(input_engine_) {
|
|
|
|
UpdateCallback engine_callback{[this]() { OnChange(); }};
|
|
|
|
const InputIdentifier button_input_identifier{
|
|
|
|
.identifier = identifier,
|
|
|
|
.type = EngineInputType::Button,
|
|
|
|
.index = button,
|
|
|
|
.callback = engine_callback,
|
|
|
|
};
|
|
|
|
const InputIdentifier axis_input_identifier{
|
|
|
|
.identifier = identifier,
|
|
|
|
.type = EngineInputType::Analog,
|
|
|
|
.index = axis,
|
|
|
|
.callback = engine_callback,
|
|
|
|
};
|
|
|
|
last_axis_value = 0.0f;
|
|
|
|
last_button_value = false;
|
|
|
|
callback_key_button = input_engine->SetCallback(button_input_identifier);
|
|
|
|
axis_callback_key = input_engine->SetCallback(axis_input_identifier);
|
|
|
|
}
|
|
|
|
|
2021-12-13 19:37:45 -06:00
|
|
|
~InputFromTrigger() override {
|
2021-09-20 16:41:15 -05:00
|
|
|
input_engine->DeleteCallback(callback_key_button);
|
|
|
|
input_engine->DeleteCallback(axis_callback_key);
|
|
|
|
}
|
|
|
|
|
2021-10-30 22:23:10 -05:00
|
|
|
Common::Input::TriggerStatus GetStatus() const {
|
|
|
|
const Common::Input::AnalogStatus analog_status{
|
2021-09-20 16:41:15 -05:00
|
|
|
.raw_value = input_engine->GetAxis(identifier, axis),
|
|
|
|
.properties = properties,
|
|
|
|
};
|
2021-10-31 10:41:44 -05:00
|
|
|
const Common::Input::ButtonStatus button_status{
|
|
|
|
.value = input_engine->GetButton(identifier, button),
|
|
|
|
.inverted = inverted,
|
|
|
|
.toggle = toggle,
|
|
|
|
};
|
2021-09-20 16:41:15 -05:00
|
|
|
return {
|
|
|
|
.analog = analog_status,
|
2021-10-31 10:41:44 -05:00
|
|
|
.pressed = button_status,
|
2021-09-20 16:41:15 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnChange() {
|
2021-10-30 22:23:10 -05:00
|
|
|
const Common::Input::CallbackStatus status{
|
|
|
|
.type = Common::Input::InputType::Trigger,
|
2021-09-20 16:41:15 -05:00
|
|
|
.trigger_status = GetStatus(),
|
|
|
|
};
|
|
|
|
|
|
|
|
if (status.trigger_status.analog.raw_value != last_axis_value ||
|
2021-10-31 10:41:44 -05:00
|
|
|
status.trigger_status.pressed.value != last_button_value) {
|
2021-09-20 16:41:15 -05:00
|
|
|
last_axis_value = status.trigger_status.analog.raw_value;
|
2021-10-31 10:41:44 -05:00
|
|
|
last_button_value = status.trigger_status.pressed.value;
|
2021-09-20 16:41:15 -05:00
|
|
|
TriggerOnChange(status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const PadIdentifier identifier;
|
2021-10-31 10:41:44 -05:00
|
|
|
const int button;
|
2021-09-20 16:41:15 -05:00
|
|
|
const bool toggle;
|
|
|
|
const bool inverted;
|
2021-10-31 10:41:44 -05:00
|
|
|
const int axis;
|
2021-10-30 22:23:10 -05:00
|
|
|
const Common::Input::AnalogProperties properties;
|
2021-09-20 16:41:15 -05:00
|
|
|
int callback_key_button;
|
|
|
|
int axis_callback_key;
|
|
|
|
bool last_button_value;
|
|
|
|
float last_axis_value;
|
|
|
|
InputEngine* input_engine;
|
|
|
|
};
|
|
|
|
|
2021-10-30 22:23:10 -05:00
|
|
|
class InputFromAnalog final : public Common::Input::InputDevice {
|
2021-09-20 16:41:15 -05:00
|
|
|
public:
|
2021-10-31 10:41:44 -05:00
|
|
|
explicit InputFromAnalog(PadIdentifier identifier_, int axis_,
|
2021-10-30 22:23:10 -05:00
|
|
|
Common::Input::AnalogProperties properties_,
|
|
|
|
InputEngine* input_engine_)
|
2021-09-20 16:41:15 -05:00
|
|
|
: identifier(identifier_), axis(axis_), properties(properties_),
|
|
|
|
input_engine(input_engine_) {
|
|
|
|
UpdateCallback engine_callback{[this]() { OnChange(); }};
|
|
|
|
const InputIdentifier input_identifier{
|
|
|
|
.identifier = identifier,
|
|
|
|
.type = EngineInputType::Analog,
|
|
|
|
.index = axis,
|
|
|
|
.callback = engine_callback,
|
|
|
|
};
|
|
|
|
last_axis_value = 0.0f;
|
|
|
|
callback_key = input_engine->SetCallback(input_identifier);
|
|
|
|
}
|
|
|
|
|
2021-12-13 19:37:45 -06:00
|
|
|
~InputFromAnalog() override {
|
2021-09-20 16:41:15 -05:00
|
|
|
input_engine->DeleteCallback(callback_key);
|
|
|
|
}
|
|
|
|
|
2021-10-30 22:23:10 -05:00
|
|
|
Common::Input::AnalogStatus GetStatus() const {
|
2021-09-20 16:41:15 -05:00
|
|
|
return {
|
|
|
|
.raw_value = input_engine->GetAxis(identifier, axis),
|
|
|
|
.properties = properties,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnChange() {
|
2021-10-30 22:23:10 -05:00
|
|
|
const Common::Input::CallbackStatus status{
|
|
|
|
.type = Common::Input::InputType::Analog,
|
2021-09-20 16:41:15 -05:00
|
|
|
.analog_status = GetStatus(),
|
|
|
|
};
|
|
|
|
|
|
|
|
if (status.analog_status.raw_value != last_axis_value) {
|
|
|
|
last_axis_value = status.analog_status.raw_value;
|
|
|
|
TriggerOnChange(status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const PadIdentifier identifier;
|
2021-10-31 10:41:44 -05:00
|
|
|
const int axis;
|
2021-10-30 22:23:10 -05:00
|
|
|
const Common::Input::AnalogProperties properties;
|
2021-09-20 16:41:15 -05:00
|
|
|
int callback_key;
|
|
|
|
float last_axis_value;
|
|
|
|
InputEngine* input_engine;
|
|
|
|
};
|
|
|
|
|
2021-10-30 22:23:10 -05:00
|
|
|
class InputFromBattery final : public Common::Input::InputDevice {
|
2021-09-20 16:41:15 -05:00
|
|
|
public:
|
|
|
|
explicit InputFromBattery(PadIdentifier identifier_, InputEngine* input_engine_)
|
|
|
|
: identifier(identifier_), input_engine(input_engine_) {
|
|
|
|
UpdateCallback engine_callback{[this]() { OnChange(); }};
|
|
|
|
const InputIdentifier input_identifier{
|
|
|
|
.identifier = identifier,
|
|
|
|
.type = EngineInputType::Battery,
|
|
|
|
.index = 0,
|
|
|
|
.callback = engine_callback,
|
|
|
|
};
|
2021-10-30 22:23:10 -05:00
|
|
|
last_battery_value = Common::Input::BatteryStatus::Charging;
|
2021-09-20 16:41:15 -05:00
|
|
|
callback_key = input_engine->SetCallback(input_identifier);
|
|
|
|
}
|
|
|
|
|
2021-12-13 19:37:45 -06:00
|
|
|
~InputFromBattery() override {
|
2021-09-20 16:41:15 -05:00
|
|
|
input_engine->DeleteCallback(callback_key);
|
|
|
|
}
|
|
|
|
|
2021-10-30 22:23:10 -05:00
|
|
|
Common::Input::BatteryStatus GetStatus() const {
|
2022-02-06 18:20:12 -06:00
|
|
|
return input_engine->GetBattery(identifier);
|
2021-09-20 16:41:15 -05:00
|
|
|
}
|
|
|
|
|
2021-12-13 19:37:45 -06:00
|
|
|
void ForceUpdate() override {
|
2021-10-30 22:23:10 -05:00
|
|
|
const Common::Input::CallbackStatus status{
|
|
|
|
.type = Common::Input::InputType::Battery,
|
2021-10-24 23:23:54 -05:00
|
|
|
.battery_status = GetStatus(),
|
|
|
|
};
|
|
|
|
|
|
|
|
last_battery_value = status.battery_status;
|
|
|
|
TriggerOnChange(status);
|
|
|
|
}
|
|
|
|
|
2021-09-20 16:41:15 -05:00
|
|
|
void OnChange() {
|
2021-10-30 22:23:10 -05:00
|
|
|
const Common::Input::CallbackStatus status{
|
|
|
|
.type = Common::Input::InputType::Battery,
|
2021-09-20 16:41:15 -05:00
|
|
|
.battery_status = GetStatus(),
|
|
|
|
};
|
|
|
|
|
|
|
|
if (status.battery_status != last_battery_value) {
|
|
|
|
last_battery_value = status.battery_status;
|
|
|
|
TriggerOnChange(status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const PadIdentifier identifier;
|
|
|
|
int callback_key;
|
2021-10-30 22:23:10 -05:00
|
|
|
Common::Input::BatteryStatus last_battery_value;
|
2021-09-20 16:41:15 -05:00
|
|
|
InputEngine* input_engine;
|
|
|
|
};
|
|
|
|
|
2021-10-30 22:23:10 -05:00
|
|
|
class InputFromMotion final : public Common::Input::InputDevice {
|
2021-09-20 16:41:15 -05:00
|
|
|
public:
|
2022-01-23 21:54:33 -06:00
|
|
|
explicit InputFromMotion(PadIdentifier identifier_, int motion_sensor_, float gyro_threshold_,
|
2021-09-20 16:41:15 -05:00
|
|
|
InputEngine* input_engine_)
|
2022-01-23 21:54:33 -06:00
|
|
|
: identifier(identifier_), motion_sensor(motion_sensor_), gyro_threshold(gyro_threshold_),
|
|
|
|
input_engine(input_engine_) {
|
2021-09-20 16:41:15 -05:00
|
|
|
UpdateCallback engine_callback{[this]() { OnChange(); }};
|
|
|
|
const InputIdentifier input_identifier{
|
|
|
|
.identifier = identifier,
|
|
|
|
.type = EngineInputType::Motion,
|
|
|
|
.index = motion_sensor,
|
|
|
|
.callback = engine_callback,
|
|
|
|
};
|
|
|
|
callback_key = input_engine->SetCallback(input_identifier);
|
|
|
|
}
|
|
|
|
|
2021-12-13 19:37:45 -06:00
|
|
|
~InputFromMotion() override {
|
2021-09-20 16:41:15 -05:00
|
|
|
input_engine->DeleteCallback(callback_key);
|
|
|
|
}
|
|
|
|
|
2021-10-30 22:23:10 -05:00
|
|
|
Common::Input::MotionStatus GetStatus() const {
|
2021-09-20 16:41:15 -05:00
|
|
|
const auto basic_motion = input_engine->GetMotion(identifier, motion_sensor);
|
2021-10-30 22:23:10 -05:00
|
|
|
Common::Input::MotionStatus status{};
|
|
|
|
const Common::Input::AnalogProperties properties = {
|
2022-01-23 21:54:33 -06:00
|
|
|
.deadzone = 0.0f,
|
2021-09-20 16:41:15 -05:00
|
|
|
.range = 1.0f,
|
2022-01-23 21:54:33 -06:00
|
|
|
.threshold = gyro_threshold,
|
2021-09-20 16:41:15 -05:00
|
|
|
.offset = 0.0f,
|
|
|
|
};
|
|
|
|
status.accel.x = {.raw_value = basic_motion.accel_x, .properties = properties};
|
|
|
|
status.accel.y = {.raw_value = basic_motion.accel_y, .properties = properties};
|
|
|
|
status.accel.z = {.raw_value = basic_motion.accel_z, .properties = properties};
|
|
|
|
status.gyro.x = {.raw_value = basic_motion.gyro_x, .properties = properties};
|
|
|
|
status.gyro.y = {.raw_value = basic_motion.gyro_y, .properties = properties};
|
|
|
|
status.gyro.z = {.raw_value = basic_motion.gyro_z, .properties = properties};
|
|
|
|
status.delta_timestamp = basic_motion.delta_timestamp;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnChange() {
|
2021-10-30 22:23:10 -05:00
|
|
|
const Common::Input::CallbackStatus status{
|
|
|
|
.type = Common::Input::InputType::Motion,
|
2021-09-20 16:41:15 -05:00
|
|
|
.motion_status = GetStatus(),
|
|
|
|
};
|
|
|
|
|
|
|
|
TriggerOnChange(status);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const PadIdentifier identifier;
|
2021-10-31 10:41:44 -05:00
|
|
|
const int motion_sensor;
|
2022-01-23 21:54:33 -06:00
|
|
|
const float gyro_threshold;
|
2021-09-20 16:41:15 -05:00
|
|
|
int callback_key;
|
|
|
|
InputEngine* input_engine;
|
|
|
|
};
|
|
|
|
|
2021-10-30 22:23:10 -05:00
|
|
|
class InputFromAxisMotion final : public Common::Input::InputDevice {
|
2021-09-20 16:41:15 -05:00
|
|
|
public:
|
2021-10-31 10:41:44 -05:00
|
|
|
explicit InputFromAxisMotion(PadIdentifier identifier_, int axis_x_, int axis_y_, int axis_z_,
|
2021-10-30 22:23:10 -05:00
|
|
|
Common::Input::AnalogProperties properties_x_,
|
|
|
|
Common::Input::AnalogProperties properties_y_,
|
|
|
|
Common::Input::AnalogProperties properties_z_,
|
|
|
|
InputEngine* input_engine_)
|
2021-09-20 16:41:15 -05:00
|
|
|
: identifier(identifier_), axis_x(axis_x_), axis_y(axis_y_), axis_z(axis_z_),
|
|
|
|
properties_x(properties_x_), properties_y(properties_y_), properties_z(properties_z_),
|
|
|
|
input_engine(input_engine_) {
|
|
|
|
UpdateCallback engine_callback{[this]() { OnChange(); }};
|
|
|
|
const InputIdentifier x_input_identifier{
|
|
|
|
.identifier = identifier,
|
|
|
|
.type = EngineInputType::Analog,
|
|
|
|
.index = axis_x,
|
|
|
|
.callback = engine_callback,
|
|
|
|
};
|
|
|
|
const InputIdentifier y_input_identifier{
|
|
|
|
.identifier = identifier,
|
|
|
|
.type = EngineInputType::Analog,
|
|
|
|
.index = axis_y,
|
|
|
|
.callback = engine_callback,
|
|
|
|
};
|
|
|
|
const InputIdentifier z_input_identifier{
|
|
|
|
.identifier = identifier,
|
|
|
|
.type = EngineInputType::Analog,
|
|
|
|
.index = axis_z,
|
|
|
|
.callback = engine_callback,
|
|
|
|
};
|
|
|
|
last_axis_x_value = 0.0f;
|
|
|
|
last_axis_y_value = 0.0f;
|
|
|
|
last_axis_z_value = 0.0f;
|
|
|
|
callback_key_x = input_engine->SetCallback(x_input_identifier);
|
|
|
|
callback_key_y = input_engine->SetCallback(y_input_identifier);
|
|
|
|
callback_key_z = input_engine->SetCallback(z_input_identifier);
|
|
|
|
}
|
|
|
|
|
2021-12-13 19:37:45 -06:00
|
|
|
~InputFromAxisMotion() override {
|
2021-09-20 16:41:15 -05:00
|
|
|
input_engine->DeleteCallback(callback_key_x);
|
|
|
|
input_engine->DeleteCallback(callback_key_y);
|
|
|
|
input_engine->DeleteCallback(callback_key_z);
|
|
|
|
}
|
|
|
|
|
2021-10-30 22:23:10 -05:00
|
|
|
Common::Input::MotionStatus GetStatus() const {
|
|
|
|
Common::Input::MotionStatus status{};
|
2021-09-20 16:41:15 -05:00
|
|
|
status.gyro.x = {
|
|
|
|
.raw_value = input_engine->GetAxis(identifier, axis_x),
|
|
|
|
.properties = properties_x,
|
|
|
|
};
|
|
|
|
status.gyro.y = {
|
|
|
|
.raw_value = input_engine->GetAxis(identifier, axis_y),
|
|
|
|
.properties = properties_y,
|
|
|
|
};
|
|
|
|
status.gyro.z = {
|
|
|
|
.raw_value = input_engine->GetAxis(identifier, axis_z),
|
|
|
|
.properties = properties_z,
|
|
|
|
};
|
2021-11-03 18:06:21 -05:00
|
|
|
status.delta_timestamp = 5000;
|
|
|
|
status.force_update = true;
|
2021-09-20 16:41:15 -05:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2021-12-13 19:37:45 -06:00
|
|
|
void ForceUpdate() override {
|
2021-10-30 22:23:10 -05:00
|
|
|
const Common::Input::CallbackStatus status{
|
|
|
|
.type = Common::Input::InputType::Motion,
|
2021-10-24 23:23:54 -05:00
|
|
|
.motion_status = GetStatus(),
|
|
|
|
};
|
|
|
|
|
|
|
|
last_axis_x_value = status.motion_status.gyro.x.raw_value;
|
|
|
|
last_axis_y_value = status.motion_status.gyro.y.raw_value;
|
|
|
|
last_axis_z_value = status.motion_status.gyro.z.raw_value;
|
|
|
|
TriggerOnChange(status);
|
|
|
|
}
|
|
|
|
|
2021-09-20 16:41:15 -05:00
|
|
|
void OnChange() {
|
2021-10-30 22:23:10 -05:00
|
|
|
const Common::Input::CallbackStatus status{
|
|
|
|
.type = Common::Input::InputType::Motion,
|
2021-09-20 16:41:15 -05:00
|
|
|
.motion_status = GetStatus(),
|
|
|
|
};
|
|
|
|
|
|
|
|
if (status.motion_status.gyro.x.raw_value != last_axis_x_value ||
|
|
|
|
status.motion_status.gyro.y.raw_value != last_axis_y_value ||
|
|
|
|
status.motion_status.gyro.z.raw_value != last_axis_z_value) {
|
|
|
|
last_axis_x_value = status.motion_status.gyro.x.raw_value;
|
|
|
|
last_axis_y_value = status.motion_status.gyro.y.raw_value;
|
|
|
|
last_axis_z_value = status.motion_status.gyro.z.raw_value;
|
|
|
|
TriggerOnChange(status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const PadIdentifier identifier;
|
2021-10-31 10:41:44 -05:00
|
|
|
const int axis_x;
|
|
|
|
const int axis_y;
|
|
|
|
const int axis_z;
|
2021-10-30 22:23:10 -05:00
|
|
|
const Common::Input::AnalogProperties properties_x;
|
|
|
|
const Common::Input::AnalogProperties properties_y;
|
|
|
|
const Common::Input::AnalogProperties properties_z;
|
2021-09-20 16:41:15 -05:00
|
|
|
int callback_key_x;
|
|
|
|
int callback_key_y;
|
|
|
|
int callback_key_z;
|
|
|
|
float last_axis_x_value;
|
|
|
|
float last_axis_y_value;
|
|
|
|
float last_axis_z_value;
|
|
|
|
InputEngine* input_engine;
|
|
|
|
};
|
|
|
|
|
2022-06-18 23:32:07 -05:00
|
|
|
class InputFromCamera final : public Common::Input::InputDevice {
|
|
|
|
public:
|
|
|
|
explicit InputFromCamera(PadIdentifier identifier_, InputEngine* input_engine_)
|
|
|
|
: identifier(identifier_), input_engine(input_engine_) {
|
|
|
|
UpdateCallback engine_callback{[this]() { OnChange(); }};
|
|
|
|
const InputIdentifier input_identifier{
|
|
|
|
.identifier = identifier,
|
|
|
|
.type = EngineInputType::Camera,
|
|
|
|
.index = 0,
|
|
|
|
.callback = engine_callback,
|
|
|
|
};
|
|
|
|
callback_key = input_engine->SetCallback(input_identifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
~InputFromCamera() override {
|
|
|
|
input_engine->DeleteCallback(callback_key);
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::Input::CameraStatus GetStatus() const {
|
|
|
|
return input_engine->GetCamera(identifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ForceUpdate() override {
|
|
|
|
OnChange();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnChange() {
|
2022-10-09 12:49:07 -05:00
|
|
|
const auto camera_status = GetStatus();
|
|
|
|
|
2022-06-18 23:32:07 -05:00
|
|
|
const Common::Input::CallbackStatus status{
|
|
|
|
.type = Common::Input::InputType::IrSensor,
|
2022-10-09 12:49:07 -05:00
|
|
|
.camera_status = camera_status.format,
|
|
|
|
.raw_data = camera_status.data,
|
2022-06-18 23:32:07 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
TriggerOnChange(status);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const PadIdentifier identifier;
|
|
|
|
int callback_key;
|
|
|
|
InputEngine* input_engine;
|
|
|
|
};
|
|
|
|
|
2022-09-24 20:28:27 -05:00
|
|
|
class InputFromNfc final : public Common::Input::InputDevice {
|
|
|
|
public:
|
|
|
|
explicit InputFromNfc(PadIdentifier identifier_, InputEngine* input_engine_)
|
|
|
|
: identifier(identifier_), input_engine(input_engine_) {
|
|
|
|
UpdateCallback engine_callback{[this]() { OnChange(); }};
|
|
|
|
const InputIdentifier input_identifier{
|
|
|
|
.identifier = identifier,
|
|
|
|
.type = EngineInputType::Nfc,
|
|
|
|
.index = 0,
|
|
|
|
.callback = engine_callback,
|
|
|
|
};
|
|
|
|
callback_key = input_engine->SetCallback(input_identifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
~InputFromNfc() override {
|
|
|
|
input_engine->DeleteCallback(callback_key);
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::Input::NfcStatus GetStatus() const {
|
|
|
|
return input_engine->GetNfc(identifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ForceUpdate() override {
|
|
|
|
OnChange();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnChange() {
|
2022-10-09 12:49:07 -05:00
|
|
|
const auto nfc_status = GetStatus();
|
|
|
|
|
2022-09-24 20:28:27 -05:00
|
|
|
const Common::Input::CallbackStatus status{
|
|
|
|
.type = Common::Input::InputType::Nfc,
|
2022-10-09 12:49:07 -05:00
|
|
|
.nfc_status = nfc_status.state,
|
|
|
|
.raw_data = nfc_status.data,
|
2022-09-24 20:28:27 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
TriggerOnChange(status);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const PadIdentifier identifier;
|
|
|
|
int callback_key;
|
|
|
|
InputEngine* input_engine;
|
|
|
|
};
|
|
|
|
|
2021-10-30 22:23:10 -05:00
|
|
|
class OutputFromIdentifier final : public Common::Input::OutputDevice {
|
2021-10-11 00:43:11 -05:00
|
|
|
public:
|
|
|
|
explicit OutputFromIdentifier(PadIdentifier identifier_, InputEngine* input_engine_)
|
|
|
|
: identifier(identifier_), input_engine(input_engine_) {}
|
|
|
|
|
2021-12-13 19:37:45 -06:00
|
|
|
void SetLED(const Common::Input::LedStatus& led_status) override {
|
2021-10-11 00:43:11 -05:00
|
|
|
input_engine->SetLeds(identifier, led_status);
|
|
|
|
}
|
|
|
|
|
2021-12-13 19:37:45 -06:00
|
|
|
Common::Input::VibrationError SetVibration(
|
|
|
|
const Common::Input::VibrationStatus& vibration_status) override {
|
2021-10-11 00:43:11 -05:00
|
|
|
return input_engine->SetRumble(identifier, vibration_status);
|
|
|
|
}
|
|
|
|
|
2021-12-13 19:37:45 -06:00
|
|
|
Common::Input::PollingError SetPollingMode(Common::Input::PollingMode polling_mode) override {
|
2021-10-11 00:43:11 -05:00
|
|
|
return input_engine->SetPollingMode(identifier, polling_mode);
|
|
|
|
}
|
|
|
|
|
2022-06-18 23:32:07 -05:00
|
|
|
Common::Input::CameraError SetCameraFormat(Common::Input::CameraFormat camera_format) override {
|
|
|
|
return input_engine->SetCameraFormat(identifier, camera_format);
|
|
|
|
}
|
|
|
|
|
2022-09-24 22:52:33 -05:00
|
|
|
Common::Input::NfcState SupportsNfc() const override {
|
2022-09-24 20:28:27 -05:00
|
|
|
return input_engine->SupportsNfc(identifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::Input::NfcState WriteNfcData(const std::vector<u8>& data) override {
|
|
|
|
return input_engine->WriteNfcData(identifier, data);
|
|
|
|
}
|
|
|
|
|
2021-10-11 00:43:11 -05:00
|
|
|
private:
|
|
|
|
const PadIdentifier identifier;
|
|
|
|
InputEngine* input_engine;
|
|
|
|
};
|
|
|
|
|
2021-10-30 22:23:10 -05:00
|
|
|
std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateButtonDevice(
|
2021-09-20 16:41:15 -05:00
|
|
|
const Common::ParamPackage& params) {
|
|
|
|
const PadIdentifier identifier = {
|
|
|
|
.guid = Common::UUID{params.Get("guid", "")},
|
|
|
|
.port = static_cast<std::size_t>(params.Get("port", 0)),
|
|
|
|
.pad = static_cast<std::size_t>(params.Get("pad", 0)),
|
|
|
|
};
|
|
|
|
|
2021-10-31 10:41:44 -05:00
|
|
|
const auto button_id = params.Get("button", 0);
|
|
|
|
const auto keyboard_key = params.Get("code", 0);
|
2021-09-20 16:41:15 -05:00
|
|
|
const auto toggle = params.Get("toggle", false);
|
|
|
|
const auto inverted = params.Get("inverted", false);
|
|
|
|
input_engine->PreSetController(identifier);
|
|
|
|
input_engine->PreSetButton(identifier, button_id);
|
|
|
|
input_engine->PreSetButton(identifier, keyboard_key);
|
|
|
|
if (keyboard_key != 0) {
|
|
|
|
return std::make_unique<InputFromButton>(identifier, keyboard_key, toggle, inverted,
|
|
|
|
input_engine.get());
|
|
|
|
}
|
|
|
|
return std::make_unique<InputFromButton>(identifier, button_id, toggle, inverted,
|
|
|
|
input_engine.get());
|
|
|
|
}
|
|
|
|
|
2021-10-30 22:23:10 -05:00
|
|
|
std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateHatButtonDevice(
|
2021-09-20 16:41:15 -05:00
|
|
|
const Common::ParamPackage& params) {
|
|
|
|
const PadIdentifier identifier = {
|
|
|
|
.guid = Common::UUID{params.Get("guid", "")},
|
|
|
|
.port = static_cast<std::size_t>(params.Get("port", 0)),
|
|
|
|
.pad = static_cast<std::size_t>(params.Get("pad", 0)),
|
|
|
|
};
|
|
|
|
|
2021-10-31 10:41:44 -05:00
|
|
|
const auto button_id = params.Get("hat", 0);
|
2021-09-20 16:41:15 -05:00
|
|
|
const auto direction = input_engine->GetHatButtonId(params.Get("direction", ""));
|
|
|
|
const auto toggle = params.Get("toggle", false);
|
|
|
|
const auto inverted = params.Get("inverted", false);
|
|
|
|
|
|
|
|
input_engine->PreSetController(identifier);
|
|
|
|
input_engine->PreSetHatButton(identifier, button_id);
|
|
|
|
return std::make_unique<InputFromHatButton>(identifier, button_id, direction, toggle, inverted,
|
|
|
|
input_engine.get());
|
|
|
|
}
|
|
|
|
|
2021-10-30 22:23:10 -05:00
|
|
|
std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateStickDevice(
|
2021-09-20 16:41:15 -05:00
|
|
|
const Common::ParamPackage& params) {
|
|
|
|
const auto deadzone = std::clamp(params.Get("deadzone", 0.15f), 0.0f, 1.0f);
|
2022-04-26 18:19:17 -05:00
|
|
|
const auto range = std::clamp(params.Get("range", 0.95f), 0.25f, 1.50f);
|
2021-09-20 16:41:15 -05:00
|
|
|
const auto threshold = std::clamp(params.Get("threshold", 0.5f), 0.0f, 1.0f);
|
|
|
|
const PadIdentifier identifier = {
|
|
|
|
.guid = Common::UUID{params.Get("guid", "")},
|
|
|
|
.port = static_cast<std::size_t>(params.Get("port", 0)),
|
|
|
|
.pad = static_cast<std::size_t>(params.Get("pad", 0)),
|
|
|
|
};
|
|
|
|
|
2021-10-31 10:41:44 -05:00
|
|
|
const auto axis_x = params.Get("axis_x", 0);
|
2021-10-30 22:23:10 -05:00
|
|
|
const Common::Input::AnalogProperties properties_x = {
|
2021-09-20 16:41:15 -05:00
|
|
|
.deadzone = deadzone,
|
|
|
|
.range = range,
|
|
|
|
.threshold = threshold,
|
|
|
|
.offset = std::clamp(params.Get("offset_x", 0.0f), -1.0f, 1.0f),
|
|
|
|
.inverted = params.Get("invert_x", "+") == "-",
|
|
|
|
};
|
|
|
|
|
2021-10-31 10:41:44 -05:00
|
|
|
const auto axis_y = params.Get("axis_y", 1);
|
2021-10-30 22:23:10 -05:00
|
|
|
const Common::Input::AnalogProperties properties_y = {
|
2021-09-20 16:41:15 -05:00
|
|
|
.deadzone = deadzone,
|
|
|
|
.range = range,
|
|
|
|
.threshold = threshold,
|
|
|
|
.offset = std::clamp(params.Get("offset_y", 0.0f), -1.0f, 1.0f),
|
|
|
|
.inverted = params.Get("invert_y", "+") != "+",
|
|
|
|
};
|
|
|
|
input_engine->PreSetController(identifier);
|
|
|
|
input_engine->PreSetAxis(identifier, axis_x);
|
|
|
|
input_engine->PreSetAxis(identifier, axis_y);
|
|
|
|
return std::make_unique<InputFromStick>(identifier, axis_x, axis_y, properties_x, properties_y,
|
|
|
|
input_engine.get());
|
|
|
|
}
|
|
|
|
|
2021-10-30 22:23:10 -05:00
|
|
|
std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateAnalogDevice(
|
2021-09-20 16:41:15 -05:00
|
|
|
const Common::ParamPackage& params) {
|
|
|
|
const PadIdentifier identifier = {
|
|
|
|
.guid = Common::UUID{params.Get("guid", "")},
|
|
|
|
.port = static_cast<std::size_t>(params.Get("port", 0)),
|
|
|
|
.pad = static_cast<std::size_t>(params.Get("pad", 0)),
|
|
|
|
};
|
|
|
|
|
2021-10-31 10:41:44 -05:00
|
|
|
const auto axis = params.Get("axis", 0);
|
2021-10-30 22:23:10 -05:00
|
|
|
const Common::Input::AnalogProperties properties = {
|
2021-09-20 16:41:15 -05:00
|
|
|
.deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f),
|
|
|
|
.range = std::clamp(params.Get("range", 1.0f), 0.25f, 1.50f),
|
|
|
|
.threshold = std::clamp(params.Get("threshold", 0.5f), 0.0f, 1.0f),
|
|
|
|
.offset = std::clamp(params.Get("offset", 0.0f), -1.0f, 1.0f),
|
|
|
|
.inverted = params.Get("invert", "+") == "-",
|
2022-09-06 11:20:53 -05:00
|
|
|
.toggle = static_cast<bool>(params.Get("toggle", false)),
|
2021-09-20 16:41:15 -05:00
|
|
|
};
|
|
|
|
input_engine->PreSetController(identifier);
|
|
|
|
input_engine->PreSetAxis(identifier, axis);
|
|
|
|
return std::make_unique<InputFromAnalog>(identifier, axis, properties, input_engine.get());
|
|
|
|
}
|
|
|
|
|
2021-10-30 22:23:10 -05:00
|
|
|
std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateTriggerDevice(
|
2021-09-20 16:41:15 -05:00
|
|
|
const Common::ParamPackage& params) {
|
|
|
|
const PadIdentifier identifier = {
|
|
|
|
.guid = Common::UUID{params.Get("guid", "")},
|
|
|
|
.port = static_cast<std::size_t>(params.Get("port", 0)),
|
|
|
|
.pad = static_cast<std::size_t>(params.Get("pad", 0)),
|
|
|
|
};
|
|
|
|
|
2021-10-31 10:41:44 -05:00
|
|
|
const auto button = params.Get("button", 0);
|
2021-09-20 16:41:15 -05:00
|
|
|
const auto toggle = params.Get("toggle", false);
|
|
|
|
const auto inverted = params.Get("inverted", false);
|
|
|
|
|
2021-10-31 10:41:44 -05:00
|
|
|
const auto axis = params.Get("axis", 0);
|
2021-10-30 22:23:10 -05:00
|
|
|
const Common::Input::AnalogProperties properties = {
|
2021-09-20 16:41:15 -05:00
|
|
|
.deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f),
|
|
|
|
.range = std::clamp(params.Get("range", 1.0f), 0.25f, 2.50f),
|
|
|
|
.threshold = std::clamp(params.Get("threshold", 0.5f), 0.0f, 1.0f),
|
|
|
|
.offset = std::clamp(params.Get("offset", 0.0f), -1.0f, 1.0f),
|
|
|
|
.inverted = params.Get("invert", false) != 0,
|
|
|
|
};
|
|
|
|
input_engine->PreSetController(identifier);
|
|
|
|
input_engine->PreSetAxis(identifier, axis);
|
|
|
|
input_engine->PreSetButton(identifier, button);
|
|
|
|
return std::make_unique<InputFromTrigger>(identifier, button, toggle, inverted, axis,
|
|
|
|
properties, input_engine.get());
|
|
|
|
}
|
|
|
|
|
2021-10-30 22:23:10 -05:00
|
|
|
std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateTouchDevice(
|
2021-09-20 16:41:15 -05:00
|
|
|
const Common::ParamPackage& params) {
|
|
|
|
const auto touch_id = params.Get("touch_id", 0);
|
|
|
|
const auto deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f);
|
|
|
|
const auto range = std::clamp(params.Get("range", 1.0f), 0.25f, 1.50f);
|
|
|
|
const auto threshold = std::clamp(params.Get("threshold", 0.5f), 0.0f, 1.0f);
|
|
|
|
const PadIdentifier identifier = {
|
|
|
|
.guid = Common::UUID{params.Get("guid", "")},
|
|
|
|
.port = static_cast<std::size_t>(params.Get("port", 0)),
|
|
|
|
.pad = static_cast<std::size_t>(params.Get("pad", 0)),
|
|
|
|
};
|
|
|
|
|
2021-10-31 10:41:44 -05:00
|
|
|
const auto button = params.Get("button", 0);
|
2021-09-20 16:41:15 -05:00
|
|
|
const auto toggle = params.Get("toggle", false);
|
|
|
|
const auto inverted = params.Get("inverted", false);
|
|
|
|
|
2021-10-31 10:41:44 -05:00
|
|
|
const auto axis_x = params.Get("axis_x", 0);
|
2021-10-30 22:23:10 -05:00
|
|
|
const Common::Input::AnalogProperties properties_x = {
|
2021-09-20 16:41:15 -05:00
|
|
|
.deadzone = deadzone,
|
|
|
|
.range = range,
|
|
|
|
.threshold = threshold,
|
|
|
|
.offset = std::clamp(params.Get("offset_x", 0.0f), -1.0f, 1.0f),
|
|
|
|
.inverted = params.Get("invert_x", "+") == "-",
|
|
|
|
};
|
|
|
|
|
2021-10-31 10:41:44 -05:00
|
|
|
const auto axis_y = params.Get("axis_y", 1);
|
2021-10-30 22:23:10 -05:00
|
|
|
const Common::Input::AnalogProperties properties_y = {
|
2021-09-20 16:41:15 -05:00
|
|
|
.deadzone = deadzone,
|
|
|
|
.range = range,
|
|
|
|
.threshold = threshold,
|
|
|
|
.offset = std::clamp(params.Get("offset_y", 0.0f), -1.0f, 1.0f),
|
|
|
|
.inverted = params.Get("invert_y", false) != 0,
|
|
|
|
};
|
|
|
|
input_engine->PreSetController(identifier);
|
|
|
|
input_engine->PreSetAxis(identifier, axis_x);
|
|
|
|
input_engine->PreSetAxis(identifier, axis_y);
|
|
|
|
input_engine->PreSetButton(identifier, button);
|
|
|
|
return std::make_unique<InputFromTouch>(identifier, touch_id, button, toggle, inverted, axis_x,
|
|
|
|
axis_y, properties_x, properties_y, input_engine.get());
|
|
|
|
}
|
|
|
|
|
2021-10-30 22:23:10 -05:00
|
|
|
std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateBatteryDevice(
|
2021-09-20 16:41:15 -05:00
|
|
|
const Common::ParamPackage& params) {
|
|
|
|
const PadIdentifier identifier = {
|
|
|
|
.guid = Common::UUID{params.Get("guid", "")},
|
|
|
|
.port = static_cast<std::size_t>(params.Get("port", 0)),
|
|
|
|
.pad = static_cast<std::size_t>(params.Get("pad", 0)),
|
|
|
|
};
|
|
|
|
|
|
|
|
input_engine->PreSetController(identifier);
|
|
|
|
return std::make_unique<InputFromBattery>(identifier, input_engine.get());
|
|
|
|
}
|
|
|
|
|
2021-10-30 22:23:10 -05:00
|
|
|
std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateMotionDevice(
|
|
|
|
Common::ParamPackage params) {
|
2021-09-20 16:41:15 -05:00
|
|
|
const PadIdentifier identifier = {
|
|
|
|
.guid = Common::UUID{params.Get("guid", "")},
|
|
|
|
.port = static_cast<std::size_t>(params.Get("port", 0)),
|
|
|
|
.pad = static_cast<std::size_t>(params.Get("pad", 0)),
|
|
|
|
};
|
|
|
|
|
|
|
|
if (params.Has("motion")) {
|
|
|
|
const auto motion_sensor = params.Get("motion", 0);
|
2022-01-23 21:54:33 -06:00
|
|
|
const auto gyro_threshold = params.Get("threshold", 0.007f);
|
2021-09-20 16:41:15 -05:00
|
|
|
input_engine->PreSetController(identifier);
|
|
|
|
input_engine->PreSetMotion(identifier, motion_sensor);
|
2022-01-23 21:54:33 -06:00
|
|
|
return std::make_unique<InputFromMotion>(identifier, motion_sensor, gyro_threshold,
|
|
|
|
input_engine.get());
|
2021-09-20 16:41:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
const auto deadzone = std::clamp(params.Get("deadzone", 0.15f), 0.0f, 1.0f);
|
|
|
|
const auto range = std::clamp(params.Get("range", 1.0f), 0.25f, 1.50f);
|
|
|
|
const auto threshold = std::clamp(params.Get("threshold", 0.5f), 0.0f, 1.0f);
|
|
|
|
|
2021-10-31 10:41:44 -05:00
|
|
|
const auto axis_x = params.Get("axis_x", 0);
|
2021-10-30 22:23:10 -05:00
|
|
|
const Common::Input::AnalogProperties properties_x = {
|
2021-09-20 16:41:15 -05:00
|
|
|
.deadzone = deadzone,
|
|
|
|
.range = range,
|
|
|
|
.threshold = threshold,
|
|
|
|
.offset = std::clamp(params.Get("offset_x", 0.0f), -1.0f, 1.0f),
|
|
|
|
.inverted = params.Get("invert_x", "+") == "-",
|
|
|
|
};
|
|
|
|
|
2021-10-31 10:41:44 -05:00
|
|
|
const auto axis_y = params.Get("axis_y", 1);
|
2021-10-30 22:23:10 -05:00
|
|
|
const Common::Input::AnalogProperties properties_y = {
|
2021-09-20 16:41:15 -05:00
|
|
|
.deadzone = deadzone,
|
|
|
|
.range = range,
|
|
|
|
.threshold = threshold,
|
|
|
|
.offset = std::clamp(params.Get("offset_y", 0.0f), -1.0f, 1.0f),
|
|
|
|
.inverted = params.Get("invert_y", "+") != "+",
|
|
|
|
};
|
|
|
|
|
2021-10-31 10:41:44 -05:00
|
|
|
const auto axis_z = params.Get("axis_z", 1);
|
2021-10-30 22:23:10 -05:00
|
|
|
const Common::Input::AnalogProperties properties_z = {
|
2021-09-20 16:41:15 -05:00
|
|
|
.deadzone = deadzone,
|
|
|
|
.range = range,
|
|
|
|
.threshold = threshold,
|
|
|
|
.offset = std::clamp(params.Get("offset_z", 0.0f), -1.0f, 1.0f),
|
|
|
|
.inverted = params.Get("invert_z", "+") != "+",
|
|
|
|
};
|
|
|
|
input_engine->PreSetController(identifier);
|
|
|
|
input_engine->PreSetAxis(identifier, axis_x);
|
|
|
|
input_engine->PreSetAxis(identifier, axis_y);
|
|
|
|
input_engine->PreSetAxis(identifier, axis_z);
|
|
|
|
return std::make_unique<InputFromAxisMotion>(identifier, axis_x, axis_y, axis_z, properties_x,
|
|
|
|
properties_y, properties_z, input_engine.get());
|
|
|
|
}
|
|
|
|
|
2022-06-18 23:32:07 -05:00
|
|
|
std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateCameraDevice(
|
|
|
|
const Common::ParamPackage& params) {
|
|
|
|
const PadIdentifier identifier = {
|
|
|
|
.guid = Common::UUID{params.Get("guid", "")},
|
|
|
|
.port = static_cast<std::size_t>(params.Get("port", 0)),
|
|
|
|
.pad = static_cast<std::size_t>(params.Get("pad", 0)),
|
|
|
|
};
|
|
|
|
|
|
|
|
input_engine->PreSetController(identifier);
|
|
|
|
return std::make_unique<InputFromCamera>(identifier, input_engine.get());
|
|
|
|
}
|
|
|
|
|
2022-09-24 20:28:27 -05:00
|
|
|
std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateNfcDevice(
|
|
|
|
const Common::ParamPackage& params) {
|
|
|
|
const PadIdentifier identifier = {
|
|
|
|
.guid = Common::UUID{params.Get("guid", "")},
|
|
|
|
.port = static_cast<std::size_t>(params.Get("port", 0)),
|
|
|
|
.pad = static_cast<std::size_t>(params.Get("pad", 0)),
|
|
|
|
};
|
|
|
|
|
|
|
|
input_engine->PreSetController(identifier);
|
|
|
|
return std::make_unique<InputFromNfc>(identifier, input_engine.get());
|
|
|
|
}
|
|
|
|
|
2021-09-20 16:41:15 -05:00
|
|
|
InputFactory::InputFactory(std::shared_ptr<InputEngine> input_engine_)
|
|
|
|
: input_engine(std::move(input_engine_)) {}
|
|
|
|
|
2021-10-30 22:23:10 -05:00
|
|
|
std::unique_ptr<Common::Input::InputDevice> InputFactory::Create(
|
|
|
|
const Common::ParamPackage& params) {
|
2021-10-24 23:23:54 -05:00
|
|
|
if (params.Has("battery")) {
|
|
|
|
return CreateBatteryDevice(params);
|
|
|
|
}
|
2022-06-18 23:32:07 -05:00
|
|
|
if (params.Has("camera")) {
|
|
|
|
return CreateCameraDevice(params);
|
|
|
|
}
|
2022-09-24 20:28:27 -05:00
|
|
|
if (params.Has("nfc")) {
|
|
|
|
return CreateNfcDevice(params);
|
|
|
|
}
|
2021-09-20 16:41:15 -05:00
|
|
|
if (params.Has("button") && params.Has("axis")) {
|
|
|
|
return CreateTriggerDevice(params);
|
|
|
|
}
|
|
|
|
if (params.Has("button") && params.Has("axis_x") && params.Has("axis_y")) {
|
|
|
|
return CreateTouchDevice(params);
|
|
|
|
}
|
|
|
|
if (params.Has("button") || params.Has("code")) {
|
|
|
|
return CreateButtonDevice(params);
|
|
|
|
}
|
|
|
|
if (params.Has("hat")) {
|
|
|
|
return CreateHatButtonDevice(params);
|
|
|
|
}
|
|
|
|
if (params.Has("axis_x") && params.Has("axis_y") && params.Has("axis_z")) {
|
|
|
|
return CreateMotionDevice(params);
|
|
|
|
}
|
|
|
|
if (params.Has("motion")) {
|
|
|
|
return CreateMotionDevice(params);
|
|
|
|
}
|
|
|
|
if (params.Has("axis_x") && params.Has("axis_y")) {
|
|
|
|
return CreateStickDevice(params);
|
|
|
|
}
|
|
|
|
if (params.Has("axis")) {
|
|
|
|
return CreateAnalogDevice(params);
|
|
|
|
}
|
|
|
|
LOG_ERROR(Input, "Invalid parameters given");
|
|
|
|
return std::make_unique<DummyInput>();
|
|
|
|
}
|
|
|
|
|
2021-10-11 00:43:11 -05:00
|
|
|
OutputFactory::OutputFactory(std::shared_ptr<InputEngine> input_engine_)
|
|
|
|
: input_engine(std::move(input_engine_)) {}
|
|
|
|
|
2021-10-30 22:23:10 -05:00
|
|
|
std::unique_ptr<Common::Input::OutputDevice> OutputFactory::Create(
|
|
|
|
const Common::ParamPackage& params) {
|
2021-10-11 00:43:11 -05:00
|
|
|
const PadIdentifier identifier = {
|
|
|
|
.guid = Common::UUID{params.Get("guid", "")},
|
|
|
|
.port = static_cast<std::size_t>(params.Get("port", 0)),
|
|
|
|
.pad = static_cast<std::size_t>(params.Get("pad", 0)),
|
|
|
|
};
|
|
|
|
|
|
|
|
input_engine->PreSetController(identifier);
|
|
|
|
return std::make_unique<OutputFromIdentifier>(identifier, input_engine.get());
|
|
|
|
}
|
|
|
|
|
2021-09-20 16:41:15 -05:00
|
|
|
} // namespace InputCommon
|