Kill off dangling else's in the InputCommon project.

Some indentations were also too far for some things. Fixed this.

Also update the license header to show Git instead of SVN.

Got rid of some trailing spaces/tabs too.
This commit is contained in:
Lioncash 2013-04-14 22:53:10 -04:00
parent b91930a2d4
commit 8a9fcd3014
10 changed files with 148 additions and 69 deletions

View File

@ -12,7 +12,7 @@
// A copy of the GPL 2.0 should have been included with the program. // A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/ // If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at // Official Git repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
#include "ControllerEmu.h" #include "ControllerEmu.h"

View File

@ -12,7 +12,7 @@
// A copy of the GPL 2.0 should have been included with the program. // A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/ // If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at // Official Git repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
#ifndef _CONTROLLEREMU_H_ #ifndef _CONTROLLEREMU_H_
@ -196,11 +196,15 @@ public:
template <typename C> template <typename C>
void GetState(C* const buttons, const C* bitmasks) void GetState(C* const buttons, const C* bitmasks)
{ {
std::vector<Control*>::iterator i = controls.begin(), std::vector<Control*>::iterator
i = controls.begin(),
e = controls.end(); e = controls.end();
for (; i!=e; ++i, ++bitmasks) for (; i!=e; ++i, ++bitmasks)
{
if ((*i)->control_ref->State() > settings[0]->value) // threshold if ((*i)->control_ref->State() > settings[0]->value) // threshold
*buttons |= *bitmasks; *buttons |= *bitmasks;
}
} }
}; };
@ -221,8 +225,9 @@ public:
*digital |= *bitmasks; *digital |= *bitmasks;
} }
else else
{
*analog = S(controls[i+trig_count]->control_ref->State() * range); *analog = S(controls[i+trig_count]->control_ref->State() * range);
}
} }
} }

View File

@ -157,7 +157,7 @@ bool ControllerInterface::UpdateOutput(const bool force)
if (force) if (force)
lk.lock(); lk.lock();
else if (!lk.try_lock()) else if (!lk.try_lock())
return false; return false;
size_t ok_count = 0; size_t ok_count = 0;
@ -173,7 +173,7 @@ bool ControllerInterface::UpdateOutput(const bool force)
// //
// Device :: ~Device // Device :: ~Device
// //
// dtor, delete all inputs/outputs on device destruction // Destructor, delete all inputs/outputs on device destruction
// //
ControllerInterface::Device::~Device() ControllerInterface::Device::~Device()
{ {
@ -209,9 +209,9 @@ void ControllerInterface::Device::AddOutput(Output* const o)
// //
// Device :: ClearInputState // Device :: ClearInputState
// //
// device classes should override this func // Device classes should override this function
// ControllerInterface will call this when the device returns failure durring UpdateInput // ControllerInterface will call this when the device returns failure during UpdateInput
// used to try to set all buttons and axes to their default state when user unplugs a gamepad durring play // used to try to set all buttons and axes to their default state when user unplugs a gamepad during play
// buttons/axes that were held down at the time of unplugging should be seen as not pressed after unplugging // buttons/axes that were held down at the time of unplugging should be seen as not pressed after unplugging
// //
void ControllerInterface::Device::ClearInputState() void ControllerInterface::Device::ClearInputState()
@ -239,8 +239,10 @@ ControlState ControllerInterface::InputReference::State( const ControlState igno
// bit of hax for "NOT" to work at start of expression // bit of hax for "NOT" to work at start of expression
if (ci != ce) if (ci != ce)
{
if (ci->mode == 2) if (ci->mode == 2)
state = 1; state = 1;
}
for (; ci!=ce; ++ci) for (; ci!=ce; ++ci)
{ {
@ -354,7 +356,8 @@ bool ControllerInterface::DeviceQualifier::operator==(const ControllerInterface:
if (name == devq.name) if (name == devq.name)
if (source == devq.source) if (source == devq.source)
return true; return true;
return false;
return false;
} }
// //
@ -421,7 +424,9 @@ void ControllerInterface::UpdateReference(ControllerInterface::ControlReference*
break; // no terminating '`' character break; // no terminating '`' character
} }
else else
{
ctrl_str += c; ctrl_str += c;
}
} }
} }
@ -478,7 +483,9 @@ ControllerInterface::Device::Control* ControllerInterface::InputReference::Detec
return *i; return *i;
} }
else if ((*i)->GetState() < (1 - INPUT_DETECT_THRESHOLD)) else if ((*i)->GetState() < (1 - INPUT_DETECT_THRESHOLD))
{
*state = false; *state = false;
}
} }
Common::SleepCurrentThread(10); time += 10; Common::SleepCurrentThread(10); time += 10;
} }
@ -490,8 +497,8 @@ ControllerInterface::Device::Control* ControllerInterface::InputReference::Detec
// //
// OutputReference :: Detect // OutputReference :: Detect
// //
// totally different from the inputReference detect / i have them combined so it was simplier to make the gui. // Totally different from the inputReference detect / I have them combined so it was simpler to make the GUI.
// the gui doesnt know the difference between an input and an output / its odd but i was lazy and it was easy // The GUI doesn't know the difference between an input and an output / it's odd but I was lazy and it was easy
// //
// set all binded outputs to <range> power for x milliseconds return false // set all binded outputs to <range> power for x milliseconds return false
// //
@ -499,7 +506,7 @@ ControllerInterface::Device::Control* ControllerInterface::OutputReference::Dete
{ {
// ignore device // ignore device
// dont hang if we dont even have any controls mapped // don't hang if we don't even have any controls mapped
if (m_controls.size()) if (m_controls.size())
{ {
State(1); State(1);

View File

@ -319,9 +319,13 @@ Joystick::Joystick( /*const LPCDIDEVICEINSTANCE lpddi, */const LPDIRECTINPUTDEVI
eff.lpvTypeSpecificParams = &diCF; eff.lpvTypeSpecificParams = &diCF;
} }
else if (1 == f) else if (1 == f)
{
eff.cbTypeSpecificParams = sizeof(DIRAMPFORCE); eff.cbTypeSpecificParams = sizeof(DIRAMPFORCE);
}
else else
{
eff.cbTypeSpecificParams = sizeof(DIPERIODIC); eff.cbTypeSpecificParams = sizeof(DIPERIODIC);
}
LPDIRECTINPUTEFFECT pEffect; LPDIRECTINPUTEFFECT pEffect;
if (SUCCEEDED(m_device->CreateEffect(force_type_names[f].guid, &eff, &pEffect, NULL))) if (SUCCEEDED(m_device->CreateEffect(force_type_names[f].guid, &eff, &pEffect, NULL)))
@ -427,7 +431,9 @@ bool Joystick::UpdateInput()
} }
} }
else else
{
hr = m_device->GetDeviceState(sizeof(m_state_in), &m_state_in); hr = m_device->GetDeviceState(sizeof(m_state_in), &m_state_in);
}
// try reacquire if input lost // try reacquire if input lost
if (DIERR_INPUTLOST == hr || DIERR_NOTACQUIRED == hr) if (DIERR_INPUTLOST == hr || DIERR_NOTACQUIRED == hr)
@ -460,12 +466,16 @@ bool Joystick::UpdateOutput()
ok_count += SUCCEEDED(i->iface->SetParameters(&eff, DIEP_TYPESPECIFICPARAMS | DIEP_START)); ok_count += SUCCEEDED(i->iface->SetParameters(&eff, DIEP_TYPESPECIFICPARAMS | DIEP_START));
} }
else else
{
ok_count += SUCCEEDED(i->iface->Stop()); ok_count += SUCCEEDED(i->iface->Stop());
}
i->params = NULL; i->params = NULL;
} }
else else
{
++ok_count; ++ok_count;
}
} }
return (m_state_out.size() == ok_count); return (m_state_out.size() == ok_count);
@ -492,7 +502,9 @@ std::string Joystick::Axis::GetName() const
} }
// slider // slider
else else
{
ss << "Slider " << (int)(m_index - 6); ss << "Slider " << (int)(m_index - 6);
}
ss << (m_range < 0 ? '-' : '+'); ss << (m_range < 0 ? '-' : '+');
return ss.str(); return ss.str();

View File

@ -56,15 +56,19 @@ void InitKeyboardMouse(IDirectInput8* const idi8, std::vector<ControllerInterfac
if (SUCCEEDED(idi8->CreateDevice( GUID_SysKeyboard, &kb_device, NULL))) if (SUCCEEDED(idi8->CreateDevice( GUID_SysKeyboard, &kb_device, NULL)))
{ {
if (SUCCEEDED(kb_device->SetDataFormat(&c_dfDIKeyboard))) if (SUCCEEDED(kb_device->SetDataFormat(&c_dfDIKeyboard)))
if (SUCCEEDED(kb_device->SetCooperativeLevel(NULL, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE)))
{ {
if (SUCCEEDED(idi8->CreateDevice( GUID_SysMouse, &mo_device, NULL ))) if (SUCCEEDED(kb_device->SetCooperativeLevel(NULL, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE)))
{ {
if (SUCCEEDED(mo_device->SetDataFormat(&c_dfDIMouse2))) if (SUCCEEDED(idi8->CreateDevice( GUID_SysMouse, &mo_device, NULL )))
if (SUCCEEDED(mo_device->SetCooperativeLevel(NULL, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE)))
{ {
devices.push_back(new KeyboardMouse(kb_device, mo_device)); if (SUCCEEDED(mo_device->SetDataFormat(&c_dfDIMouse2)))
return; {
if (SUCCEEDED(mo_device->SetCooperativeLevel(NULL, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE)))
{
devices.push_back(new KeyboardMouse(kb_device, mo_device));
return;
}
}
} }
} }
} }
@ -203,7 +207,9 @@ bool KeyboardMouse::UpdateOutput()
memset( this, 0, sizeof(*this) ); memset( this, 0, sizeof(*this) );
type = INPUT_KEYBOARD; type = INPUT_KEYBOARD;
ki.wVk = key; ki.wVk = key;
if (up) ki.dwFlags = KEYEVENTF_KEYUP;
if (up)
ki.dwFlags = KEYEVENTF_KEYUP;
} }
}; };

View File

@ -34,7 +34,7 @@ void Init( std::vector<ControllerInterface::Device*>& devices )
std::map<std::string, int> name_counts; std::map<std::string, int> name_counts;
if (SDL_Init( SDL_INIT_FLAGS ) >= 0) if (SDL_Init( SDL_INIT_FLAGS ) >= 0)
{ {
// joysticks // joysticks
for(int i = 0; i < SDL_NumJoysticks(); ++i) for(int i = 0; i < SDL_NumJoysticks(); ++i)
{ {
@ -49,7 +49,7 @@ void Init( std::vector<ControllerInterface::Device*>& devices )
delete js; delete js;
} }
} }
} }
} }
Joystick::Joystick(SDL_Joystick* const joystick, const int sdl_index, const unsigned int index) Joystick::Joystick(SDL_Joystick* const joystick, const int sdl_index, const unsigned int index)
@ -63,7 +63,7 @@ Joystick::Joystick(SDL_Joystick* const joystick, const int sdl_index, const unsi
// "why don't my 360 gamepad triggers/rumble work correctly" // "why don't my 360 gamepad triggers/rumble work correctly"
#ifdef _WIN32 #ifdef _WIN32
// checking the name is probably good (and hacky) enough // checking the name is probably good (and hacky) enough
// but i'll double check with the num of buttons/axes // but I'll double check with the num of buttons/axes
std::string lcasename = GetName(); std::string lcasename = GetName();
std::transform(lcasename.begin(), lcasename.end(), lcasename.begin(), tolower); std::transform(lcasename.begin(), lcasename.end(), lcasename.begin(), tolower);
@ -204,7 +204,9 @@ void Joystick::ConstantEffect::SetState(const ControlState state)
m_effect.effect.constant.length = SDL_HAPTIC_INFINITY; m_effect.effect.constant.length = SDL_HAPTIC_INFINITY;
} }
else else
{
m_effect.effect.type = 0; m_effect.effect.type = 0;
}
const Sint16 old = m_effect.effect.constant.level; const Sint16 old = m_effect.effect.constant.level;
m_effect.effect.constant.level = state * 0x7FFF; m_effect.effect.constant.level = state * 0x7FFF;
@ -220,7 +222,9 @@ void Joystick::RampEffect::SetState(const ControlState state)
m_effect.effect.ramp.length = SDL_HAPTIC_INFINITY; m_effect.effect.ramp.length = SDL_HAPTIC_INFINITY;
} }
else else
{
m_effect.effect.type = 0; m_effect.effect.type = 0;
}
const Sint16 old = m_effect.effect.ramp.start; const Sint16 old = m_effect.effect.ramp.start;
m_effect.effect.ramp.start = state * 0x7FFF; m_effect.effect.ramp.start = state * 0x7FFF;
@ -235,15 +239,17 @@ void Joystick::SineEffect::SetState(const ControlState state)
m_effect.effect.type = SDL_HAPTIC_SINE; m_effect.effect.type = SDL_HAPTIC_SINE;
m_effect.effect.periodic.length = 250; m_effect.effect.periodic.length = 250;
} }
else { else
{
m_effect.effect.type = 0; m_effect.effect.type = 0;
} }
const Sint16 old = m_effect.effect.periodic.magnitude; const Sint16 old = m_effect.effect.periodic.magnitude;
m_effect.effect.periodic.period = 5; m_effect.effect.periodic.period = 5;
m_effect.effect.periodic.magnitude = state * 0x5000; m_effect.effect.periodic.magnitude = state * 0x5000;
m_effect.effect.periodic.attack_length = 0; m_effect.effect.periodic.attack_length = 0;
m_effect.effect.periodic.fade_length = 500; m_effect.effect.periodic.fade_length = 500;
if (old != m_effect.effect.periodic.magnitude) if (old != m_effect.effect.periodic.magnitude)
m_effect.changed = true; m_effect.changed = true;
} }
@ -255,15 +261,17 @@ void Joystick::SquareEffect::SetState(const ControlState state)
m_effect.effect.type = SDL_HAPTIC_SQUARE; m_effect.effect.type = SDL_HAPTIC_SQUARE;
m_effect.effect.periodic.length = 250; m_effect.effect.periodic.length = 250;
} }
else { else
{
m_effect.effect.type = 0; m_effect.effect.type = 0;
} }
const Sint16 old = m_effect.effect.periodic.magnitude; const Sint16 old = m_effect.effect.periodic.magnitude;
m_effect.effect.periodic.period = 5; m_effect.effect.periodic.period = 5;
m_effect.effect.periodic.magnitude = state * 0x5000; m_effect.effect.periodic.magnitude = state * 0x5000;
m_effect.effect.periodic.attack_length = 0; m_effect.effect.periodic.attack_length = 0;
m_effect.effect.periodic.fade_length = 100; m_effect.effect.periodic.fade_length = 100;
if (old != m_effect.effect.periodic.magnitude) if (old != m_effect.effect.periodic.magnitude)
m_effect.changed = true; m_effect.changed = true;
} }
@ -275,15 +283,17 @@ void Joystick::TriangleEffect::SetState(const ControlState state)
m_effect.effect.type = SDL_HAPTIC_TRIANGLE; m_effect.effect.type = SDL_HAPTIC_TRIANGLE;
m_effect.effect.periodic.length = 250; m_effect.effect.periodic.length = 250;
} }
else { else
{
m_effect.effect.type = 0; m_effect.effect.type = 0;
} }
const Sint16 old = m_effect.effect.periodic.magnitude; const Sint16 old = m_effect.effect.periodic.magnitude;
m_effect.effect.periodic.period = 5; m_effect.effect.periodic.period = 5;
m_effect.effect.periodic.magnitude = state * 0x5000; m_effect.effect.periodic.magnitude = state * 0x5000;
m_effect.effect.periodic.attack_length = 0; m_effect.effect.periodic.attack_length = 0;
m_effect.effect.periodic.fade_length = 100; m_effect.effect.periodic.fade_length = 100;
if (old != m_effect.effect.periodic.magnitude) if (old != m_effect.effect.periodic.magnitude)
m_effect.changed = true; m_effect.changed = true;
} }
@ -316,7 +326,9 @@ bool Joystick::UpdateOutput()
else // effect is already uploaded else // effect is already uploaded
{ {
if (i->effect.type) // if ouputstate >0 if (i->effect.type) // if ouputstate >0
{
SDL_HapticUpdateEffect(m_haptic, i->id, &i->effect); // update the effect SDL_HapticUpdateEffect(m_haptic, i->id, &i->effect); // update the effect
}
else else
{ {
SDL_HapticStopEffect(m_haptic, i->id); // else, stop and remove the effect SDL_HapticStopEffect(m_haptic, i->id); // else, stop and remove the effect

View File

@ -31,13 +31,13 @@ static const struct
{ "Thumb R", XINPUT_GAMEPAD_RIGHT_THUMB } { "Thumb R", XINPUT_GAMEPAD_RIGHT_THUMB }
}; };
static const char* const named_triggers[] = static const char* const named_triggers[] =
{ {
"Trigger L", "Trigger L",
"Trigger R" "Trigger R"
}; };
static const char* const named_axes[] = static const char* const named_axes[] =
{ {
"Left X", "Left X",
"Left Y", "Left Y",
@ -45,7 +45,7 @@ static const char* const named_axes[] =
"Right Y" "Right Y"
}; };
static const char* const named_motors[] = static const char* const named_motors[] =
{ {
"Motor L", "Motor L",
"Motor R" "Motor R"
@ -66,12 +66,14 @@ Device::Device(const XINPUT_CAPABILITIES& caps, u8 index)
ZeroMemory(&m_current_state_out, sizeof(m_current_state_out)); ZeroMemory(&m_current_state_out, sizeof(m_current_state_out));
// XInputGetCaps seems to always claim all capabilities are supported // XInputGetCaps seems to always claim all capabilities are supported
// but i will leave all this stuff in, incase m$ fixes xinput up a bit // but I will leave all this stuff in, incase m$ fixes xinput up a bit
// get supported buttons // get supported buttons
for (int i = 0; i != sizeof(named_buttons)/sizeof(*named_buttons); ++i) for (int i = 0; i != sizeof(named_buttons)/sizeof(*named_buttons); ++i)
{
if (named_buttons[i].bitmask & caps.Gamepad.wButtons) if (named_buttons[i].bitmask & caps.Gamepad.wButtons)
AddInput(new Button(i, m_state_in.Gamepad.wButtons)); AddInput(new Button(i, m_state_in.Gamepad.wButtons));
}
// get supported triggers // get supported triggers
for (int i = 0; i != sizeof(named_triggers)/sizeof(*named_triggers); ++i) for (int i = 0; i != sizeof(named_triggers)/sizeof(*named_triggers); ++i)
@ -114,8 +116,8 @@ void Device::ClearInputState()
std::string Device::GetName() const std::string Device::GetName() const
{ {
// why aren't these defined // why aren't these defined
// subtype doesn't seem to work, i tested with 2 diff arcade sticks, both were shown as gamepad // subtype doesn't seem to work, I tested with 2 different arcade sticks, both were shown as gamepad
// ill leave it in anyway, maybe m$ will fix it // I'll leave it in anyway, maybe m$ will fix it
switch (m_subtype) switch (m_subtype)
{ {
@ -140,7 +142,7 @@ std::string Device::GetSource() const
return "XInput"; return "XInput";
} }
// update i/o // Update I/O
bool Device::UpdateInput() bool Device::UpdateInput()
{ {
@ -157,7 +159,9 @@ bool Device::UpdateOutput()
return (ERROR_SUCCESS == XInputSetState(m_index, &m_state_out)); return (ERROR_SUCCESS == XInputSetState(m_index, &m_state_out));
} }
else else
{
return true; return true;
}
} }
// GET name/source/id // GET name/source/id

View File

@ -12,7 +12,7 @@
// A copy of the GPL 2.0 should have been included with the program. // A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/ // If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at // Official Git repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
#ifndef _GCPAD_H_INCLUDED__ #ifndef _GCPAD_H_INCLUDED__

View File

@ -78,7 +78,10 @@ bool InputPlugin::LoadConfig(bool isGC)
(*i)->LoadConfig(profile_ini.GetOrCreateSection("Profile")); (*i)->LoadConfig(profile_ini.GetOrCreateSection("Profile"));
} }
else else
{
(*i)->LoadConfig(inifile.GetOrCreateSection((*i)->GetName().c_str())); (*i)->LoadConfig(inifile.GetOrCreateSection((*i)->GetName().c_str()));
}
// update refs // update refs
(*i)->UpdateReferences(g_controller_interface); (*i)->UpdateReferences(g_controller_interface);
} }

View File

@ -96,32 +96,39 @@ UDPWiimote::UDPWiimote(const char *_port, const char * name, int _index) :
hints.ai_socktype = SOCK_DGRAM; hints.ai_socktype = SOCK_DGRAM;
hints.ai_flags = AI_PASSIVE; // use my IP hints.ai_flags = AI_PASSIVE; // use my IP
if (!int_port){ if (!int_port)
{
cleanup; cleanup;
err=-1; err=-1;
return; return;
} }
if ((rv = getaddrinfo(NULL, _port, &hints, &servinfo)) != 0) { if ((rv = getaddrinfo(NULL, _port, &hints, &servinfo)) != 0)
{
cleanup; cleanup;
err=-1; err=-1;
return; return;
} }
// loop through all the results and bind to everything we can // loop through all the results and bind to everything we can
for(p = servinfo; p != NULL; p = p->ai_next) { for(p = servinfo; p != NULL; p = p->ai_next)
{
sock_t sock; sock_t sock;
if ((sock = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == BAD_SOCK) { if ((sock = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == BAD_SOCK)
{
continue; continue;
} }
if (bind(sock, p->ai_addr, (int)p->ai_addrlen) == -1) {
if (bind(sock, p->ai_addr, (int)p->ai_addrlen) == -1)
{
close(sock); close(sock);
continue; continue;
} }
d->sockfds.push_back(sock); d->sockfds.push_back(sock);
} }
if (d->sockfds.empty()) { if (d->sockfds.empty())
{
cleanup; cleanup;
err=-2; err=-2;
return; return;
@ -170,7 +177,9 @@ void UDPWiimote::mainThread()
timeout.tv_sec=1; timeout.tv_sec=1;
timeout.tv_usec=500000; timeout.tv_usec=500000;
broadcastPresence(); broadcastPresence();
} else { }
else
{
tleft-=telapsed; tleft-=telapsed;
timeout.tv_sec=(long)(tleft/1000); timeout.tv_sec=(long)(tleft/1000);
timeout.tv_usec=(tleft%1000)*1000; timeout.tv_usec=(tleft%1000)*1000;
@ -186,6 +195,7 @@ void UDPWiimote::mainThread()
if (rt) if (rt)
{ {
for (std::list<sock_t>::iterator i=d->sockfds.begin(); i!=d->sockfds.end(); i++) for (std::list<sock_t>::iterator i=d->sockfds.begin(); i!=d->sockfds.end(); i++)
{
if (FD_ISSET(*i,&fds)) if (FD_ISSET(*i,&fds))
{ {
sock_t fd=*i; sock_t fd=*i;
@ -206,11 +216,14 @@ void UDPWiimote::mainThread()
if (pharsePacket(bf,size)==0) if (pharsePacket(bf,size)==0)
{ {
//NOTICE_LOG(WIIMOTE,"UDPWII New pack"); //NOTICE_LOG(WIIMOTE,"UDPWII New pack");
} else { }
else
{
//NOTICE_LOG(WIIMOTE,"UDPWII Wrong pack format... ignoring"); //NOTICE_LOG(WIIMOTE,"UDPWII Wrong pack format... ignoring");
} }
} }
} }
}
} }
} while (!(d->exit)); } while (!(d->exit));
} }
@ -230,16 +243,18 @@ UDPWiimote::~UDPWiimote()
delete d; delete d;
} }
#define ACCEL_FLAG (1<<0) #define ACCEL_FLAG (1 << 0)
#define BUTT_FLAG (1<<1) #define BUTT_FLAG (1 << 1)
#define IR_FLAG (1<<2) #define IR_FLAG (1 << 2)
#define NUN_FLAG (1<<3) #define NUN_FLAG (1 << 3)
#define NUNACCEL_FLAG (1<<4) #define NUNACCEL_FLAG (1 << 4)
int UDPWiimote::pharsePacket(u8 * bf, size_t size) int UDPWiimote::pharsePacket(u8 * bf, size_t size)
{ {
if (size<3) return -1; if (size < 3)
if (bf[0]!=0xde) return -1;
if (bf[0] != 0xde)
return -1; return -1;
//if (bf[1]==0) //if (bf[1]==0)
// time=0; // time=0;
@ -247,9 +262,11 @@ int UDPWiimote::pharsePacket(u8 * bf, size_t size)
// return -1; // return -1;
//time=bf[1]; //time=bf[1];
u32 *p=(u32*)(&bf[3]); u32 *p=(u32*)(&bf[3]);
if (bf[2]&ACCEL_FLAG) if (bf[2] & ACCEL_FLAG)
{ {
if ((size-(((u8*)p)-bf))<12) return -1; if ((size-(((u8*)p)-bf)) < 12)
return -1;
double ux,uy,uz; double ux,uy,uz;
ux=(double)((s32)ntohl(*p)); p++; ux=(double)((s32)ntohl(*p)); p++;
uy=(double)((s32)ntohl(*p)); p++; uy=(double)((s32)ntohl(*p)); p++;
@ -258,27 +275,39 @@ int UDPWiimote::pharsePacket(u8 * bf, size_t size)
y=uy/1048576; y=uy/1048576;
z=uz/1048576; z=uz/1048576;
} }
if (bf[2]&BUTT_FLAG)
if (bf[2] & BUTT_FLAG)
{ {
if ((size-(((u8*)p)-bf))<4) return -1; if ((size-(((u8*)p)-bf)) < 4)
return -1;
mask=ntohl(*p); p++; mask=ntohl(*p); p++;
} }
if (bf[2]&IR_FLAG)
if (bf[2] & IR_FLAG)
{ {
if ((size-(((u8*)p)-bf))<8) return -1; if ((size-(((u8*)p)-bf)) < 8)
return -1;
pointerX=((double)((s32)ntohl(*p)))/1048576; p++; pointerX=((double)((s32)ntohl(*p)))/1048576; p++;
pointerY=((double)((s32)ntohl(*p)))/1048576; p++; pointerY=((double)((s32)ntohl(*p)))/1048576; p++;
} }
if (bf[2]&NUN_FLAG)
if (bf[2] & NUN_FLAG)
{ {
if ((size-(((u8*)p)-bf))<9) return -1; if ((size-(((u8*)p)-bf)) < 9)
return -1;
nunMask=*((u8*)p); p=(u32*)(((u8*)p)+1); nunMask=*((u8*)p); p=(u32*)(((u8*)p)+1);
nunX=((double)((s32)ntohl(*p)))/1048576; p++; nunX=((double)((s32)ntohl(*p)))/1048576; p++;
nunY=((double)((s32)ntohl(*p)))/1048576; p++; nunY=((double)((s32)ntohl(*p)))/1048576; p++;
} }
if (bf[2]&NUNACCEL_FLAG)
if (bf[2] & NUNACCEL_FLAG)
{ {
if ((size-(((u8*)p)-bf))<12) return -1; if ((size-(((u8*)p)-bf)) < 12)
return -1;
double ux,uy,uz; double ux,uy,uz;
ux=(double)((s32)ntohl(*p)); p++; ux=(double)((s32)ntohl(*p)); p++;
uy=(double)((s32)ntohl(*p)); p++; uy=(double)((s32)ntohl(*p)); p++;
@ -287,6 +316,7 @@ int UDPWiimote::pharsePacket(u8 * bf, size_t size)
naY=uy/1048576; naY=uy/1048576;
naZ=uz/1048576; naZ=uz/1048576;
} }
return 0; return 0;
} }
@ -314,7 +344,7 @@ void UDPWiimote::broadcastIPv4(const void * data, size_t size)
their_addr.sin_family = AF_INET; their_addr.sin_family = AF_INET;
their_addr.sin_port = htons(4431); their_addr.sin_port = htons(4431);
their_addr.sin_addr.s_addr = INADDR_BROADCAST; their_addr.sin_addr.s_addr = INADDR_BROADCAST;
memset(their_addr.sin_zero, '\0', sizeof their_addr.sin_zero); memset(their_addr.sin_zero, '\0', sizeof their_addr.sin_zero);
int num; int num;
if ((num=sendto(d->bipv4_fd,(const dataz)data,(int)size,0,(struct sockaddr *) &their_addr, sizeof their_addr)) == -1) if ((num=sendto(d->bipv4_fd,(const dataz)data,(int)size,0,(struct sockaddr *) &their_addr, sizeof their_addr)) == -1)