| 1 |
/* |
| 2 |
* Copyright (C) 2015-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 "JoystickTypes.h" |
| 12 |
|
| 13 |
namespace KODI |
| 14 |
{ |
| 15 |
namespace JOYSTICK |
| 16 |
{ |
| 17 |
class CDriverPrimitive; |
| 18 |
|
| 19 |
/*! |
| 20 |
* \ingroup joystick |
| 21 |
* |
| 22 |
* \brief Joystick translation utilities |
| 23 |
*/ |
| 24 |
class CJoystickTranslator |
| 25 |
{ |
| 26 |
public: |
| 27 |
/*! |
| 28 |
* \brief Translate a hat state to a string representation |
| 29 |
* |
| 30 |
* \param state The hat state |
| 31 |
* |
| 32 |
* \return A capitalized string representation, or "RELEASED" if the hat is centered. |
| 33 |
*/ |
| 34 |
static const char* HatStateToString(HAT_STATE state); |
| 35 |
|
| 36 |
/*! |
| 37 |
* \brief Translate an analog stick direction to a lower-case string |
| 38 |
* |
| 39 |
* \param dir The analog stick direction |
| 40 |
* |
| 41 |
* \return A lower-case string representation, or "" if the direction is invalid |
| 42 |
*/ |
| 43 |
static const char* TranslateAnalogStickDirection(ANALOG_STICK_DIRECTION dir); |
| 44 |
|
| 45 |
/*! |
| 46 |
* \brief Translate an analog stick direction string to an enum value |
| 47 |
* |
| 48 |
* \param dir The analog stick direction |
| 49 |
* |
| 50 |
* \return The translated direction, or ANALOG_STICK_DIRECTION::UNKNOWN if unknown |
| 51 |
*/ |
| 52 |
static ANALOG_STICK_DIRECTION TranslateAnalogStickDirection(const std::string& dir); |
| 53 |
|
| 54 |
/*! |
| 55 |
* \brief Translate a wheel direction to a lower-case string |
| 56 |
* |
| 57 |
* \param dir The wheel direction |
| 58 |
* |
| 59 |
* \return A lower-case string representation, or "" if the direction is invalid |
| 60 |
*/ |
| 61 |
static const char* TranslateWheelDirection(WHEEL_DIRECTION dir); |
| 62 |
|
| 63 |
/*! |
| 64 |
* \brief Translate a wheel direction string to an enum value |
| 65 |
* |
| 66 |
* \param dir The wheel direction |
| 67 |
* |
| 68 |
* \return The translated direction, or WHEEL_DIRECTION::UNKNOWN if unknown |
| 69 |
*/ |
| 70 |
static WHEEL_DIRECTION TranslateWheelDirection(const std::string& dir); |
| 71 |
|
| 72 |
/*! |
| 73 |
* \brief Translate a throttle direction to a lower-case string |
| 74 |
* |
| 75 |
* \param dir The analog stick direction |
| 76 |
* |
| 77 |
* \return A lower-case string representation, or "" if the direction is invalid |
| 78 |
*/ |
| 79 |
static const char* TranslateThrottleDirection(THROTTLE_DIRECTION dir); |
| 80 |
|
| 81 |
/*! |
| 82 |
* \brief Translate a throttle direction string to an enum value |
| 83 |
* |
| 84 |
* \param dir The throttle direction |
| 85 |
* |
| 86 |
* \return The translated direction, or THROTTLE_DIRECTION::UNKNOWN if unknown |
| 87 |
*/ |
| 88 |
static THROTTLE_DIRECTION TranslateThrottleDirection(const std::string& dir); |
| 89 |
|
| 90 |
/*! |
| 91 |
* \brief Get the semi-axis direction containing the specified position |
| 92 |
* |
| 93 |
* \param position The position of the axis |
| 94 |
* |
| 95 |
* \return POSITIVE, NEGATIVE, or UNKNOWN if position is 0 |
| 96 |
*/ |
| 97 |
static SEMIAXIS_DIRECTION PositionToSemiAxisDirection(float position); |
| 98 |
|
| 99 |
/*! |
| 100 |
* \brief Get the wheel direction containing the specified position |
| 101 |
* |
| 102 |
* \param position The position of the axis |
| 103 |
* |
| 104 |
* \return LEFT, RIGHT, or UNKNOWN if position is 0 |
| 105 |
*/ |
| 106 |
static WHEEL_DIRECTION PositionToWheelDirection(float position); |
| 107 |
|
| 108 |
/*! |
| 109 |
* \brief Get the throttle direction containing the specified position |
| 110 |
* |
| 111 |
* \param position The position of the axis |
| 112 |
* |
| 113 |
* \return UP, DOWN, or UNKNOWN if position is 0 |
| 114 |
*/ |
| 115 |
static THROTTLE_DIRECTION PositionToThrottleDirection(float position); |
| 116 |
|
| 117 |
/*! |
| 118 |
* \brief Get the localized name of the primitive |
| 119 |
* |
| 120 |
* \param primitive The primitive, currently only buttons and axes are supported |
| 121 |
* |
| 122 |
* \return A title for the primitive, e.g. "Button 0" or "Axis 1" |
| 123 |
*/ |
| 124 |
static std::string GetPrimitiveName(const CDriverPrimitive& primitive); |
| 125 |
}; |
| 126 |
} // namespace JOYSTICK |
| 127 |
} // namespace KODI |