ecore_input: add API to set/get deadzone of joystick event for an axis.
authorShinwoo Kim <cinoo.kim@samsung.com>
Wed, 15 Feb 2017 04:00:13 +0000 (13:00 +0900)
committerJean-Philippe Andre <jp.andre@samsung.com>
Wed, 15 Feb 2017 04:03:02 +0000 (13:03 +0900)
Summary:
The axis type joystick event could occur without user's control if joystick is too sensitive.
The deadzone prevents this unnecessary event. The default value is 200.
The event value for an axis is a signed integer between -32767 and +32767.

Test Plan: Using example

Reviewers: raster, cedric, jpeg

Reviewed By: jpeg

Subscribers: stefan_schmidt

Differential Revision: https://phab.enlightenment.org/D4654

src/examples/ecore/ecore_input_joystick_example.c
src/lib/ecore_input/Ecore_Input.h
src/lib/ecore_input/ecore_input_joystick.c

index ecf3433..c2c962b 100644 (file)
@@ -7,6 +7,7 @@
 static Eina_Bool
 _joystick_event_handler_cb(void *data, int type EINA_UNUSED, void *event)
 {
+   printf("deadzone: %d\n", ecore_input_joystick_event_axis_deadzone_get());
    Ecore_Event_Joystick *ev = event;
    switch (ev->type)
      {
@@ -50,6 +51,7 @@ main(void)
    ecore_event_handler_add(ECORE_EVENT_JOYSTICK,
                            _joystick_event_handler_cb,
                            NULL);
+   ecore_input_joystick_event_axis_deadzone_set(300);
 
    printf("start the main loop.\n");
 
index 6486c13..c1050cc 100644 (file)
@@ -457,6 +457,27 @@ extern "C" {
     */
    EAPI Ecore_Compose_State  ecore_compose_get(const Eina_List *seq, char **seqstr_ret);
 
+   /**
+    * Set deadzone of joystick event for an axis.
+    *
+    * The axis type joystick event occurs without user's control if joystick is
+    * too sensitive. The deadzone prevents unnecessary events.
+    * The default value is 200. The event value for an axis is a signed integer
+    * between -32767 and +32767.
+    *
+    * @param event_axis_deadzone The joystick event axis deadzone.
+    * @since 1.19
+    */
+   EAPI void ecore_input_joystick_event_axis_deadzone_set(int event_axis_deadzone);
+
+   /**
+    * Get deadzone of joystick event for an axis.
+    *
+    * @return deadzone of joystick event for an axis.
+    * @since 1.19
+    */
+   EAPI int ecore_input_joystick_event_axis_deadzone_get(void);
+
 #ifdef __cplusplus
 }
 #endif
index 33ce129..4f2fd11 100644 (file)
@@ -19,6 +19,7 @@
 #include "ecore_input_private.h"
 
 static int _ecore_input_joystick_init_count = 0;
+static int _event_axis_deadzone = 200;
 
 #ifdef HAVE_EEZE
 
@@ -382,8 +383,14 @@ _joystick_event_add(struct js_event *event, Joystick_Info *ji)
    Ecore_Event_Joystick *e;
 
    if ((event->type != JS_EVENT_BUTTON) && (event->type != JS_EVENT_AXIS)) return;
+   if ((event->type == JS_EVENT_AXIS) &&
+       ((event->value != 0) && (abs(event->value) < _event_axis_deadzone)))
+     {
+        INF("axis event value(%d) is less than deadzone(%d)\n",
+            event->value,_event_axis_deadzone);
+        return;
+     }
    if (!(e = calloc(1, sizeof(Ecore_Event_Joystick)))) return;
-
    e->index = ji->index;
    e->timestamp = event->time;
 
@@ -599,3 +606,18 @@ ecore_input_joystick_shutdown(void)
 
    return _ecore_input_joystick_init_count;
 }
+
+EAPI void
+ecore_input_joystick_event_axis_deadzone_set(int event_axis_deadzone)
+{
+   event_axis_deadzone = abs(event_axis_deadzone);
+   if (event_axis_deadzone > 32767) event_axis_deadzone = 32767;
+
+   _event_axis_deadzone = event_axis_deadzone;
+}
+
+EAPI int
+ecore_input_joystick_event_axis_deadzone_get(void)
+{
+   return _event_axis_deadzone;
+}