diff --git a/ctru-rs/examples/ir-user.rs b/ctru-rs/examples/ir-user.rs index 252dbf7..24a9013 100644 --- a/ctru-rs/examples/ir-user.rs +++ b/ctru-rs/examples/ir-user.rs @@ -2,6 +2,7 @@ use ctru::prelude::*; use ctru::services::ir_user::{CirclePadProInputResponse, IrDeviceId, IrUser}; +use ctru::services::srv; use ctru_sys::Handle; use std::io::Write; use std::time::Duration; @@ -37,7 +38,7 @@ fn main() { // Check if we've received a packet from the circle pad pro let packet_received = - IrUser::wait_for_event(demo.receive_packet_event, Duration::ZERO).is_ok(); + srv::wait_for_event(demo.receive_packet_event, Duration::ZERO).is_ok(); if packet_received { demo.handle_packets(); } @@ -125,7 +126,7 @@ impl<'screen> CirclePadProDemo<'screen> { // Wait for the connection to establish if let Err(e) = - IrUser::wait_for_event(self.connection_status_event, Duration::from_millis(100)) + srv::wait_for_event(self.connection_status_event, Duration::from_millis(100)) { if !e.is_timeout() { panic!("Couldn't initialize circle pad pro connection: {e}"); @@ -145,7 +146,7 @@ impl<'screen> CirclePadProDemo<'screen> { // Wait for the disconnect to go through if let Err(e) = - IrUser::wait_for_event(self.connection_status_event, Duration::from_millis(100)) + srv::wait_for_event(self.connection_status_event, Duration::from_millis(100)) { if !e.is_timeout() { panic!("Couldn't initialize circle pad pro connection: {e}"); @@ -171,7 +172,7 @@ impl<'screen> CirclePadProDemo<'screen> { // Wait for the response let recv_event_result = - IrUser::wait_for_event(self.receive_packet_event, Duration::from_millis(100)); + srv::wait_for_event(self.receive_packet_event, Duration::from_millis(100)); self.print_status_info(); if recv_event_result.is_ok() { diff --git a/ctru-rs/src/services/ir_user.rs b/ctru-rs/src/services/ir_user.rs index adbc690..df35e99 100644 --- a/ctru-rs/src/services/ir_user.rs +++ b/ctru-rs/src/services/ir_user.rs @@ -6,7 +6,6 @@ use std::cmp::max; use std::ffi::CString; use std::ptr::{slice_from_raw_parts, slice_from_raw_parts_mut}; use std::sync::Mutex; -use std::time::Duration; static IR_USER_ACTIVE: Mutex = Mutex::new(0); static IR_USER_STATE: Mutex> = Mutex::new(None); @@ -172,18 +171,6 @@ impl IrUser { Ok(recv_event) } - /// Wait for an event to fire. If the timeout is reached, an error is returned. You can use - /// [`Error::is_timeout`] to check if the error is due to a timeout. - pub fn wait_for_event(event: Handle, timeout: Duration) -> crate::Result<()> { - unsafe { - ResultCode(ctru_sys::svcWaitSynchronization( - event, - timeout.as_nanos() as i64, - ))?; - } - Ok(()) - } - /// Circle Pad Pro specific request. /// /// This will send a packet to the CPP requesting it to send back packets diff --git a/ctru-rs/src/services/mod.rs b/ctru-rs/src/services/mod.rs index 97e1a0f..62bf822 100644 --- a/ctru-rs/src/services/mod.rs +++ b/ctru-rs/src/services/mod.rs @@ -8,6 +8,7 @@ pub mod ir_user; pub mod ps; mod reference; pub mod soc; +pub mod srv; pub mod sslc; pub use self::apt::Apt; diff --git a/ctru-rs/src/services/srv.rs b/ctru-rs/src/services/srv.rs new file mode 100644 index 0000000..00ca358 --- /dev/null +++ b/ctru-rs/src/services/srv.rs @@ -0,0 +1,20 @@ +//! Service API +//! +//! Not all APIs are wrapped in this module, since a lot are fundamentally unsafe. +//! Most APIs should be used directly from `ctru-sys`. + +use crate::error::ResultCode; +use ctru_sys::Handle; +use std::time::Duration; + +/// Wait for an event to fire. If the timeout is reached, an error is returned. You can use +/// [`Error::is_timeout`] to check if the error is due to a timeout. +pub fn wait_for_event(event: Handle, timeout: Duration) -> crate::Result<()> { + unsafe { + ResultCode(ctru_sys::svcWaitSynchronization( + event, + timeout.as_nanos() as i64, + ))?; + } + Ok(()) +}