| 1 |
/* |
| 2 |
* Copyright (C) 2014-2024 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" |
| 13 |
#include "input/joysticks/JoystickTypes.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 |
class CPeripherals; |
| 22 |
|
| 23 |
/*! |
| 24 |
* \ingroup peripherals |
| 25 |
*/ |
| 26 |
class CAddonButtonMap : public KODI::JOYSTICK::IButtonMap |
| 27 |
{ |
| 28 |
public: |
| 29 |
CAddonButtonMap(CPeripheral* device, |
| 30 |
const std::weak_ptr<CPeripheralAddon>& addon, |
| 31 |
const std::string& strControllerId, |
| 32 |
CPeripherals& manager); |
| 33 |
|
| 34 |
~CAddonButtonMap(void) override; |
| 35 |
|
| 36 |
// Implementation of IButtonMap |
| 37 |
std::string ControllerID(void) const override { return m_strControllerId; } |
| 38 |
|
| 39 |
std::string Location(void) const override; |
| 40 |
|
| 41 |
bool Load(void) override; |
| 42 |
|
| 43 |
void Reset(void) override; |
| 44 |
|
| 45 |
bool IsEmpty(void) const override; |
| 46 |
|
| 47 |
std::string GetAppearance() const override; |
| 48 |
|
| 49 |
bool SetAppearance(const std::string& controllerId) const override; |
| 50 |
|
| 51 |
bool GetFeature(const KODI::JOYSTICK::CDriverPrimitive& primitive, |
| 52 |
KODI::JOYSTICK::FeatureName& feature) override; |
| 53 |
|
| 54 |
KODI::JOYSTICK::FEATURE_TYPE GetFeatureType(const KODI::JOYSTICK::FeatureName& feature) override; |
| 55 |
|
| 56 |
bool GetScalar(const KODI::JOYSTICK::FeatureName& feature, |
| 57 |
KODI::JOYSTICK::CDriverPrimitive& primitive) override; |
| 58 |
|
| 59 |
void AddScalar(const KODI::JOYSTICK::FeatureName& feature, |
| 60 |
const KODI::JOYSTICK::CDriverPrimitive& primitive) override; |
| 61 |
|
| 62 |
bool GetAnalogStick(const KODI::JOYSTICK::FeatureName& feature, |
| 63 |
KODI::JOYSTICK::ANALOG_STICK_DIRECTION direction, |
| 64 |
KODI::JOYSTICK::CDriverPrimitive& primitive) override; |
| 65 |
|
| 66 |
void AddAnalogStick(const KODI::JOYSTICK::FeatureName& feature, |
| 67 |
KODI::JOYSTICK::ANALOG_STICK_DIRECTION direction, |
| 68 |
const KODI::JOYSTICK::CDriverPrimitive& primitive) override; |
| 69 |
|
| 70 |
bool GetRelativePointer(const KODI::JOYSTICK::FeatureName& feature, |
| 71 |
KODI::JOYSTICK::RELATIVE_POINTER_DIRECTION direction, |
| 72 |
KODI::JOYSTICK::CDriverPrimitive& primitive) override; |
| 73 |
|
| 74 |
void AddRelativePointer(const KODI::JOYSTICK::FeatureName& feature, |
| 75 |
KODI::JOYSTICK::RELATIVE_POINTER_DIRECTION direction, |
| 76 |
const KODI::JOYSTICK::CDriverPrimitive& primitive) override; |
| 77 |
|
| 78 |
bool GetAccelerometer(const KODI::JOYSTICK::FeatureName& feature, |
| 79 |
KODI::JOYSTICK::CDriverPrimitive& positiveX, |
| 80 |
KODI::JOYSTICK::CDriverPrimitive& positiveY, |
| 81 |
KODI::JOYSTICK::CDriverPrimitive& positiveZ) override; |
| 82 |
|
| 83 |
void AddAccelerometer(const KODI::JOYSTICK::FeatureName& feature, |
| 84 |
const KODI::JOYSTICK::CDriverPrimitive& positiveX, |
| 85 |
const KODI::JOYSTICK::CDriverPrimitive& positiveY, |
| 86 |
const KODI::JOYSTICK::CDriverPrimitive& positiveZ) override; |
| 87 |
|
| 88 |
bool GetWheel(const KODI::JOYSTICK::FeatureName& feature, |
| 89 |
KODI::JOYSTICK::WHEEL_DIRECTION direction, |
| 90 |
KODI::JOYSTICK::CDriverPrimitive& primitive) override; |
| 91 |
|
| 92 |
void AddWheel(const KODI::JOYSTICK::FeatureName& feature, |
| 93 |
KODI::JOYSTICK::WHEEL_DIRECTION direction, |
| 94 |
const KODI::JOYSTICK::CDriverPrimitive& primitive) override; |
| 95 |
|
| 96 |
bool GetThrottle(const KODI::JOYSTICK::FeatureName& feature, |
| 97 |
KODI::JOYSTICK::THROTTLE_DIRECTION direction, |
| 98 |
KODI::JOYSTICK::CDriverPrimitive& primitive) override; |
| 99 |
|
| 100 |
void AddThrottle(const KODI::JOYSTICK::FeatureName& feature, |
| 101 |
KODI::JOYSTICK::THROTTLE_DIRECTION direction, |
| 102 |
const KODI::JOYSTICK::CDriverPrimitive& primitive) override; |
| 103 |
|
| 104 |
bool GetKey(const KODI::JOYSTICK::FeatureName& feature, |
| 105 |
KODI::JOYSTICK::CDriverPrimitive& primitive) override; |
| 106 |
|
| 107 |
void AddKey(const KODI::JOYSTICK::FeatureName& feature, |
| 108 |
const KODI::JOYSTICK::CDriverPrimitive& primitive) override; |
| 109 |
|
| 110 |
void SetIgnoredPrimitives( |
| 111 |
const std::vector<KODI::JOYSTICK::CDriverPrimitive>& primitives) override; |
| 112 |
|
| 113 |
bool IsIgnored(const KODI::JOYSTICK::CDriverPrimitive& primitive) override; |
| 114 |
|
| 115 |
bool GetAxisProperties(unsigned int axisIndex, int& center, unsigned int& range) override; |
| 116 |
|
| 117 |
void SaveButtonMap() override; |
| 118 |
|
| 119 |
void RevertButtonMap() override; |
| 120 |
|
| 121 |
private: |
| 122 |
typedef std::map<KODI::JOYSTICK::CDriverPrimitive, KODI::JOYSTICK::FeatureName> DriverMap; |
| 123 |
typedef std::vector<KODI::JOYSTICK::CDriverPrimitive> JoystickPrimitiveVector; |
| 124 |
|
| 125 |
// Utility functions |
| 126 |
static DriverMap CreateLookupTable(const FeatureMap& features); |
| 127 |
|
| 128 |
static JOYSTICK_FEATURE_PRIMITIVE GetAnalogStickIndex(KODI::JOYSTICK::ANALOG_STICK_DIRECTION dir); |
| 129 |
static JOYSTICK_FEATURE_PRIMITIVE GetRelativePointerIndex( |
| 130 |
KODI::JOYSTICK::RELATIVE_POINTER_DIRECTION dir); |
| 131 |
static JOYSTICK_FEATURE_PRIMITIVE GetPrimitiveIndex(KODI::JOYSTICK::WHEEL_DIRECTION dir); |
| 132 |
static JOYSTICK_FEATURE_PRIMITIVE GetPrimitiveIndex(KODI::JOYSTICK::THROTTLE_DIRECTION dir); |
| 133 |
|
| 134 |
// Construction parameters |
| 135 |
CPeripheral* const m_device; |
| 136 |
const std::weak_ptr<CPeripheralAddon> m_addon; |
| 137 |
const std::string m_strControllerId; |
| 138 |
CPeripherals& m_manager; |
| 139 |
|
| 140 |
// Button map state |
| 141 |
std::string m_controllerAppearance; |
| 142 |
FeatureMap m_features; |
| 143 |
DriverMap m_driverMap; |
| 144 |
JoystickPrimitiveVector m_ignoredPrimitives; |
| 145 |
|
| 146 |
// Synchronization parameters |
| 147 |
mutable CCriticalSection m_mutex; |
| 148 |
}; |
| 149 |
} // namespace PERIPHERALS |