xbmc
wiiuse_internal.h
Go to the documentation of this file.
1 /*
2  * wiiuse
3  *
4  * Written By:
5  * Michael Laforest < para >
6  * Email: < thepara (--AT--) g m a i l [--DOT--] com >
7  *
8  * Copyright 2006-2007
9  *
10  * This file is part of wiiuse.
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <http://www.gnu.org/licenses/>.
24  *
25  * $Header$
26  *
27  */
28 
44 #pragma once
45 
46 #ifndef WIN32
47  #include <arpa/inet.h> /* htons() */
48  #include <bluetooth/bluetooth.h>
49 #endif
50 
51 #include "definitions.h"
52 
53 /* wiiuse version */
54 #define WIIUSE_VERSION "0.12"
55 
56 /********************
57  *
58  * Wiimote internal codes
59  *
60  ********************/
61 
62 /* Communication channels */
63 #define WM_OUTPUT_CHANNEL 0x11
64 #define WM_INPUT_CHANNEL 0x13
65 
66 #define WM_SET_REPORT 0x50
67 
68 /* commands */
69 #define WM_CMD_LED 0x11
70 #define WM_CMD_REPORT_TYPE 0x12
71 #define WM_CMD_RUMBLE 0x13
72 #define WM_CMD_IR 0x13
73 #define WM_CMD_CTRL_STATUS 0x15
74 #define WM_CMD_WRITE_DATA 0x16
75 #define WM_CMD_READ_DATA 0x17
76 #define WM_CMD_IR_2 0x1A
77 
78 /* input report ids */
79 #define WM_RPT_CTRL_STATUS 0x20
80 #define WM_RPT_READ 0x21
81 #define WM_RPT_WRITE 0x22
82 #define WM_RPT_BTN 0x30
83 #define WM_RPT_BTN_ACC 0x31
84 #define WM_RPT_BTN_ACC_IR 0x33
85 #define WM_RPT_BTN_EXP 0x34
86 #define WM_RPT_BTN_ACC_EXP 0x35
87 #define WM_RPT_BTN_IR_EXP 0x36
88 #define WM_RPT_BTN_ACC_IR_EXP 0x37
89 
90 #define WM_BT_INPUT 0x01
91 #define WM_BT_OUTPUT 0x02
92 
93 /* Identify the wiimote device by its class */
94 #define WM_DEV_CLASS_0 0x04
95 #define WM_DEV_CLASS_1 0x25
96 #define WM_DEV_CLASS_2 0x00
97 #define WM_VENDOR_ID 0x057E
98 #define WM_PRODUCT_ID 0x0306
99 
100 /* controller status stuff */
101 #define WM_MAX_BATTERY_CODE 0xC8
102 
103 /* offsets in wiimote memory */
104 #define WM_MEM_OFFSET_CALIBRATION 0x16
105 #define WM_EXP_MEM_BASE 0x04A40000
106 #define WM_EXP_MEM_ENABLE 0x04A40040
107 #define WM_EXP_MEM_CALIBR 0x04A40020
108 
109 #define WM_REG_IR 0x04B00030
110 #define WM_REG_IR_BLOCK1 0x04B00000
111 #define WM_REG_IR_BLOCK2 0x04B0001A
112 #define WM_REG_IR_MODENUM 0x04B00033
113 
114 /* ir block data */
115 #define WM_IR_BLOCK1_LEVEL1 "\x02\x00\x00\x71\x01\x00\x64\x00\xfe"
116 #define WM_IR_BLOCK2_LEVEL1 "\xfd\x05"
117 #define WM_IR_BLOCK1_LEVEL2 "\x02\x00\x00\x71\x01\x00\x96\x00\xb4"
118 #define WM_IR_BLOCK2_LEVEL2 "\xb3\x04"
119 #define WM_IR_BLOCK1_LEVEL3 "\x02\x00\x00\x71\x01\x00\xaa\x00\x64"
120 #define WM_IR_BLOCK2_LEVEL3 "\x63\x03"
121 #define WM_IR_BLOCK1_LEVEL4 "\x02\x00\x00\x71\x01\x00\xc8\x00\x36"
122 #define WM_IR_BLOCK2_LEVEL4 "\x35\x03"
123 #define WM_IR_BLOCK1_LEVEL5 "\x07\x00\x00\x71\x01\x00\x72\x00\x20"
124 #define WM_IR_BLOCK2_LEVEL5 "\x1f\x03"
125 
126 #define WM_IR_TYPE_BASIC 0x01
127 #define WM_IR_TYPE_EXTENDED 0x03
128 
129 /* controller status flags for the first message byte */
130 /* bit 1 is unknown */
131 #define WM_CTRL_STATUS_BYTE1_ATTACHMENT 0x02
132 #define WM_CTRL_STATUS_BYTE1_SPEAKER_ENABLED 0x04
133 #define WM_CTRL_STATUS_BYTE1_IR_ENABLED 0x08
134 #define WM_CTRL_STATUS_BYTE1_LED_1 0x10
135 #define WM_CTRL_STATUS_BYTE1_LED_2 0x20
136 #define WM_CTRL_STATUS_BYTE1_LED_3 0x40
137 #define WM_CTRL_STATUS_BYTE1_LED_4 0x80
138 
139 /* aspect ratio */
140 #define WM_ASPECT_16_9_X 660
141 #define WM_ASPECT_16_9_Y 370
142 #define WM_ASPECT_4_3_X 560
143 #define WM_ASPECT_4_3_Y 420
144 
145 
150 /* encrypted expansion id codes (located at 0x04A400FC) */
151 #define EXP_ID_CODE_NUNCHUK 0x9A1EFEFE
152 #define EXP_ID_CODE_CLASSIC_CONTROLLER 0x9A1EFDFD
153 #define EXP_ID_CODE_GUITAR 0x9A1EFDFB
154 
155 #define EXP_HANDSHAKE_LEN 224
156 
157 /********************
158  *
159  * End Wiimote internal codes
160  *
161  ********************/
162 
163 /* wiimote state flags - (some duplicated in wiiuse.h)*/
164 #define WIIMOTE_STATE_DEV_FOUND 0x0001
165 #define WIIMOTE_STATE_HANDSHAKE 0x0002 /* actual connection exists but no handshake yet */
166 #define WIIMOTE_STATE_HANDSHAKE_COMPLETE 0x0004 /* actual connection exists but no handshake yet */
167 #define WIIMOTE_STATE_CONNECTED 0x0008
168 #define WIIMOTE_STATE_RUMBLE 0x0010
169 #define WIIMOTE_STATE_ACC 0x0020
170 #define WIIMOTE_STATE_EXP 0x0040
171 #define WIIMOTE_STATE_IR 0x0080
172 #define WIIMOTE_STATE_SPEAKER 0x0100
173 #define WIIMOTE_STATE_IR_SENS_LVL1 0x0200
174 #define WIIMOTE_STATE_IR_SENS_LVL2 0x0400
175 #define WIIMOTE_STATE_IR_SENS_LVL3 0x0800
176 #define WIIMOTE_STATE_IR_SENS_LVL4 0x1000
177 #define WIIMOTE_STATE_IR_SENS_LVL5 0x2000
178 
179 #define WIIMOTE_INIT_STATES (WIIMOTE_STATE_IR_SENS_LVL3)
180 
181 /* macro to manage states */
182 #define WIIMOTE_IS_SET(wm, s) ((wm->state & (s)) == (s))
183 #define WIIMOTE_ENABLE_STATE(wm, s) (wm->state |= (s))
184 #define WIIMOTE_DISABLE_STATE(wm, s) (wm->state &= ~(s))
185 #define WIIMOTE_TOGGLE_STATE(wm, s) ((wm->state & (s)) ? WIIMOTE_DISABLE_STATE(wm, s) : WIIMOTE_ENABLE_STATE(wm, s))
186 
187 #define WIIMOTE_IS_FLAG_SET(wm, s) ((wm->flags & (s)) == (s))
188 #define WIIMOTE_ENABLE_FLAG(wm, s) (wm->flags |= (s))
189 #define WIIMOTE_DISABLE_FLAG(wm, s) (wm->flags &= ~(s))
190 #define WIIMOTE_TOGGLE_FLAG(wm, s) ((wm->flags & (s)) ? WIIMOTE_DISABLE_FLAG(wm, s) : WIIMOTE_ENABLE_FLAG(wm, s))
191 
192 #define NUNCHUK_IS_FLAG_SET(wm, s) ((*(wm->flags) & (s)) == (s))
193 
194 /* misc macros */
195 #define WIIMOTE_ID(wm) (wm->unid)
196 #define WIIMOTE_IS_CONNECTED(wm) (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_CONNECTED))
197 
198 /*
199  * Smooth tilt calculations are computed with the
200  * exponential moving average formula:
201  * St = St_last + (alpha * (tilt - St_last))
202  * alpha is between 0 and 1
203  */
204 #define WIIUSE_DEFAULT_SMOOTH_ALPHA 0.07f
205 
206 #define SMOOTH_ROLL 0x01
207 #define SMOOTH_PITCH 0x02
208 
209 #include "wiiuse.h"
210 
211 #ifdef __cplusplus
212 extern "C" {
213 #endif
214 
215 /* not part of the api */
216 int wiiuse_set_report_type(struct wiimote_t* wm);
218 int wiiuse_send(struct wiimote_t* wm, byte report_type, byte* msg, int len);
219 int wiiuse_read_data_cb(struct wiimote_t* wm, wiiuse_read_cb read_cb, byte* buffer, unsigned int offset, unsigned short len);
220 
221 #ifdef __cplusplus
222 }
223 #endif
224 
Wiimote structure.
Definition: wiiuse.h:531
void wiiuse_send_next_pending_read_request(struct wiimote_t *wm)
Send the next pending data read request to the wiimote.
Definition: wiiuse.c:452
API header file.
int wiiuse_send(struct wiimote_t *wm, byte report_type, byte *msg, int len)
Send a packet to the wiimote.
Definition: wiiuse.c:570
int wiiuse_set_report_type(struct wiimote_t *wm)
Set the report type based on the current wiimote state.
Definition: wiiuse.c:295
int wiiuse_read_data_cb(struct wiimote_t *wm, wiiuse_read_cb read_cb, byte *buffer, unsigned int offset, unsigned short len)
Read data from the wiimote (callback version).
Definition: wiiuse.c:349
void(* wiiuse_read_cb)(struct wiimote_t *wm, byte *data, unsigned short len)
Callback that handles a read event.
Definition: wiiuse.h:232