[HID] Added option to turn off vibration

This commit is contained in:
Gliniak
2021-05-24 15:09:40 +02:00
parent 7977d7ab98
commit 613f5ebe02
4 changed files with 46 additions and 2 deletions

View File

@@ -16,6 +16,8 @@
namespace xe {
namespace hid {
DEFINE_bool(vibration, true, "Toggle controller vibration.", "HID");
InputSystem::InputSystem(xe::ui::Window* window) : window_(window) {}
InputSystem::~InputSystem() = default;
@@ -62,10 +64,10 @@ X_RESULT InputSystem::GetState(uint32_t user_index, X_INPUT_STATE* out_state) {
X_RESULT InputSystem::SetState(uint32_t user_index,
X_INPUT_VIBRATION* vibration) {
SCOPE_profile_cpu_f("hid");
X_INPUT_VIBRATION modified_vibration = ModifyVibrationLevel(vibration);
bool any_connected = false;
for (auto& driver : drivers_) {
X_RESULT result = driver->SetState(user_index, vibration);
X_RESULT result = driver->SetState(user_index, &modified_vibration);
if (result != X_ERROR_DEVICE_NOT_CONNECTED) {
any_connected = true;
}
@@ -93,5 +95,28 @@ X_RESULT InputSystem::GetKeystroke(uint32_t user_index, uint32_t flags,
return any_connected ? X_ERROR_EMPTY : X_ERROR_DEVICE_NOT_CONNECTED;
}
void InputSystem::ToggleVibration() {
OVERRIDE_bool(vibration, !cvars::vibration);
// Send instant update to vibration state to prevent awaiting for next tick.
X_INPUT_VIBRATION vibration = X_INPUT_VIBRATION();
for (uint8_t user_index = 0; user_index < 4; user_index++) {
SetState(user_index, &vibration);
}
}
X_INPUT_VIBRATION InputSystem::ModifyVibrationLevel(
X_INPUT_VIBRATION* vibration) {
X_INPUT_VIBRATION modified_vibration = *vibration;
if (cvars::vibration) {
return modified_vibration;
}
// TODO(Gliniak): Use modifier instead of boolean value.
modified_vibration.left_motor_speed = 0;
modified_vibration.right_motor_speed = 0;
return modified_vibration;
}
} // namespace hid
} // namespace xe