00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifdef _MSC_VER // VC
00015 # pragma once
00016 #endif
00017
00018 #ifndef _WIIMOTE_STATE_H
00019 # define _WIIMOTE_STATE_H
00020
00021 #include "wiimote_common.h"
00022
00023
00024
00025 struct wiimote_state
00026 {
00027 friend class wiimote;
00028
00029
00030 struct calibration_info
00031 {
00032 BYTE X0, Y0, Z0;
00033 BYTE XG, YG, ZG;
00034 } CalibrationInfo;
00035
00036
00037 struct buttons
00038 {
00039
00040 inline bool A () const { return (Bits & _A) != 0; }
00041 inline bool B () const { return (Bits & _B) != 0; }
00042 inline bool Plus () const { return (Bits & PLUS) != 0; }
00043 inline bool Home () const { return (Bits & HOME) != 0; }
00044 inline bool Minus () const { return (Bits & MINUS) != 0; }
00045 inline bool One () const { return (Bits & ONE) != 0; }
00046 inline bool Two () const { return (Bits & TWO) != 0; }
00047 inline bool Up () const { return (Bits & UP) != 0; }
00048 inline bool Down () const { return (Bits & DOWN) != 0; }
00049 inline bool Left () const { return (Bits & LEFT) != 0; }
00050 inline bool Right () const { return (Bits & RIGHT) != 0; }
00051
00052
00053 WORD Bits;
00054
00055
00056 enum mask
00057 {
00058 LEFT = 0x0001,
00059 RIGHT = 0x0002,
00060 DOWN = 0x0004,
00061 UP = 0x0008,
00062 PLUS = 0x0010,
00063 TWO = 0x0100,
00064 ONE = 0x0200,
00065 _B = 0x0400,
00066 _A = 0x0800,
00067 MINUS = 0x1000,
00068 HOME = 0x8000,
00069
00070 ALL = LEFT|RIGHT|DOWN|UP|PLUS|TWO|ONE|_A|_B|MINUS|HOME,
00071 };
00072 } Button;
00073
00074
00075 struct acceleration
00076 {
00077 BYTE RawX, RawY, RawZ;
00078 float X, Y, Z;
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 struct orientation
00091 {
00092 float X, Y, Z;
00093 unsigned UpdateAge;
00094
00095
00096
00097
00098
00099
00100
00101
00102 float Pitch;
00103 float Roll;
00104
00105 } Orientation;
00106 } Acceleration;
00107
00108
00109 struct ir
00110 {
00111
00112
00113
00114
00115
00116
00117 static const unsigned MAX_RAW_X = 1016;
00118 static const unsigned MAX_RAW_Y = 760;
00119
00120
00121 enum mode
00122 {
00123 OFF = 0x00,
00124 BASIC = 0x01,
00125 EXTENDED = 0x03,
00126 FULL = 0x05,
00127 };
00128
00129 mode Mode;
00130
00131 struct dot
00132 {
00133 bool bVisible;
00134 unsigned RawX;
00135 unsigned RawY;
00136 float X;
00137 float Y;
00138 int Size;
00139 } Dot[4];
00140 } IR;
00141
00142 struct leds
00143 {
00144
00145 BYTE Bits;
00146
00147
00148 inline bool Lit (unsigned index)
00149 { _ASSERT(index < 4);
00150 return (index >= 4)? false : ((Bits & (1<<index)) != 0); }
00151 } LED;
00152
00153 BYTE BatteryRaw;
00154 BYTE BatteryPercent;
00155 bool bBatteryDrained;
00156 bool bRumble;
00157 bool bExtension;
00158
00159
00160 struct speaker
00161 {
00162 bool bEnabled;
00163 bool bMuted;
00164 speaker_freq Freq;
00165 BYTE Volume;
00166 } Speaker;
00167
00168
00169 enum extension_type
00170 {
00171 NONE = 0,
00172 NUNCHUK,
00173 CLASSIC,
00174 GH3_GHWT_GUITAR,
00175 GHWT_DRUMS,
00176 BALANCE_BOARD,
00177 MOTION_PLUS,
00178 PARTIALLY_INSERTED,
00179 };
00180 extension_type ExtensionType;
00181
00182
00183 struct joystick
00184 {
00185 friend class wiimote;
00186
00187
00188 float RawX, RawY;
00189
00190
00191
00192
00193 float X, Y;
00194
00195
00196
00197
00198
00199 struct deadzone
00200 {
00201 float X, Y;
00202 } DeadZone;
00203 };
00204
00205
00206 struct nunchuk
00207 {
00208 struct calibration_info
00209 {
00210 BYTE X0, Y0, Z0;
00211 BYTE XG, YG, ZG;
00212 BYTE MinX, MidX, MaxX;
00213 BYTE MinY, MidY, MaxY;
00214 } CalibrationInfo;
00215
00216 acceleration Acceleration;
00217 joystick Joystick;
00218 bool C;
00219 bool Z;
00220 } Nunchuk;
00221
00222
00223 struct classic_controller
00224 {
00225
00226 struct calibration_info
00227 {
00228 BYTE MinXL, MidXL, MaxXL;
00229 BYTE MinYL, MidYL, MaxYL;
00230 BYTE MinXR, MidXR, MaxXR;
00231 BYTE MinYR, MidYR, MaxYR;
00232 BYTE MinTriggerL, MaxTriggerL;
00233 BYTE MinTriggerR, MaxTriggerR;
00234 } CalibrationInfo;
00235
00236
00237 struct buttons
00238 {
00239
00240 inline bool A () const { return (Bits & _A) != 0; }
00241 inline bool B () const { return (Bits & _B) != 0; }
00242 inline bool Plus () const { return (Bits & PLUS) != 0; }
00243 inline bool Minus () const { return (Bits & MINUS) != 0; }
00244 inline bool Home () const { return (Bits & HOME) != 0; }
00245 inline bool Up () const { return (Bits & UP) != 0; }
00246 inline bool Down () const { return (Bits & DOWN) != 0; }
00247 inline bool Left () const { return (Bits & LEFT) != 0; }
00248 inline bool Right () const { return (Bits & RIGHT) != 0; }
00249 inline bool X () const { return (Bits & _X) != 0; }
00250 inline bool Y () const { return (Bits & _Y) != 0; }
00251 inline bool ZL () const { return (Bits & _ZL) != 0; }
00252 inline bool ZR () const { return (Bits & _ZR) != 0; }
00253 inline bool TriggerL () const { return (Bits & TRIG_L) != 0; }
00254 inline bool TriggerR () const { return (Bits & TRIG_R) != 0; }
00255
00256
00257 WORD Bits;
00258
00259
00260 enum mask
00261 {
00262 TRIG_R = 0x0002,
00263 PLUS = 0x0004,
00264 HOME = 0x0008,
00265 MINUS = 0x0010,
00266 TRIG_L = 0x0020,
00267 DOWN = 0x0040,
00268 RIGHT = 0x0080,
00269 UP = 0x0100,
00270 LEFT = 0x0200,
00271 _ZR = 0x0400,
00272 _X = 0x0800,
00273 _A = 0x1000,
00274 _Y = 0x2000,
00275 _B = 0x4000,
00276 _ZL = 0x8000,
00277
00278 ALL = TRIG_R|PLUS|HOME|MINUS|TRIG_L|DOWN|RIGHT|UP|LEFT|
00279 _ZR|_X|_A|_Y|_B|_ZL,
00280 };
00281 } Button;
00282
00283
00284 joystick JoystickL;
00285 joystick JoystickR;
00286
00287
00288 BYTE RawTriggerL, RawTriggerR;
00289 float TriggerL, TriggerR;
00290 } ClassicController;
00291
00292 struct balance_board
00293 {
00294
00295
00296 struct sensors_raw
00297 {
00298 short TopR;
00299 short TopL;
00300 short BottomR;
00301 short BottomL;
00302 };
00303 struct sensors_f
00304 {
00305 float TopL;
00306 float TopR;
00307 float BottomL;
00308 float BottomR;
00309
00310 float Total;
00311 };
00312
00313
00314 struct calibration_info
00315 {
00316 sensors_raw Kg0;
00317 sensors_raw Kg17;
00318 sensors_raw Kg34;
00319 } CalibrationInfo;
00320
00321
00322 sensors_raw Raw;
00323 sensors_f AtRestKg;
00324
00325 sensors_f Kg;
00326 sensors_f Lb;
00327 } BalanceBoard;
00328
00329 struct motion_plus
00330 {
00331
00332 struct sensors_raw
00333 {
00334 short Yaw;
00335 short Pitch;
00336 short Roll;
00337 };
00338 struct sensors_f
00339 {
00340 float Yaw;
00341 float Pitch;
00342 float Roll;
00343 };
00344
00345
00346 sensors_raw Raw;
00347 sensors_f Speed;
00348 } MotionPlus;
00349
00350
00351 protected:
00352 unsigned WiimoteNearGUpdates;
00353 unsigned NunchukNearGUpdates;
00354
00355 void Clear (bool including_deadzones)
00356 {
00357 joystick::deadzone nunchuk_deadzone,
00358 classic_joyl_deadzone,
00359 classic_joyr_deadzone;
00360
00361
00362 if(!including_deadzones) {
00363 nunchuk_deadzone = Nunchuk.Joystick.DeadZone;
00364 classic_joyl_deadzone = ClassicController.JoystickL.DeadZone;
00365 classic_joyr_deadzone = ClassicController.JoystickR.DeadZone;
00366 }
00367
00368 memset(this, 0, sizeof(wiimote_state));
00369
00370
00371 if(!including_deadzones) {
00372 Nunchuk.Joystick.DeadZone = nunchuk_deadzone;
00373 ClassicController.JoystickL.DeadZone = classic_joyl_deadzone;
00374 ClassicController.JoystickR.DeadZone = classic_joyr_deadzone;
00375 }
00376 }
00377 };
00378
00379 #endif // _WIIMOTE_STATE_H