00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "Wiimote.hpp"
00023 #include "ControllerException.hpp"
00024
00025 namespace kn {
00026
00027 Wiimote::Wiimote(wiimote* wiimote)
00028 :InputController(),wm(wiimote){
00029
00030 nunchuk = Nunchuk(wiimote);
00031
00032 expansion = wm->exp.type;
00033
00034 rumble=false;
00035 wiiuse_rumble(wm,0);
00036
00037 accelerations = true;
00038 wiiuse_motion_sensing(wm,accelerations);
00039
00040 smoothing = true;
00041
00042 ledsstatus=WIIMOTE_LED_NONE;
00043 wiiuse_set_leds(wm,ledsstatus);
00044
00045 ir = false;
00046
00047 }
00048
00049
00050 void Wiimote::addEvent(const unsigned int& event){
00051 while(eventsqueue.size() >= maxevents){
00052 eventsqueue.pop();
00053 }
00054 eventsqueue.push(event);
00055 this->flagAsUpdated();
00056 }
00057
00058
00059 void Wiimote::clearEvents(void){
00060 while(eventsqueue.size() != 0){
00061 eventsqueue.pop();
00062 }
00063 this->updateAsNotUpdated();
00064 }
00065
00066 bool Wiimote::isLEDSet(const unsigned int& id)const{
00067 if(id==1)
00068 return WIIUSE_IS_LED_SET(wm,1);
00069 if(id==2)
00070 return WIIUSE_IS_LED_SET(wm,2);
00071 if(id==3)
00072 return WIIUSE_IS_LED_SET(wm,3);
00073 if(id==4)
00074 return WIIUSE_IS_LED_SET(wm,4);
00075 return false;
00076 }
00077
00078
00079 void Wiimote::toggleLED(const unsigned int& id){
00080 int tmpstatus = WIIMOTE_LED_NONE;
00081 if(id==1) tmpstatus = WIIMOTE_LED_1;
00082 if(id==2) tmpstatus = WIIMOTE_LED_2;
00083 if(id==3) tmpstatus = WIIMOTE_LED_3;
00084 if(id==4) tmpstatus = WIIMOTE_LED_4;
00085 if(tmpstatus == WIIMOTE_LED_NONE) ledsstatus = WIIMOTE_LED_NONE;
00086 else ledsstatus ^= tmpstatus;
00087 wiiuse_set_leds(wm,ledsstatus);
00088 }
00089
00090 WiimoteIRDot Wiimote::getDot(const unsigned int& i) const{
00091 if(i > wm->ir.num_dots) throw ControllerException("No such dot","getDot");
00092 WiimoteIRDot ird;
00093 ird.x = wm->ir.dot[i].x;
00094 ird.y = wm->ir.dot[i].y;
00095 ird.rx = wm->ir.dot[i].rx;
00096 ird.ry = wm->ir.dot[i].ry;
00097 ird.size = wm->ir.dot[i].size;
00098 ird.visible = wm->ir.dot[i].visible;
00099 return ird;
00100 }
00101
00102 WiimoteIRPointer Wiimote::getPointer(void) const{
00103 WiimoteIRPointer irp;
00104 irp.x = wm->ir.x;
00105 irp.y = wm->ir.y;
00106 irp.z = wm->ir.z;
00107 return irp;
00108 }
00109
00110 void Wiimote::setIRParameters(const unsigned int& width,
00111 const unsigned int& height,
00112 const unsigned int& aspect,
00113 const unsigned int& position){
00114 if(aspect==ASPECT_16_9)
00115 wiiuse_set_aspect_ratio(wm,WIIUSE_ASPECT_16_9);
00116 else
00117 wiiuse_set_aspect_ratio(wm,WIIUSE_ASPECT_4_3);
00118
00119 if(position==IR_POSITION_ABOVE)
00120 wiiuse_set_ir_position(wm,WIIUSE_IR_ABOVE);
00121 else
00122 wiiuse_set_ir_position(wm,WIIUSE_IR_BELOW);
00123
00124 wiiuse_set_ir_vres(wm, width, height);
00125 }
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141 void Wiimote::showStatus(void){
00142 std::cout << *this << std::endl;
00143 }
00144
00145 std::ostream& operator<<(std::ostream &os, const Wiimote &wiimote)
00146 {
00147 os << "--- WIIMOTE STATUS [wiimote id " << wiimote.wm->unid << "] ---"<< std::endl;
00148 os << "attachment:" ;
00149 switch(wiimote.wm->exp.type)
00150 {
00151 case EXP_NONE:
00152 os << "none";
00153 break;
00154 case EXP_NUNCHUK:
00155 os << "nunchuk";
00156 break;
00157 case EXP_CLASSIC:
00158 os << "classic";
00159 break;
00160 case EXP_GUITAR_HERO_3:
00161 os << "guitar hero 3";
00162 break;
00163 default:
00164 os << "unknown attachment";
00165 break;
00166 }
00167 os << std::endl;
00168 os << "ir:" ;
00169 wiimote.ir ? os << "on" : os << "off";
00170 os << std::endl;
00171 os << "motion:";
00172 wiimote.accelerations ? os << "on": os << "off";
00173 os << std::endl;
00174 os << "leds:";
00175 WIIUSE_IS_LED_SET(wiimote.wm, 1) ? os << "on ": os << "off ";
00176 WIIUSE_IS_LED_SET(wiimote.wm, 2) ? os << "on ": os << "off ";
00177 WIIUSE_IS_LED_SET(wiimote.wm, 3) ? os << "on ": os << "off ";
00178 WIIUSE_IS_LED_SET(wiimote.wm, 4) ? os << "on ": os << "off ";
00179 os << std::endl;
00180 os << "battery:"<< int(100 * wiimote.wm->battery_level) << "%"<<std::endl;
00181 os << "smooth:" ;
00182 wiimote.wm->flags&WIIUSE_SMOOTHING? os << "on": os << "off";
00183 return os;
00184 }
00185 }