00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __OPENKN_CONTROLLER__WIIMOTE_HPP__
00025 #define __OPENKN_CONTROLLER__WIIMOTE_HPP__
00026
00027
00028
00029
00030 #include "WiimoteNunchuk.hpp"
00031
00032
00033
00034
00035 #include <queue>
00036 #include <iostream>
00037
00038 namespace kn{
00039
00040
00041 static const unsigned int EVENT_BUTTON_UP_UP= 0x4;
00042 static const unsigned int EVENT_BUTTON_UP_DOWN= 0x8;
00043 static const unsigned int EVENT_BUTTON_DOWN_UP= 0x10;
00044 static const unsigned int EVENT_BUTTON_DOWN_DOWN= 0x20;
00045 static const unsigned int EVENT_BUTTON_LEFT_UP= 0x40;
00046 static const unsigned int EVENT_BUTTON_LEFT_DOWN= 0x80;
00047 static const unsigned int EVENT_BUTTON_RIGHT_UP= 0x100;
00048 static const unsigned int EVENT_BUTTON_RIGHT_DOWN= 0x200;
00049 static const unsigned int EVENT_BUTTON_PLUS_UP= 0x400;
00050 static const unsigned int EVENT_BUTTON_PLUS_DOWN= 0x800;
00051 static const unsigned int EVENT_BUTTON_MINUS_UP= 0x1000;
00052 static const unsigned int EVENT_BUTTON_MINUS_DOWN= 0x2000;
00053 static const unsigned int EVENT_BUTTON_HOME_UP= 0x4000;
00054 static const unsigned int EVENT_BUTTON_HOME_DOWN= 0x8000;
00055 static const unsigned int EVENT_BUTTON_ONE_UP= 0x10000;
00056 static const unsigned int EVENT_BUTTON_ONE_DOWN= 0x20000;
00057 static const unsigned int EVENT_BUTTON_TWO_UP= 0x40000;
00058 static const unsigned int EVENT_BUTTON_TWO_DOWN= 0x80000;
00059 static const unsigned int EVENT_BUTTON_A_UP= 0x100000;
00060 static const unsigned int EVENT_BUTTON_A_DOWN= 0x200000;
00061 static const unsigned int EVENT_BUTTON_B_UP= 0x400000;
00062 static const unsigned int EVENT_BUTTON_B_DOWN= 0x800000;
00063
00064
00065 static const unsigned int ASPECT_16_9 = 0x0;
00066 static const unsigned int ASPECT_4_3 = 0x1;
00067 static const unsigned int IR_POSITION_ABOVE = 0x0;
00068 static const unsigned int IR_POSITION_BELOW = 0x1;
00069
00075 struct WiimoteIRDot{
00076 unsigned int x,y;
00077 short rx,ry;
00078 size_t size;
00079 bool visible;
00080 };
00081
00087 struct WiimoteIRPointer{
00088 int x,y;
00089 float z;
00090 };
00091
00098 class Wiimote : public InputController{
00099
00100 private:
00101
00105 std::queue<unsigned int> eventsqueue;
00106
00110 static const unsigned int maxevents = 10;
00111
00112
00113 unsigned int expansion;
00114
00118 wiimote * wm;
00119
00123 int ledsstatus;
00124
00128 bool rumble;
00129
00133 bool ir;
00134
00138 bool smoothing;
00139
00143 bool accelerations;
00144
00148 Nunchuk nunchuk;
00149
00150 public:
00151
00156 Wiimote(void):InputController(){}
00157
00165 Wiimote(wiimote* wiimote);
00166
00172 ~Wiimote(void){clearEvents();wiiuse_disconnect(wm);}
00173
00181 void addEvent(const unsigned int& event);
00182
00191 unsigned int popEvent(void) { if(eventsqueue.empty()){ return EVENT_NONE; this->updateAsNotUpdated();} unsigned int ev = eventsqueue.front(); eventsqueue.pop(); return ev;}
00192
00201 unsigned int topEvent(void) { if(eventsqueue.empty()){ return EVENT_NONE; this->updateAsNotUpdated();} return eventsqueue.front();}
00202
00212 unsigned int popError(void) {return 0;}
00213
00223 unsigned int topError(void) {return 0;}
00224
00230 void clearEvents(void);
00231
00239 unsigned int getExpansion(void)const{return expansion;}
00240
00246 void toggleRumble(void){wiiuse_toggle_rumble(wm); rumble=!rumble;}
00247
00255 bool isRumbleSet(void)const{return rumble;}
00256
00257
00265 void toggleLED(const unsigned int& id);
00266
00274 bool isLEDSet(const unsigned int& id)const;
00275
00281 void toggleIR(void){ir=!ir;wiiuse_set_ir(wm,ir);}
00282
00290 bool isIRSet(void)const{return ir;}
00291
00299 int getIRSensitivity(void)const{int lvl; WIIUSE_GET_IR_SENSITIVITY(wm,&lvl); return lvl;}
00300
00310 void setIRSensitivity(const int& lvl){wiiuse_set_ir_sensitivity(wm,lvl);}
00311
00319 unsigned int getDotsNumber(void) const {return wm->ir.num_dots;}
00320
00330 WiimoteIRDot getDot(const unsigned int& i) const;
00331
00339 WiimoteIRPointer getPointer(void) const;
00340
00351 void setIRParameters(const unsigned int& width, const unsigned int& height, const unsigned int& aspect=ASPECT_4_3, const unsigned int& position=IR_POSITION_BELOW);
00352
00358 void toggleMotion(void){accelerations = !accelerations; wiiuse_motion_sensing(wm,accelerations);}
00359
00367 bool isMotionSet(void)const{return accelerations;}
00368
00374 void toggleSmoothAccelerations(void){if(smoothing) wiiuse_set_flags(wm,0,WIIUSE_SMOOTHING); else wiiuse_set_flags(wm,WIIUSE_SMOOTHING,0); smoothing = !smoothing;}
00375
00385 float getRoll(void)const{return wm->orient.roll;}
00386
00396 float getAbsoluteRoll(void)const{return wm->orient.a_roll;}
00397
00407 float getPitch(void)const{return wm->orient.pitch;}
00408
00418 float getAbsolutePitch(void)const{return wm->orient.a_pitch;}
00419
00429 float getYaw(void)const{return wm->orient.yaw;}
00430
00439 float getXForce(void)const{return wm->gforce.x;}
00440
00449 float getYForce(void)const{return wm->gforce.y;}
00450
00459 float getZForce(void)const{return wm->gforce.z;}
00460
00461
00467 void showStatus(void);
00468
00477 Nunchuk& getNunchuk(void){return nunchuk;}
00478
00485 friend std::ostream& operator<<(std::ostream & , const Wiimote&);
00486
00487 };
00488
00489 }
00490
00491 #endif