3 * Copyright (C) 2012-2013 Team XBMC
6 * This Program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
11 * This Program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with XBMC; see the file COPYING. If not, see
18 * <http://www.gnu.org/licenses/>.
24 #include "threads/CriticalSection.h"
26 #define JACTIVE_BUTTON 0x00000001
27 #define JACTIVE_AXIS 0x00000002
28 #define JACTIVE_HAT 0x00000004
29 #define JACTIVE_NONE 0x00000000
30 #define JACTIVE_HAT_UP 0x01
31 #define JACTIVE_HAT_RIGHT 0x02
32 #define JACTIVE_HAT_DOWN 0x04
33 #define JACTIVE_HAT_LEFT 0x08
37 // Class to manage all connected joysticks
46 void Reset(bool axis=false);
47 void ResetAxis(int axisId) { m_Amount[axisId] = 0; }
49 bool GetButton (int& id, bool consider_repeat=true);
50 bool GetAxis (int &id);
51 bool GetHat (int &id, int &position, bool consider_repeat=true);
52 std::string GetJoystick() { return (m_JoyId>-1)?m_JoystickNames[m_JoyId]:""; }
53 int GetAxisWithMaxAmount();
54 float GetAmount(int axis);
55 float GetAmount() { return GetAmount(m_AxisId); }
56 bool IsEnabled() const { return m_joystickEnabled; }
57 void SetEnabled(bool enabled = true);
58 float SetDeadzone(float val);
63 void SetAxisActive(bool active=true) { m_ActiveFlags = active?(m_ActiveFlags|JACTIVE_AXIS):(m_ActiveFlags&(~JACTIVE_AXIS)); }
64 void SetButtonActive(bool active=true) { m_ActiveFlags = active?(m_ActiveFlags|JACTIVE_BUTTON):(m_ActiveFlags&(~JACTIVE_BUTTON)); }
65 void SetHatActive(bool active=true) { m_ActiveFlags = active?(m_ActiveFlags|JACTIVE_HAT):(m_ActiveFlags&(~JACTIVE_HAT)); }
66 bool IsButtonActive() { return (m_ActiveFlags & JACTIVE_BUTTON) == JACTIVE_BUTTON; }
67 bool IsAxisActive() { return (m_ActiveFlags & JACTIVE_AXIS) == JACTIVE_AXIS; }
68 bool IsHatActive() { return (m_ActiveFlags & JACTIVE_HAT) == JACTIVE_HAT; }
70 void ReleaseJoysticks();
71 static BOOL CALLBACK EnumJoysticksCallback( const DIDEVICEINSTANCE* pdidInstance, VOID* pContext );
72 static BOOL CALLBACK EnumObjectsCallback( const DIDEVICEOBJECTINSTANCE* pdidoi, VOID* pContext );
74 int m_Amount[MAX_AXES];
82 bool m_joystickEnabled;
83 uint32_t m_pressTicksButton;
84 uint32_t m_pressTicksHat;
85 uint8_t m_ActiveFlags;
86 uint32_t m_lastPressTicks;
88 CCriticalSection m_critSection;
91 std::vector<LPDIRECTINPUTDEVICE8> m_pJoysticks;
92 std::vector<std::string> m_JoystickNames;
93 std::vector<DIDEVCAPS> m_devCaps;
96 extern CJoystick g_Joystick;