Browse Source

Add enum for connection status

pull/86/head
AzureMarker 1 year ago
parent
commit
051ab2614d
  1. 4
      ctru-rs/examples/ir-user.rs
  2. 23
      ctru-rs/src/services/ir_user.rs

4
ctru-rs/examples/ir-user.rs

@ -1,7 +1,7 @@
//! A demo of using the ir:USER service to connect to the Circle Pad Pro. //! A demo of using the ir:USER service to connect to the Circle Pad Pro.
use ctru::prelude::*; use ctru::prelude::*;
use ctru::services::ir_user::{CirclePadProInputResponse, IrDeviceId, IrUser}; use ctru::services::ir_user::{CirclePadProInputResponse, ConnectionStatus, IrDeviceId, IrUser};
use ctru::services::srv::HandleExt; use ctru::services::srv::HandleExt;
use ctru_sys::Handle; use ctru_sys::Handle;
use std::io::Write; use std::io::Write;
@ -137,7 +137,7 @@ impl<'screen> CirclePadProDemo<'screen> {
} }
self.print_status_info(); self.print_status_info();
if self.ir_user.get_status_info().connection_status == 2 { if self.ir_user.get_status_info().connection_status == ConnectionStatus::Connected {
println!("Connected!"); println!("Connected!");
break; break;
} }

23
ctru-rs/src/services/ir_user.rs

@ -232,7 +232,12 @@ impl IrUser {
shared_mem[6], shared_mem[6],
shared_mem[7], shared_mem[7],
]), ]),
connection_status: shared_mem[8], connection_status: match shared_mem[8] {
0 => ConnectionStatus::Disconnected,
1 => ConnectionStatus::Connecting,
2 => ConnectionStatus::Connected,
n => ConnectionStatus::Unknown(n),
},
trying_to_connect_status: shared_mem[9], trying_to_connect_status: shared_mem[9],
connection_role: shared_mem[10], connection_role: shared_mem[10],
machine_id: shared_mem[11], machine_id: shared_mem[11],
@ -436,7 +441,7 @@ impl IrDeviceId {
pub struct IrUserStatusInfo { pub struct IrUserStatusInfo {
pub recv_err_result: ctru_sys::Result, pub recv_err_result: ctru_sys::Result,
pub send_err_result: ctru_sys::Result, pub send_err_result: ctru_sys::Result,
pub connection_status: u8, pub connection_status: ConnectionStatus,
pub trying_to_connect_status: u8, pub trying_to_connect_status: u8,
pub connection_role: u8, pub connection_role: u8,
pub machine_id: u8, pub machine_id: u8,
@ -446,6 +451,20 @@ pub struct IrUserStatusInfo {
pub unknown_field_3: u8, pub unknown_field_3: u8,
} }
/// Connection status values for [`IrUserStatusInfo`].
#[repr(u8)]
#[derive(Debug, PartialEq, Eq)]
pub enum ConnectionStatus {
/// Device is not connected
Disconnected = 0,
/// Waiting for device to connect
Connecting = 1,
/// Device is connected
Connected = 2,
/// Unknown connection status
Unknown(u8),
}
/// A packet of data sent/received to/from the IR device. /// A packet of data sent/received to/from the IR device.
#[derive(Debug)] #[derive(Debug)]
pub struct IrUserPacket { pub struct IrUserPacket {

Loading…
Cancel
Save