input_common: Add manual update options to input devices
This commit is contained in:
parent
f01dac3bf9
commit
c6c32daf40
|
@ -164,6 +164,16 @@ class InputDevice {
|
||||||
public:
|
public:
|
||||||
virtual ~InputDevice() = default;
|
virtual ~InputDevice() = default;
|
||||||
|
|
||||||
|
// Request input device to update if necessary
|
||||||
|
virtual void SoftUpdate() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Force input device to update data regarless of the current state
|
||||||
|
virtual void ForceUpdate() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
void SetCallback(InputCallback callback_) {
|
void SetCallback(InputCallback callback_) {
|
||||||
callback = std::move(callback_);
|
callback = std::move(callback_);
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,6 +122,7 @@ void EmulatedController::ReloadInput() {
|
||||||
Input::InputCallback button_callback{
|
Input::InputCallback button_callback{
|
||||||
[this, index](Input::CallbackStatus callback) { SetButton(callback, index); }};
|
[this, index](Input::CallbackStatus callback) { SetButton(callback, index); }};
|
||||||
button_devices[index]->SetCallback(button_callback);
|
button_devices[index]->SetCallback(button_callback);
|
||||||
|
button_devices[index]->ForceUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::size_t index = 0; index < stick_devices.size(); ++index) {
|
for (std::size_t index = 0; index < stick_devices.size(); ++index) {
|
||||||
|
@ -131,6 +132,7 @@ void EmulatedController::ReloadInput() {
|
||||||
Input::InputCallback stick_callback{
|
Input::InputCallback stick_callback{
|
||||||
[this, index](Input::CallbackStatus callback) { SetStick(callback, index); }};
|
[this, index](Input::CallbackStatus callback) { SetStick(callback, index); }};
|
||||||
stick_devices[index]->SetCallback(stick_callback);
|
stick_devices[index]->SetCallback(stick_callback);
|
||||||
|
stick_devices[index]->ForceUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::size_t index = 0; index < trigger_devices.size(); ++index) {
|
for (std::size_t index = 0; index < trigger_devices.size(); ++index) {
|
||||||
|
@ -140,6 +142,7 @@ void EmulatedController::ReloadInput() {
|
||||||
Input::InputCallback trigger_callback{
|
Input::InputCallback trigger_callback{
|
||||||
[this, index](Input::CallbackStatus callback) { SetTrigger(callback, index); }};
|
[this, index](Input::CallbackStatus callback) { SetTrigger(callback, index); }};
|
||||||
trigger_devices[index]->SetCallback(trigger_callback);
|
trigger_devices[index]->SetCallback(trigger_callback);
|
||||||
|
trigger_devices[index]->ForceUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::size_t index = 0; index < battery_devices.size(); ++index) {
|
for (std::size_t index = 0; index < battery_devices.size(); ++index) {
|
||||||
|
@ -149,6 +152,7 @@ void EmulatedController::ReloadInput() {
|
||||||
Input::InputCallback battery_callback{
|
Input::InputCallback battery_callback{
|
||||||
[this, index](Input::CallbackStatus callback) { SetBattery(callback, index); }};
|
[this, index](Input::CallbackStatus callback) { SetBattery(callback, index); }};
|
||||||
battery_devices[index]->SetCallback(battery_callback);
|
battery_devices[index]->SetCallback(battery_callback);
|
||||||
|
battery_devices[index]->ForceUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::size_t index = 0; index < motion_devices.size(); ++index) {
|
for (std::size_t index = 0; index < motion_devices.size(); ++index) {
|
||||||
|
@ -158,6 +162,7 @@ void EmulatedController::ReloadInput() {
|
||||||
Input::InputCallback motion_callback{
|
Input::InputCallback motion_callback{
|
||||||
[this, index](Input::CallbackStatus callback) { SetMotion(callback, index); }};
|
[this, index](Input::CallbackStatus callback) { SetMotion(callback, index); }};
|
||||||
motion_devices[index]->SetCallback(motion_callback);
|
motion_devices[index]->SetCallback(motion_callback);
|
||||||
|
motion_devices[index]->ForceUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -843,6 +848,10 @@ AnalogSticks EmulatedController::GetSticks() const {
|
||||||
if (is_configuring) {
|
if (is_configuring) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
// Some drivers like stick from buttons need constant refreshing
|
||||||
|
for (auto& device : stick_devices) {
|
||||||
|
device->SoftUpdate();
|
||||||
|
}
|
||||||
return controller.analog_stick_state;
|
return controller.analog_stick_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -200,6 +200,22 @@ public:
|
||||||
TriggerOnChange(status);
|
TriggerOnChange(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ForceUpdate() override{
|
||||||
|
up->ForceUpdate();
|
||||||
|
down->ForceUpdate();
|
||||||
|
left->ForceUpdate();
|
||||||
|
right->ForceUpdate();
|
||||||
|
modifier->ForceUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SoftUpdate() override {
|
||||||
|
Input::CallbackStatus status{
|
||||||
|
.type = Input::InputType::Stick,
|
||||||
|
.stick_status = GetStatus(),
|
||||||
|
};
|
||||||
|
TriggerOnChange(status);
|
||||||
|
}
|
||||||
|
|
||||||
Input::StickStatus GetStatus() const {
|
Input::StickStatus GetStatus() const {
|
||||||
Input::StickStatus status{};
|
Input::StickStatus status{};
|
||||||
status.x.properties = properties;
|
status.x.properties = properties;
|
||||||
|
|
|
@ -17,6 +17,7 @@ public:
|
||||||
Input::InputCallback button_up_callback{
|
Input::InputCallback button_up_callback{
|
||||||
[this](Input::CallbackStatus callback_) { UpdateButtonStatus(callback_); }};
|
[this](Input::CallbackStatus callback_) { UpdateButtonStatus(callback_); }};
|
||||||
button->SetCallback(button_up_callback);
|
button->SetCallback(button_up_callback);
|
||||||
|
button->ForceUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
Input::TouchStatus GetStatus(bool pressed) const {
|
Input::TouchStatus GetStatus(bool pressed) const {
|
||||||
|
|
|
@ -45,6 +45,16 @@ public:
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ForceUpdate() {
|
||||||
|
const Input::CallbackStatus status{
|
||||||
|
.type = Input::InputType::Button,
|
||||||
|
.button_status = GetStatus(),
|
||||||
|
};
|
||||||
|
|
||||||
|
last_button_value = status.button_status.value;
|
||||||
|
TriggerOnChange(status);
|
||||||
|
}
|
||||||
|
|
||||||
void OnChange() {
|
void OnChange() {
|
||||||
const Input::CallbackStatus status{
|
const Input::CallbackStatus status{
|
||||||
.type = Input::InputType::Button,
|
.type = Input::InputType::Button,
|
||||||
|
@ -96,6 +106,16 @@ public:
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ForceUpdate() {
|
||||||
|
const Input::CallbackStatus status{
|
||||||
|
.type = Input::InputType::Button,
|
||||||
|
.button_status = GetStatus(),
|
||||||
|
};
|
||||||
|
|
||||||
|
last_button_value = status.button_status.value;
|
||||||
|
TriggerOnChange(status);
|
||||||
|
}
|
||||||
|
|
||||||
void OnChange() {
|
void OnChange() {
|
||||||
const Input::CallbackStatus status{
|
const Input::CallbackStatus status{
|
||||||
.type = Input::InputType::Button,
|
.type = Input::InputType::Button,
|
||||||
|
|
Reference in New Issue