root/wiimote/wiimote.h @ d2323a579f283ed7393c20b762697766d2d01e1f

Revision d2323a579f283ed7393c20b762697766d2d01e1f, 6.1 KB (checked in by dsmith <dsmith@…>, 6 years ago)

Added struct wiimote info and info retrieval functions

git-svn-id: http://abstrakraft.org/cwiid/svn/trunk@47 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 *  04/01/2007: L. Donnie Smith <cwiid@abstrakraft.org>
19 *  * added wiimote_info definition and macros
20 *  * added wiimote_get_info_array prototype
21 *  * changed wiimote_findfirst to wiimote_find_wiimote
22 *
23 *  03/05/2007: L. Donnie Smith <cwiid@abstrakraft.org>
24 *  * added wiimote_err_t definition
25 *  * added wiimote_set_err prototype
26 *
27 *  03/01/2007: L. Donnie Smith <cwiid@abstrakraft.org>
28 *  * Initial ChangeLog
29 *  * type audit (stdint, const, char booleans)
30 */
31
32#ifndef WIIMOTE_H
33#define WIIMOTE_H
34
35#include <stdint.h>
36#include <bluetooth/bluetooth.h>        /* bdaddr_t */
37
38/* Report Mode Flags */
39#define WIIMOTE_RPT_STATUS      0x01
40#define WIIMOTE_RPT_BTN         0x02
41#define WIIMOTE_RPT_ACC         0x04
42#define WIIMOTE_RPT_IR          0x08
43#define WIIMOTE_RPT_NUNCHUK     0x10
44#define WIIMOTE_RPT_CLASSIC     0x20
45#define WIIMOTE_RPT_EXT         (WIIMOTE_RPT_NUNCHUK | WIIMOTE_RPT_CLASSIC)
46
47/* LED flags */
48#define WIIMOTE_LED1_ON         0x01
49#define WIIMOTE_LED2_ON         0x02
50#define WIIMOTE_LED3_ON         0x04
51#define WIIMOTE_LED4_ON         0x08
52
53/* Button flags */
54#define WIIMOTE_BTN_2           0x0001
55#define WIIMOTE_BTN_1           0x0002
56#define WIIMOTE_BTN_B           0x0004
57#define WIIMOTE_BTN_A           0x0008
58#define WIIMOTE_BTN_MINUS       0x0010
59#define WIIMOTE_BTN_HOME        0x0080
60#define WIIMOTE_BTN_LEFT        0x0100
61#define WIIMOTE_BTN_RIGHT       0x0200
62#define WIIMOTE_BTN_DOWN        0x0400
63#define WIIMOTE_BTN_UP          0x0800
64#define WIIMOTE_BTN_PLUS        0x1000
65
66#define WIIMOTE_NUNCHUK_BTN_Z   0x01
67#define WIIMOTE_NUNCHUK_BTN_C   0x02
68
69#define WIIMOTE_CLASSIC_BTN_UP          0x0001
70#define WIIMOTE_CLASSIC_BTN_LEFT        0x0002
71#define WIIMOTE_CLASSIC_BTN_ZR          0x0004
72#define WIIMOTE_CLASSIC_BTN_X           0x0008
73#define WIIMOTE_CLASSIC_BTN_A           0x0010
74#define WIIMOTE_CLASSIC_BTN_Y           0x0020
75#define WIIMOTE_CLASSIC_BTN_B           0x0040
76#define WIIMOTE_CLASSIC_BTN_ZL          0x0080
77#define WIIMOTE_CLASSIC_BTN_R           0x0200
78#define WIIMOTE_CLASSIC_BTN_PLUS        0x0400
79#define WIIMOTE_CLASSIC_BTN_HOME        0x0800
80#define WIIMOTE_CLASSIC_BTN_MINUS       0x1000
81#define WIIMOTE_CLASSIC_BTN_L           0x2000
82#define WIIMOTE_CLASSIC_BTN_DOWN        0x4000
83#define WIIMOTE_CLASSIC_BTN_RIGHT       0x8000
84
85/* Data Read/Write flags */
86#define WIIMOTE_RW_EEPROM       0x00
87#define WIIMOTE_RW_REG          0x04
88#define WIIMOTE_RW_DECODE       0x01
89
90/* Maximum Data Read Length */
91#define WIIMOTE_MAX_READ_LEN    0xFFFF
92
93/* IR Defs */
94#define WIIMOTE_IR_SRC_COUNT    4
95#define WIIMOTE_IR_X_MAX                1024
96#define WIIMOTE_IR_Y_MAX                768
97
98/* Battery */
99#define WIIMOTE_BATTERY_MAX     0xD0
100
101/* Classic Controller Maxes */
102#define WIIMOTE_CLASSIC_L_STICK_MAX     0x3F
103#define WIIMOTE_CLASSIC_R_STICK_MAX     0x1F
104#define WIIMOTE_CLASSIC_LR_MAX  0x1F
105
106/* Environment Variables */
107#define WIIMOTE_BDADDR  "WIIMOTE_BDADDR"
108
109/* Callback Maximum Message Count */
110#define WIIMOTE_MAX_MESG_COUNT  5
111
112enum wiimote_command {
113        WIIMOTE_CMD_STATUS,
114        WIIMOTE_CMD_LED,
115        WIIMOTE_CMD_RUMBLE,
116        WIIMOTE_CMD_RPT_MODE
117};
118
119enum wiimote_mesg_type {
120        WIIMOTE_MESG_STATUS,
121        WIIMOTE_MESG_BTN,
122        WIIMOTE_MESG_ACC,
123        WIIMOTE_MESG_IR,
124        WIIMOTE_MESG_NUNCHUK,
125        WIIMOTE_MESG_CLASSIC,
126        WIIMOTE_MESG_UNKNOWN
127};
128
129enum wiimote_ext_type {
130        WIIMOTE_EXT_NONE,
131        WIIMOTE_EXT_NUNCHUK,
132        WIIMOTE_EXT_CLASSIC,
133        WIIMOTE_EXT_UNKNOWN
134};
135
136struct wiimote_status_mesg {
137        enum wiimote_mesg_type type;
138        uint8_t battery;
139        enum wiimote_ext_type extension;
140};     
141
142struct wiimote_btn_mesg {
143        enum wiimote_mesg_type type;
144        uint16_t buttons;
145};
146
147struct wiimote_acc_mesg {
148        enum wiimote_mesg_type type;
149        uint8_t x;
150        uint8_t y;
151        uint8_t z;
152};
153
154struct wiimote_ir_src {
155        int valid;
156        uint16_t x;
157        uint16_t y;
158        int8_t size;
159};
160
161struct wiimote_ir_mesg {
162        enum wiimote_mesg_type type;
163        struct wiimote_ir_src src[WIIMOTE_IR_SRC_COUNT];
164};
165
166struct wiimote_nunchuk_mesg {
167        enum wiimote_mesg_type type;
168        uint8_t stick_x;
169        uint8_t stick_y;
170        uint8_t acc_x;
171        uint8_t acc_y;
172        uint8_t acc_z;
173        uint8_t buttons;
174};
175
176struct wiimote_classic_mesg {
177        enum wiimote_mesg_type type;
178        uint8_t l_stick_x;
179        uint8_t l_stick_y;
180        uint8_t r_stick_x;
181        uint8_t r_stick_y;
182        uint8_t l;
183        uint8_t r;
184        uint16_t buttons;
185};
186
187union wiimote_mesg {
188        enum wiimote_mesg_type type;
189        struct wiimote_status_mesg status_mesg;
190        struct wiimote_btn_mesg btn_mesg;
191        struct wiimote_acc_mesg acc_mesg;
192        struct wiimote_ir_mesg ir_mesg;
193        struct wiimote_nunchuk_mesg nunchuk_mesg;
194        struct wiimote_classic_mesg classic_mesg;
195};
196
197typedef struct wiimote wiimote_t;
198
199typedef void wiimote_mesg_callback_t(int, int, union wiimote_mesg* []);
200typedef void wiimote_err_t(int, const char *, ...);
201
202/* getinfo flags */
203#define BT_NO_WIIMOTE_FILTER 0x01
204#define BT_WM_NAME_LEN 32
205
206struct wiimote_info {
207        bdaddr_t bdaddr;
208        uint8_t class[3];
209        char name[BT_WM_NAME_LEN];
210};
211
212#ifdef __cplusplus
213extern "C" {
214#endif
215
216int wiimote_set_err(wiimote_err_t *err);
217wiimote_t *wiimote_connect(bdaddr_t bdaddr,
218                           wiimote_mesg_callback_t *mesg_callback,
219                           int *id);
220int wiimote_disconnect(wiimote_t *wiimote);
221int wiimote_command(wiimote_t *wiimote, enum wiimote_command command,
222                    uint8_t flags);
223int wiimote_read(wiimote_t *wiimote, uint8_t flags, uint32_t offset,
224                 uint16_t len, void *data);
225int wiimote_write(wiimote_t *wiimote, uint8_t flags, uint32_t offset,
226                  uint16_t len, const void *data);
227/* int wiimote_beep(wiimote_t *wiimote); */
228int wiimote_get_info_array(int dev_id, unsigned int timeout, int max_wm,
229                           struct wiimote_info **wm, uint8_t flags);
230int wiimote_find_wiimote(bdaddr_t *bdaddr, int timeout);
231
232#ifdef __cplusplus
233}
234#endif
235
236#endif
237
Note: See TracBrowser for help on using the browser.