aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarrett Brown <themagnificentmrb@gmail.com>2023-02-23 03:08:14 -0800
committerGarrett Brown <themagnificentmrb@gmail.com>2023-02-24 15:14:38 -0800
commit82300b250610f78e2111c47b9390a66c0b10cb9d (patch)
tree2fc76701877281228b1554a5415e479c7b23b698
parentdbd0c8a6697327ddd456cc508fc85711258175c9 (diff)
Peripherals: Refactor button map creation out of deadzone initialization
-rw-r--r--xbmc/peripherals/devices/PeripheralJoystick.cpp41
-rw-r--r--xbmc/peripherals/devices/PeripheralJoystick.h2
2 files changed, 16 insertions, 27 deletions
diff --git a/xbmc/peripherals/devices/PeripheralJoystick.cpp b/xbmc/peripherals/devices/PeripheralJoystick.cpp
index 3ebd5658a7..2e64eb2871 100644
--- a/xbmc/peripherals/devices/PeripheralJoystick.cpp
+++ b/xbmc/peripherals/devices/PeripheralJoystick.cpp
@@ -76,7 +76,8 @@ bool CPeripheralJoystick::InitialiseFeature(const PeripheralFeature feature)
if (feature == FEATURE_JOYSTICK)
{
// Ensure an add-on is present to translate input
- if (!m_manager.GetAddonWithButtonMap(this))
+ PeripheralAddonPtr addon = m_manager.GetAddonWithButtonMap(this);
+ if (!addon)
{
CLog::Log(LOGERROR, "CPeripheralJoystick: No button mapping add-on for {}", m_strLocation);
}
@@ -90,7 +91,17 @@ bool CPeripheralJoystick::InitialiseFeature(const PeripheralFeature feature)
if (bSuccess)
{
- InitializeDeadzoneFiltering();
+ m_buttonMap = std::make_unique<CAddonButtonMap>(this, addon, DEFAULT_CONTROLLER_ID);
+ if (m_buttonMap->Load())
+ {
+ InitializeDeadzoneFiltering(*m_buttonMap);
+ }
+ else
+ {
+ CLog::Log(LOGERROR, "CPeripheralJoystick: Failed to load button map for {}",
+ m_strLocation);
+ m_buttonMap.reset();
+ }
// Give joystick monitor priority over default controller
m_appInput.reset(
@@ -112,31 +123,9 @@ bool CPeripheralJoystick::InitialiseFeature(const PeripheralFeature feature)
return bSuccess;
}
-void CPeripheralJoystick::InitializeDeadzoneFiltering()
+void CPeripheralJoystick::InitializeDeadzoneFiltering(IButtonMap& buttonMap)
{
- // Get a button map for deadzone filtering
- PeripheralAddonPtr addon = m_manager.GetAddonWithButtonMap(this);
- if (addon)
- {
- m_buttonMap.reset(new CAddonButtonMap(this, addon, DEFAULT_CONTROLLER_ID));
- if (m_buttonMap->Load())
- {
- m_deadzoneFilter.reset(new CDeadzoneFilter(m_buttonMap.get(), this));
- }
- else
- {
- CLog::Log(LOGERROR,
- "CPeripheralJoystick: Failed to load button map for deadzone filtering on {}",
- m_strLocation);
- m_buttonMap.reset();
- }
- }
- else
- {
- CLog::Log(LOGERROR,
- "CPeripheralJoystick: Failed to create button map for deadzone filtering on {}",
- m_strLocation);
- }
+ m_deadzoneFilter.reset(new CDeadzoneFilter(&buttonMap, this));
}
void CPeripheralJoystick::OnUserNotification()
diff --git a/xbmc/peripherals/devices/PeripheralJoystick.h b/xbmc/peripherals/devices/PeripheralJoystick.h
index f94b9cd466..3b19abf135 100644
--- a/xbmc/peripherals/devices/PeripheralJoystick.h
+++ b/xbmc/peripherals/devices/PeripheralJoystick.h
@@ -104,7 +104,7 @@ public:
void SetSupportsPowerOff(bool bSupportsPowerOff); // specialized to update m_features
protected:
- void InitializeDeadzoneFiltering();
+ void InitializeDeadzoneFiltering(KODI::JOYSTICK::IButtonMap& buttonMap);
void PowerOff();