ecore_input: support Xbox One joystick 58/117658/1
authorShinwoo Kim <cinoo.kim@samsung.com>
Wed, 1 Feb 2017 07:33:52 +0000 (16:33 +0900)
committerShinwoo Kim <cinoo.kim@samsung.com>
Tue, 7 Mar 2017 04:56:12 +0000 (13:56 +0900)
Add joystick mapper for Microsoft X-Box One pad (Covert Forces)

Change-Id: I4c8610bb76968ec3dfad347c7f266c76734a443c

src/lib/ecore_input/ecore_input_joystick.c

index 7913a0e..33ce129 100644 (file)
@@ -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;