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  std::string GetAppearance() const override;
43 
44  bool SetAppearance(const std::string& controllerId) const override;
45 
46  bool GetFeature(const KODI::JOYSTICK::CDriverPrimitive& primitive,
47  KODI::JOYSTICK::FeatureName& feature) override;
48 
50 
51  bool GetScalar(const KODI::JOYSTICK::FeatureName& feature,
52  KODI::JOYSTICK::CDriverPrimitive& primitive) override;
53 
54  void AddScalar(const KODI::JOYSTICK::FeatureName& feature,
55  const KODI::JOYSTICK::CDriverPrimitive& primitive) override;
56 
57  bool GetAnalogStick(const KODI::JOYSTICK::FeatureName& feature,
58  KODI::JOYSTICK::ANALOG_STICK_DIRECTION direction,
59  KODI::JOYSTICK::CDriverPrimitive& primitive) override;
60 
61  void AddAnalogStick(const KODI::JOYSTICK::FeatureName& feature,
62  KODI::JOYSTICK::ANALOG_STICK_DIRECTION direction,
63  const KODI::JOYSTICK::CDriverPrimitive& primitive) override;
64 
66  KODI::JOYSTICK::RELATIVE_POINTER_DIRECTION direction,
67  KODI::JOYSTICK::CDriverPrimitive& primitive) override;
68 
70  KODI::JOYSTICK::RELATIVE_POINTER_DIRECTION direction,
71  const KODI::JOYSTICK::CDriverPrimitive& primitive) override;
72 
76  KODI::JOYSTICK::CDriverPrimitive& positiveZ) override;
77 
79  const KODI::JOYSTICK::CDriverPrimitive& positiveX,
80  const KODI::JOYSTICK::CDriverPrimitive& positiveY,
81  const KODI::JOYSTICK::CDriverPrimitive& positiveZ) override;
82 
83  bool GetWheel(const KODI::JOYSTICK::FeatureName& feature,
85  KODI::JOYSTICK::CDriverPrimitive& primitive) override;
86 
87  void AddWheel(const KODI::JOYSTICK::FeatureName& feature,
89  const KODI::JOYSTICK::CDriverPrimitive& primitive) override;
90 
91  bool GetThrottle(const KODI::JOYSTICK::FeatureName& feature,
93  KODI::JOYSTICK::CDriverPrimitive& primitive) override;
94 
95  void AddThrottle(const KODI::JOYSTICK::FeatureName& feature,
97  const KODI::JOYSTICK::CDriverPrimitive& primitive) override;
98 
99  bool GetKey(const KODI::JOYSTICK::FeatureName& feature,
100  KODI::JOYSTICK::CDriverPrimitive& primitive) override;
101 
102  void AddKey(const KODI::JOYSTICK::FeatureName& feature,
103  const KODI::JOYSTICK::CDriverPrimitive& primitive) override;
104 
106  const std::vector<KODI::JOYSTICK::CDriverPrimitive>& primitives) override;
107 
108  bool IsIgnored(const KODI::JOYSTICK::CDriverPrimitive& primitive) override;
109 
110  bool GetAxisProperties(unsigned int axisIndex, int& center, unsigned int& range) override;
111 
112  void SaveButtonMap() override;
113 
114  void RevertButtonMap() override;
115 
116 private:
117  typedef std::map<KODI::JOYSTICK::CDriverPrimitive, KODI::JOYSTICK::FeatureName> DriverMap;
118  typedef std::vector<KODI::JOYSTICK::CDriverPrimitive> JoystickPrimitiveVector;
119 
120  // Utility functions
121  static DriverMap CreateLookupTable(const FeatureMap& features);
122 
123  static JOYSTICK_FEATURE_PRIMITIVE GetAnalogStickIndex(KODI::JOYSTICK::ANALOG_STICK_DIRECTION dir);
124  static JOYSTICK_FEATURE_PRIMITIVE GetRelativePointerIndex(
125  KODI::JOYSTICK::RELATIVE_POINTER_DIRECTION dir);
126  static JOYSTICK_FEATURE_PRIMITIVE GetPrimitiveIndex(KODI::JOYSTICK::WHEEL_DIRECTION dir);
128 
129  // Construction parameters
130  CPeripheral* const m_device;
131  const std::weak_ptr<CPeripheralAddon> m_addon;
132  const std::string m_strControllerId;
133 
134  // Button map state
135  std::string m_controllerAppearance;
136  FeatureMap m_features;
137  DriverMap m_driverMap;
138  JoystickPrimitiveVector m_ignoredPrimitives;
139 
140  // Synchronization parameters
141  mutable CCriticalSection m_mutex;
142 };
143 } // 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:112
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:338
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:538
void Reset(void) override
Reset the button map to its defaults, or clear button map if no defaults.
Definition: AddonButtonMap.cpp:84
std::string GetAppearance() const override
Get the ID of the controller profile that best represents the appearance of the peripheral.
Definition: AddonButtonMap.cpp:97
bool IsEmpty(void) const override
Check if the button map is empty.
Definition: AddonButtonMap.cpp:90
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:362
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:474
void SaveButtonMap() override
Save the button map.
Definition: AddonButtonMap.cpp:520
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:199
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:526
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:318
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:256
bool SetAppearance(const std::string &controllerId) const override
Set the ID of the controller that best represents the appearance of the peripheral.
Definition: AddonButtonMap.cpp:104
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:419
KODI::JOYSTICK::FEATURE_TYPE GetFeatureType(const KODI::JOYSTICK::FeatureName &feature) override
Get the type of the feature for the given name.
Definition: AddonButtonMap.cpp:126
void AddScalar(const KODI::JOYSTICK::FeatureName &feature, const KODI::JOYSTICK::CDriverPrimitive &primitive) override
Add or update a scalar feature.
Definition: AddonButtonMap.cpp:162
bool GetKey(const KODI::JOYSTICK::FeatureName &feature, KODI::JOYSTICK::CDriverPrimitive &primitive) override
Get the driver primitive for a keyboard key.
Definition: AddonButtonMap.cpp:452
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:175
bool GetAxisProperties(unsigned int axisIndex, int &center, unsigned int &range) override
Get the properties of an axis.
Definition: AddonButtonMap.cpp:498
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:139
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:232
bool IsIgnored(const KODI::JOYSTICK::CDriverPrimitive &primitive) override
Check if a primitive is in the list of primitives to be ignored.
Definition: AddonButtonMap.cpp:492
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:395
Definition: Peripheral.h:61
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:484
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:289