[Windows] Remove redundant DirectSound error codes
[xbmc.git] / xbmc / platform / android / peripherals / AndroidJoystickState.h
blob550222d6f76a9ce639c633f9d740636f1b44f6a3
1 /*
2 * Copyright (C) 2016-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #pragma once
11 #include "addons/kodi-dev-kit/include/kodi/addon-instance/peripheral/PeripheralUtils.h"
12 #include "threads/CriticalSection.h"
14 #include <string>
15 #include <utility>
16 #include <vector>
18 struct AInputEvent;
19 class CJNIViewInputDevice;
21 namespace KODI
23 namespace JOYSTICK
25 class IButtonMap;
26 } // namespace JOYSTICK
27 } // namespace KODI
29 namespace PERIPHERALS
31 class CAndroidJoystickState
33 public:
34 CAndroidJoystickState() = default;
35 CAndroidJoystickState(CAndroidJoystickState&& other) noexcept;
36 virtual ~CAndroidJoystickState();
38 int GetDeviceId() const { return m_deviceId; }
40 unsigned int GetButtonCount() const { return static_cast<unsigned int>(m_buttons.size()); }
41 unsigned int GetAxisCount() const { return static_cast<unsigned int>(m_axes.size()); }
43 /*!
44 * \brief Initialize the joystick object
46 * Joystick will be initialized before the first call to GetEvents().
48 bool Initialize(const CJNIViewInputDevice& inputDevice);
50 /*!
51 * \brief Initialize a joystick buttonmap, if possible
53 * Android has a large database of buttonmaps, which it uses to provide
54 * mapped button keycodes such as AKEYCODE_BUTTON_A. We can take advantage of
55 * this to initialize a default buttonmap based on these mappings.
57 * If Android can't map the buttons, it will use generic button keycodes such
58 * as AKEYCODE_BUTTON_1, in which case we can't initialize the buttonmap.
60 bool InitializeButtonMap(KODI::JOYSTICK::IButtonMap& buttonMap) const;
62 /*!
63 * \brief Deinitialize the joystick object
65 * GetEvents() will not be called after deinitialization.
67 void Deinitialize();
69 /*!
70 * \brief Processes the given input event.
72 bool ProcessEvent(const AInputEvent* event);
74 /*!
75 * \brief Get events that have occurred since the last call to GetEvents()
77 void GetEvents(std::vector<kodi::addon::PeripheralEvent>& events);
79 private:
80 bool SetButtonValue(int axisId, JOYSTICK_STATE_BUTTON buttonValue);
81 bool SetAxisValue(const std::vector<int>& axisIds, JOYSTICK_STATE_AXIS axisValue);
83 void GetButtonEvents(std::vector<kodi::addon::PeripheralEvent>& events);
84 void GetAxisEvents(std::vector<kodi::addon::PeripheralEvent>& events) const;
86 bool MapButton(KODI::JOYSTICK::IButtonMap& buttonMap, int buttonKeycode) const;
87 bool MapTrigger(KODI::JOYSTICK::IButtonMap& buttonMap,
88 int axisId,
89 const std::string& triggerName) const;
90 bool MapDpad(KODI::JOYSTICK::IButtonMap& buttonMap, int horizAxisId, int vertAxisId) const;
91 bool MapAnalogStick(KODI::JOYSTICK::IButtonMap& buttonMap,
92 int horizAxisId,
93 int vertAxisId,
94 const std::string& analogStickName) const;
96 static float Contain(float value, float min, float max);
97 static float Scale(float value, float max, float scaledMax);
98 static float Deadzone(float value, float deadzone);
100 struct JoystickAxis
102 std::vector<int> ids;
103 float flat = 0.0f;
104 float fuzz = 0.0f;
105 float min = 0.0f;
106 float max = 0.0f;
107 float range = 0.0f;
108 float resolution = 0.0f;
111 using JoystickAxes = std::vector<JoystickAxis>;
113 static JoystickAxes::const_iterator GetAxis(const std::vector<int>& axisIds,
114 const JoystickAxes& axes);
115 static bool ContainsAxis(int axisId, const JoystickAxes& axes);
116 static bool GetAxesIndex(const std::vector<int>& axisIds,
117 const JoystickAxes& axes,
118 size_t& axesIndex);
120 int m_deviceId = -1;
122 JoystickAxes m_buttons;
123 JoystickAxes m_axes;
125 std::vector<JOYSTICK_STATE_AXIS> m_analogState;
127 CCriticalSection m_eventMutex;
128 std::vector<kodi::addon::PeripheralEvent> m_digitalEvents;
130 } // namespace PERIPHERALS