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