2014-02-10 18:54:46 +00:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
2014-02-19 01:17:31 +00:00
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
#include "InputCommon/UDPWrapper.h"
|
2010-07-05 10:46:32 +00:00
|
|
|
|
2014-02-08 05:50:37 +00:00
|
|
|
const std::string DefaultPort(const int index)
|
2010-07-10 06:48:24 +00:00
|
|
|
{
|
|
|
|
static std::string s;
|
|
|
|
s = "443";
|
|
|
|
s += (char)('2' + index);
|
2014-02-08 05:50:37 +00:00
|
|
|
return s;
|
2010-07-10 06:48:24 +00:00
|
|
|
}
|
|
|
|
|
2013-10-29 05:23:17 +00:00
|
|
|
UDPWrapper::UDPWrapper(int indx, const char* const _name) :
|
2010-07-06 01:37:34 +00:00
|
|
|
ControllerEmu::ControlGroup(_name,GROUP_TYPE_UDPWII),
|
2014-03-09 20:14:26 +00:00
|
|
|
inst(nullptr), index(indx),
|
2010-07-06 01:37:34 +00:00
|
|
|
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;
|
2014-02-08 05:50:37 +00:00
|
|
|
sec->Get(group + "Enable",&_udpEn, 0);
|
|
|
|
sec->Get(group + "Port", &port, DefaultPort(index));
|
|
|
|
sec->Get(group + "Update_Accel", &_updAccel, 1);
|
|
|
|
sec->Get(group + "Update_IR", &_updIR, 1);
|
|
|
|
sec->Get(group + "Update_Butt", &_updButt, 1);
|
|
|
|
sec->Get(group + "Update_Nunchuk", &_updNun, 1);
|
|
|
|
sec->Get(group + "Update_NunchukAccel", &_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 += "/";
|
2014-02-08 05:50:37 +00:00
|
|
|
sec->Set(group + "Enable", (int)udpEn, 0);
|
|
|
|
sec->Set(group + "Port", port, DefaultPort(index));
|
|
|
|
sec->Set(group + "Update_Accel", (int)updAccel, 1);
|
|
|
|
sec->Set(group + "Update_IR", (int)updIR, 1);
|
|
|
|
sec->Set(group + "Update_Butt", (int)updButt, 1);
|
|
|
|
sec->Set(group + "Update_Nunchuk", (int)updNun, 1);
|
|
|
|
sec->Set(group + "Update_NunchukAccel", (int)updNunAccel, 0);
|
2010-07-05 10:46:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UDPWrapper::Refresh()
|
|
|
|
{
|
2014-03-09 20:14:26 +00:00
|
|
|
bool udpAEn=(inst!=nullptr);
|
2014-03-12 19:33:41 +00:00
|
|
|
if (udpEn && udpAEn)
|
2010-07-05 10:46:32 +00:00
|
|
|
{
|
2014-03-12 19:33:41 +00:00
|
|
|
if (inst->getPort() == port)
|
2010-07-05 10:46:32 +00:00
|
|
|
{
|
|
|
|
delete inst;
|
2014-03-12 19:33:41 +00:00
|
|
|
inst = new UDPWiimote(port, "Dolphin-Emu", index); //TODO: Changeable display name
|
2010-07-05 10:46:32 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!udpEn)
|
|
|
|
{
|
|
|
|
if (inst)
|
|
|
|
delete inst;
|
2014-03-09 20:14:26 +00:00
|
|
|
inst = nullptr;
|
2010-07-05 10:46:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
//else
|
2014-03-12 19:33:41 +00:00
|
|
|
inst = new UDPWiimote(port, "Dolphin-Emu", index);
|
2010-07-05 10:46:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UDPWrapper::~UDPWrapper()
|
|
|
|
{
|
|
|
|
if (inst)
|
|
|
|
delete inst;
|
|
|
|
}
|