Browse Source

Refreshed PS module due to ctru::init

pull/92/head
Andrea Ciliberti 2 years ago
parent
commit
60f3e1fe5a
  1. 4
      ctru-rs/Cargo.toml
  2. 6
      ctru-rs/src/applets/swkbd.rs
  3. 30
      ctru-rs/src/services/ps.rs

4
ctru-rs/Cargo.toml

@ -15,8 +15,8 @@ name = "ctru"
cfg-if = "1.0" cfg-if = "1.0"
ctru-sys = { path = "../ctru-sys", version = "0.4" } ctru-sys = { path = "../ctru-sys", version = "0.4" }
const-zero = "0.1.0" const-zero = "0.1.0"
linker-fix-3ds = { path = "../../rust-linker-fix-3ds" } linker-fix-3ds = { git = "https://github.com/rust3ds/rust-linker-fix-3ds.git" }
pthread-3ds = { path = "../../pthread-3ds" } pthread-3ds = {git = "https://github.com/rust3ds/pthread-3ds.git" }
libc = "0.2.121" libc = "0.2.121"
bitflags = "1.0.0" bitflags = "1.0.0"
widestring = "0.2.2" widestring = "0.2.2"

6
ctru-rs/src/applets/swkbd.rs

@ -126,11 +126,7 @@ impl Swkbd {
/// the output will be truncated but should still be well-formed UTF-8 /// the output will be truncated but should still be well-formed UTF-8
pub fn get_bytes(&mut self, buf: &mut [u8]) -> Result<Button, Error> { pub fn get_bytes(&mut self, buf: &mut [u8]) -> Result<Button, Error> {
unsafe { unsafe {
match swkbdInputText( match swkbdInputText(self.state.as_mut(), buf.as_mut_ptr(), buf.len()) {
self.state.as_mut(),
buf.as_mut_ptr(),
buf.len(),
) {
ctru_sys::SWKBD_BUTTON_NONE => Err(self.parse_swkbd_error()), ctru_sys::SWKBD_BUTTON_NONE => Err(self.parse_swkbd_error()),
ctru_sys::SWKBD_BUTTON_LEFT => Ok(Button::Left), ctru_sys::SWKBD_BUTTON_LEFT => Ok(Button::Left),
ctru_sys::SWKBD_BUTTON_MIDDLE => Ok(Button::Middle), ctru_sys::SWKBD_BUTTON_MIDDLE => Ok(Button::Middle),

30
ctru-rs/src/services/ps.rs

@ -5,6 +5,7 @@
//! See also <https://www.3dbrew.org/wiki/Process_Services> //! See also <https://www.3dbrew.org/wiki/Process_Services>
use crate::error::ResultCode; use crate::error::ResultCode;
use crate::Result;
#[repr(u32)] #[repr(u32)]
pub enum AESAlgorithm { pub enum AESAlgorithm {
@ -30,24 +31,45 @@ pub enum AESKeyType {
Keyslot39Nfc, Keyslot39Nfc,
} }
pub fn local_friend_code_seed() -> crate::Result<u64> { pub struct Ps(());
impl Ps {
pub fn new() -> Result<Self> {
unsafe {
ResultCode(ctru_sys::psInit())?;
Ok(Ps(()))
}
}
pub fn local_friend_code_seed(&self) -> crate::Result<u64> {
let mut seed: u64 = 0; let mut seed: u64 = 0;
ResultCode(unsafe { ctru_sys::PS_GetLocalFriendCodeSeed(&mut seed) })?; ResultCode(unsafe { ctru_sys::PS_GetLocalFriendCodeSeed(&mut seed) })?;
Ok(seed) Ok(seed)
} }
pub fn device_id() -> crate::Result<u32> { pub fn device_id(&self) -> crate::Result<u32> {
let mut id: u32 = 0; let mut id: u32 = 0;
ResultCode(unsafe { ctru_sys::PS_GetDeviceId(&mut id) })?; ResultCode(unsafe { ctru_sys::PS_GetDeviceId(&mut id) })?;
Ok(id) Ok(id)
} }
pub fn generate_random_bytes(out: &mut [u8]) -> crate::Result<()> { pub fn generate_random_bytes(&self, out: &mut [u8]) -> crate::Result<()> {
ResultCode(unsafe { ctru_sys::PS_GenerateRandomBytes(out as *mut _ as *mut _, out.len()) })?; ResultCode(unsafe {
ctru_sys::PS_GenerateRandomBytes(out as *mut _ as *mut _, out.len())
})?;
Ok(()) Ok(())
} }
}
impl Drop for Ps {
fn drop(&mut self) {
unsafe {
ctru_sys::psExit();
}
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {

Loading…
Cancel
Save