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
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2020-02-11 23:30:16 +00:00
|
|
|
#include <chrono>
|
2019-11-22 20:19:45 +00:00
|
|
|
#include <optional>
|
2019-09-06 15:09:30 +00:00
|
|
|
#include <string>
|
|
|
|
|
2020-02-11 23:30:16 +00:00
|
|
|
#include "Common/MathUtil.h"
|
2019-09-06 15:09:30 +00:00
|
|
|
#include "Common/Matrix.h"
|
|
|
|
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
|
2020-02-04 01:45:36 +00:00
|
|
|
#include "InputCommon/ControllerEmu/Setting/NumericSetting.h"
|
2019-09-06 15:09:30 +00:00
|
|
|
|
|
|
|
namespace ControllerEmu
|
|
|
|
{
|
|
|
|
class IMUGyroscope : public ControlGroup
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
using StateData = Common::Vec3;
|
|
|
|
|
|
|
|
IMUGyroscope(std::string name, std::string ui_name);
|
|
|
|
|
2020-02-04 01:45:36 +00:00
|
|
|
StateData GetRawState() const;
|
2021-05-04 21:04:47 +00:00
|
|
|
// Also updates the state by default
|
|
|
|
std::optional<StateData> GetState(bool update = true);
|
2020-02-04 01:45:36 +00:00
|
|
|
|
|
|
|
// Value is in rad/s.
|
|
|
|
ControlState GetDeadzone() const;
|
|
|
|
|
2020-02-11 23:30:16 +00:00
|
|
|
bool IsCalibrating() const;
|
|
|
|
|
2020-02-04 01:45:36 +00:00
|
|
|
private:
|
2020-02-11 23:30:16 +00:00
|
|
|
using Clock = std::chrono::steady_clock;
|
|
|
|
|
2021-05-04 21:04:47 +00:00
|
|
|
bool AreInputsBound() const;
|
|
|
|
bool CanCalibrate() const;
|
|
|
|
void RestartCalibration();
|
|
|
|
void UpdateCalibration(const StateData&);
|
2020-02-11 23:30:16 +00:00
|
|
|
|
2020-02-04 01:45:36 +00:00
|
|
|
SettingValue<double> m_deadzone_setting;
|
2020-02-11 23:30:16 +00:00
|
|
|
SettingValue<double> m_calibration_period_setting;
|
|
|
|
|
2021-05-04 21:04:47 +00:00
|
|
|
StateData m_calibration = {};
|
|
|
|
MathUtil::RunningMean<StateData> m_running_calibration;
|
|
|
|
Clock::time_point m_calibration_period_start = Clock::now();
|
2019-09-06 15:09:30 +00:00
|
|
|
};
|
|
|
|
} // namespace ControllerEmu
|