jpeg pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=32fbf64d285b0d3172f305c6fe0392c7e2624c2b

commit 32fbf64d285b0d3172f305c6fe0392c7e2624c2b
Author: Shinwoo Kim <cinoo....@samsung.com>
Date:   Wed Feb 15 13:00:13 2017 +0900

    ecore_input: add API to set/get deadzone of joystick event for an axis.
    
    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 |  2 ++
 src/lib/ecore_input/Ecore_Input.h                 | 21 ++++++++++++++++++++
 src/lib/ecore_input/ecore_input_joystick.c        | 24 ++++++++++++++++++++++-
 3 files changed, 46 insertions(+), 1 deletion(-)

diff --git a/src/examples/ecore/ecore_input_joystick_example.c 
b/src/examples/ecore/ecore_input_joystick_example.c
index ecf3433..c2c962b 100644
--- a/src/examples/ecore/ecore_input_joystick_example.c
+++ b/src/examples/ecore/ecore_input_joystick_example.c
@@ -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");
 
diff --git a/src/lib/ecore_input/Ecore_Input.h 
b/src/lib/ecore_input/Ecore_Input.h
index 6486c13..c1050cc 100644
--- a/src/lib/ecore_input/Ecore_Input.h
+++ b/src/lib/ecore_input/Ecore_Input.h
@@ -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
diff --git a/src/lib/ecore_input/ecore_input_joystick.c 
b/src/lib/ecore_input/ecore_input_joystick.c
index 33ce129..4f2fd11 100644
--- a/src/lib/ecore_input/ecore_input_joystick.c
+++ b/src/lib/ecore_input/ecore_input_joystick.c
@@ -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;
+}

-- 


Reply via email to