summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinwoo Kim <cinoo.kim@samsung.com>2017-01-25 22:31:03 +0900
committerShinwoo Kim <cinoo.kim@samsung.com>2017-01-25 22:35:47 +0900
commit308b0f82fa6ad0a44914e12a36eec5b91c58f06e (patch)
tree69ddb5ce49ab44d68c22706e50e9168ed6b36094
parente22de294617c77770d64f3bfec9b08bac89e5017 (diff)
ecore_input: support PS4 joystick
Add joystick mapper for Sony Computer Entertainment Wireless Controller
-rw-r--r--src/lib/ecore_input/ecore_input_joystick.c109
1 files changed, 108 insertions, 1 deletions
diff --git a/src/lib/ecore_input/ecore_input_joystick.c b/src/lib/ecore_input/ecore_input_joystick.c
index 1b17abf140..7913a0ef7f 100644
--- a/src/lib/ecore_input/ecore_input_joystick.c
+++ b/src/lib/ecore_input/ecore_input_joystick.c
@@ -24,6 +24,7 @@ static int _ecore_input_joystick_init_count = 0;
24 24
25typedef void (*Joystick_Mapper)(struct js_event *event, Ecore_Event_Joystick *e); 25typedef void (*Joystick_Mapper)(struct js_event *event, Ecore_Event_Joystick *e);
26static void _joystick_xiinput_mapper(struct js_event *event, Ecore_Event_Joystick *e); 26static void _joystick_xiinput_mapper(struct js_event *event, Ecore_Event_Joystick *e);
27static void _joystick_ps4_mapper(struct js_event *event, Ecore_Event_Joystick *e);
27 28
28struct _Joystick_Info 29struct _Joystick_Info
29{ 30{
@@ -39,7 +40,10 @@ struct _Joystick_Mapping_Info
39 const char *vendor; 40 const char *vendor;
40 const char *product; 41 const char *product;
41 Joystick_Mapper mapper; 42 Joystick_Mapper mapper;
42} Joystick_Mapping_Info[] = {{"045e", "028e", _joystick_xiinput_mapper}}; 43} Joystick_Mapping_Info[] = {
44 {"045e", "028e", _joystick_xiinput_mapper}, /* Microsoft X-Box 360 pad */
45 {"054c", "05c4", _joystick_ps4_mapper} /* Sony Computer Entertainment Wireless Controller */
46};
43 47
44static const char joystickPrefix[] = "/dev/input/js"; 48static const char joystickPrefix[] = "/dev/input/js";
45static Eina_List *joystick_list; 49static Eina_List *joystick_list;
@@ -62,6 +66,109 @@ _joystick_connected_event_add(int index, Eina_Bool connected)
62} 66}
63 67
64static void 68static void
69_joystick_ps4_mapper(struct js_event *event, Ecore_Event_Joystick *e)
70{
71 if (event->type == JS_EVENT_BUTTON)
72 {
73 e->type = ECORE_EVENT_JOYSTICK_EVENT_TYPE_BUTTON;
74 e->button.value = event->value;
75 switch (event->number)
76 {
77 case 0:
78 e->button.index = ECORE_EVENT_JOYSTICK_BUTTON_FACE_0;
79 break;
80
81 case 1:
82 e->button.index = ECORE_EVENT_JOYSTICK_BUTTON_FACE_1;
83 break;
84
85 case 2:
86 e->button.index = ECORE_EVENT_JOYSTICK_BUTTON_FACE_2;
87 break;
88
89 case 3:
90 e->button.index = ECORE_EVENT_JOYSTICK_BUTTON_FACE_3;
91 break;
92
93 case 4:
94 e->button.index = ECORE_EVENT_JOYSTICK_BUTTON_LEFT_SHOULDER;
95 break;
96
97 case 5:
98 e->button.index = ECORE_EVENT_JOYSTICK_BUTTON_RIGHT_SHOULDER;
99 break;
100
101 case 8:
102 e->button.index = ECORE_EVENT_JOYSTICK_BUTTON_SELECT;
103 break;
104
105 case 9:
106 e->button.index = ECORE_EVENT_JOYSTICK_BUTTON_META;
107 break;
108
109 case 10:
110 e->button.index = ECORE_EVENT_JOYSTICK_BUTTON_LEFT_ANALOG_STICK;
111 break;
112
113 case 11:
114 e->button.index = ECORE_EVENT_JOYSTICK_BUTTON_RIGHT_ANALOG_STICK;
115 break;
116
117 case 12:
118 e->button.index = ECORE_EVENT_JOYSTICK_BUTTON_START;
119 break;
120
121 default:
122 ERR("Unsupported joystick event: %d", event->number);
123 break;
124 }
125 }
126 else
127 {
128 e->type = ECORE_EVENT_JOYSTICK_EVENT_TYPE_AXIS;
129 e->axis.value = event->value / 32767.0f;;
130 switch (event->number)
131 {
132 case 0:
133 e->axis.index = ECORE_EVENT_JOYSTICK_AXIS_LEFT_ANALOG_HOR;
134 break;
135
136 case 1:
137 e->axis.index = ECORE_EVENT_JOYSTICK_AXIS_LEFT_ANALOG_VER;
138 break;
139
140 case 2:
141 e->axis.index = ECORE_EVENT_JOYSTICK_AXIS_RIGHT_ANALOG_HOR;
142 break;
143
144 case 3:
145 e->axis.index = ECORE_EVENT_JOYSTICK_AXIS_LEFT_SHOULDER;
146 break;
147
148 case 4:
149 e->axis.index = ECORE_EVENT_JOYSTICK_AXIS_RIGHT_SHOULDER;
150 break;
151
152 case 5:
153 e->axis.index = ECORE_EVENT_JOYSTICK_AXIS_RIGHT_ANALOG_VER;
154 break;
155
156 case 6:
157 e->axis.index = ECORE_EVENT_JOYSTICK_AXIS_HAT_X;
158 break;
159
160 case 7:
161 e->axis.index = ECORE_EVENT_JOYSTICK_AXIS_HAT_Y;
162 break;
163
164 default:
165 ERR("Unsupported joystick event: %d", event->number);
166 break;
167 }
168 }
169}
170
171static void
65_joystick_xiinput_mapper(struct js_event *event, Ecore_Event_Joystick *e) 172_joystick_xiinput_mapper(struct js_event *event, Ecore_Event_Joystick *e)
66{ 173{
67 if (event->type == JS_EVENT_BUTTON) 174 if (event->type == JS_EVENT_BUTTON)