mirror of
				https://github.com/PabloMK7/citra.git
				synced 2025-10-31 13:50:03 +00:00 
			
		
		
		
	input_common/udp: allow changing pad index
This commit is contained in:
		
							parent
							
								
									d1c364bb85
								
							
						
					
					
						commit
						e1ae14d508
					
				
					 6 changed files with 21 additions and 12 deletions
				
			
		|  | @ -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…
	
	Add table
		Add a link
		
	
		Reference in a new issue