00001 #include "mitkWiiMoteAddOn.h" 00002 00003 #include "mitkGlobalInteraction.h" 00004 #include "mitkInteractionConst.h" 00005 00006 #include "mitkWiiMoteThread.h" 00007 00008 mitk::WiiMoteAddOn* mitk::WiiMoteAddOn::GetInstance() 00009 { 00010 static WiiMoteAddOn instance; 00011 return &instance; 00012 } 00013 00014 mitk::WiiMoteAddOn::WiiMoteAddOn(): m_WiiMoteThread(NULL) 00015 { 00016 } 00017 00018 mitk::WiiMoteAddOn::~WiiMoteAddOn() 00019 { 00020 this->DeactivateWiiMotes(); 00021 } 00022 00023 void mitk::WiiMoteAddOn::ActivateWiiMotes() 00024 { 00025 if(m_WiiMoteThread == NULL) 00026 { 00027 m_WiiMoteThread = new WiiMoteThread(); 00028 m_WiiMoteThread->Run(); 00029 } 00030 } 00031 00032 void mitk::WiiMoteAddOn::DeactivateWiiMotes() 00033 { 00034 if(m_WiiMoteThread != NULL) 00035 { 00036 m_WiiMoteThread->StopWiiMote(); 00037 00038 //needed, otherwise the mutex wants to unlock 00039 //when the object is already destroyed 00040 Sleep(1000); 00041 00042 m_WiiMoteThread->Delete(); 00043 m_WiiMoteThread = NULL; 00044 } 00045 } 00046 00047 void mitk::WiiMoteAddOn::WiiMoteInput(const itk::EventObject& e) 00048 { 00049 // apparently the dynamic cast does not work here 00050 // reason unknown - the normal cast however works fine 00051 mitk::StateEvent* se = new mitk::StateEvent(mitk::EIDWIIMOTEINPUT, (const mitk::WiiMoteIREvent*)&e); 00052 this->ForwardEvent(se); 00053 delete se; 00054 } 00055 00056 void mitk::WiiMoteAddOn::WiiMoteButtonPressed(const itk::EventObject &e) 00057 { 00058 mitk::WiiMoteButtonEvent const* wiiEvent = (const mitk::WiiMoteButtonEvent*)(&e); 00059 int key = wiiEvent->GetKey(); 00060 mitk::StateEvent* se; 00061 00062 switch(key) 00063 { 00064 case mitk::Key_Home: 00065 se = new mitk::StateEvent(mitk::EIDWIIMOTEBUTTON, wiiEvent); 00066 break; 00067 case mitk::Key_A: 00068 se = new mitk::StateEvent(mitk::EV_INIT, wiiEvent); 00069 break; 00070 } 00071 00072 if(se != NULL) 00073 { 00074 this->ForwardEvent(se); 00075 delete se; 00076 } 00077 } 00078 00079 void mitk::WiiMoteAddOn::WiiMoteCalibrationInput(const itk::EventObject &e) 00080 { 00081 mitk::StateEvent* se = new mitk::StateEvent(mitk::EIDWIIMOTEINPUT, (const mitk::WiiMoteCalibrationEvent*)&e); 00082 this->ForwardEvent(se); 00083 delete se; 00084 } 00085 00086 void mitk::WiiMoteAddOn::ForwardEvent(const mitk::StateEvent *e) 00087 { 00088 mitk::GlobalInteraction::GetInstance()->HandleEvent(e); 00089 } 00090 00091 00092 00093