2010-07-05 10:46:32 +00:00
|
|
|
#include "UDPWrapper.h"
|
2010-10-12 19:42:29 +00:00
|
|
|
|
2010-07-05 10:46:32 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2010-07-10 06:48:24 +00:00
|
|
|
const char* DefaultPort(const int index)
|
|
|
|
{
|
|
|
|
static std::string s;
|
|
|
|
s = "443";
|
|
|
|
s += (char)('2' + index);
|
|
|
|
return s.c_str();
|
|
|
|
}
|
|
|
|
|
2010-07-05 10:46:32 +00:00
|
|
|
UDPWrapper::UDPWrapper(int indx, const char* const _name) :
|
2010-07-06 01:37:34 +00:00
|
|
|
ControllerEmu::ControlGroup(_name,GROUP_TYPE_UDPWII),
|
|
|
|
inst(NULL), index(indx),
|
|
|
|
updIR(false),updAccel(false),
|
|
|
|
updButt(false),udpEn(false)
|
2010-07-10 06:48:24 +00:00
|
|
|
, port(DefaultPort(indx))
|
2010-07-05 10:46:32 +00:00
|
|
|
{
|
|
|
|
//PanicAlert("UDPWrapper #%d ctor",index);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UDPWrapper::LoadConfig(IniFile::Section *sec, const std::string& defdev, const std::string& base )
|
|
|
|
{
|
|
|
|
ControlGroup::LoadConfig(sec,defdev,base);
|
|
|
|
|
|
|
|
std::string group( base + name ); group += "/";
|
|
|
|
|
2010-07-14 17:33:14 +00:00
|
|
|
int _updAccel,_updIR,_updButt,_udpEn,_updNun,_updNunAccel;
|
2010-07-10 06:48:24 +00:00
|
|
|
sec->Get((group + "Enable").c_str(),&_udpEn, 0);
|
|
|
|
sec->Get((group + "Port").c_str(), &port, DefaultPort(index));
|
|
|
|
sec->Get((group + "Update_Accel").c_str(), &_updAccel, 1);
|
|
|
|
sec->Get((group + "Update_IR").c_str(), &_updIR, 1);
|
|
|
|
sec->Get((group + "Update_Butt").c_str(), &_updButt, 1);
|
2010-07-14 17:33:14 +00:00
|
|
|
sec->Get((group + "Update_Nunchuk").c_str(), &_updNun, 1);
|
|
|
|
sec->Get((group + "Update_NunchukAccel").c_str(), &_updNunAccel, 0);
|
2010-07-05 10:46:32 +00:00
|
|
|
|
|
|
|
udpEn=(_udpEn>0);
|
|
|
|
updAccel=(_updAccel>0);
|
|
|
|
updIR=(_updIR>0);
|
|
|
|
updButt=(_updButt>0);
|
2010-07-14 17:33:14 +00:00
|
|
|
updNun=(_updNun>0);
|
|
|
|
updNunAccel=(_updNunAccel>0);
|
2010-07-05 10:46:32 +00:00
|
|
|
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UDPWrapper::SaveConfig(IniFile::Section *sec, const std::string& defdev, const std::string& base )
|
|
|
|
{
|
|
|
|
ControlGroup::SaveConfig(sec,defdev,base);
|
|
|
|
std::string group( base + name ); group += "/";
|
2010-07-14 20:20:25 +00:00
|
|
|
sec->Set((group + "Enable").c_str(), (int)udpEn, 0);
|
|
|
|
sec->Set((group + "Port").c_str(), port, DefaultPort(index));
|
|
|
|
sec->Set((group + "Update_Accel").c_str(), (int)updAccel, 1);
|
|
|
|
sec->Set((group + "Update_IR").c_str(), (int)updIR, 1);
|
|
|
|
sec->Set((group + "Update_Butt").c_str(), (int)updButt, 1);
|
|
|
|
sec->Set((group + "Update_Nunchuk").c_str(), (int)updNun, 1);
|
|
|
|
sec->Set((group + "Update_NunchukAccel").c_str(), (int)updNunAccel, 0);
|
2010-07-05 10:46:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UDPWrapper::Refresh()
|
|
|
|
{
|
|
|
|
bool udpAEn=(inst!=NULL);
|
|
|
|
if (udpEn&&udpAEn)
|
|
|
|
{
|
|
|
|
if (strcmp(inst->getPort(),port.c_str()))
|
|
|
|
{
|
|
|
|
delete inst;
|
2010-07-19 10:36:30 +00:00
|
|
|
inst= new UDPWiimote(port.c_str(),"Dolphin-Emu",index); //TODO: Changeable display name
|
2010-07-05 10:46:32 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!udpEn)
|
|
|
|
{
|
|
|
|
if (inst)
|
|
|
|
delete inst;
|
|
|
|
inst=NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
//else
|
2010-07-19 10:36:30 +00:00
|
|
|
inst= new UDPWiimote(port.c_str(),"Dolphin-Emu",index);
|
2010-07-05 10:46:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UDPWrapper::~UDPWrapper()
|
|
|
|
{
|
|
|
|
if (inst)
|
|
|
|
delete inst;
|
|
|
|
}
|