xbmc
AddonButtonMap.h
1 /*
2  * Copyright (C) 2014-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "PeripheralAddon.h" // for FeatureMap
12 #include "input/joysticks/DriverPrimitive.h"
14 #include "input/joysticks/interfaces/IButtonMap.h"
15 #include "peripherals/PeripheralTypes.h"
16 #include "threads/CriticalSection.h"
17 
18 namespace PERIPHERALS
19 {
20 class CPeripheral;
21 
23 {
24 public:
26  const std::weak_ptr<CPeripheralAddon>& addon,
27  const std::string& strControllerId);
28 
29  ~CAddonButtonMap(void) override;
30 
31  // Implementation of IButtonMap
32  std::string ControllerID(void) const override { return m_strControllerId; }
33 
34  std::string Location(void) const override;
35 
36  bool Load(void) override;
37 
38  void Reset(void) override;
39 
40  bool IsEmpty(void) const override;
41 
42  bool GetFeature(const KODI::JOYSTICK::CDriverPrimitive& primitive,
43  KODI::JOYSTICK::FeatureName& feature) override;
44 
46 
47  bool GetScalar(const KODI::JOYSTICK::FeatureName& feature,
48  KODI::JOYSTICK::CDriverPrimitive& primitive) override;
49 
50  void AddScalar(const KODI::JOYSTICK::FeatureName& feature,
51  const KODI::JOYSTICK::CDriverPrimitive& primitive) override;
52 
53  bool GetAnalogStick(const KODI::JOYSTICK::FeatureName& feature,
54  KODI::JOYSTICK::ANALOG_STICK_DIRECTION direction,
55  KODI::JOYSTICK::CDriverPrimitive& primitive) override;
56 
57  void AddAnalogStick(const KODI::JOYSTICK::FeatureName& feature,
58  KODI::JOYSTICK::ANALOG_STICK_DIRECTION direction,
59  const KODI::JOYSTICK::CDriverPrimitive& primitive) override;
60 
62  KODI::JOYSTICK::RELATIVE_POINTER_DIRECTION direction,
63  KODI::JOYSTICK::CDriverPrimitive& primitive) override;
64 
66  KODI::JOYSTICK::RELATIVE_POINTER_DIRECTION direction,
67  const KODI::JOYSTICK::CDriverPrimitive& primitive) override;
68 
72  KODI::JOYSTICK::CDriverPrimitive& positiveZ) override;
73 
75  const KODI::JOYSTICK::CDriverPrimitive& positiveX,
76  const KODI::JOYSTICK::CDriverPrimitive& positiveY,
77  const KODI::JOYSTICK::CDriverPrimitive& positiveZ) override;
78 
79  bool GetWheel(const KODI::JOYSTICK::FeatureName& feature,
81  KODI::JOYSTICK::CDriverPrimitive& primitive) override;
82 
83  void AddWheel(const KODI::JOYSTICK::FeatureName& feature,
85  const KODI::JOYSTICK::CDriverPrimitive& primitive) override;
86 
87  bool GetThrottle(const KODI::JOYSTICK::FeatureName& feature,
89  KODI::JOYSTICK::CDriverPrimitive& primitive) override;
90 
91  void AddThrottle(const KODI::JOYSTICK::FeatureName& feature,
93  const KODI::JOYSTICK::CDriverPrimitive& primitive) override;
94 
95  bool GetKey(const KODI::JOYSTICK::FeatureName& feature,
96  KODI::JOYSTICK::CDriverPrimitive& primitive) override;
97 
98  void AddKey(const KODI::JOYSTICK::FeatureName& feature,
99  const KODI::JOYSTICK::CDriverPrimitive& primitive) override;
100 
102  const std::vector<KODI::JOYSTICK::CDriverPrimitive>& primitives) override;
103 
104  bool IsIgnored(const KODI::JOYSTICK::CDriverPrimitive& primitive) override;
105 
106  bool GetAxisProperties(unsigned int axisIndex, int& center, unsigned int& range) override;
107 
108  void SaveButtonMap() override;
109 
110  void RevertButtonMap() override;
111 
112 private:
113  typedef std::map<KODI::JOYSTICK::CDriverPrimitive, KODI::JOYSTICK::FeatureName> DriverMap;
114  typedef std::vector<KODI::JOYSTICK::CDriverPrimitive> JoystickPrimitiveVector;
115 
116  // Utility functions
117  static DriverMap CreateLookupTable(const FeatureMap& features);
118 
119  static JOYSTICK_FEATURE_PRIMITIVE GetAnalogStickIndex(KODI::JOYSTICK::ANALOG_STICK_DIRECTION dir);
120  static JOYSTICK_FEATURE_PRIMITIVE GetRelativePointerIndex(
121  KODI::JOYSTICK::RELATIVE_POINTER_DIRECTION dir);
122  static JOYSTICK_FEATURE_PRIMITIVE GetPrimitiveIndex(KODI::JOYSTICK::WHEEL_DIRECTION dir);
124 
125  CPeripheral* const m_device;
126  std::weak_ptr<CPeripheralAddon> m_addon;
127  const std::string m_strControllerId;
128  FeatureMap m_features;
129  DriverMap m_driverMap;
130  JoystickPrimitiveVector m_ignoredPrimitives;
131  mutable CCriticalSection m_mutex;
132 };
133 } // namespace PERIPHERALS
THROTTLE_DIRECTION
Directions on a throttle.
Definition: JoystickTypes.h:130
bool GetFeature(const KODI::JOYSTICK::CDriverPrimitive &primitive, KODI::JOYSTICK::FeatureName &feature) override
Get the feature associated with a driver primitive.
Definition: AddonButtonMap.cpp:94
bool GetWheel(const KODI::JOYSTICK::FeatureName &feature, KODI::JOYSTICK::WHEEL_DIRECTION direction, KODI::JOYSTICK::CDriverPrimitive &primitive) override
Get a wheel direction from the button map.
Definition: AddonButtonMap.cpp:320
std::string Location(void) const override
The Location of the peripheral associated with this button map.
Definition: AddonButtonMap.cpp:42
JOYSTICK_FEATURE_PRIMITIVE
Definition: peripheral.h:535
void Reset(void) override
Reset the button map to its defaults, or clear button map if no defaults.
Definition: AddonButtonMap.cpp:81
bool IsEmpty(void) const override
Check if the button map is empty.
Definition: AddonButtonMap.cpp:87
void AddWheel(const KODI::JOYSTICK::FeatureName &feature, KODI::JOYSTICK::WHEEL_DIRECTION direction, const KODI::JOYSTICK::CDriverPrimitive &primitive) override
Add or update a wheel direction.
Definition: AddonButtonMap.cpp:344
Definition: RetroPlayerInput.h:15
void AddKey(const KODI::JOYSTICK::FeatureName &feature, const KODI::JOYSTICK::CDriverPrimitive &primitive) override
Add or update a key.
Definition: AddonButtonMap.cpp:456
void SaveButtonMap() override
Save the button map.
Definition: AddonButtonMap.cpp:502
void AddAnalogStick(const KODI::JOYSTICK::FeatureName &feature, KODI::JOYSTICK::ANALOG_STICK_DIRECTION direction, const KODI::JOYSTICK::CDriverPrimitive &primitive) override
Add or update an analog stick direction.
Definition: AddonButtonMap.cpp:181
FEATURE_TYPE
Types of features used in the joystick library.
Definition: JoystickTypes.h:49
Button map interface to translate between the driver&#39;s raw button/hat/axis elements and physical joys...
Definition: IButtonMap.h:28
std::string ControllerID(void) const override
The add-on ID of the game controller associated with this button map.
Definition: AddonButtonMap.h:32
void RevertButtonMap() override
Revert changes to the button map since the last time it was loaded or committed to disk...
Definition: AddonButtonMap.cpp:508
void AddAccelerometer(const KODI::JOYSTICK::FeatureName &feature, const KODI::JOYSTICK::CDriverPrimitive &positiveX, const KODI::JOYSTICK::CDriverPrimitive &positiveY, const KODI::JOYSTICK::CDriverPrimitive &positiveZ) override
Get or update an accelerometer.
Definition: AddonButtonMap.cpp:300
void AddRelativePointer(const KODI::JOYSTICK::FeatureName &feature, KODI::JOYSTICK::RELATIVE_POINTER_DIRECTION direction, const KODI::JOYSTICK::CDriverPrimitive &primitive) override
Add or update a relative pointer direction.
Definition: AddonButtonMap.cpp:238
void AddThrottle(const KODI::JOYSTICK::FeatureName &feature, KODI::JOYSTICK::THROTTLE_DIRECTION direction, const KODI::JOYSTICK::CDriverPrimitive &primitive) override
Add or update a throttle direction.
Definition: AddonButtonMap.cpp:401
KODI::JOYSTICK::FEATURE_TYPE GetFeatureType(const KODI::JOYSTICK::FeatureName &feature) override
Get the type of the feature for the given name.
Definition: AddonButtonMap.cpp:108
void AddScalar(const KODI::JOYSTICK::FeatureName &feature, const KODI::JOYSTICK::CDriverPrimitive &primitive) override
Add or update a scalar feature.
Definition: AddonButtonMap.cpp:144
bool GetKey(const KODI::JOYSTICK::FeatureName &feature, KODI::JOYSTICK::CDriverPrimitive &primitive) override
Get the driver primitive for a keyboard key.
Definition: AddonButtonMap.cpp:434
bool GetAnalogStick(const KODI::JOYSTICK::FeatureName &feature, KODI::JOYSTICK::ANALOG_STICK_DIRECTION direction, KODI::JOYSTICK::CDriverPrimitive &primitive) override
Get an analog stick direction from the button map.
Definition: AddonButtonMap.cpp:157
bool GetAxisProperties(unsigned int axisIndex, int &center, unsigned int &range) override
Get the properties of an axis.
Definition: AddonButtonMap.cpp:480
WHEEL_DIRECTION
Directions on a wheel.
Definition: JoystickTypes.h:120
bool Load(void) override
Load the button map into memory.
Definition: AddonButtonMap.cpp:47
bool GetScalar(const KODI::JOYSTICK::FeatureName &feature, KODI::JOYSTICK::CDriverPrimitive &primitive) override
Get the driver primitive for a scalar feature.
Definition: AddonButtonMap.cpp:121
bool GetRelativePointer(const KODI::JOYSTICK::FeatureName &feature, KODI::JOYSTICK::RELATIVE_POINTER_DIRECTION direction, KODI::JOYSTICK::CDriverPrimitive &primitive) override
Get a relative pointer direction from the button map.
Definition: AddonButtonMap.cpp:214
bool IsIgnored(const KODI::JOYSTICK::CDriverPrimitive &primitive) override
Check if a primitive is in the list of primitives to be ignored.
Definition: AddonButtonMap.cpp:474
Basic driver element associated with input events.
Definition: DriverPrimitive.h:69
std::string FeatureName
Name of a physical feature belonging to the joystick.
Definition: JoystickTypes.h:28
bool GetThrottle(const KODI::JOYSTICK::FeatureName &feature, KODI::JOYSTICK::THROTTLE_DIRECTION direction, KODI::JOYSTICK::CDriverPrimitive &primitive) override
Get a throttle direction from the button map.
Definition: AddonButtonMap.cpp:377
Definition: Peripheral.h:62
Definition: AddonButtonMap.h:22
void SetIgnoredPrimitives(const std::vector< KODI::JOYSTICK::CDriverPrimitive > &primitives) override
Set a list of driver primitives to be ignored.
Definition: AddonButtonMap.cpp:466
bool GetAccelerometer(const KODI::JOYSTICK::FeatureName &feature, KODI::JOYSTICK::CDriverPrimitive &positiveX, KODI::JOYSTICK::CDriverPrimitive &positiveY, KODI::JOYSTICK::CDriverPrimitive &positiveZ) override
Get an accelerometer from the button map.
Definition: AddonButtonMap.cpp:271