-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWiiRemote.h
244 lines (200 loc) · 6.65 KB
/
WiiRemote.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
//
// WiiRemote.h
// DarwiinRemote
//
// Created by KIMURA Hiroaki on 06/12/04.
// Copyright 2006 KIMURA Hiroaki. All rights reserved.
//
#import "Mii.h"
#import <Cocoa/Cocoa.h>
#import <IOBluetooth/objc/IOBluetoothDevice.h>
#import <IOBluetooth/objc/IOBluetoothL2CAPChannel.h>
// useful logging macros
#ifndef NSLogDebug
#if DEBUG
# define NSLogDebug(log, ...) NSLog(log, ##__VA_ARGS__)
# define LogIOReturn(result) if (result != kIOReturnSuccess) { printf ("IOReturn error (%s [%d]): system 0x%x, sub 0x%x, error 0x%x\n", __FILE__, __LINE__, err_get_system (result), err_get_sub (result), err_get_code (result)); }
#else
# define NSLogDebug(log, ...)
# define LogIOReturn(result)
#endif
#endif
extern NSString * WiiRemoteExpansionPortChangedNotification;
typedef unsigned char WiiIRModeType;
enum {
kWiiIRModeBasic = 0x01,
kWiiIRModeExtended = 0x03,
kWiiIRModeFull = 0x05
};
typedef struct {
int x, y, s;
} IRData;
typedef struct {
unsigned short accX_zero, accY_zero, accZ_zero, accX_1g, accY_1g, accZ_1g;
} WiiAccCalibData;
typedef struct {
unsigned short x_min, x_max, x_center, y_min, y_max, y_center;
} WiiJoyStickCalibData;
typedef struct {
float tr, br, tl, bl;
} WiiBalanceBoardGrid;
typedef struct {
WiiBalanceBoardGrid kg0, kg17, kg34;
} WiiBalanceBoardCalibData;
typedef enum {
WiiRemoteAButton,
WiiRemoteBButton,
WiiRemoteOneButton,
WiiRemoteTwoButton,
WiiRemoteMinusButton,
WiiRemoteHomeButton,
WiiRemotePlusButton,
WiiRemoteUpButton,
WiiRemoteDownButton,
WiiRemoteLeftButton,
WiiRemoteRightButton,
WiiNunchukZButton,
WiiNunchukCButton,
WiiClassicControllerXButton,
WiiClassicControllerYButton,
WiiClassicControllerAButton,
WiiClassicControllerBButton,
WiiClassicControllerLButton,
WiiClassicControllerRButton,
WiiClassicControllerZLButton,
WiiClassicControllerZRButton,
WiiClassicControllerUpButton,
WiiClassicControllerDownButton,
WiiClassicControllerLeftButton,
WiiClassicControllerRightButton,
WiiClassicControllerMinusButton,
WiiClassicControllerHomeButton,
WiiClassicControllerPlusButton
} WiiButtonType;
unsigned char mii_data_buf[WIIMOTE_MII_DATA_BYTES_PER_SLOT + 16];
unsigned short mii_data_offset;
typedef enum {
WiiExpUknown,
WiiExpNotAttached,
WiiNunchuk,
WiiClassicController,
WiiBalanceBoard
} WiiExpansionPortType;
typedef enum {
WiiRemoteAccelerationSensor,
WiiNunchukAccelerationSensor
} WiiAccelerationSensorType;
typedef enum {
WiiBalanceBoardPressureSensor
} WiiPressureSensorType;
typedef enum {
WiiNunchukJoyStick = 0,
WiiClassicControllerLeftJoyStick = 1,
WiiClassicControllerRightJoyStick = 2
} WiiJoyStickType;
@interface WiiRemote : NSObject
{
#ifdef DEBUG
BOOL _dump;
#endif
BOOL _opened;
BOOL _shouldUpdateReportMode;
BOOL _shouldReadExpansionCalibration;
BOOL _shouldSetInitialConfiguration;
BOOL _isMotionSensorEnabled;
BOOL _isIRSensorEnabled;
BOOL _isVibrationEnabled;
BOOL _isExpansionPortEnabled;
BOOL _isExpansionPortAttached;
BOOL _isLED1Illuminated;
BOOL _isLED2Illuminated;
BOOL _isLED3Illuminated;
BOOL _isLED4Illuminated;
IOBluetoothDevice * _wiiDevice;
IOBluetoothL2CAPChannel * _ichan;
IOBluetoothL2CAPChannel * _cchan;
id _delegate;
float _lowZ, _lowX;
int orientation;
int leftPoint; // is point 0 or 1 on the left. -1 when not tracking.
WiiExpansionPortType expType;
WiiAccCalibData wiiCalibData, nunchukCalibData;
WiiJoyStickCalibData nunchukJoyStickCalibData;
WiiBalanceBoardCalibData balanceBoardCalibData;
WiiIRModeType wiiIRMode;
IRData irData[4];
double _batteryLevel;
double _warningBatteryLevel;
NSTimer * statusTimer;
IOBluetoothUserNotification * disconnectNotification;
BOOL buttonState[28];
//wiimote
unsigned short accX;
unsigned short accY;
unsigned short accZ;
unsigned short buttonData;
//nunchuk
unsigned short nStickX;
unsigned short nStickY;
unsigned short nAccX;
unsigned short nAccY;
unsigned short nAccZ;
unsigned short nButtonData;
// classic controller
unsigned short cButtonData;
unsigned short cStickX1;
unsigned short cStickY1;
unsigned short cStickX2;
unsigned short cStickY2;
unsigned short cAnalogL;
unsigned short cAnalogR;
/* balance board raw values */
WiiBalanceBoardGrid bPressure;
/* balance board encoded values */
WiiBalanceBoardGrid bKg;
}
- (NSString*) address;
- (void) setDelegate:(id) delegate;
- (double) batteryLevel;
- (WiiExpansionPortType) expansionPortType;
- (BOOL) isExpansionPortAttached;
- (BOOL) available;
- (BOOL) isButtonPressed:(WiiButtonType) type;
- (WiiJoyStickCalibData) joyStickCalibData:(WiiJoyStickType) type;
- (WiiAccCalibData) accCalibData:(WiiAccelerationSensorType) type;
- (IOReturn) connectTo:(IOBluetoothDevice*) device;
- (IOReturn) closeConnection;
- (IOReturn) getCurrentStatus:(NSTimer*) timer;
- (IOReturn) writeData:(const unsigned char*) data at:(unsigned long) address length:(size_t) length;
- (IOReturn) readData:(unsigned long) address length:(unsigned short) length;
- (IOReturn) sendCommand:(const unsigned char*) data length:(size_t) length;
- (void) updateReportMode;
- (IOReturn) doUpdateReportMode;
- (void) setInitialConfiguration;
- (void) setIRSensorEnabled:(BOOL) enabled;
- (void) setForceFeedbackEnabled:(BOOL) enabled;
- (void) setMotionSensorEnabled:(BOOL) enabled;
- (void) setExpansionPortEnabled:(BOOL) enabled;
- (void) setLEDEnabled1:(BOOL) enabled1 enabled2:(BOOL) enabled2 enabled3:(BOOL) enabled3 enabled4:(BOOL) enabled4;
- (IOReturn) getMii:(unsigned int) slot;
- (void) sendWiiRemoteButtonEvent:(UInt16) data;
- (void) sendWiiNunchukButtonEvent:(UInt16) data;
- (void) sendWiiClassicControllerButtonEvent:(UInt16) data;
@end
@interface NSObject (WiiRemoteDelegate)
- (void) wiimoteWillSendData;
- (void) wiimoteDidSendData;
- (void) irPointMovedX:(float) px Y:(float) py;
- (void) rawIRData: (IRData[4]) irData;
- (void) buttonChanged:(WiiButtonType) type isPressed:(BOOL) isPressed;
- (void) accelerationChanged:(WiiAccelerationSensorType) type accX:(unsigned short) accX accY:(unsigned short) accY accZ:(unsigned short) accZ;
- (void) joyStickChanged:(WiiJoyStickType) type tiltX:(unsigned short) tiltX tiltY:(unsigned short) tiltY;
- (void) analogButtonChanged:(WiiButtonType) type amount:(unsigned short) press;
- (void) pressureChanged:(WiiPressureSensorType) type pressureTR:(float) bPressureTR pressureBR:(float) bPressureBR
pressureTL:(float) bPressureTL pressureBL:(float) bPressureBL;
- (void) batteryLevelChanged:(double) level;
- (void) wiiRemoteDisconnected:(IOBluetoothDevice*) device;
- (void) gotMiiData: (Mii*) mii_data_buf at: (int) slot;
- (void) rawPressureChanged:(WiiBalanceBoardGrid) bbData;
- (void) allPressureChanged:(WiiPressureSensorType) type bbData:(WiiBalanceBoardGrid) bbData bbDataInKg:(WiiBalanceBoardGrid) bbDataInKg;
@end