root/branches/dev/wminput/conf.h

Revision 124, 5.7 kB (checked in by dsmith, 2 years ago)

wminput plugin refactoring

Line 
1 /* Copyright (C) 2007 L. Donnie Smith <wiimote@abstrakraft.org>
2  *
3  *  This program is free software; you can redistribute it and/or modify
4  *  it under the terms of the GNU General Public License as published by
5  *  the Free Software Foundation; either version 2 of the License, or
6  *  (at your option) any later version.
7  *
8  *  This program is distributed in the hope that it will be useful,
9  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  *  GNU General Public License for more details.
12  *
13  *  You should have received a copy of the GNU General Public License
14  *  along with this program; if not, write to the Free Software
15  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
16  *
17  *  ChangeLog:
18  *  2007-06-05 L. Donnie Smith <cwiid@abstrakraft.org>
19  *  * refactored to isolate plugin logic
20  *
21  *  2007-06-01 L. Donnie Smith <cwiid@abstrakraft.org>
22  *  * added python plugin support
23  *
24  *  2007-04-09 L. Donnie Smith <cwiid@abstrakraft.org>
25  *  * updated for libcwiid rename
26  *
27  *  2007-04-08 L. Donnie Smith <cwiid@abstrakraft.org>
28  *  * added conf_plugin_param_{int,float} prototypes
29  *
30  *  2007-04-03 L. Donnie Smith <cwiid@abstrakraft.org>
31  *  * added stdio.h include
32  *
33  *  2007-03-02 L. Donnie Smith <cwiid@abstrakraft.org>
34  *  * Initial ChangeLog
35  *  * type audit (stdint, const, char booleans)
36  */
37
38 #ifndef CONF_H
39 #define CONF_H
40
41 #include <stdint.h>
42 #include <stdio.h>
43 #include <linux/input.h>
44 #include <linux/uinput.h>
45
46 #include "cwiid.h"
47 #include "wmplugin.h"
48 #include "y.tab.h"
49
50 #define CONF_WM 1
51 #define CONF_NC 2
52 #define CONF_CC 3
53
54 #define CONF_WM_BTN_UP          0
55 #define CONF_WM_BTN_DOWN        1
56 #define CONF_WM_BTN_LEFT        2
57 #define CONF_WM_BTN_RIGHT       3
58 #define CONF_WM_BTN_A           4
59 #define CONF_WM_BTN_B           5
60 #define CONF_WM_BTN_MINUS       6
61 #define CONF_WM_BTN_PLUS        7
62 #define CONF_WM_BTN_HOME        8
63 #define CONF_WM_BTN_1           9
64 #define CONF_WM_BTN_2           10
65
66 #define CONF_NC_BTN_C           0
67 #define CONF_NC_BTN_Z           1
68
69 #define CONF_CC_BTN_UP          0
70 #define CONF_CC_BTN_DOWN        1
71 #define CONF_CC_BTN_LEFT        2
72 #define CONF_CC_BTN_RIGHT       3
73 #define CONF_CC_BTN_MINUS       4
74 #define CONF_CC_BTN_PLUS        5
75 #define CONF_CC_BTN_HOME        6
76 #define CONF_CC_BTN_A           7
77 #define CONF_CC_BTN_B           8
78 #define CONF_CC_BTN_X           9
79 #define CONF_CC_BTN_Y           10
80 #define CONF_CC_BTN_ZL          11
81 #define CONF_CC_BTN_ZR          12
82 #define CONF_CC_BTN_L           13
83 #define CONF_CC_BTN_R           14
84
85 #define CONF_WM_BTN_COUNT       11
86 #define CONF_NC_BTN_COUNT       2
87 #define CONF_CC_BTN_COUNT       15
88
89 #define CONF_WM_AXIS_DPAD_X             0
90 #define CONF_WM_AXIS_DPAD_Y             1
91 #define CONF_NC_AXIS_STICK_X    2
92 #define CONF_NC_AXIS_STICK_Y    3
93 #define CONF_CC_AXIS_DPAD_X             4
94 #define CONF_CC_AXIS_DPAD_Y             5
95 #define CONF_CC_AXIS_L_STICK_X  6
96 #define CONF_CC_AXIS_L_STICK_Y  7
97 #define CONF_CC_AXIS_R_STICK_X  8
98 #define CONF_CC_AXIS_R_STICK_Y  9
99 #define CONF_CC_AXIS_L                  10
100 #define CONF_CC_AXIS_R                  11
101
102 #define CONF_AXIS_COUNT         12
103
104 #define CONF_MAX_PLUGINS        6
105
106 #define CONF_ABS        EV_ABS
107 #define CONF_REL        EV_REL
108
109 /* flags */
110 #define CONF_INVERT             0x01
111 #define CONF_POINTER    0x02
112
113 #define UINPUT_NAME             "Nintendo Wiimote"
114 #ifdef BUS_BLUETOOTH
115 #define UINPUT_BUSTYPE  BUS_BLUETOOTH
116 #else
117 #define UINPUT_BUSTYPE BUS_USB
118 #endif
119 #define UINPUT_VENDOR   0x0001
120 #define UINPUT_PRODUCT  0x0001
121 #define UINPUT_VERSION  0x0001
122
123 struct lookup_enum {
124         const char *name;
125         __u16 value;
126 };
127
128 struct btn_map {
129         unsigned char active;
130         uint16_t mask;
131         __u16 action;
132 };
133
134 struct axis_map {
135         unsigned char active;
136         __u16 axis_type;
137         __u16 action;
138         uint8_t flags;
139 };
140
141 enum plugin_type {
142         PLUGIN_C,
143         PLUGIN_PYTHON
144 };
145
146 struct plugin {
147         char *name;
148         enum plugin_type type;
149         uint8_t rpt_mode_flags;
150         struct wmplugin_info *info;
151         struct wmplugin_data *data;
152         uint16_t prev_buttons;
153         struct btn_map bmap[WMPLUGIN_MAX_BUTTON_COUNT];
154         struct axis_map amap[WMPLUGIN_MAX_AXIS_COUNT];
155         void *p;
156 };
157
158 #define CONF_MAX_INCLUDE_DEPTH  10
159
160 struct conf {
161         int fd;
162         char **config_search_dirs;
163         char **plugin_search_dirs;
164         char *current_config_filename;
165         int stack_index;
166         char *config_filename_stack[CONF_MAX_INCLUDE_DEPTH];
167         YYLTYPE yyloc_stack[CONF_MAX_INCLUDE_DEPTH];
168         uint8_t rpt_mode_flags;
169         struct uinput_user_dev dev;
170         unsigned char ff;
171         struct btn_map wiimote_bmap[CONF_WM_BTN_COUNT];
172         struct btn_map nunchuk_bmap[CONF_NC_BTN_COUNT];
173         struct btn_map classic_bmap[CONF_CC_BTN_COUNT];
174         struct axis_map amap[CONF_AXIS_COUNT];
175         struct plugin plugins[CONF_MAX_PLUGINS];
176 };
177
178 struct uinput_listen_data {
179         cwiid_wiimote_t *wiimote;
180         struct conf *conf;
181 };
182
183 int conf_load(struct conf *conf, const char *conf_name,
184               char *config_search_dirs[], char *plugin_search_dirs[]);
185 int conf_unload(struct conf *conf);
186
187 int conf_ff(struct conf *conf, unsigned char enabled);
188 int conf_button(struct conf *conf, int source, __u16 button, __u16 action);
189 int conf_axis(struct conf *conf, int axis, __u16 axis_type, __u16 action,
190               char flags);
191 int conf_plugin_button(struct conf *conf, const char *name, const char *button,
192                        __u16 action);
193 int conf_plugin_axis(struct conf *conf, const char *name, const char *axis,
194                      __u16 axis_type, __u16 action, char flags);
195 int conf_plugin_param_int(struct conf *conf, const char *name,
196                           const char *param, int value);
197 int conf_plugin_param_float(struct conf *conf, const char *name,
198                             const char *param, float value);
199
200 void conf_init(struct conf *conf);
201 FILE *conf_push_config(struct conf *conf, const char *filename, YYLTYPE *yyloc);
202 int conf_pop_config(struct conf *conf, YYLTYPE *yyloc);
203 int lookup_action(const char *str_action);
204
205 int uinput_open(struct conf *conf);
206 int uinput_close(struct conf *conf);
207 int send_event(struct conf *conf, __u16 type, __u16 code, __s32 value);
208 void *uinput_listen(struct uinput_listen_data *data);
209
210 #endif
211
Note: See TracBrowser for help on using the browser.