mirror of
https://github.com/citra-emu/citra.git
synced 2024-12-22 14:00:05 +00:00
input_common/udp: allow changing pad index
This commit is contained in:
parent
d1c364bb85
commit
e1ae14d508
@ -81,6 +81,9 @@ udp_input_address=
|
|||||||
# Port of the udp input server. (Default 26760)
|
# Port of the udp input server. (Default 26760)
|
||||||
udp_input_port=
|
udp_input_port=
|
||||||
|
|
||||||
|
# The pad to request data on. Should be between 0 (Pad 1) and 3 (Pad 4). (Default 0)
|
||||||
|
udp_pad_index=
|
||||||
|
|
||||||
[Core]
|
[Core]
|
||||||
# Whether to use the Just-In-Time (JIT) compiler for CPU emulation
|
# Whether to use the Just-In-Time (JIT) compiler for CPU emulation
|
||||||
# 0: Interpreter (slow), 1 (default): JIT (fast)
|
# 0: Interpreter (slow), 1 (default): JIT (fast)
|
||||||
|
@ -81,6 +81,7 @@ void Config::ReadValues() {
|
|||||||
.toStdString();
|
.toStdString();
|
||||||
Settings::values.udp_input_port = static_cast<u16>(
|
Settings::values.udp_input_port = static_cast<u16>(
|
||||||
ReadSetting("udp_input_port", InputCommon::CemuhookUDP::DEFAULT_PORT).toInt());
|
ReadSetting("udp_input_port", InputCommon::CemuhookUDP::DEFAULT_PORT).toInt());
|
||||||
|
Settings::values.udp_pad_index = static_cast<u8>(ReadSetting("udp_pad_index", 0).toUInt());
|
||||||
|
|
||||||
qt_config->endGroup();
|
qt_config->endGroup();
|
||||||
|
|
||||||
@ -331,6 +332,7 @@ void Config::SaveValues() {
|
|||||||
InputCommon::CemuhookUDP::DEFAULT_ADDR);
|
InputCommon::CemuhookUDP::DEFAULT_ADDR);
|
||||||
WriteSetting("udp_input_port", Settings::values.udp_input_port,
|
WriteSetting("udp_input_port", Settings::values.udp_input_port,
|
||||||
InputCommon::CemuhookUDP::DEFAULT_PORT);
|
InputCommon::CemuhookUDP::DEFAULT_PORT);
|
||||||
|
WriteSetting("udp_pad_index", Settings::values.udp_pad_index, 0);
|
||||||
qt_config->endGroup();
|
qt_config->endGroup();
|
||||||
|
|
||||||
qt_config->beginGroup("Core");
|
qt_config->beginGroup("Core");
|
||||||
|
@ -98,6 +98,7 @@ struct Values {
|
|||||||
std::string touch_device;
|
std::string touch_device;
|
||||||
std::string udp_input_address;
|
std::string udp_input_address;
|
||||||
u16 udp_input_port;
|
u16 udp_input_port;
|
||||||
|
u8 udp_pad_index;
|
||||||
|
|
||||||
// Core
|
// Core
|
||||||
bool use_cpu_jit;
|
bool use_cpu_jit;
|
||||||
|
@ -30,10 +30,12 @@ class Socket {
|
|||||||
public:
|
public:
|
||||||
using clock = std::chrono::system_clock;
|
using clock = std::chrono::system_clock;
|
||||||
|
|
||||||
explicit Socket(const std::string& host, u16 port, u32 client_id, SocketCallback callback)
|
explicit Socket(const std::string& host, u16 port, u8 pad_index, u32 client_id,
|
||||||
|
SocketCallback callback)
|
||||||
: client_id(client_id), timer(io_service),
|
: client_id(client_id), timer(io_service),
|
||||||
send_endpoint(udp::endpoint(address_v4::from_string(host), port)),
|
send_endpoint(udp::endpoint(address_v4::from_string(host), port)),
|
||||||
socket(io_service, udp::endpoint(udp::v4(), 0)), callback(std::move(callback)) {}
|
socket(io_service, udp::endpoint(udp::v4(), 0)), pad_index(pad_index),
|
||||||
|
callback(std::move(callback)) {}
|
||||||
|
|
||||||
void Stop() {
|
void Stop() {
|
||||||
io_service.stop();
|
io_service.stop();
|
||||||
@ -85,15 +87,14 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void HandleSend(const boost::system::error_code& error) {
|
void HandleSend(const boost::system::error_code& error) {
|
||||||
// TODO: add something to the UI to let people choose what ports to listen on
|
// Send a request for getting port info for the pad
|
||||||
// Send a request for getting port info for pad 1
|
Request::PortInfo port_info{1, {pad_index, 0, 0, 0}};
|
||||||
Request::PortInfo port_info{1, {0, 0, 0, 0}};
|
|
||||||
auto port_message = Request::Create(port_info, client_id);
|
auto port_message = Request::Create(port_info, client_id);
|
||||||
std::memcpy(&send_buffer1, &port_message, PORT_INFO_SIZE);
|
std::memcpy(&send_buffer1, &port_message, PORT_INFO_SIZE);
|
||||||
size_t len = socket.send_to(boost::asio::buffer(send_buffer1), send_endpoint);
|
size_t len = socket.send_to(boost::asio::buffer(send_buffer1), send_endpoint);
|
||||||
|
|
||||||
// Send a request for getting pad data for pad 1
|
// Send a request for getting pad data for the pad
|
||||||
Request::PadData pad_data{Request::PadData::Flags::Id, 0, EMPTY_MAC_ADDRESS};
|
Request::PadData pad_data{Request::PadData::Flags::Id, pad_index, EMPTY_MAC_ADDRESS};
|
||||||
auto pad_message = Request::Create(pad_data, client_id);
|
auto pad_message = Request::Create(pad_data, client_id);
|
||||||
std::memcpy(send_buffer2.data(), &pad_message, PAD_DATA_SIZE);
|
std::memcpy(send_buffer2.data(), &pad_message, PAD_DATA_SIZE);
|
||||||
size_t len2 = socket.send_to(boost::asio::buffer(send_buffer2), send_endpoint);
|
size_t len2 = socket.send_to(boost::asio::buffer(send_buffer2), send_endpoint);
|
||||||
@ -106,6 +107,7 @@ private:
|
|||||||
udp::socket socket;
|
udp::socket socket;
|
||||||
|
|
||||||
u32 client_id;
|
u32 client_id;
|
||||||
|
u8 pad_index;
|
||||||
|
|
||||||
static constexpr size_t PORT_INFO_SIZE = sizeof(Message<Request::PortInfo>);
|
static constexpr size_t PORT_INFO_SIZE = sizeof(Message<Request::PortInfo>);
|
||||||
static constexpr size_t PAD_DATA_SIZE = sizeof(Message<Request::PadData>);
|
static constexpr size_t PAD_DATA_SIZE = sizeof(Message<Request::PadData>);
|
||||||
@ -124,13 +126,13 @@ static void SocketLoop(Socket* socket) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Client::Client(std::shared_ptr<DeviceStatus> status, const std::string& host, u16 port,
|
Client::Client(std::shared_ptr<DeviceStatus> status, const std::string& host, u16 port,
|
||||||
u32 client_id)
|
u8 pad_index, u32 client_id)
|
||||||
: status(status) {
|
: status(status) {
|
||||||
SocketCallback callback{[this](Response::Version version) { OnVersion(version); },
|
SocketCallback callback{[this](Response::Version version) { OnVersion(version); },
|
||||||
[this](Response::PortInfo info) { OnPortInfo(info); },
|
[this](Response::PortInfo info) { OnPortInfo(info); },
|
||||||
[this](Response::PadData data) { OnPadData(data); }};
|
[this](Response::PadData data) { OnPadData(data); }};
|
||||||
LOG_INFO(Input, "Starting communication with UDP input server on {}:{}", host, port);
|
LOG_INFO(Input, "Starting communication with UDP input server on {}:{}", host, port);
|
||||||
socket = std::make_unique<Socket>(host, port, client_id, callback);
|
socket = std::make_unique<Socket>(host, port, pad_index, client_id, callback);
|
||||||
thread = std::thread{SocketLoop, this->socket.get()};
|
thread = std::thread{SocketLoop, this->socket.get()};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ struct DeviceStatus {
|
|||||||
class Client {
|
class Client {
|
||||||
public:
|
public:
|
||||||
explicit Client(std::shared_ptr<DeviceStatus> status, const std::string& host = DEFAULT_ADDR,
|
explicit Client(std::shared_ptr<DeviceStatus> status, const std::string& host = DEFAULT_ADDR,
|
||||||
u16 port = DEFAULT_PORT, u32 client_id = 24872);
|
u16 port = DEFAULT_PORT, u8 pad_index = 0, u32 client_id = 24872);
|
||||||
~Client();
|
~Client();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -70,8 +70,9 @@ private:
|
|||||||
|
|
||||||
State::State() {
|
State::State() {
|
||||||
auto status = std::make_shared<DeviceStatus>();
|
auto status = std::make_shared<DeviceStatus>();
|
||||||
client = std::make_unique<Client>(status, Settings::values.udp_input_address,
|
client =
|
||||||
Settings::values.udp_input_port);
|
std::make_unique<Client>(status, Settings::values.udp_input_address,
|
||||||
|
Settings::values.udp_input_port, Settings::values.udp_pad_index);
|
||||||
|
|
||||||
Input::RegisterFactory<Input::TouchDevice>("cemuhookudp",
|
Input::RegisterFactory<Input::TouchDevice>("cemuhookudp",
|
||||||
std::make_shared<UDPTouchFactory>(status));
|
std::make_shared<UDPTouchFactory>(status));
|
||||||
|
Loading…
Reference in New Issue
Block a user