root/trunk/libcwiid/cwiid.h

Revision 155, 9.0 kB (checked in by dsmith, 1 year ago)

type fixes

Line 
1 /* Copyright (C) 2007 L. Donnie Smith <cwiid@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-08-14 L. Donnie Smith <cwiid@abstrakraft.org>
19  *  * make cwiid_err_default public
20  *
21  *  2007-05-16 L. Donnie Smith <cwiid@abstrakraft.org>
22  *  * changed cwiid_connect, cwiid_disconnect to cwiid_open, cwiid_close
23  *  * added cwiid_request_status, cwiid_set_let, cwiid_set_rumble,
24  *    cwiid_set_rpt_mode
25  *
26  *  2007-05-14 L. Donnie Smith <cwiid@abstrakraft.org>
27  *  * added timestamp to message functions
28  *  * added cwiid_get_acc_cal
29  *
30  *  2007-04-24 L. Donnie Smith <cwiid@abstrakraft.org>
31  *  * rewrite for API overhaul
32  *
33  *  2007-04-09 L. Donnie Smith <cwiid@abstrakraft.org>
34  *  * renamed wiimote to libcwiid, renamed structures accordingly
35  *
36  *  2007-04-07 L. Donnie Smith <cwiid@abstrakraft.org>
37  *  * changed cwiid_info.class to btclass
38  *
39  *  2007-04-04 L. Donnie Smith <cwiid@abstrakraft.org>
40  *  * added cwiid_mesg_error message type
41  *
42  *  2007-04-01 L. Donnie Smith <cwiid@abstrakraft.org>
43  *  * cwiid_connect now takes a pointer to bdaddr_t
44  *  * added cwiid_info definition and macros
45  *  * added cwiid_get_info_array prototype
46  *  * changed cwiid_findfirst to cwiid_find_wiimote
47  *
48  *  2007-03-05 L. Donnie Smith <cwiid@abstrakraft.org>
49  *  * added cwiid_err_t definition
50  *  * added cwiid_set_err prototype
51  *
52  *  2007-03-01 L. Donnie Smith <cwiid@abstrakraft.org>
53  *  * Initial ChangeLog
54  *  * type audit (stdint, const, char booleans)
55  */
56
57 #ifndef CWIID_H
58 #define CWIID_H
59
60 #include <stdarg.h>
61 #include <stdint.h>
62 #include <time.h>
63 #include <bluetooth/bluetooth.h>        /* bdaddr_t */
64
65 /* Flags */
66 #define CWIID_FLAG_MESG_IFC             0x01
67 #define CWIID_FLAG_CONTINUOUS   0x02
68 #define CWIID_FLAG_REPEAT_BTN   0x04
69 #define CWIID_FLAG_NONBLOCK             0x08
70
71 /* Report Mode Flags */
72 #define CWIID_RPT_STATUS        0x01
73 #define CWIID_RPT_BTN           0x02
74 #define CWIID_RPT_ACC           0x04
75 #define CWIID_RPT_IR            0x08
76 #define CWIID_RPT_NUNCHUK       0x10
77 #define CWIID_RPT_CLASSIC       0x20
78 #define CWIID_RPT_EXT           (CWIID_RPT_NUNCHUK | CWIID_RPT_CLASSIC)
79
80 /* LED flags */
81 #define CWIID_LED1_ON   0x01
82 #define CWIID_LED2_ON   0x02
83 #define CWIID_LED3_ON   0x04
84 #define CWIID_LED4_ON   0x08
85
86 /* Button flags */
87 #define CWIID_BTN_2             0x0001
88 #define CWIID_BTN_1             0x0002
89 #define CWIID_BTN_B             0x0004
90 #define CWIID_BTN_A             0x0008
91 #define CWIID_BTN_MINUS 0x0010
92 #define CWIID_BTN_HOME  0x0080
93 #define CWIID_BTN_LEFT  0x0100
94 #define CWIID_BTN_RIGHT 0x0200
95 #define CWIID_BTN_DOWN  0x0400
96 #define CWIID_BTN_UP    0x0800
97 #define CWIID_BTN_PLUS  0x1000
98
99 #define CWIID_NUNCHUK_BTN_Z     0x01
100 #define CWIID_NUNCHUK_BTN_C     0x02
101
102 #define CWIID_CLASSIC_BTN_UP    0x0001
103 #define CWIID_CLASSIC_BTN_LEFT  0x0002
104 #define CWIID_CLASSIC_BTN_ZR    0x0004
105 #define CWIID_CLASSIC_BTN_X             0x0008
106 #define CWIID_CLASSIC_BTN_A             0x0010
107 #define CWIID_CLASSIC_BTN_Y             0x0020
108 #define CWIID_CLASSIC_BTN_B             0x0040
109 #define CWIID_CLASSIC_BTN_ZL    0x0080
110 #define CWIID_CLASSIC_BTN_R             0x0200
111 #define CWIID_CLASSIC_BTN_PLUS  0x0400
112 #define CWIID_CLASSIC_BTN_HOME  0x0800
113 #define CWIID_CLASSIC_BTN_MINUS 0x1000
114 #define CWIID_CLASSIC_BTN_L             0x2000
115 #define CWIID_CLASSIC_BTN_DOWN  0x4000
116 #define CWIID_CLASSIC_BTN_RIGHT 0x8000
117
118 /* Data Read/Write flags */
119 #define CWIID_RW_EEPROM 0x00
120 #define CWIID_RW_REG    0x04
121 #define CWIID_RW_DECODE 0x01
122
123 /* Maximum Data Read Length */
124 #define CWIID_MAX_READ_LEN      0xFFFF
125
126 /* Array Index Defs */
127 #define CWIID_X         0
128 #define CWIID_Y         1
129 #define CWIID_Z         2
130
131 /* Acc Defs */
132 #define CWIID_ACC_MAX   0xFF
133
134 /* IR Defs */
135 #define CWIID_IR_SRC_COUNT      4
136 #define CWIID_IR_X_MAX          1024
137 #define CWIID_IR_Y_MAX          768
138
139 /* Battery */
140 #define CWIID_BATTERY_MAX       0xD0
141
142 /* Classic Controller Maxes */
143 #define CWIID_CLASSIC_L_STICK_MAX       0x3F
144 #define CWIID_CLASSIC_R_STICK_MAX       0x1F
145 #define CWIID_CLASSIC_LR_MAX    0x1F
146
147 /* Environment Variables */
148 #define WIIMOTE_BDADDR  "WIIMOTE_BDADDR"
149
150 /* Callback Maximum Message Count */
151 #define CWIID_MAX_MESG_COUNT    5
152
153 /* Enumerations */
154 enum cwiid_command {
155         CWIID_CMD_STATUS,
156         CWIID_CMD_LED,
157         CWIID_CMD_RUMBLE,
158         CWIID_CMD_RPT_MODE
159 };
160
161 enum cwiid_mesg_type {
162         CWIID_MESG_STATUS,
163         CWIID_MESG_BTN,
164         CWIID_MESG_ACC,
165         CWIID_MESG_IR,
166         CWIID_MESG_NUNCHUK,
167         CWIID_MESG_CLASSIC,
168         CWIID_MESG_ERROR,
169         CWIID_MESG_UNKNOWN
170 };
171
172 enum cwiid_ext_type {
173         CWIID_EXT_NONE,
174         CWIID_EXT_NUNCHUK,
175         CWIID_EXT_CLASSIC,
176         CWIID_EXT_UNKNOWN
177 };
178
179 enum cwiid_error {
180         CWIID_ERROR_NONE,
181         CWIID_ERROR_DISCONNECT,
182         CWIID_ERROR_COMM
183 };
184
185 struct acc_cal {
186         uint8_t zero[3];
187         uint8_t one[3];
188 };
189
190 /* Message Structs */
191 struct cwiid_status_mesg {
192         enum cwiid_mesg_type type;
193         uint8_t battery;
194         enum cwiid_ext_type ext_type;
195 };     
196
197 struct cwiid_btn_mesg {
198         enum cwiid_mesg_type type;
199         uint16_t buttons;
200 };
201
202 struct cwiid_acc_mesg {
203         enum cwiid_mesg_type type;
204         uint8_t acc[3];
205 };
206
207 struct cwiid_ir_src {
208         char valid;
209         uint16_t pos[2];
210         int8_t size;
211 };
212
213 struct cwiid_ir_mesg {
214         enum cwiid_mesg_type type;
215         struct cwiid_ir_src src[CWIID_IR_SRC_COUNT];
216 };
217
218 struct cwiid_nunchuk_mesg {
219         enum cwiid_mesg_type type;
220         uint8_t stick[2];
221         uint8_t acc[3];
222         uint8_t buttons;
223 };
224
225 struct cwiid_classic_mesg {
226         enum cwiid_mesg_type type;
227         uint8_t l_stick[2];
228         uint8_t r_stick[2];
229         uint8_t l;
230         uint8_t r;
231         uint16_t buttons;
232 };
233
234 struct cwiid_error_mesg {
235         enum cwiid_mesg_type type;
236         enum cwiid_error error;
237 };
238
239 union cwiid_mesg {
240         enum cwiid_mesg_type type;
241         struct cwiid_status_mesg status_mesg;
242         struct cwiid_btn_mesg btn_mesg;
243         struct cwiid_acc_mesg acc_mesg;
244         struct cwiid_ir_mesg ir_mesg;
245         struct cwiid_nunchuk_mesg nunchuk_mesg;
246         struct cwiid_classic_mesg classic_mesg;
247         struct cwiid_error_mesg error_mesg;
248 };
249
250 /* State Structs */
251 struct nunchuk_state {
252         uint8_t stick[2];
253         uint8_t acc[3];
254         uint8_t buttons;
255 };
256
257 struct classic_state {
258         uint8_t l_stick[2];
259         uint8_t r_stick[2];
260         uint8_t l;
261         uint8_t r;
262         uint16_t buttons;
263 };
264
265 union ext_state {
266         struct nunchuk_state nunchuk;
267         struct classic_state classic;
268 };
269
270 struct cwiid_state {
271         uint8_t rpt_mode;
272         uint8_t led;
273         uint8_t rumble;
274         uint8_t battery;
275         uint16_t buttons;
276         uint8_t acc[3];
277         struct cwiid_ir_src ir_src[CWIID_IR_SRC_COUNT];
278         enum cwiid_ext_type ext_type;
279         union ext_state ext;
280         enum cwiid_error error;
281 };
282
283 /* Typedefs */
284 typedef struct wiimote cwiid_wiimote_t;
285
286 typedef void cwiid_mesg_callback_t(cwiid_wiimote_t *, int,
287                                    union cwiid_mesg [], struct timespec *);
288 typedef void cwiid_err_t(cwiid_wiimote_t *, const char *, va_list ap);
289
290 /* get_bdinfo */
291 #define BT_NO_WIIMOTE_FILTER 0x01
292 #define BT_NAME_LEN 32
293
294 struct cwiid_bdinfo {
295         bdaddr_t bdaddr;
296         uint8_t btclass[3];
297         char name[BT_NAME_LEN];
298 };
299
300 #ifdef __cplusplus
301 extern "C" {
302 #endif
303
304 /* Error reporting (library wide) */
305 int cwiid_set_err(cwiid_err_t *err);
306 void cwiid_err_default(struct wiimote *wiimote, const char *str, va_list ap);
307
308 /* Connection */
309 #define cwiid_connect cwiid_open
310 #define cwiid_disconnect cwiid_close
311 cwiid_wiimote_t *cwiid_open(bdaddr_t *bdaddr, int flags);
312 int cwiid_close(cwiid_wiimote_t *wiimote);
313
314 int cwiid_get_id(cwiid_wiimote_t *wiimote);
315 int cwiid_set_data(cwiid_wiimote_t *wiimote, const void *data);
316 const void *cwiid_get_data(cwiid_wiimote_t *wiimote);
317 int cwiid_enable(cwiid_wiimote_t *wiimote, int flags);
318 int cwiid_disable(cwiid_wiimote_t *wiimote, int flags);
319
320 /* Interfaces */
321 int cwiid_set_mesg_callback(cwiid_wiimote_t *wiimote,
322                        cwiid_mesg_callback_t *callback);
323 int cwiid_get_mesg(cwiid_wiimote_t *wiimote, int *mesg_count,
324                    union cwiid_mesg *mesg[], struct timespec *timestamp);
325 int cwiid_get_state(cwiid_wiimote_t *wiimote, struct cwiid_state *state);
326 int cwiid_get_acc_cal(struct wiimote *wiimote, enum cwiid_ext_type ext_type,
327                       struct acc_cal *acc_cal);
328
329 /* Operations */
330 int cwiid_command(cwiid_wiimote_t *wiimote, enum cwiid_command command,
331                   int flags);
332 int cwiid_request_status(cwiid_wiimote_t *wiimote);
333 int cwiid_set_led(cwiid_wiimote_t *wiimote, uint8_t led);
334 int cwiid_set_rumble(cwiid_wiimote_t *wiimote, uint8_t rumble);
335 int cwiid_set_rpt_mode(cwiid_wiimote_t *wiimote, uint8_t rpt_mode);
336 int cwiid_read(cwiid_wiimote_t *wiimote, uint8_t flags, uint32_t offset,
337                uint16_t len, void *data);
338 int cwiid_write(cwiid_wiimote_t *wiimote, uint8_t flags, uint32_t offset,
339                 uint16_t len, const void *data);
340 /* int cwiid_beep(cwiid_wiimote_t *wiimote); */
341
342 /* HCI functions */
343 int cwiid_get_bdinfo_array(int dev_id, unsigned int timeout, int max_bdinfo,
344                            struct cwiid_bdinfo **bdinfo, uint8_t flags);
345 int cwiid_find_wiimote(bdaddr_t *bdaddr, int timeout);
346
347 #ifdef __cplusplus
348 }
349 #endif
350
351 #endif
Note: See TracBrowser for help on using the browser.