Support for my crappy cheap DragonRise Datex gamepad
This commit is contained in:
@@ -112,6 +112,8 @@ abstract class DifferentTouchInput
|
||||
Log.i("SDL", "Device model: " + android.os.Build.MODEL);
|
||||
if( android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH )
|
||||
{
|
||||
if( DetectCrappyDragonRiseDatexGamepad() )
|
||||
return CrappyDragonRiseDatexGamepadInputWhichNeedsItsOwnHandlerBecauseImTooCheapAndStupidToBuyProperGamepad.Holder.sInstance;
|
||||
return IcsTouchInput.Holder.sInstance;
|
||||
}
|
||||
if( android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD )
|
||||
@@ -131,6 +133,13 @@ abstract class DifferentTouchInput
|
||||
}
|
||||
}
|
||||
}
|
||||
private static boolean DetectCrappyDragonRiseDatexGamepad()
|
||||
{
|
||||
if( CrappyDragonRiseDatexGamepadInputWhichNeedsItsOwnHandlerBecauseImTooCheapAndStupidToBuyProperGamepad.Holder.sInstance == null )
|
||||
return false;
|
||||
return CrappyDragonRiseDatexGamepadInputWhichNeedsItsOwnHandlerBecauseImTooCheapAndStupidToBuyProperGamepad.Holder.sInstance.detect();
|
||||
}
|
||||
|
||||
private static class SingleTouchInput extends DifferentTouchInput
|
||||
{
|
||||
private static class Holder
|
||||
@@ -351,7 +360,6 @@ abstract class DifferentTouchInput
|
||||
// Joysticks are supported since Honeycomb, but I don't care about it, because very little devices have it
|
||||
if( (event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) == InputDevice.SOURCE_CLASS_JOYSTICK )
|
||||
{
|
||||
// event.getAxisValue(AXIS_HAT_X) and event.getAxisValue(AXIS_HAT_Y) are joystick arrow keys, they also send keyboard events
|
||||
DemoGLSurfaceView.nativeGamepadAnalogJoystickInput(
|
||||
event.getAxisValue(MotionEvent.AXIS_X), event.getAxisValue(MotionEvent.AXIS_Y),
|
||||
event.getAxisValue(MotionEvent.AXIS_Z), event.getAxisValue(MotionEvent.AXIS_RZ),
|
||||
@@ -369,6 +377,69 @@ abstract class DifferentTouchInput
|
||||
super.processGenericEvent(event);
|
||||
}
|
||||
}
|
||||
private static class CrappyDragonRiseDatexGamepadInputWhichNeedsItsOwnHandlerBecauseImTooCheapAndStupidToBuyProperGamepad extends IcsTouchInput
|
||||
{
|
||||
private static class Holder
|
||||
{
|
||||
private static final CrappyDragonRiseDatexGamepadInputWhichNeedsItsOwnHandlerBecauseImTooCheapAndStupidToBuyProperGamepad sInstance = new CrappyDragonRiseDatexGamepadInputWhichNeedsItsOwnHandlerBecauseImTooCheapAndStupidToBuyProperGamepad();
|
||||
}
|
||||
float hatX = 0.0f, hatY = 0.0f;
|
||||
public void processGenericEvent(final MotionEvent event)
|
||||
{
|
||||
// Joysticks are supported since Honeycomb, but I don't care about it, because very little devices have it
|
||||
if( (event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) == InputDevice.SOURCE_CLASS_JOYSTICK )
|
||||
{
|
||||
// event.getAxisValue(AXIS_HAT_X) and event.getAxisValue(AXIS_HAT_Y) are joystick arrow keys, they also send keyboard events
|
||||
DemoGLSurfaceView.nativeGamepadAnalogJoystickInput(
|
||||
event.getAxisValue(MotionEvent.AXIS_X), event.getAxisValue(MotionEvent.AXIS_Y),
|
||||
event.getAxisValue(MotionEvent.AXIS_RX), event.getAxisValue(MotionEvent.AXIS_RZ),
|
||||
0, 0);
|
||||
if( event.getAxisValue(MotionEvent.AXIS_HAT_X) != hatX )
|
||||
{
|
||||
hatX = event.getAxisValue(MotionEvent.AXIS_HAT_X);
|
||||
if( hatX == 0.0f )
|
||||
{
|
||||
DemoGLSurfaceView.nativeKey(KeyEvent.KEYCODE_DPAD_LEFT, 0);
|
||||
DemoGLSurfaceView.nativeKey(KeyEvent.KEYCODE_DPAD_RIGHT, 0);
|
||||
}
|
||||
else
|
||||
DemoGLSurfaceView.nativeKey(hatX < 0.0f ? KeyEvent.KEYCODE_DPAD_LEFT : KeyEvent.KEYCODE_DPAD_RIGHT, 1);
|
||||
}
|
||||
if( event.getAxisValue(MotionEvent.AXIS_HAT_Y) != hatY )
|
||||
{
|
||||
hatY = event.getAxisValue(MotionEvent.AXIS_HAT_Y);
|
||||
if( hatY == 0.0f )
|
||||
{
|
||||
DemoGLSurfaceView.nativeKey(KeyEvent.KEYCODE_DPAD_UP, 0);
|
||||
DemoGLSurfaceView.nativeKey(KeyEvent.KEYCODE_DPAD_DOWN, 0);
|
||||
}
|
||||
else
|
||||
DemoGLSurfaceView.nativeKey(hatY < 0.0f ? KeyEvent.KEYCODE_DPAD_UP : KeyEvent.KEYCODE_DPAD_DOWN, 1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
super.processGenericEvent(event);
|
||||
}
|
||||
public boolean detect()
|
||||
{
|
||||
int[] devIds = InputDevice.getDeviceIds();
|
||||
for( int id : devIds )
|
||||
{
|
||||
InputDevice device = InputDevice.getDevice(id);
|
||||
if( device == null )
|
||||
continue;
|
||||
System.out.println("libSDL: input device ID " + id + " type " + device.getSources() + " name " + device.getName() );
|
||||
if( (device.getSources() & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD &&
|
||||
(device.getSources() & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK &&
|
||||
device.getName().indexOf("DragonRise Inc") == 0 )
|
||||
{
|
||||
System.out.println("libSDL: Detected crappy DragonRise gamepad, enabling special hack for it. Please press button labeled 'Analog', otherwise it won't work, because it's cheap and crappy");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -222,18 +222,19 @@ void SDL_android_init_keymap(SDLKey *SDL_android_keymap)
|
||||
keymap[KEYCODE_PROG_YELLOW] = SDL_KEY(F15);
|
||||
keymap[KEYCODE_PROG_BLUE] = SDL_KEY(F1);
|
||||
keymap[KEYCODE_APP_SWITCH] = SDL_KEY(F2);
|
||||
keymap[KEYCODE_BUTTON_1] = SDL_KEY(A);
|
||||
keymap[KEYCODE_BUTTON_2] = SDL_KEY(B);
|
||||
keymap[KEYCODE_BUTTON_3] = SDL_KEY(C);
|
||||
keymap[KEYCODE_BUTTON_4] = SDL_KEY(D);
|
||||
keymap[KEYCODE_BUTTON_5] = SDL_KEY(E);
|
||||
keymap[KEYCODE_BUTTON_6] = SDL_KEY(F);
|
||||
keymap[KEYCODE_BUTTON_7] = SDL_KEY(G);
|
||||
keymap[KEYCODE_BUTTON_8] = SDL_KEY(H);
|
||||
keymap[KEYCODE_BUTTON_9] = SDL_KEY(I);
|
||||
keymap[KEYCODE_BUTTON_10] = SDL_KEY(J);
|
||||
keymap[KEYCODE_BUTTON_11] = SDL_KEY(K);
|
||||
keymap[KEYCODE_BUTTON_12] = SDL_KEY(L);
|
||||
// Key layout of my cheap crappy Datex gamepad, USB identifier is "DragonRise Inc."
|
||||
keymap[KEYCODE_BUTTON_1] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_3));
|
||||
keymap[KEYCODE_BUTTON_2] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_1));
|
||||
keymap[KEYCODE_BUTTON_3] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_0));
|
||||
keymap[KEYCODE_BUTTON_4] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_2));
|
||||
keymap[KEYCODE_BUTTON_5] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_4));
|
||||
keymap[KEYCODE_BUTTON_6] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_5));
|
||||
keymap[KEYCODE_BUTTON_7] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_6));
|
||||
keymap[KEYCODE_BUTTON_8] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_7));
|
||||
keymap[KEYCODE_BUTTON_9] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_KEYCODE_5));
|
||||
keymap[KEYCODE_BUTTON_10] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_KEYCODE_4));
|
||||
keymap[KEYCODE_BUTTON_11] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_8));
|
||||
keymap[KEYCODE_BUTTON_12] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_GAMEPAD_KEYCODE_9));
|
||||
keymap[KEYCODE_BUTTON_13] = SDL_KEY(M);
|
||||
keymap[KEYCODE_BUTTON_14] = SDL_KEY(N);
|
||||
keymap[KEYCODE_BUTTON_15] = SDL_KEY(O);
|
||||
|
||||
Reference in New Issue
Block a user