Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #1111 from Karlson2k/UseJoystick

[input] Add 'Enable Joystick' to GUI settings. Fix for http://trac.xbmc.org/ticket/13146
  • Loading branch information...
commit ba554f1bc0f165ac494bae3ccaec4b74631f3574 2 parents ac5bd34 + bd9b6c6
@jmarshallnz jmarshallnz authored
View
8 language/English/strings.po
@@ -9304,7 +9304,13 @@ msgctxt "#35009"
msgid "Do not use the custom keymap for this device"
msgstr ""
-#empty strings from id 35010 to 35499
+#empty strings from id 35010 to 35099
+
+msgctxt "#35100"
+msgid "Enable joystick and gamepad support"
+msgstr ""
+
+#empty strings from id 35101 to 35499
msgctxt "#35500"
msgid "Location"
View
9 xbmc/Application.cpp
@@ -1351,7 +1351,7 @@ bool CApplication::Initialize()
ResetScreenSaver();
#ifdef HAS_SDL_JOYSTICK
- g_Joystick.Initialize();
+ g_Joystick.SetEnabled(g_guiSettings.GetBool("input.enablejoystick"));
#endif
return true;
@@ -2815,8 +2815,9 @@ bool CApplication::ProcessGamepad(float frameTime)
#ifdef HAS_SDL_JOYSTICK
if (!m_AppFocused)
return false;
+
int iWin = GetActiveWindowID();
- int bid;
+ int bid = 0;
g_Joystick.Update();
if (g_Joystick.GetButton(bid))
{
@@ -2875,7 +2876,7 @@ bool CApplication::ProcessGamepad(float frameTime)
g_Joystick.ResetAxis(abs(bid));
}
}
- int position;
+ int position = 0;
if (g_Joystick.GetHat(bid, position))
{
// reset Idle Timer
@@ -2894,7 +2895,7 @@ bool CApplication::ProcessGamepad(float frameTime)
bid = position<<16|bid;
- if (CButtonTranslator::GetInstance().TranslateJoystickString(iWin, g_Joystick.GetJoystick().c_str(), bid, JACTIVE_HAT, actionID, actionName, fullrange))
+ if (bid && CButtonTranslator::GetInstance().TranslateJoystickString(iWin, g_Joystick.GetJoystick().c_str(), bid, JACTIVE_HAT, actionID, actionName, fullrange))
{
CAction action(actionID, 1.0f, 0.0f, actionName);
g_audioManager.PlayActionSound(action);
View
10 xbmc/SystemGlobals.cpp
@@ -41,6 +41,13 @@
#ifdef HAS_PYTHON
#include "interfaces/python/XBPython.h"
#endif
+#if defined(TARGET_WINDOWS)
+#include "input/windows/WINJoystick.h"
+#elif defined(HAS_SDL_JOYSTICK) || defined(HAS_EVENT_SERVER)
+#include "input/SDLJoystick.h"
+#endif
+
+
CGUISettings g_guiSettings;
CSettings g_settings;
@@ -57,6 +64,9 @@
CGUITextureManager g_TextureManager;
CGUILargeTextureManager g_largeTextureManager;
CMouseStat g_Mouse;
+#if defined(HAS_SDL_JOYSTICK) || defined(HAS_EVENT_SERVER)
+ CJoystick g_Joystick;
+#endif
CGUIPassword g_passwordManager;
CGUIInfoManager g_infoManager;
View
79 xbmc/input/SDLJoystick.cpp
@@ -32,11 +32,10 @@
using namespace std;
-CJoystick g_Joystick; // global
-
CJoystick::CJoystick()
{
- Reset();
+ Reset(true);
+ m_joystickEnabled = false;
m_NumAxes = 0;
m_AxisId = 0;
m_JoyId = 0;
@@ -44,13 +43,20 @@ CJoystick::CJoystick()
m_HatId = 0;
m_HatState = SDL_HAT_CENTERED;
m_ActiveFlags = JACTIVE_NONE;
- for (int i = 0 ; i<MAX_AXES ; i++)
- m_Amount[i] = 0;
SetDeadzone(0);
}
void CJoystick::Initialize()
{
+ if (!IsEnabled())
+ return;
+
+ if(SDL_InitSubSystem(SDL_INIT_JOYSTICK) != 0)
+ {
+ CLog::Log(LOGERROR, "(Re)start joystick subsystem failed : %s",SDL_GetError());
+ return;
+ }
+
// clear old joystick names
m_JoystickNames.clear();
@@ -108,7 +114,7 @@ void CJoystick::Initialize()
SDL_JoystickEventState(SDL_DISABLE);
}
-void CJoystick::Reset(bool axis)
+void CJoystick::Reset(bool axis /*=false*/)
{
if (axis)
{
@@ -122,6 +128,9 @@ void CJoystick::Reset(bool axis)
void CJoystick::Update()
{
+ if (!IsEnabled())
+ return;
+
int buttonId = -1;
int axisId = -1;
int hatId = -1;
@@ -236,6 +245,9 @@ void CJoystick::Update()
void CJoystick::Update(SDL_Event& joyEvent)
{
+ if (!IsEnabled())
+ return;
+
int buttonId = -1;
int axisId = -1;
int joyId = -1;
@@ -303,8 +315,11 @@ void CJoystick::Update(SDL_Event& joyEvent)
bool CJoystick::GetHat(int &id, int &position,bool consider_repeat)
{
- if (!IsHatActive())
+ if (!IsEnabled() || !IsHatActive())
+ {
+ id = position = 0;
return false;
+ }
position = m_HatState;
id = m_HatId;
if (!consider_repeat)
@@ -336,8 +351,11 @@ bool CJoystick::GetHat(int &id, int &position,bool consider_repeat)
bool CJoystick::GetButton(int &id, bool consider_repeat)
{
- if (!IsButtonActive())
+ if (!IsEnabled() || !IsButtonActive())
+ {
+ id = 0;
return false;
+ }
if (!consider_repeat)
{
id = m_ButtonId;
@@ -372,6 +390,17 @@ bool CJoystick::GetButton(int &id, bool consider_repeat)
return true;
}
+bool CJoystick::GetAxis (int &id)
+{
+ if (!IsEnabled() || !IsAxisActive())
+ {
+ id = 0;
+ return false;
+ }
+ id = m_AxisId;
+ return true;
+}
+
int CJoystick::GetAxisWithMaxAmount()
{
static int maxAmount;
@@ -401,6 +430,20 @@ float CJoystick::GetAmount(int axis)
return 0;
}
+void CJoystick::SetEnabled(bool enabled /*=true*/)
+{
+ if( enabled && !m_joystickEnabled )
+ {
+ m_joystickEnabled = true;
+ Initialize();
+ }
+ else if( !enabled && m_joystickEnabled )
+ {
+ ReleaseJoysticks();
+ m_joystickEnabled = false;
+ }
+}
+
float CJoystick::SetDeadzone(float val)
{
if (val<0) val=0;
@@ -409,8 +452,16 @@ float CJoystick::SetDeadzone(float val)
return val;
}
-bool CJoystick::Reinitialize()
+bool CJoystick::ReleaseJoysticks()
{
+ m_pJoysticks.clear();
+ m_JoystickNames.clear();
+ m_HatId = 0;
+ m_ButtonId = 0;
+ m_HatState = SDL_HAT_CENTERED;
+ m_ActiveFlags = JACTIVE_NONE;
+ Reset(true);
+
// Restart SDL joystick subsystem
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
if (SDL_WasInit(SDL_INIT_JOYSTICK) != 0)
@@ -418,12 +469,12 @@ bool CJoystick::Reinitialize()
CLog::Log(LOGERROR, "Stop joystick subsystem failed");
return false;
}
- if(SDL_InitSubSystem(SDL_INIT_JOYSTICK) != 0)
- {
- CLog::Log(LOGERROR, "Restart joystick subsystem failed : %s",SDL_GetError());
- return false;
- }
+ return true;
+}
+bool CJoystick::Reinitialize()
+{
+ if( !ReleaseJoysticks() ) return false;
Initialize();
return true;
View
7 xbmc/input/SDLJoystick.h
@@ -57,12 +57,14 @@ class CJoystick
void Update();
void Update(SDL_Event& event);
bool GetButton (int& id, bool consider_repeat=true);
- bool GetAxis (int &id) { if (!IsAxisActive()) return false; id=m_AxisId; return true; }
+ bool GetAxis (int &id);
bool GetHat (int &id, int &position, bool consider_repeat=true);
std::string GetJoystick() { return (m_JoyId>-1)?m_JoystickNames[m_JoyId]:""; }
int GetAxisWithMaxAmount();
float GetAmount(int axis);
float GetAmount() { return GetAmount(m_AxisId); }
+ bool IsEnabled() const { return m_joystickEnabled; }
+ void SetEnabled(bool enabled = true);
float SetDeadzone(float val);
bool Reinitialize();
@@ -74,6 +76,8 @@ class CJoystick
bool IsAxisActive() { return (m_ActiveFlags & JACTIVE_AXIS) == JACTIVE_AXIS; }
bool IsHatActive() { return (m_ActiveFlags & JACTIVE_HAT) == JACTIVE_HAT; }
+ bool ReleaseJoysticks();
+
int m_Amount[MAX_AXES];
int m_AxisId;
int m_ButtonId;
@@ -82,6 +86,7 @@ class CJoystick
int m_JoyId;
int m_NumAxes;
int m_DeadzoneRange;
+ bool m_joystickEnabled;
uint32_t m_pressTicksButton;
uint32_t m_pressTicksHat;
uint8_t m_ActiveFlags;
View
59 xbmc/input/windows/WINJoystick.cpp
@@ -31,8 +31,6 @@
using namespace std;
-CJoystick g_Joystick; // global
-
extern HWND g_hWnd;
#define MAX_AXISAMOUNT 32768
@@ -53,7 +51,8 @@ extern HWND g_hWnd;
CJoystick::CJoystick()
{
- Reset();
+ Reset(true);
+ m_joystickEnabled = false;
m_NumAxes = 0;
m_AxisId = 0;
m_JoyId = 0;
@@ -61,8 +60,6 @@ CJoystick::CJoystick()
m_HatId = 0;
m_HatState = SDL_HAT_CENTERED;
m_ActiveFlags = JACTIVE_NONE;
- for (int i = 0 ; i<MAX_AXES ; i++)
- m_Amount[i] = 0;
SetDeadzone(0);
m_pDI = NULL;
@@ -88,6 +85,13 @@ void CJoystick::ReleaseJoysticks()
m_pJoysticks.clear();
m_JoystickNames.clear();
m_devCaps.clear();
+ m_HatId = 0;
+ m_ButtonId = 0;
+ m_HatState = SDL_HAT_CENTERED;
+ m_ActiveFlags = JACTIVE_NONE;
+ Reset(true);
+ m_lastPressTicks = 0;
+ m_lastTicks = 0;
// Release any DirectInput objects.
SAFE_RELEASE( m_pDI );
}
@@ -172,6 +176,9 @@ BOOL CALLBACK CJoystick::EnumObjectsCallback( const DIDEVICEOBJECTINSTANCE* pdid
void CJoystick::Initialize()
{
+ if (!IsEnabled())
+ return;
+
HRESULT hr;
// clear old joystick names
@@ -208,7 +215,7 @@ void CJoystick::Initialize()
SetDeadzone(g_advancedSettings.m_controllerDeadzone);
}
-void CJoystick::Reset(bool axis)
+void CJoystick::Reset(bool axis /*=true*/)
{
if (axis)
{
@@ -222,6 +229,9 @@ void CJoystick::Reset(bool axis)
void CJoystick::Update()
{
+ if (!IsEnabled())
+ return;
+
int buttonId = -1;
int axisId = -1;
int hatId = -1;
@@ -360,8 +370,11 @@ void CJoystick::Update()
bool CJoystick::GetHat(int &id, int &position,bool consider_repeat)
{
- if (!IsHatActive())
+ if (!IsEnabled() || !IsHatActive())
+ {
+ id = position = 0;
return false;
+ }
position = m_HatState;
id = m_HatId;
if (!consider_repeat)
@@ -391,8 +404,11 @@ bool CJoystick::GetHat(int &id, int &position,bool consider_repeat)
bool CJoystick::GetButton(int &id, bool consider_repeat)
{
- if (!IsButtonActive())
+ if (!IsEnabled() || !IsButtonActive())
+ {
+ id = 0;
return false;
+ }
if (!consider_repeat)
{
id = m_ButtonId;
@@ -425,6 +441,17 @@ bool CJoystick::GetButton(int &id, bool consider_repeat)
return true;
}
+bool CJoystick::GetAxis (int &id)
+{
+ if (!IsEnabled() || !IsAxisActive())
+ {
+ id = 0;
+ return false;
+ }
+ id = m_AxisId;
+ return true;
+}
+
int CJoystick::GetAxisWithMaxAmount()
{
int maxAmount = 0;
@@ -452,6 +479,20 @@ float CJoystick::GetAmount(int axis)
return 0;
}
+void CJoystick::SetEnabled(bool enabled /*=true*/)
+{
+ if( enabled && !m_joystickEnabled )
+ {
+ m_joystickEnabled = true;
+ Initialize();
+ }
+ else if( !enabled && m_joystickEnabled )
+ {
+ ReleaseJoysticks();
+ m_joystickEnabled = false;
+ }
+}
+
float CJoystick::SetDeadzone(float val)
{
if (val<0) val=0;
@@ -468,6 +509,8 @@ bool CJoystick::Reinitialize()
void CJoystick::Acquire()
{
+ if (!IsEnabled())
+ return;
if(!m_pJoysticks.empty())
{
CLog::Log(LOGDEBUG, __FUNCTION__": Focus back, acquire Joysticks");
View
5 xbmc/input/windows/WINJoystick.h
@@ -47,12 +47,14 @@ class CJoystick
void ResetAxis(int axisId) { m_Amount[axisId] = 0; }
void Update();
bool GetButton (int& id, bool consider_repeat=true);
- bool GetAxis (int &id) { if (!IsAxisActive()) return false; id=m_AxisId; return true; }
+ bool GetAxis (int &id);
bool GetHat (int &id, int &position, bool consider_repeat=true);
std::string GetJoystick() { return (m_JoyId>-1)?m_JoystickNames[m_JoyId]:""; }
int GetAxisWithMaxAmount();
float GetAmount(int axis);
float GetAmount() { return GetAmount(m_AxisId); }
+ bool IsEnabled() const { return m_joystickEnabled; }
+ void SetEnabled(bool enabled = true);
float SetDeadzone(float val);
bool Reinitialize();
void Acquire();
@@ -77,6 +79,7 @@ class CJoystick
int m_JoyId;
int m_NumAxes;
int m_DeadzoneRange;
+ bool m_joystickEnabled;
uint32_t m_pressTicksButton;
uint32_t m_pressTicksHat;
uint8_t m_ActiveFlags;
View
3  xbmc/settings/GUISettings.cpp
@@ -520,6 +520,9 @@ void CGUISettings::Initialize()
#else
AddBool(in, "input.enablemouse", 21369, true);
#endif
+#if defined(HAS_SDL_JOYSTICK)
+ AddBool(in, "input.enablejoystick", 35100, true);
+#endif
CSettingsCategory* net = AddCategory(4, "network", 798);
if (g_application.IsStandAlone())
View
11 xbmc/settings/GUIWindowSettingsCategory.cpp
@@ -92,6 +92,11 @@
#include "Settings.h"
#include "AdvancedSettings.h"
#include "input/MouseStat.h"
+#if defined(TARGET_WINDOWS)
+#include "input/windows/WINJoystick.h"
+#elif defined(HAS_SDL_JOYSTICK)
+#include "input/SDLJoystick.h"
+#endif
#include "guilib/LocalizeStrings.h"
#include "LangInfo.h"
#include "utils/StringUtils.h"
@@ -1388,6 +1393,12 @@ void CGUIWindowSettingsCategory::OnSettingChanged(CBaseSettingControl *pSettingC
{
g_Mouse.SetEnabled(g_guiSettings.GetBool("input.enablemouse"));
}
+ else if (strSetting.Equals("input.enablejoystick"))
+ {
+#if defined(HAS_SDL_JOYSTICK)
+ g_Joystick.SetEnabled(g_guiSettings.GetBool("input.enablejoystick"));
+#endif
+ }
else if (strSetting.Equals("videoscreen.screen"))
{
DisplayMode mode = g_guiSettings.GetInt("videoscreen.screen");
Please sign in to comment.
Something went wrong with that request. Please try again.