| 1 |
/* |
| 2 |
* Copyright (C) 2016-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 |
namespace PERIPHERALS |
| 12 |
{ |
| 13 |
class CPeripheral; |
| 14 |
} |
| 15 |
|
| 16 |
namespace KODI |
| 17 |
{ |
| 18 |
namespace JOYSTICK |
| 19 |
{ |
| 20 |
class IButtonMap; |
| 21 |
|
| 22 |
/*! |
| 23 |
* \ingroup joystick |
| 24 |
* |
| 25 |
* \brief Analog axis deadzone filtering |
| 26 |
* |
| 27 |
* Axis is scaled appropriately, so position is continuous |
| 28 |
* from -1.0 to 1.0: |
| 29 |
* |
| 30 |
* | / 1.0 |
| 31 |
* | / |
| 32 |
* __|__/ |
| 33 |
* / | |
| 34 |
* / |--| Deadzone |
| 35 |
* -1.0 / | |
| 36 |
* |
| 37 |
* After deadzone filtering, the value will be: |
| 38 |
* |
| 39 |
* - Negative in the interval [-1.0, -deadzone) |
| 40 |
* - Zero in the interval [-deadzone, deadzone] |
| 41 |
* - Positive in the interval (deadzone, 1.0] |
| 42 |
*/ |
| 43 |
class CDeadzoneFilter |
| 44 |
{ |
| 45 |
public: |
| 46 |
CDeadzoneFilter(IButtonMap* buttonMap, PERIPHERALS::CPeripheral* peripheral); |
| 47 |
|
| 48 |
/*! |
| 49 |
* \brief Apply deadzone filtering to an axis |
| 50 |
* \param axisIndex The axis index |
| 51 |
* \param axisValue The axis value |
| 52 |
* \return The value after applying deadzone filtering |
| 53 |
*/ |
| 54 |
float FilterAxis(unsigned int axisIndex, float axisValue); |
| 55 |
|
| 56 |
private: |
| 57 |
/*! |
| 58 |
* \brief Get the deadzone value from the peripheral's settings |
| 59 |
* \param axisIndex The axis index |
| 60 |
* \param[out] result The deadzone value |
| 61 |
* \param featureName The feature that axisIndex is mapped to |
| 62 |
* \param settingName The setting corresponding to the given feature |
| 63 |
* \return True if the feature is an analog stick and the peripheral has the setting |
| 64 |
*/ |
| 65 |
bool GetDeadzone(unsigned int axisIndex, |
| 66 |
float& result, |
| 67 |
const char* featureName, |
| 68 |
const char* settingName); |
| 69 |
|
| 70 |
/*! |
| 71 |
* \brief Utility function to calculate the deadzone |
| 72 |
* \param value The value |
| 73 |
* \param deadzone The deadzone |
| 74 |
* \return The scaled deadzone |
| 75 |
*/ |
| 76 |
static float ApplyDeadzone(float value, float deadzone); |
| 77 |
|
| 78 |
// Construction parameters |
| 79 |
IButtonMap* const m_buttonMap; |
| 80 |
PERIPHERALS::CPeripheral* const m_peripheral; |
| 81 |
}; |
| 82 |
} // namespace JOYSTICK |
| 83 |
} // namespace KODI |