mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2024-11-23 18:19:21 +01:00
Merge pull request #4084 from zhaowenlan1779/udp-input-port
input_common/udp: allow changing pad index
This commit is contained in:
commit
58639220a0
@ -81,6 +81,9 @@ udp_input_address=
|
||||
# Port of the udp input server. (Default 26760)
|
||||
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]
|
||||
# Whether to use the Just-In-Time (JIT) compiler for CPU emulation
|
||||
# 0: Interpreter (slow), 1 (default): JIT (fast)
|
||||
|
@ -81,6 +81,7 @@ void Config::ReadValues() {
|
||||
.toStdString();
|
||||
Settings::values.udp_input_port = static_cast<u16>(
|
||||
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();
|
||||
|
||||
@ -331,6 +332,7 @@ void Config::SaveValues() {
|
||||
InputCommon::CemuhookUDP::DEFAULT_ADDR);
|
||||
WriteSetting("udp_input_port", Settings::values.udp_input_port,
|
||||
InputCommon::CemuhookUDP::DEFAULT_PORT);
|
||||
WriteSetting("udp_pad_index", Settings::values.udp_pad_index, 0);
|
||||
qt_config->endGroup();
|
||||
|
||||
qt_config->beginGroup("Core");
|
||||
|
@ -98,6 +98,7 @@ struct Values {
|
||||
std::string touch_device;
|
||||
std::string udp_input_address;
|
||||
u16 udp_input_port;
|
||||
u8 udp_pad_index;
|
||||
|
||||
// Core
|
||||
bool use_cpu_jit;
|
||||
|
@ -30,10 +30,12 @@ class Socket {
|
||||
public:
|
||||
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),
|
||||
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() {
|
||||
io_service.stop();
|
||||
@ -85,15 +87,14 @@ private:
|
||||
}
|
||||
|
||||
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 pad 1
|
||||
Request::PortInfo port_info{1, {0, 0, 0, 0}};
|
||||
// Send a request for getting port info for the pad
|
||||
Request::PortInfo port_info{1, {pad_index, 0, 0, 0}};
|
||||
auto port_message = Request::Create(port_info, client_id);
|
||||
std::memcpy(&send_buffer1, &port_message, PORT_INFO_SIZE);
|
||||
size_t len = socket.send_to(boost::asio::buffer(send_buffer1), send_endpoint);
|
||||
|
||||
// Send a request for getting pad data for pad 1
|
||||
Request::PadData pad_data{Request::PadData::Flags::Id, 0, EMPTY_MAC_ADDRESS};
|
||||
// Send a request for getting pad data for the pad
|
||||
Request::PadData pad_data{Request::PadData::Flags::Id, pad_index, EMPTY_MAC_ADDRESS};
|
||||
auto pad_message = Request::Create(pad_data, client_id);
|
||||
std::memcpy(send_buffer2.data(), &pad_message, PAD_DATA_SIZE);
|
||||
size_t len2 = socket.send_to(boost::asio::buffer(send_buffer2), send_endpoint);
|
||||
@ -106,6 +107,7 @@ private:
|
||||
udp::socket socket;
|
||||
|
||||
u32 client_id;
|
||||
u8 pad_index;
|
||||
|
||||
static constexpr size_t PORT_INFO_SIZE = sizeof(Message<Request::PortInfo>);
|
||||
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,
|
||||
u32 client_id)
|
||||
u8 pad_index, u32 client_id)
|
||||
: status(status) {
|
||||
SocketCallback callback{[this](Response::Version version) { OnVersion(version); },
|
||||
[this](Response::PortInfo info) { OnPortInfo(info); },
|
||||
[this](Response::PadData data) { OnPadData(data); }};
|
||||
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()};
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ struct DeviceStatus {
|
||||
class Client {
|
||||
public:
|
||||
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();
|
||||
|
||||
private:
|
||||
|
@ -70,8 +70,9 @@ private:
|
||||
|
||||
State::State() {
|
||||
auto status = std::make_shared<DeviceStatus>();
|
||||
client = std::make_unique<Client>(status, Settings::values.udp_input_address,
|
||||
Settings::values.udp_input_port);
|
||||
client =
|
||||
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",
|
||||
std::make_shared<UDPTouchFactory>(status));
|
||||
|
Loading…
Reference in New Issue
Block a user