summaryrefslogtreecommitdiffstats
path: root/xbmc/peripherals/addons/AddonButtonMap.h
blob: cade54bb14e31ba44abba690c1145a80fdcc9f5b (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
 *  Copyright (C) 2014-2018 Team Kodi
 *  This file is part of Kodi - https://kodi.tv
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 *  See LICENSES/README.md for more information.
 */

#pragma once

#include "PeripheralAddon.h" // for FeatureMap
#include "input/joysticks/DriverPrimitive.h"
#include "input/joysticks/JoystickTypes.h"
#include "input/joysticks/interfaces/IButtonMap.h"
#include "peripherals/PeripheralTypes.h"
#include "threads/CriticalSection.h"

namespace PERIPHERALS
{
class CPeripheral;
class CPeripherals;

class CAddonButtonMap : public KODI::JOYSTICK::IButtonMap
{
public:
  CAddonButtonMap(CPeripheral* device,
                  const std::weak_ptr<CPeripheralAddon>& addon,
                  const std::string& strControllerId,
                  CPeripherals& manager);

  ~CAddonButtonMap(void) override;

  // Implementation of IButtonMap
  std::string ControllerID(void) const override { return m_strControllerId; }

  std::string Location(void) const override;

  bool Load(void) override;

  void Reset(void) override;

  bool IsEmpty(void) const override;

  std::string GetAppearance() const override;

  bool SetAppearance(const std::string& controllerId) const override;

  bool GetFeature(const KODI::JOYSTICK::CDriverPrimitive& primitive,
                  KODI::JOYSTICK::FeatureName& feature) override;

  KODI::JOYSTICK::FEATURE_TYPE GetFeatureType(const KODI::JOYSTICK::FeatureName& feature) override;

  bool GetScalar(const KODI::JOYSTICK::FeatureName& feature,
                 KODI::JOYSTICK::CDriverPrimitive& primitive) override;

  void AddScalar(const KODI::JOYSTICK::FeatureName& feature,
                 const KODI::JOYSTICK::CDriverPrimitive& primitive) override;

  bool GetAnalogStick(const KODI::JOYSTICK::FeatureName& feature,
                      KODI::JOYSTICK::ANALOG_STICK_DIRECTION direction,
                      KODI::JOYSTICK::CDriverPrimitive& primitive) override;

  void AddAnalogStick(const KODI::JOYSTICK::FeatureName& feature,
                      KODI::JOYSTICK::ANALOG_STICK_DIRECTION direction,
                      const KODI::JOYSTICK::CDriverPrimitive& primitive) override;

  bool GetRelativePointer(const KODI::JOYSTICK::FeatureName& feature,
                          KODI::JOYSTICK::RELATIVE_POINTER_DIRECTION direction,
                          KODI::JOYSTICK::CDriverPrimitive& primitive) override;

  void AddRelativePointer(const KODI::JOYSTICK::FeatureName& feature,
                          KODI::JOYSTICK::RELATIVE_POINTER_DIRECTION direction,
                          const KODI::JOYSTICK::CDriverPrimitive& primitive) override;

  bool GetAccelerometer(const KODI::JOYSTICK::FeatureName& feature,
                        KODI::JOYSTICK::CDriverPrimitive& positiveX,
                        KODI::JOYSTICK::CDriverPrimitive& positiveY,
                        KODI::JOYSTICK::CDriverPrimitive& positiveZ) override;

  void AddAccelerometer(const KODI::JOYSTICK::FeatureName& feature,
                        const KODI::JOYSTICK::CDriverPrimitive& positiveX,
                        const KODI::JOYSTICK::CDriverPrimitive& positiveY,
                        const KODI::JOYSTICK::CDriverPrimitive& positiveZ) override;

  bool GetWheel(const KODI::JOYSTICK::FeatureName& feature,
                KODI::JOYSTICK::WHEEL_DIRECTION direction,
                KODI::JOYSTICK::CDriverPrimitive& primitive) override;

  void AddWheel(const KODI::JOYSTICK::FeatureName& feature,
                KODI::JOYSTICK::WHEEL_DIRECTION direction,
                const KODI::JOYSTICK::CDriverPrimitive& primitive) override;

  bool GetThrottle(const KODI::JOYSTICK::FeatureName& feature,
                   KODI::JOYSTICK::THROTTLE_DIRECTION direction,
                   KODI::JOYSTICK::CDriverPrimitive& primitive) override;

  void AddThrottle(const KODI::JOYSTICK::FeatureName& feature,
                   KODI::JOYSTICK::THROTTLE_DIRECTION direction,
                   const KODI::JOYSTICK::CDriverPrimitive& primitive) override;

  bool GetKey(const KODI::JOYSTICK::FeatureName& feature,
              KODI::JOYSTICK::CDriverPrimitive& primitive) override;

  void AddKey(const KODI::JOYSTICK::FeatureName& feature,
              const KODI::JOYSTICK::CDriverPrimitive& primitive) override;

  void SetIgnoredPrimitives(
      const std::vector<KODI::JOYSTICK::CDriverPrimitive>& primitives) override;

  bool IsIgnored(const KODI::JOYSTICK::CDriverPrimitive& primitive) override;

  bool GetAxisProperties(unsigned int axisIndex, int& center, unsigned int& range) override;

  void SaveButtonMap() override;

  void RevertButtonMap() override;

private:
  typedef std::map<KODI::JOYSTICK::CDriverPrimitive, KODI::JOYSTICK::FeatureName> DriverMap;
  typedef std::vector<KODI::JOYSTICK::CDriverPrimitive> JoystickPrimitiveVector;

  // Utility functions
  static DriverMap CreateLookupTable(const FeatureMap& features);

  static JOYSTICK_FEATURE_PRIMITIVE GetAnalogStickIndex(KODI::JOYSTICK::ANALOG_STICK_DIRECTION dir);
  static JOYSTICK_FEATURE_PRIMITIVE GetRelativePointerIndex(
      KODI::JOYSTICK::RELATIVE_POINTER_DIRECTION dir);
  static JOYSTICK_FEATURE_PRIMITIVE GetPrimitiveIndex(KODI::JOYSTICK::WHEEL_DIRECTION dir);
  static JOYSTICK_FEATURE_PRIMITIVE GetPrimitiveIndex(KODI::JOYSTICK::THROTTLE_DIRECTION dir);

  // Construction parameters
  CPeripheral* const m_device;
  const std::weak_ptr<CPeripheralAddon> m_addon;
  const std::string m_strControllerId;
  CPeripherals& m_manager;

  // Button map state
  std::string m_controllerAppearance;
  FeatureMap m_features;
  DriverMap m_driverMap;
  JoystickPrimitiveVector m_ignoredPrimitives;

  // Synchronization parameters
  mutable CCriticalSection m_mutex;
};
} // namespace PERIPHERALS