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