fix clang warnings
[libpicofe.git] / linux / in_evdev.c
index 7dd631e..fed27f7 100644 (file)
@@ -1,10 +1,11 @@
 /*
- * (C) Gražvydas "notaz" Ignotas, 2008-2010
+ * (C) Gražvydas "notaz" Ignotas, 2008-2012
  *
  * This work is licensed under the terms of any of these licenses
  * (at your option):
  *  - GNU GPL, version 2 or later.
  *  - GNU LGPL, version 2.1 or later.
+ *  - MAME license.
  * See the COPYING file in the top-level directory.
  */
 
@@ -19,7 +20,7 @@
 #include <linux/input.h>
 #include <errno.h>
 
-#include "../common/input.h"
+#include "../input.h"
 #include "in_evdev.h"
 
 #define MAX_ABS_DEVS 8
@@ -37,8 +38,8 @@ typedef struct {
        int kc_first;
        int kc_last;
        unsigned int abs_count;
-       /* 16.16 multiplier to IN_ABS_RANGE */
-       unsigned int abs_mult[MAX_ABS_DEVS];
+       int abs_mult[MAX_ABS_DEVS]; /* 16.16 multiplier to IN_ABS_RANGE */
+       int abs_adj[MAX_ABS_DEVS];  /* adjust for centering */
        unsigned int abs_to_digital:1;
 } in_evdev_t;
 
@@ -60,7 +61,7 @@ int in_evdev_allow_abs_only;
 #define IN_EVDEV_PREFIX "evdev:"
 
 static const char * const in_evdev_keys[KEY_CNT] = {
-       [0 ... KEY_MAX] = NULL,
+       // [0 ... KEY_MAX] = NULL, // not necessary
        [KEY_RESERVED] = "Reserved",            [KEY_ESC] = "Esc",
        [KEY_1] = "1",                          [KEY_2] = "2",
        [KEY_3] = "3",                          [KEY_4] = "4",
@@ -246,6 +247,7 @@ static void in_evdev_probe(void)
                                dist = ainfo.maximum - ainfo.minimum;
                                if (dist != 0)
                                        dev->abs_mult[u] = IN_ABS_RANGE * 2 * 65536 / dist;
+                               dev->abs_adj[u] = -(ainfo.maximum + ainfo.minimum + 1) / 2;
                                have_abs = 1;
                        }
                        dev->abs_count = u;
@@ -371,7 +373,8 @@ static int in_evdev_update_analog(void *drv_data, int axis_id, int *result)
        if (ret != 0)
                return ret;
 
-       *result = (int)(ainfo.value * dev->abs_mult[axis_id]) >> 16;
+       *result = (ainfo.value + dev->abs_adj[axis_id]) * dev->abs_mult[axis_id];
+       *result >>= 16;
        return 0;
 }
 
@@ -557,9 +560,10 @@ static const struct {
 
 #define KEY_PBTN_MAP_SIZE (sizeof(key_pbtn_map) / sizeof(key_pbtn_map[0]))
 
-static int in_evdev_menu_translate(void *drv_data, int keycode)
+static int in_evdev_menu_translate(void *drv_data, int keycode, char *charcode)
 {
        in_evdev_t *dev = drv_data;
+       int ret = 0;
        int i;
 
        if (keycode < 0)
@@ -576,24 +580,25 @@ static int in_evdev_menu_translate(void *drv_data, int keycode)
        }
        else
        {
-               for (i = 0; i < KEY_PBTN_MAP_SIZE; i++)
-                       if (key_pbtn_map[i].key == keycode)
-                               return key_pbtn_map[i].pbtn;
-       }
-
-       return 0;
-}
-
-static void in_evdev_get_def_binds(int *binds)
-{
-       int i;
+               for (i = 0; i < KEY_PBTN_MAP_SIZE; i++) {
+                       if (key_pbtn_map[i].key == keycode) {
+                               ret = key_pbtn_map[i].pbtn;
+                               break;
+                       }
+               }
 
-       for (i = 0; ; i++) {
-               if (in_evdev_defbinds[i].bit == 0 && in_evdev_defbinds[i].code == 0)
-                       break;
-               binds[IN_BIND_OFFS(in_evdev_defbinds[i].code, in_evdev_defbinds[i].btype)] =
-                       1 << in_evdev_defbinds[i].bit;
+               if (charcode != NULL && (unsigned int)keycode < KEY_CNT &&
+                   in_evdev_keys[keycode] != NULL && in_evdev_keys[keycode][1] == 0)
+               {
+                       char c = in_evdev_keys[keycode][0];
+                       if ('A' <= c && c <= 'Z')
+                               c = 'a' + c - 'A';
+                       ret |= PBTN_CHAR;
+                       *charcode = c;
+               }
        }
+
+       return ret;
 }
 
 /* remove binds of missing keys, count remaining ones */
@@ -635,7 +640,6 @@ static const in_drv_t in_evdev_drv = {
        .probe          = in_evdev_probe,
        .free           = in_evdev_free,
        .get_key_names  = in_evdev_get_key_names,
-       .get_def_binds  = in_evdev_get_def_binds,
        .clean_binds    = in_evdev_clean_binds,
        .get_config     = in_evdev_get_config,
        .set_config     = in_evdev_set_config,
@@ -645,8 +649,8 @@ static const in_drv_t in_evdev_drv = {
        .menu_translate = in_evdev_menu_translate,
 };
 
-void in_evdev_init(void)
+void in_evdev_init(const struct in_default_bind *defbinds)
 {
-       in_register_driver(&in_evdev_drv);
+       in_register_driver(&in_evdev_drv, defbinds);
 }