Add support for the hat switch. This only works if the hid device uses 3 or 7 values plus a null position for the hat and furthermore, the minimum value needs to correspond to up with increasing values moving clockwise.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "global.h"
|
||||
#include "JoystickDevice.h"
|
||||
#include "RageUtil.h"
|
||||
#include "RageLog.h"
|
||||
#include "Foreach.h"
|
||||
|
||||
using namespace std;
|
||||
@@ -12,7 +13,8 @@ Joystick::Joystick() : id( InputDevice_Invalid ),
|
||||
z_axis( 0 ), z_min( 0 ), z_max( 0 ),
|
||||
x_rot( 0 ), rx_min( 0 ), rx_max( 0 ),
|
||||
y_rot( 0 ), ry_min( 0 ), ry_max( 0 ),
|
||||
z_rot( 0 ), rz_min( 0 ), rz_max( 0 )
|
||||
z_rot( 0 ), rz_min( 0 ), rz_max( 0 ),
|
||||
hat( 0 ), hat_min( 0 ), hat_max( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
@@ -35,6 +37,9 @@ bool JoystickDevice::AddLogicalDevice( int usagePage, int usage )
|
||||
|
||||
void JoystickDevice::AddElement( int usagePage, int usage, int cookie, const CFDictionaryRef properties )
|
||||
{
|
||||
if( usagePage >= kHIDPage_VendorDefinedStart )
|
||||
return;
|
||||
|
||||
ASSERT( m_vSticks.size() );
|
||||
Joystick& js = m_vSticks.back();
|
||||
|
||||
@@ -92,6 +97,18 @@ void JoystickDevice::AddElement( int usagePage, int usage, int cookie, const CFD
|
||||
case kHIDUsage_GD_DPadLeft:
|
||||
js.mapping[cookie] = JOY_LEFT;
|
||||
break;
|
||||
case kHIDUsage_GD_Hatswitch:
|
||||
{
|
||||
if( iMax - iMin != 7 && iMax - iMin != 3 )
|
||||
break;
|
||||
js.hat = cookie;
|
||||
js.hat_min = iMin;
|
||||
js.hat_max = iMax;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LOG->Warn( "Unknown usagePage usage pair: (kHIDPage_GenericDesktop, %d).", usage );
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -101,8 +118,13 @@ void JoystickDevice::AddElement( int usagePage, int usage, int cookie, const CFD
|
||||
|
||||
if( buttonID <= JOY_BUTTON_32 )
|
||||
js.mapping[cookie] = buttonID;
|
||||
else
|
||||
LOG->Warn( "Button id too large: %d.", int(buttonID) );
|
||||
break;
|
||||
}
|
||||
default:
|
||||
//LOG->Warn( "Unknown usagePage usage pair: (%d, %d).", usagePage, usage );
|
||||
break;
|
||||
} // end switch (usagePage)
|
||||
}
|
||||
|
||||
@@ -115,6 +137,7 @@ void JoystickDevice::Open()
|
||||
#define ADD(x) if( js.x ) AddElementToQueue( js.x )
|
||||
ADD( x_axis ); ADD( y_axis ); ADD( z_axis );
|
||||
ADD( x_rot ); ADD( y_rot ); ADD( z_rot );
|
||||
ADD( hat );
|
||||
#undef ADD
|
||||
for( hash_map<int,DeviceButton>::const_iterator j = js.mapping.begin(); j != js.mapping.end(); ++j )
|
||||
AddElementToQueue( j->first );
|
||||
@@ -188,6 +211,30 @@ void JoystickDevice::GetButtonPresses( vector<DeviceInput>& vPresses, int cookie
|
||||
vPresses.push_back( DeviceInput(js.id, JOY_ROT_Z_DOWN, max(level, 0.0f), now) );
|
||||
break;
|
||||
}
|
||||
else if( js.hat == cookie )
|
||||
{
|
||||
float levelUp = 0.f, levelRight = 0.f, levelDown = 0.f, levelLeft = 0.f;
|
||||
|
||||
value -= js.hat_min; // Probably just subtracting 0.
|
||||
if( js.hat_max - js.hat_min == 3 )
|
||||
value *= 2;
|
||||
switch( value )
|
||||
{
|
||||
case 0: levelUp = 1.f; break; // U
|
||||
case 1: levelUp = 1.f; levelRight = 1.f; break; // UR
|
||||
case 2: levelRight = 1.f; break; // R
|
||||
case 3: levelDown = 1.f; levelRight = 1.f; break; // DR
|
||||
case 4: levelDown = 1.f; break; // D
|
||||
case 5: levelDown = 1.f; levelLeft = 1.f; break; // DL
|
||||
case 6: levelLeft = 1.f; break; // L
|
||||
case 7: levelUp = 1.f; levelLeft = 1.f; break; // UL
|
||||
}
|
||||
vPresses.push_back( DeviceInput(js.id, JOY_HAT_UP, levelUp, now) );
|
||||
vPresses.push_back( DeviceInput(js.id, JOY_HAT_RIGHT, levelRight, now) );
|
||||
vPresses.push_back( DeviceInput(js.id, JOY_HAT_DOWN, levelDown, now) );
|
||||
vPresses.push_back( DeviceInput(js.id, JOY_HAT_LEFT, levelLeft, now) );
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
// hash_map<T,U>::operator[] is not const
|
||||
|
||||
@@ -15,6 +15,7 @@ struct Joystick
|
||||
int x_rot, rx_min, rx_max;
|
||||
int y_rot, ry_min, ry_max;
|
||||
int z_rot, rz_min, rz_max;
|
||||
int hat, hat_min, hat_max;
|
||||
|
||||
Joystick();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user