2019-09-06 15:09:30 +00:00
|
|
|
// Copyright 2019 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2019-09-06 15:09:30 +00:00
|
|
|
|
|
|
|
#include "InputCommon/ControllerEmu/ControlGroup/IMUAccelerometer.h"
|
|
|
|
|
2021-05-04 20:58:08 +00:00
|
|
|
#include <algorithm>
|
2019-11-22 20:19:45 +00:00
|
|
|
#include <memory>
|
2019-09-06 15:09:30 +00:00
|
|
|
|
2019-11-22 20:19:45 +00:00
|
|
|
#include "Common/Common.h"
|
2019-09-06 15:09:30 +00:00
|
|
|
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
|
|
|
|
#include "InputCommon/ControllerEmu/Control/Control.h"
|
|
|
|
|
|
|
|
namespace ControllerEmu
|
|
|
|
{
|
2020-07-31 23:17:23 +00:00
|
|
|
IMUAccelerometer::IMUAccelerometer(std::string name_, std::string ui_name_)
|
|
|
|
: ControlGroup(std::move(name_), std::move(ui_name_), GroupType::IMUAccelerometer)
|
2019-09-06 15:09:30 +00:00
|
|
|
{
|
2019-10-27 16:04:08 +00:00
|
|
|
AddInput(Translate, _trans("Up"));
|
|
|
|
AddInput(Translate, _trans("Down"));
|
|
|
|
AddInput(Translate, _trans("Left"));
|
|
|
|
AddInput(Translate, _trans("Right"));
|
|
|
|
AddInput(Translate, _trans("Forward"));
|
|
|
|
AddInput(Translate, _trans("Backward"));
|
2019-09-06 15:09:30 +00:00
|
|
|
}
|
|
|
|
|
2021-05-04 20:58:08 +00:00
|
|
|
bool IMUAccelerometer::AreInputsBound() const
|
|
|
|
{
|
|
|
|
return std::all_of(controls.begin(), controls.end(),
|
|
|
|
[](const auto& control) { return control->control_ref->BoundCount() > 0; });
|
|
|
|
}
|
|
|
|
|
2019-09-06 15:09:30 +00:00
|
|
|
std::optional<IMUAccelerometer::StateData> IMUAccelerometer::GetState() const
|
|
|
|
{
|
2021-05-04 20:58:08 +00:00
|
|
|
if (!AreInputsBound())
|
2019-09-06 15:09:30 +00:00
|
|
|
return std::nullopt;
|
2020-01-18 19:56:11 +00:00
|
|
|
|
|
|
|
StateData state;
|
2020-02-09 02:36:26 +00:00
|
|
|
state.x = (controls[2]->GetState() - controls[3]->GetState());
|
|
|
|
state.y = (controls[5]->GetState() - controls[4]->GetState());
|
|
|
|
state.z = (controls[0]->GetState() - controls[1]->GetState());
|
2020-01-18 19:56:11 +00:00
|
|
|
return state;
|
2019-09-06 15:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace ControllerEmu
|