Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add support to CJoystick for IsEnabled Just like in CStatMouse

  • Loading branch information...
commit 3a10025812095000a88444389ff8492bb04b2f6b 1 parent 444ebb4
@Karlson2k authored
View
56 xbmc/input/SDLJoystick.cpp
@@ -35,6 +35,7 @@ using namespace std;
CJoystick::CJoystick()
{
Reset(true);
+ m_joystickEnabled = false;
m_NumAxes = 0;
m_AxisId = 0;
m_JoyId = 0;
@@ -47,6 +48,15 @@ CJoystick::CJoystick()
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();
@@ -118,6 +128,9 @@ void CJoystick::Reset(bool axis /*=false*/)
void CJoystick::Update()
{
+ if (!IsEnabled())
+ return;
+
int buttonId = -1;
int axisId = -1;
int hatId = -1;
@@ -232,6 +245,9 @@ void CJoystick::Update()
void CJoystick::Update(SDL_Event& joyEvent)
{
+ if (!IsEnabled())
+ return;
+
int buttonId = -1;
int axisId = -1;
int joyId = -1;
@@ -299,7 +315,7 @@ 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;
@@ -335,7 +351,7 @@ 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;
@@ -376,7 +392,7 @@ bool CJoystick::GetButton(int &id, bool consider_repeat)
bool CJoystick::GetAxis (int &id)
{
- if (!IsAxisActive())
+ if (!IsEnabled() || !IsAxisActive())
{
id = 0;
return false;
@@ -414,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;
@@ -422,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)
@@ -431,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
5 xbmc/input/SDLJoystick.h
@@ -63,6 +63,8 @@ class CJoystick
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
29 xbmc/input/windows/WINJoystick.cpp
@@ -52,6 +52,7 @@ extern HWND g_hWnd;
CJoystick::CJoystick()
{
Reset(true);
+ m_joystickEnabled = false;
m_NumAxes = 0;
m_AxisId = 0;
m_JoyId = 0;
@@ -175,6 +176,9 @@ BOOL CALLBACK CJoystick::EnumObjectsCallback( const DIDEVICEOBJECTINSTANCE* pdid
void CJoystick::Initialize()
{
+ if (!IsEnabled())
+ return;
+
HRESULT hr;
// clear old joystick names
@@ -225,6 +229,9 @@ void CJoystick::Reset(bool axis /*=true*/)
void CJoystick::Update()
{
+ if (!IsEnabled())
+ return;
+
int buttonId = -1;
int axisId = -1;
int hatId = -1;
@@ -363,7 +370,7 @@ void CJoystick::Update()
bool CJoystick::GetHat(int &id, int &position,bool consider_repeat)
{
- if (!IsHatActive())
+ if (!IsEnabled() || !IsHatActive())
{
id = position = 0;
return false;
@@ -397,7 +404,7 @@ 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;
@@ -436,7 +443,7 @@ bool CJoystick::GetButton(int &id, bool consider_repeat)
bool CJoystick::GetAxis (int &id)
{
- if (!IsAxisActive())
+ if (!IsEnabled() || !IsAxisActive())
{
id = 0;
return false;
@@ -472,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;
@@ -488,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
3  xbmc/input/windows/WINJoystick.h
@@ -53,6 +53,8 @@ class CJoystick
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;
Please sign in to comment.
Something went wrong with that request. Please try again.