2019-09-06 15:09:30 +00:00
|
|
|
// Copyright 2019 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#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;
|
2019-09-06 15:09:30 +00:00
|
|
|
std::optional<StateData> GetState() const;
|
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;
|
|
|
|
|
|
|
|
void RestartCalibration() const;
|
|
|
|
void UpdateCalibration(const StateData&) const;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
mutable StateData m_calibration = {};
|
|
|
|
mutable MathUtil::RunningMean<StateData> m_running_calibration;
|
|
|
|
mutable Clock::time_point m_calibration_period_start = Clock::now();
|
2019-09-06 15:09:30 +00:00
|
|
|
};
|
|
|
|
} // namespace ControllerEmu
|