droid: add controller/gamepad handling
[vuplus_xbmc] / xbmc / android / activity / AndroidJoyStick.h
1 #pragma once
2 /*
3  *      Copyright (C) 2012-2013 Team XBMC
4  *      http://xbmc.org
5  *
6  *  This Program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2, or (at your option)
9  *  any later version.
10  *
11  *  This Program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with XBMC; see the file COPYING.  If not, see
18  *  <http://www.gnu.org/licenses/>.
19  *
20  */
21
22 #include <string>
23 #include <vector>
24
25 struct AInputEvent;
26
27 typedef struct {
28   float     flat;
29   float     fuzz;
30   float     min;
31   float     max;
32   float     range;
33   float     value;
34   // internal helper values
35   bool      enabled;
36   float     deadzone;
37   float     buttonclamp;
38 } APP_InputDeviceAxis;
39
40 typedef struct {
41   int32_t id;
42   APP_InputDeviceAxis x_hat;
43   APP_InputDeviceAxis y_hat;
44   APP_InputDeviceAxis x_axis;
45   APP_InputDeviceAxis y_axis;
46   APP_InputDeviceAxis z_axis;
47   APP_InputDeviceAxis rz_axis;
48 } APP_InputDeviceAxes;
49
50 class CAndroidJoyStick
51 {
52 public:
53   CAndroidJoyStick();
54  ~CAndroidJoyStick();
55
56   bool onJoyStickKeyEvent(AInputEvent* event);
57   bool onJoyStickMotionEvent(AInputEvent* event);
58
59 private:
60   void  ProcessMotionEvents(AInputEvent *event, size_t pointer_index,
61           int32_t device, APP_InputDeviceAxes *axes);
62   bool  ProcessHat( AInputEvent *event, size_t pointer_index,
63           APP_InputDeviceAxis &hat, int device, int keymap_axis, int android_axis);
64   bool  ProcessAxis(AInputEvent *event, size_t pointer_index,
65           APP_InputDeviceAxis &axis, int device, int keymap_axis, int android_axis);
66
67   void  XBMC_JoyAxis(uint8_t device, uint8_t axis, float value);
68   void  XBMC_JoyButton(uint8_t device, uint8_t button, uint32_t holdtime, bool up);
69
70   uint8_t               m_prev_device;
71   uint8_t               m_prev_button;
72   uint32_t              m_prev_holdtime;
73   std::vector<APP_InputDeviceAxes*> m_input_devices;
74 };