From 735aa67171c0686e2452809cd2b8fa344957542c Mon Sep 17 00:00:00 2001 From: "simon.kagstrom" Date: Mon, 11 May 2009 19:20:59 +0000 Subject: [PATCH] Add handling of the joystick hats. This allows the classic controller Dpad to be used (maybe the wiimote as well) --- src/jd-sdl/joystick.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/jd-sdl/joystick.c b/src/jd-sdl/joystick.c index 881cab1..40932b5 100644 --- a/src/jd-sdl/joystick.c +++ b/src/jd-sdl/joystick.c @@ -29,7 +29,7 @@ static struct joyinfo joys[MAX_INPUT_DEVICES]; static void read_joy (unsigned int nr) { - unsigned int num, i, axes, axis; + unsigned int num, i, axes, axis, hats; SDL_Joystick *joy; if (currprefs.input_selected_setting == 0) { @@ -43,6 +43,25 @@ static void read_joy (unsigned int nr) setjoystickstate (nr, i, axis, 32767); } + /* Handle hat - used e.g., for the Wii */ + hats = SDL_JoystickNumHats (joy); + for (i = 0; i < hats; i++) { + Uint8 v = SDL_JoystickGetHat (joy, i); + int x = 0, y = 0; + + if (v & SDL_HAT_UP) + y = -1; + if (v & SDL_HAT_DOWN) + y = 1; + if (v & SDL_HAT_LEFT) + x = -1; + if (v & SDL_HAT_RIGHT) + x = 1; + + setjoystickstate (nr, 0, x, 1); + setjoystickstate (nr, 1, y, 1); + } + num = SDL_JoystickNumButtons (joy); for (i = 0; i < num; i++) { int bs = SDL_JoystickGetButton (joy, i) ? 1 : 0;