Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9812 was 9812, checked in by georgr, 10 years ago

Committing a few local changes, this won't work very well on non-georg boxes. @smerkli: Fix this

  • 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.h>
53        #include "/usr/include/bluetooth/bluetooth.h"
54#endif
55
56#include "definitions.h"
57
58/* WiiC version */
59#define WIIC_VERSION                                    "1.2"
60#define WIIC_LOG_VERSION                                 1.0
61
62/********************
63 *
64 *      Wiimote internal codes
65 *
66 ********************/
67
68/* Communication channels */
69#define WM_OUTPUT_CHANNEL                       0x11
70#define WM_INPUT_CHANNEL                        0x13
71
72#define WM_SET_REPORT                           0x50
73
74/* commands */
75#define WM_CMD_LED                                      0x11
76#define WM_CMD_REPORT_TYPE                      0x12
77#define WM_CMD_RUMBLE                           0x13
78#define WM_CMD_IR                                       0x13
79#define WM_CMD_SPEAKER_ENABLE           0x14
80#define WM_CMD_CTRL_STATUS                      0x15
81#define WM_CMD_WRITE_DATA                       0x16
82#define WM_CMD_READ_DATA                        0x17
83#define WM_CMD_SPEAKER_DATA                     0x18
84#define WM_CMD_SPEAKER_MUTE                     0x19
85#define WM_CMD_IR_2                                     0x1A
86
87/* input report ids */
88#define WM_RPT_CTRL_STATUS                      0x20
89#define WM_RPT_READ                                     0x21
90#define WM_RPT_WRITE                            0x22
91#define WM_RPT_BTN                                      0x30
92#define WM_RPT_BTN_ACC                          0x31
93#define WM_RPT_BTN_ACC_IR                       0x33
94#define WM_RPT_BTN_EXP                          0x34
95#define WM_RPT_BTN_ACC_EXP                      0x35
96#define WM_RPT_BTN_IR_EXP                       0x36
97#define WM_RPT_BTN_ACC_IR_EXP           0x37
98
99#define WM_BT_INPUT                                     0x01
100#define WM_BT_OUTPUT                            0x02
101
102/* Identify the wiimote device by its class */
103
104/*
105 * The different codes wrt. to Linux
106 * is a bit hard to explain.
107 * Looking at Bluetooth CoD format, we have 24 bits.
108 * In wiic Linux they are stored in three fields,
109 * each one 8bit long. The result number is
110 * 0x002504. However, MacOS Bluetooth does
111 * not store them in such a way, rather it uses
112 * the concept of major service, major class,
113 * and minor class, that are respectivelly
114 * 11bit, 5bit, and 6bit long. Hence, the
115 * numbers are different.
116 * The Wiimote CoD Bluetooth division is the following:
117 * 00000000001 00101 000001 00 (major service - major class - minor class - format type)
118 * This can also be seen in the WiiC Linux way:
119 * 00000000 00100101 00000100
120 */
121#ifdef __APPLE__
122        #define WM_DEV_MINOR_CLASS                              0x01
123        #define WM_DEV_MAJOR_CLASS                              0x05
124        #define WM_DEV_MAJOR_SERVICE                    0x01
125#else
126        #define WM_DEV_CLASS_0                          0x04
127        #define WM_DEV_CLASS_1                          0x25
128        #define WM_DEV_CLASS_2                          0x00
129#endif
130#define WM_VENDOR_ID                            0x057E
131#define WM_PRODUCT_ID                           0x0306
132
133/* controller status stuff */
134#define WM_MAX_BATTERY_CODE                     0xC8
135
136/* offsets in wiimote memory */
137#define WM_MEM_OFFSET_CALIBRATION       0x16
138#define WM_EXP_MEM_BASE                         0x04A40000
139#define WM_EXP_MEM_ENABLE                       0x04A40040
140#define WM_EXP_MEM_CALIBR                       0x04A40020
141#define WM_EXP_ID                                       0x04A400FA
142#define EXP_HANDSHAKE_LEN                                       224
143
144#define WM_REG_IR                                       0x04B00030
145#define WM_REG_IR_BLOCK1                        0x04B00000
146#define WM_REG_IR_BLOCK2                        0x04B0001A
147#define WM_REG_IR_MODENUM                       0x04B00033
148
149/*
150 * Motion Plus (please note that the first
151 * "04" in these addresses
152 * is to enable register write)
153 */
154#define WM_MOTION_PLUS_INIT                     0x04A600F0
155#define WM_MOTION_PLUS_ID_ADDR          0x04A400FA      /** This register contains the Motion Plus ID, if correctly activated */
156#define WM_MOTION_PLUS_ENABLE           0x04A600FE // We're using the unencrypted version
157#define WM_MOTION_PLUS_DISABLE          0x04A400F0
158
159/* ir block data */
160#define WM_IR_BLOCK1_LEVEL1                     "\x02\x00\x00\x71\x01\x00\x64\x00\xfe"
161#define WM_IR_BLOCK2_LEVEL1                     "\xfd\x05"
162#define WM_IR_BLOCK1_LEVEL2                     "\x02\x00\x00\x71\x01\x00\x96\x00\xb4"
163#define WM_IR_BLOCK2_LEVEL2                     "\xb3\x04"
164#define WM_IR_BLOCK1_LEVEL3                     "\x02\x00\x00\x71\x01\x00\xaa\x00\x64"
165#define WM_IR_BLOCK2_LEVEL3                     "\x63\x03"
166#define WM_IR_BLOCK1_LEVEL4                     "\x02\x00\x00\x71\x01\x00\xc8\x00\x36"
167#define WM_IR_BLOCK2_LEVEL4                     "\x35\x03"
168#define WM_IR_BLOCK1_LEVEL5                     "\x07\x00\x00\x71\x01\x00\x72\x00\x20"
169#define WM_IR_BLOCK2_LEVEL5                     "\x1f\x03"
170
171#define WM_IR_TYPE_BASIC                        0x01
172#define WM_IR_TYPE_EXTENDED                     0x03
173
174/* controller status flags for the first message byte */
175/* bit 1 is unknown */
176#define WM_CTRL_STATUS_BYTE1_ATTACHMENT                 0x02
177#define WM_CTRL_STATUS_BYTE1_SPEAKER_ENABLED    0x04
178#define WM_CTRL_STATUS_BYTE1_IR_ENABLED                 0x08
179#define WM_CTRL_STATUS_BYTE1_LED_1                              0x10
180#define WM_CTRL_STATUS_BYTE1_LED_2                              0x20
181#define WM_CTRL_STATUS_BYTE1_LED_3                              0x40
182#define WM_CTRL_STATUS_BYTE1_LED_4                              0x80
183
184/* aspect ratio */
185#define WM_ASPECT_16_9_X        660
186#define WM_ASPECT_16_9_Y        370
187#define WM_ASPECT_4_3_X         560
188#define WM_ASPECT_4_3_Y         420
189
190
191/**
192 *      Expansion stuff
193 */
194
195/* encrypted expansion id codes (located at 0x04A400FC) */
196#define EXP_ID_CODE_NUNCHUK                                     0x9A1EFEFE
197#define EXP_ID_CODE_CLASSIC_CONTROLLER          0x9A1EFDFD
198#define EXP_ID_CODE_GUITAR                                      0x9A1EFDFB
199/* unencrypted expansion id codes */
200#define EXP_ID_CODE_MOTION_PLUS                         0xA4200405 /** Motion Plus ID (when activated) */
201#define EXP_ID_BALANCE_BOARD                            0xA4200402
202
203/********************
204 *
205 *      End Wiimote internal codes
206 *
207 ********************/
208
209/*
210 *      Smooth tilt calculations are computed with the
211 *      exponential moving average formula:
212 *              St = St_last + (alpha * (tilt - St_last))
213 *      alpha is between 0 and 1
214 */
215#define WIIC_DEFAULT_SMOOTH_ALPHA                       0.9f
216
217#include "wiic.h"
218
219#ifdef __cplusplus
220extern "C" {
221#endif
222
223/* not part of the api */
224int wiic_set_report_type(struct wiimote_t* wm);
225void wiic_send_next_pending_read_request(struct wiimote_t* wm);
226int wiic_send(struct wiimote_t* wm, byte report_type, byte* msg, int len);
227int wiic_read_data_cb(struct wiimote_t* wm, wiic_read_cb read_cb, byte* buffer, unsigned int offset, unsigned short len);
228
229#ifdef __cplusplus
230}
231#endif
232
233#endif /* WIIC_INTERNAL_H_INCLUDED */
Note: See TracBrowser for help on using the repository browser.