root/libcwiid/cwiid.h @ 805477a3e8c4bccbd90c78e829870267c783904b

Revision 805477a3e8c4bccbd90c78e829870267c783904b, 6.4 KB (checked in by dsmith <dsmith@…>, 6 years ago)

Merge libcwiid rename into trunk

git-svn-id: http://abstrakraft.org/cwiid/svn/trunk@83 918edb2d-ff29-0410-9de2-eb38e7f22bc7

  • Property mode set to 100644
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-04-09 L. Donnie Smith <cwiid@abstrakraft.org>
19 *  * renamed wiimote to libcwiid, renamed structures accordingly
20 *
21 *  2007-04-07 L. Donnie Smith <cwiid@abstrakraft.org>
22 *  * changed cwiid_info.class to btclass
23 *
24 *  2007-04-04 L. Donnie Smith <cwiid@abstrakraft.org>
25 *  * added cwiid_mesg_error message type
26 *
27 *  2007-04-01 L. Donnie Smith <cwiid@abstrakraft.org>
28 *  * cwiid_connect now takes a pointer to bdaddr_t
29 *  * added cwiid_info definition and macros
30 *  * added cwiid_get_info_array prototype
31 *  * changed cwiid_findfirst to cwiid_find_wiimote
32 *
33 *  2007-03-05 L. Donnie Smith <cwiid@abstrakraft.org>
34 *  * added cwiid_err_t definition
35 *  * added cwiid_set_err prototype
36 *
37 *  2007-03-01 L. Donnie Smith <cwiid@abstrakraft.org>
38 *  * Initial ChangeLog
39 *  * type audit (stdint, const, char booleans)
40 */
41
42#ifndef CWIID_H
43#define CWIID_H
44
45#include <stdint.h>
46#include <bluetooth/bluetooth.h>        /* bdaddr_t */
47
48/* Report Mode Flags */
49#define CWIID_RPT_STATUS        0x01
50#define CWIID_RPT_BTN           0x02
51#define CWIID_RPT_ACC           0x04
52#define CWIID_RPT_IR            0x08
53#define CWIID_RPT_NUNCHUK       0x10
54#define CWIID_RPT_CLASSIC       0x20
55#define CWIID_RPT_EXT           (CWIID_RPT_NUNCHUK | CWIID_RPT_CLASSIC)
56
57/* LED flags */
58#define CWIID_LED1_ON           0x01
59#define CWIID_LED2_ON           0x02
60#define CWIID_LED3_ON           0x04
61#define CWIID_LED4_ON           0x08
62
63/* Button flags */
64#define CWIID_BTN_2             0x0001
65#define CWIID_BTN_1             0x0002
66#define CWIID_BTN_B             0x0004
67#define CWIID_BTN_A             0x0008
68#define CWIID_BTN_MINUS 0x0010
69#define CWIID_BTN_HOME  0x0080
70#define CWIID_BTN_LEFT  0x0100
71#define CWIID_BTN_RIGHT 0x0200
72#define CWIID_BTN_DOWN  0x0400
73#define CWIID_BTN_UP            0x0800
74#define CWIID_BTN_PLUS  0x1000
75
76#define CWIID_NUNCHUK_BTN_Z     0x01
77#define CWIID_NUNCHUK_BTN_C     0x02
78
79#define CWIID_CLASSIC_BTN_UP            0x0001
80#define CWIID_CLASSIC_BTN_LEFT  0x0002
81#define CWIID_CLASSIC_BTN_ZR            0x0004
82#define CWIID_CLASSIC_BTN_X             0x0008
83#define CWIID_CLASSIC_BTN_A             0x0010
84#define CWIID_CLASSIC_BTN_Y             0x0020
85#define CWIID_CLASSIC_BTN_B             0x0040
86#define CWIID_CLASSIC_BTN_ZL            0x0080
87#define CWIID_CLASSIC_BTN_R             0x0200
88#define CWIID_CLASSIC_BTN_PLUS  0x0400
89#define CWIID_CLASSIC_BTN_HOME  0x0800
90#define CWIID_CLASSIC_BTN_MINUS 0x1000
91#define CWIID_CLASSIC_BTN_L             0x2000
92#define CWIID_CLASSIC_BTN_DOWN  0x4000
93#define CWIID_CLASSIC_BTN_RIGHT 0x8000
94
95/* Data Read/Write flags */
96#define CWIID_RW_EEPROM 0x00
97#define CWIID_RW_REG            0x04
98#define CWIID_RW_DECODE 0x01
99
100/* Maximum Data Read Length */
101#define CWIID_MAX_READ_LEN      0xFFFF
102
103/* IR Defs */
104#define CWIID_IR_SRC_COUNT      4
105#define CWIID_IR_X_MAX          1024
106#define CWIID_IR_Y_MAX          768
107
108/* Battery */
109#define CWIID_BATTERY_MAX       0xD0
110
111/* Classic Controller Maxes */
112#define CWIID_CLASSIC_L_STICK_MAX       0x3F
113#define CWIID_CLASSIC_R_STICK_MAX       0x1F
114#define CWIID_CLASSIC_LR_MAX    0x1F
115
116/* Environment Variables */
117#define CWIID_BDADDR    "CWIID_BDADDR"
118
119/* Callback Maximum Message Count */
120#define CWIID_MAX_MESG_COUNT    5
121
122enum cwiid_command {
123        CWIID_CMD_STATUS,
124        CWIID_CMD_LED,
125        CWIID_CMD_RUMBLE,
126        CWIID_CMD_RPT_MODE
127};
128
129enum cwiid_mesg_type {
130        CWIID_MESG_STATUS,
131        CWIID_MESG_BTN,
132        CWIID_MESG_ACC,
133        CWIID_MESG_IR,
134        CWIID_MESG_NUNCHUK,
135        CWIID_MESG_CLASSIC,
136        CWIID_MESG_ERROR,
137        CWIID_MESG_UNKNOWN
138};
139
140enum cwiid_ext_type {
141        CWIID_EXT_NONE,
142        CWIID_EXT_NUNCHUK,
143        CWIID_EXT_CLASSIC,
144        CWIID_EXT_UNKNOWN
145};
146
147enum cwiid_error {
148        CWIID_ERROR_DISCONNECT,
149        CWIID_ERROR_COMM,
150};
151
152struct cwiid_status_mesg {
153        enum cwiid_mesg_type type;
154        uint8_t battery;
155        enum cwiid_ext_type extension;
156};     
157
158struct cwiid_btn_mesg {
159        enum cwiid_mesg_type type;
160        uint16_t buttons;
161};
162
163struct cwiid_acc_mesg {
164        enum cwiid_mesg_type type;
165        uint8_t x;
166        uint8_t y;
167        uint8_t z;
168};
169
170struct cwiid_ir_src {
171        int valid;
172        uint16_t x;
173        uint16_t y;
174        int8_t size;
175};
176
177struct cwiid_ir_mesg {
178        enum cwiid_mesg_type type;
179        struct cwiid_ir_src src[CWIID_IR_SRC_COUNT];
180};
181
182struct cwiid_nunchuk_mesg {
183        enum cwiid_mesg_type type;
184        uint8_t stick_x;
185        uint8_t stick_y;
186        uint8_t acc_x;
187        uint8_t acc_y;
188        uint8_t acc_z;
189        uint8_t buttons;
190};
191
192struct cwiid_classic_mesg {
193        enum cwiid_mesg_type type;
194        uint8_t l_stick_x;
195        uint8_t l_stick_y;
196        uint8_t r_stick_x;
197        uint8_t r_stick_y;
198        uint8_t l;
199        uint8_t r;
200        uint16_t buttons;
201};
202
203struct cwiid_error_mesg {
204        enum cwiid_mesg_type type;
205        enum cwiid_error error;
206};
207
208union cwiid_mesg {
209        enum cwiid_mesg_type type;
210        struct cwiid_status_mesg status_mesg;
211        struct cwiid_btn_mesg btn_mesg;
212        struct cwiid_acc_mesg acc_mesg;
213        struct cwiid_ir_mesg ir_mesg;
214        struct cwiid_nunchuk_mesg nunchuk_mesg;
215        struct cwiid_classic_mesg classic_mesg;
216        struct cwiid_error_mesg error_mesg;
217};
218
219typedef struct wiimote cwiid_wiimote_t;
220
221typedef void cwiid_mesg_callback_t(int, int, union cwiid_mesg* []);
222typedef void cwiid_err_t(int, const char *, ...);
223
224/* getinfo flags */
225#define BT_NO_WIIMOTE_FILTER 0x01
226#define BT_NAME_LEN 32
227
228struct cwiid_bdinfo {
229        bdaddr_t bdaddr;
230        uint8_t btclass[3];
231        char name[BT_NAME_LEN];
232};
233
234#ifdef __cplusplus
235extern "C" {
236#endif
237
238int cwiid_set_err(cwiid_err_t *err);
239cwiid_wiimote_t *cwiid_connect(bdaddr_t *bdaddr,
240                               cwiid_mesg_callback_t *mesg_callback,
241                               int *id);
242int cwiid_disconnect(cwiid_wiimote_t *wiimote);
243int cwiid_command(cwiid_wiimote_t *wiimote, enum cwiid_command command,
244                  uint8_t flags);
245int cwiid_read(cwiid_wiimote_t *wiimote, uint8_t flags, uint32_t offset,
246               uint16_t len, void *data);
247int cwiid_write(cwiid_wiimote_t *wiimote, uint8_t flags, uint32_t offset,
248                uint16_t len, const void *data);
249/* int cwiid_beep(cwiid_wiimote_t *wiimote); */
250int cwiid_get_bdinfo_array(int dev_id, unsigned int timeout, int max_bdinfo,
251                           struct cwiid_bdinfo **bdinfo, uint8_t flags);
252int cwiid_find_wiimote(bdaddr_t *bdaddr, int timeout);
253
254#ifdef __cplusplus
255}
256#endif
257
258#endif
259
Note: See TracBrowser for help on using the browser.