Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/wiimote/src/external/wiicpp/wiic/wiic_internal.h @ 10256

Last change on this file since 10256 was 9830, checked in by smerkli, 11 years ago

Fixed the ugly bluetooth hack into one that's a little less ugly:
now the only place the path has to be specified is FindBluetooth.cmake.
Kudos to reto for pointing me in the right direction.

  • Property svn:executable set to *
File size: 6.7 KB
Line 
1/*
2 *    wiic_internal.h
3 *
4 *        This file is part of WiiC, written by:
5 *              Gabriele Randelli
6 *              Email: randelli@dis.uniroma1.it
7 *
8 *    Copyright 2010
9 *             
10 *        This file is based on Wiiuse, written By:
11 *              Michael Laforest        < para >
12 *              Email: < thepara (--AT--) g m a i l [--DOT--] com >
13 *
14 *        Copyright 2006-2007
15 *
16 *    This program is free software; you can redistribute it and/or modify
17 *    it under the terms of the GNU General Public License as published by
18 *    the Free Software Foundation; either version 3 of the License, or
19 *    (at your option) any later version.
20 *
21 *    This program is distributed in the hope that it will be useful,
22 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
23 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 *    GNU General Public License for more details.
25 *
26 *    You should have received a copy of the GNU General Public License
27 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
28 *
29 *        $Header$
30 */
31
32/**
33 *      @file
34 *      @brief General internal wiic stuff.
35 *
36 *      Since WiiC is a library, wiic.h is a duplicate
37 *      of the API header.
38 *
39 *      The code that would normally go in that file, but
40 *      which is not needed by third party developers,
41 *      is put here.
42 *
43 *      So wiic_internal.h is included by other files
44 *      internally, wiic.h is included only here.
45 */
46
47#ifndef WIIC_INTERNAL_H_INCLUDED
48#define WIIC_INTERNAL_H_INCLUDED
49
50#ifndef __APPLE__
51        #include <arpa/inet.h>                          /* htons() */
52        #include <bluetooth/bluetooth.h>
53#endif
54
55#include "definitions.h"
56
57/* WiiC version */
58#define WIIC_VERSION                                    "1.2"
59#define WIIC_LOG_VERSION                                 1.0
60
61/********************
62 *
63 *      Wiimote internal codes
64 *
65 ********************/
66
67/* Communication channels */
68#define WM_OUTPUT_CHANNEL                       0x11
69#define WM_INPUT_CHANNEL                        0x13
70
71#define WM_SET_REPORT                           0x50
72
73/* commands */
74#define WM_CMD_LED                                      0x11
75#define WM_CMD_REPORT_TYPE                      0x12
76#define WM_CMD_RUMBLE                           0x13
77#define WM_CMD_IR                                       0x13
78#define WM_CMD_SPEAKER_ENABLE           0x14
79#define WM_CMD_CTRL_STATUS                      0x15
80#define WM_CMD_WRITE_DATA                       0x16
81#define WM_CMD_READ_DATA                        0x17
82#define WM_CMD_SPEAKER_DATA                     0x18
83#define WM_CMD_SPEAKER_MUTE                     0x19
84#define WM_CMD_IR_2                                     0x1A
85
86/* input report ids */
87#define WM_RPT_CTRL_STATUS                      0x20
88#define WM_RPT_READ                                     0x21
89#define WM_RPT_WRITE                            0x22
90#define WM_RPT_BTN                                      0x30
91#define WM_RPT_BTN_ACC                          0x31
92#define WM_RPT_BTN_ACC_IR                       0x33
93#define WM_RPT_BTN_EXP                          0x34
94#define WM_RPT_BTN_ACC_EXP                      0x35
95#define WM_RPT_BTN_IR_EXP                       0x36
96#define WM_RPT_BTN_ACC_IR_EXP           0x37
97
98#define WM_BT_INPUT                                     0x01
99#define WM_BT_OUTPUT                            0x02
100
101/* Identify the wiimote device by its class */
102
103/*
104 * The different codes wrt. to Linux
105 * is a bit hard to explain.
106 * Looking at Bluetooth CoD format, we have 24 bits.
107 * In wiic Linux they are stored in three fields,
108 * each one 8bit long. The result number is
109 * 0x002504. However, MacOS Bluetooth does
110 * not store them in such a way, rather it uses
111 * the concept of major service, major class,
112 * and minor class, that are respectivelly
113 * 11bit, 5bit, and 6bit long. Hence, the
114 * numbers are different.
115 * The Wiimote CoD Bluetooth division is the following:
116 * 00000000001 00101 000001 00 (major service - major class - minor class - format type)
117 * This can also be seen in the WiiC Linux way:
118 * 00000000 00100101 00000100
119 */
120#ifdef __APPLE__
121        #define WM_DEV_MINOR_CLASS                              0x01
122        #define WM_DEV_MAJOR_CLASS                              0x05
123        #define WM_DEV_MAJOR_SERVICE                    0x01
124#else
125        #define WM_DEV_CLASS_0                          0x04
126        #define WM_DEV_CLASS_1                          0x25
127        #define WM_DEV_CLASS_2                          0x00
128#endif
129#define WM_VENDOR_ID                            0x057E
130#define WM_PRODUCT_ID                           0x0306
131
132/* controller status stuff */
133#define WM_MAX_BATTERY_CODE                     0xC8
134
135/* offsets in wiimote memory */
136#define WM_MEM_OFFSET_CALIBRATION       0x16
137#define WM_EXP_MEM_BASE                         0x04A40000
138#define WM_EXP_MEM_ENABLE                       0x04A40040
139#define WM_EXP_MEM_CALIBR                       0x04A40020
140#define WM_EXP_ID                                       0x04A400FA
141#define EXP_HANDSHAKE_LEN                                       224
142
143#define WM_REG_IR                                       0x04B00030
144#define WM_REG_IR_BLOCK1                        0x04B00000
145#define WM_REG_IR_BLOCK2                        0x04B0001A
146#define WM_REG_IR_MODENUM                       0x04B00033
147
148/*
149 * Motion Plus (please note that the first
150 * "04" in these addresses
151 * is to enable register write)
152 */
153#define WM_MOTION_PLUS_INIT                     0x04A600F0
154#define WM_MOTION_PLUS_ID_ADDR          0x04A400FA      /** This register contains the Motion Plus ID, if correctly activated */
155#define WM_MOTION_PLUS_ENABLE           0x04A600FE // We're using the unencrypted version
156#define WM_MOTION_PLUS_DISABLE          0x04A400F0
157
158/* ir block data */
159#define WM_IR_BLOCK1_LEVEL1                     "\x02\x00\x00\x71\x01\x00\x64\x00\xfe"
160#define WM_IR_BLOCK2_LEVEL1                     "\xfd\x05"
161#define WM_IR_BLOCK1_LEVEL2                     "\x02\x00\x00\x71\x01\x00\x96\x00\xb4"
162#define WM_IR_BLOCK2_LEVEL2                     "\xb3\x04"
163#define WM_IR_BLOCK1_LEVEL3                     "\x02\x00\x00\x71\x01\x00\xaa\x00\x64"
164#define WM_IR_BLOCK2_LEVEL3                     "\x63\x03"
165#define WM_IR_BLOCK1_LEVEL4                     "\x02\x00\x00\x71\x01\x00\xc8\x00\x36"
166#define WM_IR_BLOCK2_LEVEL4                     "\x35\x03"
167#define WM_IR_BLOCK1_LEVEL5                     "\x07\x00\x00\x71\x01\x00\x72\x00\x20"
168#define WM_IR_BLOCK2_LEVEL5                     "\x1f\x03"
169
170#define WM_IR_TYPE_BASIC                        0x01
171#define WM_IR_TYPE_EXTENDED                     0x03
172
173/* controller status flags for the first message byte */
174/* bit 1 is unknown */
175#define WM_CTRL_STATUS_BYTE1_ATTACHMENT                 0x02
176#define WM_CTRL_STATUS_BYTE1_SPEAKER_ENABLED    0x04
177#define WM_CTRL_STATUS_BYTE1_IR_ENABLED                 0x08
178#define WM_CTRL_STATUS_BYTE1_LED_1                              0x10
179#define WM_CTRL_STATUS_BYTE1_LED_2                              0x20
180#define WM_CTRL_STATUS_BYTE1_LED_3                              0x40
181#define WM_CTRL_STATUS_BYTE1_LED_4                              0x80
182
183/* aspect ratio */
184#define WM_ASPECT_16_9_X        660
185#define WM_ASPECT_16_9_Y        370
186#define WM_ASPECT_4_3_X         560
187#define WM_ASPECT_4_3_Y         420
188
189
190/**
191 *      Expansion stuff
192 */
193
194/* encrypted expansion id codes (located at 0x04A400FC) */
195#define EXP_ID_CODE_NUNCHUK                                     0x9A1EFEFE
196#define EXP_ID_CODE_CLASSIC_CONTROLLER          0x9A1EFDFD
197#define EXP_ID_CODE_GUITAR                                      0x9A1EFDFB
198/* unencrypted expansion id codes */
199#define EXP_ID_CODE_MOTION_PLUS                         0xA4200405 /** Motion Plus ID (when activated) */
200#define EXP_ID_BALANCE_BOARD                            0xA4200402
201
202/********************
203 *
204 *      End Wiimote internal codes
205 *
206 ********************/
207
208/*
209 *      Smooth tilt calculations are computed with the
210 *      exponential moving average formula:
211 *              St = St_last + (alpha * (tilt - St_last))
212 *      alpha is between 0 and 1
213 */
214#define WIIC_DEFAULT_SMOOTH_ALPHA                       0.9f
215
216#include "wiic.h"
217
218#ifdef __cplusplus
219extern "C" {
220#endif
221
222/* not part of the api */
223int wiic_set_report_type(struct wiimote_t* wm);
224void wiic_send_next_pending_read_request(struct wiimote_t* wm);
225int wiic_send(struct wiimote_t* wm, byte report_type, byte* msg, int len);
226int wiic_read_data_cb(struct wiimote_t* wm, wiic_read_cb read_cb, byte* buffer, unsigned int offset, unsigned short len);
227
228#ifdef __cplusplus
229}
230#endif
231
232#endif /* WIIC_INTERNAL_H_INCLUDED */
Note: See TracBrowser for help on using the repository browser.