From 5c9617c2cfda6dfffc26c90b212581013786262f Mon Sep 17 00:00:00 2001 From: Shinwoo Kim Date: Wed, 1 Feb 2017 16:33:52 +0900 Subject: [PATCH] ecore_input: support Xbox One joystick Add joystick mapper for Microsoft X-Box One pad (Covert Forces) --- src/lib/ecore_input/ecore_input_joystick.c | 111 ++++++++++++++++++++++++++++- 1 file changed, 108 insertions(+), 3 deletions(-) diff --git a/src/lib/ecore_input/ecore_input_joystick.c b/src/lib/ecore_input/ecore_input_joystick.c index 7913a0e..33ce129 100644 --- a/src/lib/ecore_input/ecore_input_joystick.c +++ b/src/lib/ecore_input/ecore_input_joystick.c @@ -23,7 +23,8 @@ static int _ecore_input_joystick_init_count = 0; #ifdef HAVE_EEZE typedef void (*Joystick_Mapper)(struct js_event *event, Ecore_Event_Joystick *e); -static void _joystick_xiinput_mapper(struct js_event *event, Ecore_Event_Joystick *e); +static void _joystick_xbox360_mapper(struct js_event *event, Ecore_Event_Joystick *e); +static void _joystick_xboxone_mapper(struct js_event *event, Ecore_Event_Joystick *e); static void _joystick_ps4_mapper(struct js_event *event, Ecore_Event_Joystick *e); struct _Joystick_Info @@ -41,7 +42,8 @@ struct _Joystick_Mapping_Info const char *product; Joystick_Mapper mapper; } Joystick_Mapping_Info[] = { - {"045e", "028e", _joystick_xiinput_mapper}, /* Microsoft X-Box 360 pad */ + {"045e", "028e", _joystick_xbox360_mapper}, /* Microsoft X-Box 360 pad */ + {"045e", "02dd", _joystick_xboxone_mapper}, /* Microsoft X-Box One pad (Covert Forces) */ {"054c", "05c4", _joystick_ps4_mapper} /* Sony Computer Entertainment Wireless Controller */ }; @@ -169,7 +171,7 @@ _joystick_ps4_mapper(struct js_event *event, Ecore_Event_Joystick *e) } static void -_joystick_xiinput_mapper(struct js_event *event, Ecore_Event_Joystick *e) +_joystick_xbox360_mapper(struct js_event *event, Ecore_Event_Joystick *e) { if (event->type == JS_EVENT_BUTTON) { @@ -272,6 +274,109 @@ _joystick_xiinput_mapper(struct js_event *event, Ecore_Event_Joystick *e) } static void +_joystick_xboxone_mapper(struct js_event *event, Ecore_Event_Joystick *e) +{ + if (event->type == JS_EVENT_BUTTON) + { + e->type = ECORE_EVENT_JOYSTICK_EVENT_TYPE_BUTTON; + e->button.value = event->value; + switch (event->number) + { + case 0: + e->button.index = ECORE_EVENT_JOYSTICK_BUTTON_FACE_0; + break; + + case 1: + e->button.index = ECORE_EVENT_JOYSTICK_BUTTON_FACE_1; + break; + + case 2: + e->button.index = ECORE_EVENT_JOYSTICK_BUTTON_FACE_2; + break; + + case 3: + e->button.index = ECORE_EVENT_JOYSTICK_BUTTON_FACE_3; + break; + + case 4: + e->button.index = ECORE_EVENT_JOYSTICK_BUTTON_LEFT_SHOULDER; + break; + + case 5: + e->button.index = ECORE_EVENT_JOYSTICK_BUTTON_RIGHT_SHOULDER; + break; + + case 6: + e->button.index = ECORE_EVENT_JOYSTICK_BUTTON_META; + break; + + case 7: + e->button.index = ECORE_EVENT_JOYSTICK_BUTTON_SELECT; + break; + + case 8: + e->button.index = ECORE_EVENT_JOYSTICK_BUTTON_START; + break; + + case 9: + e->button.index = ECORE_EVENT_JOYSTICK_BUTTON_LEFT_ANALOG_STICK; + break; + + case 10: + e->button.index = ECORE_EVENT_JOYSTICK_BUTTON_RIGHT_ANALOG_STICK; + break; + + default: + ERR("Unsupported joystick event: %d", event->number); + break; + } + } + else + { + e->type = ECORE_EVENT_JOYSTICK_EVENT_TYPE_AXIS; + e->axis.value = event->value / 32767.0f;; + switch (event->number) + { + case 0: + e->axis.index = ECORE_EVENT_JOYSTICK_AXIS_LEFT_ANALOG_HOR; + break; + + case 1: + e->axis.index = ECORE_EVENT_JOYSTICK_AXIS_LEFT_ANALOG_VER; + break; + + case 2: + e->axis.index = ECORE_EVENT_JOYSTICK_AXIS_LEFT_SHOULDER; + break; + + case 3: + e->axis.index = ECORE_EVENT_JOYSTICK_AXIS_RIGHT_ANALOG_HOR; + break; + + case 4: + e->axis.index = ECORE_EVENT_JOYSTICK_AXIS_RIGHT_ANALOG_VER; + break; + + case 5: + e->axis.index = ECORE_EVENT_JOYSTICK_AXIS_RIGHT_SHOULDER; + break; + + case 6: + e->axis.index = ECORE_EVENT_JOYSTICK_AXIS_HAT_X; + break; + + case 7: + e->axis.index = ECORE_EVENT_JOYSTICK_AXIS_HAT_Y; + break; + + default: + ERR("Unsupported joystick event: %d", event->number); + break; + } + } +} + +static void _joystick_event_add(struct js_event *event, Joystick_Info *ji) { Ecore_Event_Joystick *e; -- 2.7.4