Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9827 was 9827, checked in by smerkli, 10 years ago

Tried a few fixes to get Bluetooth to be included
properly, but no success so far. Will have to ask someone
who knows more about our CMake setup for this.

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