summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerEmu/ControlGroup/IMUGyroscope.h
blob: 459f8858825eda90cfe422f7d37266f22f3f2289 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright 2019 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.

#pragma once

#include <chrono>
#include <optional>
#include <string>

#include "Common/MathUtil.h"
#include "Common/Matrix.h"
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
#include "InputCommon/ControllerEmu/Setting/NumericSetting.h"

namespace ControllerEmu
{
class IMUGyroscope : public ControlGroup
{
public:
  using StateData = Common::Vec3;

  IMUGyroscope(std::string name, std::string ui_name);

  StateData GetRawState() const;
  std::optional<StateData> GetState() const;

  // Value is in rad/s.
  ControlState GetDeadzone() const;

  bool IsCalibrating() const;

private:
  using Clock = std::chrono::steady_clock;

  void RestartCalibration() const;
  void UpdateCalibration(const StateData&) const;

  SettingValue<double> m_deadzone_setting;
  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();
};
}  // namespace ControllerEmu