Browse Source

add more methods and examples

pull/140/head
Lena 1 year ago committed by Lena
parent
commit
7d3c5814d2
No known key found for this signature in database
GPG Key ID: 5A940B96C2DA3683
  1. 7
      ctru-rs/examples/wifi-info.rs
  2. 124
      ctru-rs/src/services/ac.rs

7
ctru-rs/examples/wifi-info.rs

@ -37,6 +37,13 @@ fn print_network_info(ac: &Ac) -> ctru::Result<()> {
if connected { if connected {
println!("Wi-Fi SSID: {}", ac.get_wifi_ssid()?); println!("Wi-Fi SSID: {}", ac.get_wifi_ssid()?);
println!("Wi-Fi security: {:?}", ac.get_wifi_security()?); println!("Wi-Fi security: {:?}", ac.get_wifi_security()?);
let proxied = ac.get_proxy_enabled()?;
println!("Proxy enabled: {}", proxied);
if proxied {
println!("Proxy port: {}", ac.get_proxy_port()?);
println!("Proxy username: {}", ac.get_proxy_username()?);
println!("Proxy password: {}", ac.get_proxy_password()?);
}
} }
Ok(()) Ok(())

124
ctru-rs/src/services/ac.rs

@ -140,12 +140,134 @@ impl Ac {
let mut len = 0u32; let mut len = 0u32;
ResultCode(ctru_sys::ACU_GetSSIDLength(&mut len))?; ResultCode(ctru_sys::ACU_GetSSIDLength(&mut len))?;
// we don't really need space for the terminator // we don't really need space for the terminator
let mut vec: Vec<u8> = vec![0u8; len as usize]; let mut vec = vec![0u8; len as usize];
ResultCode(ctru_sys::ACU_GetSSID(vec.as_mut_ptr()))?; ResultCode(ctru_sys::ACU_GetSSID(vec.as_mut_ptr()))?;
// how do i handle this error? // how do i handle this error?
Ok(String::from_utf8(vec).unwrap()) Ok(String::from_utf8(vec).unwrap())
} }
} }
/// Returns whether the console is connected to a proxy.
///
/// # Example
///
/// ```
/// # let _runner = test_runner::GdbRunner::default();
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// #
/// use ctru::services::ac::Ac;
///
/// let ac = Ac::new()?;
///
/// println!("Proxy enabled: {}", ac.get_proxy_enabled()?);
///
/// #
/// # Ok(())
/// # }
/// ```
#[doc(alias = "ACU_GetProxyEnable")]
pub fn get_proxy_enabled(&self) -> crate::Result<bool> {
unsafe {
let mut ret = false;
ResultCode(ctru_sys::ACU_GetProxyEnable(&mut ret))?;
Ok(ret)
}
}
/// Returns the connected network's proxy port, if present.
///
/// You can check if the console is using a proxy with [`Self::get_proxy_enabled()`]
///
/// # Example
///
/// ```
/// # let _runner = test_runner::GdbRunner::default();
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// #
/// use ctru::services::ac::Ac;
///
/// let ac = Ac::new()?;
///
/// println!("Proxy port: {}", ac.get_proxy_port()?);
/// #
/// # Ok(())
/// # }
/// ```
#[doc(alias = "ACU_GetProxyPort")]
pub fn get_proxy_port(&self) -> crate::Result<u32> {
unsafe {
let mut ret = 0u32;
ResultCode(ctru_sys::ACU_GetProxyPort(&mut ret))?;
Ok(ret)
}
}
/// Returns the connected network's proxy username, if present.
///
/// You can check if the console is using a proxy with [`Self::get_proxy_enabled()`]
///
/// # Example
///
/// ```
/// # let _runner = test_runner::GdbRunner::default();
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// #
/// use ctru::services::ac::Ac;
///
/// let ac = Ac::new()?;
///
/// println!("Proxy username: {}", ac.get_proxy_username()?);
///
/// #
/// # Ok(())
/// # }
/// ```
#[doc(alias = "ACU_GetProxyUserName")]
pub fn get_proxy_username(&self) -> crate::Result<String> {
unsafe {
let mut vec = vec![0u8; 0x20];
ResultCode(ctru_sys::ACU_GetProxyUserName(vec.as_mut_ptr()))?;
// how do i handle this error?
Ok(String::from_utf8(vec).unwrap())
}
}
/// Returns the connected network's proxy password, if present.
///
/// You can check if the console is using a proxy with [`Self::get_proxy_enabled()`]
///
/// # Example
///
/// ```
/// # let _runner = test_runner::GdbRunner::default();
/// # use std::error::Error;
/// # fn main() -> Result<(), Box<dyn Error>> {
/// #
/// use ctru::services::ac::Ac;
///
/// let ac = Ac::new()?;
///
/// println!("Proxy password: {}", ac.get_proxy_password()?);
/// #
/// # Ok(())
/// # }
/// ```
#[doc(alias = "ACU_GetProxyPassword")]
pub fn get_proxy_password(&self) -> crate::Result<String> {
unsafe {
let mut vec = vec![0u8; 0x20];
ResultCode(ctru_sys::ACU_GetProxyPassword(vec.as_mut_ptr()))?;
// how do i handle this error?
Ok(String::from_utf8(vec).unwrap())
}
}
} }
impl Drop for Ac { impl Drop for Ac {

Loading…
Cancel
Save