Browse Source

Renamed init functions to new

pull/118/head
Andrea Ciliberti 2 years ago
parent
commit
5257d16aee
  1. 10
      ctru-rs/examples/audio-filters.rs
  2. 8
      ctru-rs/examples/buttons.rs
  3. 10
      ctru-rs/examples/camera-image.rs
  4. 14
      ctru-rs/examples/file-explorer.rs
  5. 8
      ctru-rs/examples/futures-basic.rs
  6. 8
      ctru-rs/examples/futures-tokio.rs
  7. 8
      ctru-rs/examples/gfx-3d-mode.rs
  8. 10
      ctru-rs/examples/gfx-wide-mode.rs
  9. 8
      ctru-rs/examples/graphics-bitmap.rs
  10. 8
      ctru-rs/examples/hashmaps.rs
  11. 10
      ctru-rs/examples/hello-both-screens.rs
  12. 8
      ctru-rs/examples/hello-world.rs
  13. 8
      ctru-rs/examples/linear-memory.rs
  14. 10
      ctru-rs/examples/mii-selector.rs
  15. 10
      ctru-rs/examples/network-sockets.rs
  16. 8
      ctru-rs/examples/output-3dslink.rs
  17. 10
      ctru-rs/examples/romfs.rs
  18. 10
      ctru-rs/examples/software-keyboard.rs
  19. 10
      ctru-rs/examples/system-configuration.rs
  20. 8
      ctru-rs/examples/thread-basic.rs
  21. 8
      ctru-rs/examples/thread-info.rs
  22. 8
      ctru-rs/examples/thread-locals.rs
  23. 8
      ctru-rs/examples/time-rtc.rs
  24. 12
      ctru-rs/examples/title-info.rs
  25. 4
      ctru-rs/src/applets/mii_selector.rs
  26. 4
      ctru-rs/src/applets/swkbd.rs
  27. 2
      ctru-rs/src/console.rs
  28. 2
      ctru-rs/src/lib.rs
  29. 2
      ctru-rs/src/services/am.rs
  30. 2
      ctru-rs/src/services/apt.rs
  31. 2
      ctru-rs/src/services/cam.rs
  32. 2
      ctru-rs/src/services/cfgu.rs
  33. 18
      ctru-rs/src/services/fs.rs
  34. 6
      ctru-rs/src/services/gfx.rs
  35. 2
      ctru-rs/src/services/hid.rs
  36. 2
      ctru-rs/src/services/ndsp/mod.rs
  37. 4
      ctru-rs/src/services/romfs.rs
  38. 6
      ctru-rs/src/services/soc.rs
  39. 2
      ctru-rs/src/services/sslc.rs
  40. 8
      ctru-rs/src/test_runner.rs

10
ctru-rs/examples/audio-filters.rs

@ -37,10 +37,10 @@ fn fill_buffer(audio_data: &mut [u8], frequency: f32) {
fn main() { fn main() {
ctru::use_panic_handler(); ctru::use_panic_handler();
let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); let gfx = Gfx::new().expect("Couldn't obtain GFX controller");
let mut hid = Hid::init().expect("Couldn't obtain HID controller"); let mut hid = Hid::new().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller"); let apt = Apt::new().expect("Couldn't obtain APT controller");
let _console = Console::init(gfx.top_screen.borrow_mut()); let _console = Console::new(gfx.top_screen.borrow_mut());
let mut note: usize = 4; let mut note: usize = 4;
@ -68,7 +68,7 @@ fn main() {
let mut wave_info1 = Wave::new(audio_data1, AudioFormat::PCM16Stereo, false); let mut wave_info1 = Wave::new(audio_data1, AudioFormat::PCM16Stereo, false);
let mut wave_info2 = Wave::new(audio_data2, AudioFormat::PCM16Stereo, false); let mut wave_info2 = Wave::new(audio_data2, AudioFormat::PCM16Stereo, false);
let mut ndsp = Ndsp::init().expect("Couldn't obtain NDSP controller"); let mut ndsp = Ndsp::new().expect("Couldn't obtain NDSP controller");
// This line isn't needed since the default NDSP configuration already sets the output mode to `Stereo` // This line isn't needed since the default NDSP configuration already sets the output mode to `Stereo`
ndsp.set_output_mode(OutputMode::Stereo); ndsp.set_output_mode(OutputMode::Stereo);

8
ctru-rs/examples/buttons.rs

@ -3,10 +3,10 @@ use ctru::prelude::*;
fn main() { fn main() {
ctru::use_panic_handler(); ctru::use_panic_handler();
let apt = Apt::init().unwrap(); let apt = Apt::new().unwrap();
let mut hid = Hid::init().unwrap(); let mut hid = Hid::new().unwrap();
let gfx = Gfx::init().unwrap(); let gfx = Gfx::new().unwrap();
let console = Console::init(gfx.top_screen.borrow_mut()); let console = Console::new(gfx.top_screen.borrow_mut());
println!("Hi there! Try pressing a button"); println!("Hi there! Try pressing a button");
println!("\x1b[29;16HPress Start to exit"); println!("\x1b[29;16HPress Start to exit");

10
ctru-rs/examples/camera-image.rs

@ -16,22 +16,22 @@ const WAIT_TIMEOUT: Duration = Duration::from_millis(300);
fn main() { fn main() {
ctru::use_panic_handler(); ctru::use_panic_handler();
let apt = Apt::init().expect("Failed to initialize Apt service."); let apt = Apt::new().expect("Failed to initialize Apt service.");
let mut hid = Hid::init().expect("Failed to initialize Hid service."); let mut hid = Hid::new().expect("Failed to initialize Hid service.");
let gfx = Gfx::init().expect("Failed to initialize GFX service."); let gfx = Gfx::new().expect("Failed to initialize GFX service.");
gfx.top_screen.borrow_mut().set_double_buffering(true); gfx.top_screen.borrow_mut().set_double_buffering(true);
gfx.top_screen gfx.top_screen
.borrow_mut() .borrow_mut()
.set_framebuffer_format(FramebufferFormat::Rgb565); .set_framebuffer_format(FramebufferFormat::Rgb565);
gfx.bottom_screen.borrow_mut().set_double_buffering(false); gfx.bottom_screen.borrow_mut().set_double_buffering(false);
let _console = Console::init(gfx.bottom_screen.borrow_mut()); let _console = Console::new(gfx.bottom_screen.borrow_mut());
let mut keys_down; let mut keys_down;
println!("Initializing camera"); println!("Initializing camera");
let mut cam = Cam::init().expect("Failed to initialize CAM service."); let mut cam = Cam::new().expect("Failed to initialize CAM service.");
{ {
let camera = &mut cam.outer_right_cam; let camera = &mut cam.outer_right_cam;

14
ctru-rs/examples/file-explorer.rs

@ -11,14 +11,14 @@ use std::path::{Path, PathBuf};
fn main() { fn main() {
ctru::use_panic_handler(); ctru::use_panic_handler();
let apt = Apt::init().unwrap(); let apt = Apt::new().unwrap();
let mut hid = Hid::init().unwrap(); let mut hid = Hid::new().unwrap();
let gfx = Gfx::init().unwrap(); let gfx = Gfx::new().unwrap();
#[cfg(all(feature = "romfs", romfs_exists))] #[cfg(all(feature = "romfs", romfs_exists))]
let _romfs = ctru::services::romfs::RomFS::init().unwrap(); let _romfs = ctru::services::romfs::RomFS::new().unwrap();
FileExplorer::init(&apt, &mut hid, &gfx).run(); FileExplorer::new(&apt, &mut hid, &gfx).run();
} }
struct FileExplorer<'a> { struct FileExplorer<'a> {
@ -32,10 +32,10 @@ struct FileExplorer<'a> {
} }
impl<'a> FileExplorer<'a> { impl<'a> FileExplorer<'a> {
fn init(apt: &'a Apt, hid: &'a mut Hid, gfx: &'a Gfx) -> Self { fn new(apt: &'a Apt, hid: &'a mut Hid, gfx: &'a Gfx) -> Self {
let mut top_screen = gfx.top_screen.borrow_mut(); let mut top_screen = gfx.top_screen.borrow_mut();
top_screen.set_wide_mode(true); top_screen.set_wide_mode(true);
let console = Console::init(top_screen); let console = Console::new(top_screen);
FileExplorer { FileExplorer {
apt, apt,

8
ctru-rs/examples/futures-basic.rs

@ -15,10 +15,10 @@ use std::os::horizon::thread::BuilderExt;
fn main() { fn main() {
ctru::use_panic_handler(); ctru::use_panic_handler();
let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); let gfx = Gfx::new().expect("Couldn't obtain GFX controller");
let mut hid = Hid::init().expect("Couldn't obtain HID controller"); let mut hid = Hid::new().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller"); let apt = Apt::new().expect("Couldn't obtain APT controller");
let _console = Console::init(gfx.top_screen.borrow_mut()); let _console = Console::new(gfx.top_screen.borrow_mut());
// Give ourselves up to 30% of the system core's time // Give ourselves up to 30% of the system core's time
apt.set_app_cpu_time_limit(30) apt.set_app_cpu_time_limit(30)

8
ctru-rs/examples/futures-tokio.rs

@ -8,10 +8,10 @@ use std::time::Duration;
fn main() { fn main() {
ctru::use_panic_handler(); ctru::use_panic_handler();
let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); let gfx = Gfx::new().expect("Couldn't obtain GFX controller");
let mut hid = Hid::init().expect("Couldn't obtain HID controller"); let mut hid = Hid::new().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller"); let apt = Apt::new().expect("Couldn't obtain APT controller");
let _console = Console::init(gfx.top_screen.borrow_mut()); let _console = Console::new(gfx.top_screen.borrow_mut());
// Give ourselves up to 30% of the system core's time // Give ourselves up to 30% of the system core's time
apt.set_app_cpu_time_limit(30) apt.set_app_cpu_time_limit(30)

8
ctru-rs/examples/gfx-3d-mode.rs

@ -12,10 +12,10 @@ static ZERO: &[u8] = &[0; IMAGE.len()];
fn main() { fn main() {
ctru::use_panic_handler(); ctru::use_panic_handler();
let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); let gfx = Gfx::new().expect("Couldn't obtain GFX controller");
let mut hid = Hid::init().expect("Couldn't obtain HID controller"); let mut hid = Hid::new().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller"); let apt = Apt::new().expect("Couldn't obtain APT controller");
let _console = Console::init(gfx.bottom_screen.borrow_mut()); let _console = Console::new(gfx.bottom_screen.borrow_mut());
println!("Press Start to exit.\nPress A to switch sides (be sure to have 3D mode enabled)."); println!("Press Start to exit.\nPress A to switch sides (be sure to have 3D mode enabled).");

10
ctru-rs/examples/gfx-wide-mode.rs

@ -3,10 +3,10 @@ use ctru::prelude::*;
fn main() { fn main() {
ctru::use_panic_handler(); ctru::use_panic_handler();
let apt = Apt::init().unwrap(); let apt = Apt::new().unwrap();
let mut hid = Hid::init().unwrap(); let mut hid = Hid::new().unwrap();
let gfx = Gfx::init().unwrap(); let gfx = Gfx::new().unwrap();
let mut console = Console::init(gfx.top_screen.borrow_mut()); let mut console = Console::new(gfx.top_screen.borrow_mut());
println!("Press A to enable/disable wide screen mode."); println!("Press A to enable/disable wide screen mode.");
@ -23,7 +23,7 @@ fn main() {
let wide_mode = gfx.top_screen.borrow().is_wide(); let wide_mode = gfx.top_screen.borrow().is_wide();
gfx.top_screen.borrow_mut().set_wide_mode(!wide_mode); gfx.top_screen.borrow_mut().set_wide_mode(!wide_mode);
console = Console::init(gfx.top_screen.borrow_mut()); console = Console::new(gfx.top_screen.borrow_mut());
println!("Press A to enable/disable wide screen mode."); println!("Press A to enable/disable wide screen mode.");
} }

8
ctru-rs/examples/graphics-bitmap.rs

@ -17,10 +17,10 @@ static IMAGE: &[u8] = include_bytes!("assets/ferris.rgb");
fn main() { fn main() {
ctru::use_panic_handler(); ctru::use_panic_handler();
let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); let gfx = Gfx::new().expect("Couldn't obtain GFX controller");
let mut hid = Hid::init().expect("Couldn't obtain HID controller"); let mut hid = Hid::new().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller"); let apt = Apt::new().expect("Couldn't obtain APT controller");
let _console = Console::init(gfx.top_screen.borrow_mut()); let _console = Console::new(gfx.top_screen.borrow_mut());
println!("\x1b[21;16HPress Start to exit."); println!("\x1b[21;16HPress Start to exit.");

8
ctru-rs/examples/hashmaps.rs

@ -8,10 +8,10 @@ fn main() {
// HashMaps generate hashes thanks to the 3DS' cryptografically secure generator. // HashMaps generate hashes thanks to the 3DS' cryptografically secure generator.
// This generator is only active when activating the `PS` service. // This generator is only active when activating the `PS` service.
// This service is automatically initialized. // This service is automatically initialized.
let apt = Apt::init().unwrap(); let apt = Apt::new().unwrap();
let mut hid = Hid::init().unwrap(); let mut hid = Hid::new().unwrap();
let gfx = Gfx::init().unwrap(); let gfx = Gfx::new().unwrap();
let _console = Console::init(gfx.top_screen.borrow_mut()); let _console = Console::new(gfx.top_screen.borrow_mut());
let mut map = std::collections::HashMap::new(); let mut map = std::collections::HashMap::new();
map.insert("A Key!", 102); map.insert("A Key!", 102);

10
ctru-rs/examples/hello-both-screens.rs

@ -3,16 +3,16 @@ use ctru::prelude::*;
fn main() { fn main() {
ctru::use_panic_handler(); ctru::use_panic_handler();
let apt = Apt::init().unwrap(); let apt = Apt::new().unwrap();
let mut hid = Hid::init().unwrap(); let mut hid = Hid::new().unwrap();
let gfx = Gfx::init().unwrap(); let gfx = Gfx::new().unwrap();
// Start a console on the top screen // Start a console on the top screen
let top_screen = Console::init(gfx.top_screen.borrow_mut()); let top_screen = Console::new(gfx.top_screen.borrow_mut());
// Start a console on the bottom screen. // Start a console on the bottom screen.
// The most recently initialized console will be active by default // The most recently initialized console will be active by default
let bottom_screen = Console::init(gfx.bottom_screen.borrow_mut()); let bottom_screen = Console::new(gfx.bottom_screen.borrow_mut());
// Let's print on the top screen first // Let's print on the top screen first
top_screen.select(); top_screen.select();

8
ctru-rs/examples/hello-world.rs

@ -5,10 +5,10 @@ use std::io::BufWriter;
fn main() { fn main() {
ctru::use_panic_handler(); ctru::use_panic_handler();
let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); let gfx = Gfx::new().expect("Couldn't obtain GFX controller");
let mut hid = Hid::init().expect("Couldn't obtain HID controller"); let mut hid = Hid::new().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller"); let apt = Apt::new().expect("Couldn't obtain APT controller");
let _console = Console::init(gfx.top_screen.borrow_mut()); let _console = Console::new(gfx.top_screen.borrow_mut());
let out = b"Hello fellow Rustaceans, I'm on the Nintendo 3DS!"; let out = b"Hello fellow Rustaceans, I'm on the Nintendo 3DS!";
let width = 24; let width = 24;

8
ctru-rs/examples/linear-memory.rs

@ -6,10 +6,10 @@ use ctru::prelude::*;
fn main() { fn main() {
ctru::use_panic_handler(); ctru::use_panic_handler();
let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); let gfx = Gfx::new().expect("Couldn't obtain GFX controller");
let mut hid = Hid::init().expect("Couldn't obtain HID controller"); let mut hid = Hid::new().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller"); let apt = Apt::new().expect("Couldn't obtain APT controller");
let _console = Console::init(gfx.top_screen.borrow_mut()); let _console = Console::new(gfx.top_screen.borrow_mut());
let linear_space_before = LinearAllocator::free_space(); let linear_space_before = LinearAllocator::free_space();

10
ctru-rs/examples/mii-selector.rs

@ -4,12 +4,12 @@ use ctru::prelude::*;
fn main() { fn main() {
ctru::use_panic_handler(); ctru::use_panic_handler();
let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); let gfx = Gfx::new().expect("Couldn't obtain GFX controller");
let mut hid = Hid::init().expect("Couldn't obtain HID controller"); let mut hid = Hid::new().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller"); let apt = Apt::new().expect("Couldn't obtain APT controller");
let _console = Console::init(gfx.top_screen.borrow_mut()); let _console = Console::new(gfx.top_screen.borrow_mut());
let mut mii_selector = MiiSelector::init(); let mut mii_selector = MiiSelector::new();
mii_selector.set_initial_index(3); mii_selector.set_initial_index(3);
mii_selector.blacklist_user_mii(0.into()); mii_selector.blacklist_user_mii(0.into());
mii_selector.set_title("Great Mii Selector!"); mii_selector.set_title("Great Mii Selector!");

10
ctru-rs/examples/network-sockets.rs

@ -7,14 +7,14 @@ use std::time::Duration;
fn main() { fn main() {
ctru::use_panic_handler(); ctru::use_panic_handler();
let gfx = Gfx::init().unwrap(); let gfx = Gfx::new().unwrap();
let _console = Console::init(gfx.top_screen.borrow_mut()); let _console = Console::new(gfx.top_screen.borrow_mut());
let mut hid = Hid::init().unwrap(); let mut hid = Hid::new().unwrap();
let apt = Apt::init().unwrap(); let apt = Apt::new().unwrap();
println!("\nlibctru sockets demo\n"); println!("\nlibctru sockets demo\n");
let soc = Soc::init().unwrap(); let soc = Soc::new().unwrap();
let server = TcpListener::bind("0.0.0.0:80").unwrap(); let server = TcpListener::bind("0.0.0.0:80").unwrap();
server.set_nonblocking(true).unwrap(); server.set_nonblocking(true).unwrap();

8
ctru-rs/examples/output-3dslink.rs

@ -13,11 +13,11 @@ use ctru::prelude::*;
fn main() { fn main() {
ctru::use_panic_handler(); ctru::use_panic_handler();
let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); let gfx = Gfx::new().expect("Couldn't obtain GFX controller");
let mut hid = Hid::init().expect("Couldn't obtain HID controller"); let mut hid = Hid::new().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller"); let apt = Apt::new().expect("Couldn't obtain APT controller");
let mut soc = Soc::init().expect("Couldn't obtain SOC controller"); let mut soc = Soc::new().expect("Couldn't obtain SOC controller");
soc.redirect_to_3dslink(true, true) soc.redirect_to_3dslink(true, true)
.expect("unable to redirect stdout/err to 3dslink server"); .expect("unable to redirect stdout/err to 3dslink server");

10
ctru-rs/examples/romfs.rs

@ -3,17 +3,17 @@ use ctru::prelude::*;
fn main() { fn main() {
ctru::use_panic_handler(); ctru::use_panic_handler();
let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); let gfx = Gfx::new().expect("Couldn't obtain GFX controller");
let mut hid = Hid::init().expect("Couldn't obtain HID controller"); let mut hid = Hid::new().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller"); let apt = Apt::new().expect("Couldn't obtain APT controller");
let _console = Console::init(gfx.top_screen.borrow_mut()); let _console = Console::new(gfx.top_screen.borrow_mut());
cfg_if::cfg_if! { cfg_if::cfg_if! {
// Run this code if RomFS are wanted and available // Run this code if RomFS are wanted and available
// This never fails as `ctru-rs` examples inherit all of the `ctru` features, // This never fails as `ctru-rs` examples inherit all of the `ctru` features,
// but it might if a normal user application wasn't setup correctly // but it might if a normal user application wasn't setup correctly
if #[cfg(all(feature = "romfs", romfs_exists))] { if #[cfg(all(feature = "romfs", romfs_exists))] {
let _romfs = ctru::services::romfs::RomFS::init().unwrap(); let _romfs = ctru::services::romfs::RomFS::new().unwrap();
let f = std::fs::read_to_string("romfs:/test-file.txt").unwrap(); let f = std::fs::read_to_string("romfs:/test-file.txt").unwrap();
println!("Contents of test-file.txt: \n{f}\n"); println!("Contents of test-file.txt: \n{f}\n");

10
ctru-rs/examples/software-keyboard.rs

@ -4,10 +4,10 @@ use ctru::prelude::*;
fn main() { fn main() {
ctru::use_panic_handler(); ctru::use_panic_handler();
let apt = Apt::init().unwrap(); let apt = Apt::new().unwrap();
let mut hid = Hid::init().unwrap(); let mut hid = Hid::new().unwrap();
let gfx = Gfx::init().unwrap(); let gfx = Gfx::new().unwrap();
let _console = Console::init(gfx.top_screen.borrow_mut()); let _console = Console::new(gfx.top_screen.borrow_mut());
println!("Press A to enter some text or press Start to quit"); println!("Press A to enter some text or press Start to quit");
@ -20,7 +20,7 @@ fn main() {
if hid.keys_down().contains(KeyPad::A) { if hid.keys_down().contains(KeyPad::A) {
// Prepares a software keyboard with two buttons: One to cancel input and one // Prepares a software keyboard with two buttons: One to cancel input and one
// to accept it. You can also use `Swkbd::init()` to launch the keyboard in different // to accept it. You can also use `Swkbd::new()` to launch the keyboard in different
// configurations. // configurations.
let mut keyboard = Swkbd::default(); let mut keyboard = Swkbd::default();

10
ctru-rs/examples/system-configuration.rs

@ -4,11 +4,11 @@ use ctru::services::cfgu::Cfgu;
fn main() { fn main() {
ctru::use_panic_handler(); ctru::use_panic_handler();
let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); let gfx = Gfx::new().expect("Couldn't obtain GFX controller");
let mut hid = Hid::init().expect("Couldn't obtain HID controller"); let mut hid = Hid::new().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller"); let apt = Apt::new().expect("Couldn't obtain APT controller");
let cfgu = Cfgu::init().expect("Couldn't obtain CFGU controller"); let cfgu = Cfgu::new().expect("Couldn't obtain CFGU controller");
let _console = Console::init(gfx.top_screen.borrow_mut()); let _console = Console::new(gfx.top_screen.borrow_mut());
println!("\x1b[0;0HRegion: {:?}", cfgu.region().unwrap()); println!("\x1b[0;0HRegion: {:?}", cfgu.region().unwrap());
println!("\x1b[10;0HLanguage: {:?}", cfgu.language().unwrap()); println!("\x1b[10;0HLanguage: {:?}", cfgu.language().unwrap());

8
ctru-rs/examples/thread-basic.rs

@ -8,10 +8,10 @@ use std::time::Duration;
fn main() { fn main() {
ctru::use_panic_handler(); ctru::use_panic_handler();
let apt = Apt::init().unwrap(); let apt = Apt::new().unwrap();
let mut hid = Hid::init().unwrap(); let mut hid = Hid::new().unwrap();
let gfx = Gfx::init().unwrap(); let gfx = Gfx::new().unwrap();
let _console = Console::init(gfx.top_screen.borrow_mut()); let _console = Console::new(gfx.top_screen.borrow_mut());
let prio = std::os::horizon::thread::current_priority(); let prio = std::os::horizon::thread::current_priority();
println!("Main thread prio: {}\n", prio); println!("Main thread prio: {}\n", prio);

8
ctru-rs/examples/thread-info.rs

@ -9,10 +9,10 @@ use std::os::horizon::thread::BuilderExt;
fn main() { fn main() {
ctru::use_panic_handler(); ctru::use_panic_handler();
let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); let gfx = Gfx::new().expect("Couldn't obtain GFX controller");
let mut hid = Hid::init().expect("Couldn't obtain HID controller"); let mut hid = Hid::new().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller"); let apt = Apt::new().expect("Couldn't obtain APT controller");
let _console = Console::init(gfx.top_screen.borrow_mut()); let _console = Console::new(gfx.top_screen.borrow_mut());
// Give ourselves up to 30% of the system core's time // Give ourselves up to 30% of the system core's time
apt.set_app_cpu_time_limit(30) apt.set_app_cpu_time_limit(30)

8
ctru-rs/examples/thread-locals.rs

@ -12,11 +12,11 @@ std::thread_local! {
fn main() { fn main() {
ctru::use_panic_handler(); ctru::use_panic_handler();
let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); let gfx = Gfx::new().expect("Couldn't obtain GFX controller");
gfx.top_screen.borrow_mut().set_wide_mode(true); gfx.top_screen.borrow_mut().set_wide_mode(true);
let mut hid = Hid::init().expect("Couldn't obtain HID controller"); let mut hid = Hid::new().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller"); let apt = Apt::new().expect("Couldn't obtain APT controller");
let _console = Console::init(gfx.top_screen.borrow_mut()); let _console = Console::new(gfx.top_screen.borrow_mut());
// Give ourselves up to 30% of the system core's time // Give ourselves up to 30% of the system core's time
apt.set_app_cpu_time_limit(30) apt.set_app_cpu_time_limit(30)

8
ctru-rs/examples/time-rtc.rs

@ -3,11 +3,11 @@ use ctru::prelude::*;
fn main() { fn main() {
ctru::use_panic_handler(); ctru::use_panic_handler();
let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); let gfx = Gfx::new().expect("Couldn't obtain GFX controller");
let mut hid = Hid::init().expect("Couldn't obtain HID controller"); let mut hid = Hid::new().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller"); let apt = Apt::new().expect("Couldn't obtain APT controller");
let _console = Console::init(gfx.top_screen.borrow_mut()); let _console = Console::new(gfx.top_screen.borrow_mut());
print!("\x1b[30;16HPress Start to exit."); print!("\x1b[30;16HPress Start to exit.");

12
ctru-rs/examples/title-info.rs

@ -5,12 +5,12 @@ use ctru::services::fs::FsMediaType;
fn main() { fn main() {
ctru::use_panic_handler(); ctru::use_panic_handler();
let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); let gfx = Gfx::new().expect("Couldn't obtain GFX controller");
let mut hid = Hid::init().expect("Couldn't obtain HID controller"); let mut hid = Hid::new().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller"); let apt = Apt::new().expect("Couldn't obtain APT controller");
let am = Am::init().expect("Couldn't obtain AM controller"); let am = Am::new().expect("Couldn't obtain AM controller");
let top_screen = Console::init(gfx.top_screen.borrow_mut()); let top_screen = Console::new(gfx.top_screen.borrow_mut());
let bottom_screen = Console::init(gfx.bottom_screen.borrow_mut()); let bottom_screen = Console::new(gfx.bottom_screen.borrow_mut());
let sd_count = am let sd_count = am
.title_count(FsMediaType::Sd) .title_count(FsMediaType::Sd)

4
ctru-rs/src/applets/mii_selector.rs

@ -41,7 +41,7 @@ bitflags! {
/// ``` /// ```
/// use ctru::applets::mii_selector::MiiSelector; /// use ctru::applets::mii_selector::MiiSelector;
/// ///
/// let mut mii_selector = MiiSelector::init(); /// let mut mii_selector = MiiSelector::new();
/// mii_selector.set_title("Example Mii selector"); /// mii_selector.set_title("Example Mii selector");
/// ///
/// let result = mii_selector.launch().unwrap(); /// let result = mii_selector.launch().unwrap();
@ -68,7 +68,7 @@ pub enum MiiLaunchError {
impl MiiSelector { impl MiiSelector {
/// Initializes a Mii Selector /// Initializes a Mii Selector
pub fn init() -> Self { pub fn new() -> Self {
let mut config = Box::<ctru_sys::MiiSelectorConf>::default(); let mut config = Box::<ctru_sys::MiiSelectorConf>::default();
unsafe { unsafe {
ctru_sys::miiSelectorInit(config.as_mut()); ctru_sys::miiSelectorInit(config.as_mut());

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

@ -89,7 +89,7 @@ bitflags! {
impl Swkbd { impl Swkbd {
/// Initializes a software keyboard of the specified type and the chosen number of buttons /// Initializes a software keyboard of the specified type and the chosen number of buttons
/// (from 1-3). /// (from 1-3).
pub fn init(keyboard_type: Kind, num_buttons: i32) -> Self { pub fn new(keyboard_type: Kind, num_buttons: i32) -> Self {
unsafe { unsafe {
let mut state = Box::<SwkbdState>::default(); let mut state = Box::<SwkbdState>::default();
swkbdInit(state.as_mut(), keyboard_type.into(), num_buttons, -1); swkbdInit(state.as_mut(), keyboard_type.into(), num_buttons, -1);
@ -207,7 +207,7 @@ impl Swkbd {
impl Default for Swkbd { impl Default for Swkbd {
fn default() -> Self { fn default() -> Self {
Swkbd::init(Kind::Normal, 2) Swkbd::new(Kind::Normal, 2)
} }
} }

2
ctru-rs/src/console.rs

@ -16,7 +16,7 @@ impl<'screen> Console<'screen> {
/// Initialize a console on the chosen screen, overwriting whatever was on the screen /// Initialize a console on the chosen screen, overwriting whatever was on the screen
/// previously (including other consoles). The new console is automatically selected for /// previously (including other consoles). The new console is automatically selected for
/// printing. /// printing.
pub fn init(screen: RefMut<'screen, dyn Screen>) -> Self { pub fn new(screen: RefMut<'screen, dyn Screen>) -> Self {
let mut context = Box::<PrintConsole>::default(); let mut context = Box::<PrintConsole>::default();
unsafe { consoleInit(screen.as_raw(), context.as_mut()) }; unsafe { consoleInit(screen.as_raw(), context.as_mut()) };

2
ctru-rs/src/lib.rs

@ -54,7 +54,7 @@ fn panic_hook_setup() {
if main_thread == std::thread::current().id() && console::Console::exists() { if main_thread == std::thread::current().id() && console::Console::exists() {
println!("\nPress SELECT to exit the software"); println!("\nPress SELECT to exit the software");
match Hid::init() { match Hid::new() {
Ok(mut hid) => loop { Ok(mut hid) => loop {
hid.scan_input(); hid.scan_input();
let keys = hid.keys_down(); let keys = hid.keys_down();

2
ctru-rs/src/services/am.rs

@ -61,7 +61,7 @@ impl<'a> Title<'a> {
pub struct Am(()); pub struct Am(());
impl Am { impl Am {
pub fn init() -> crate::Result<Am> { pub fn new() -> crate::Result<Am> {
unsafe { unsafe {
ResultCode(ctru_sys::amInit())?; ResultCode(ctru_sys::amInit())?;
Ok(Am(())) Ok(Am(()))

2
ctru-rs/src/services/apt.rs

@ -3,7 +3,7 @@ use crate::error::ResultCode;
pub struct Apt(()); pub struct Apt(());
impl Apt { impl Apt {
pub fn init() -> crate::Result<Apt> { pub fn new() -> crate::Result<Apt> {
unsafe { unsafe {
ResultCode(ctru_sys::aptInit())?; ResultCode(ctru_sys::aptInit())?;
Ok(Apt(())) Ok(Apt(()))

2
ctru-rs/src/services/cam.rs

@ -770,7 +770,7 @@ impl Cam {
/// This function will return an error if the service was unable to be initialized. /// This function will return an error if the service was unable to be initialized.
/// Since this service requires no special or elevated permissions, errors are /// Since this service requires no special or elevated permissions, errors are
/// rare in practice. /// rare in practice.
pub fn init() -> crate::Result<Cam> { pub fn new() -> crate::Result<Cam> {
unsafe { unsafe {
ResultCode(ctru_sys::camInit())?; ResultCode(ctru_sys::camInit())?;
Ok(Cam { Ok(Cam {

2
ctru-rs/src/services/cfgu.rs

@ -61,7 +61,7 @@ impl Cfgu {
/// ctrulib services are reference counted, so this function may be called /// ctrulib services are reference counted, so this function may be called
/// as many times as desired and the service will not exit until all /// as many times as desired and the service will not exit until all
/// instances of Cfgu drop out of scope. /// instances of Cfgu drop out of scope.
pub fn init() -> crate::Result<Cfgu> { pub fn new() -> crate::Result<Cfgu> {
ResultCode(unsafe { ctru_sys::cfguInit() })?; ResultCode(unsafe { ctru_sys::cfguInit() })?;
Ok(Cfgu(())) Ok(Cfgu(()))
} }

18
ctru-rs/src/services/fs.rs

@ -103,7 +103,7 @@ pub struct Fs(());
/// ```no_run /// ```no_run
/// use ctru::services::fs::Fs; /// use ctru::services::fs::Fs;
/// ///
/// let fs = Fs::init().unwrap(); /// let fs = Fs::new().unwrap();
/// let sdmc_archive = fs.sdmc().unwrap(); /// let sdmc_archive = fs.sdmc().unwrap();
/// ``` /// ```
pub struct Archive { pub struct Archive {
@ -126,7 +126,7 @@ pub struct Archive {
/// use std::io::prelude::*; /// use std::io::prelude::*;
/// use ctru::services::fs::{Fs, File}; /// use ctru::services::fs::{Fs, File};
/// ///
/// let fs = Fs::init()?; /// let fs = Fs::new()?;
/// let sdmc = fs.sdmc()?; /// let sdmc = fs.sdmc()?;
/// ///
/// let mut file = File::create(&sdmc, "/foo.txt")?; /// let mut file = File::create(&sdmc, "/foo.txt")?;
@ -139,7 +139,7 @@ pub struct Archive {
/// use std::io::prelude::*; /// use std::io::prelude::*;
/// use ctru::services::fs::{Fs, File}; /// use ctru::services::fs::{Fs, File};
/// ///
/// let fs = Fs::init()?; /// let fs = Fs::new()?;
/// let sdmc = fs.sdmc()?; /// let sdmc = fs.sdmc()?;
/// ///
/// let mut file = File::open(&sdmc, "/foo.txt")?; /// let mut file = File::open(&sdmc, "/foo.txt")?;
@ -156,7 +156,7 @@ pub struct Archive {
/// use std::io::prelude::*; /// use std::io::prelude::*;
/// use ctru::services::fs::{Fs, File}; /// use ctru::services::fs::{Fs, File};
/// ///
/// let fs = Fs::init()?; /// let fs = Fs::new()?;
/// let sdmc = fs.sdmc()?; /// let sdmc = fs.sdmc()?;
/// ///
/// let file = File::open(&sdmc, "/foo.txt")?; /// let file = File::open(&sdmc, "/foo.txt")?;
@ -209,7 +209,7 @@ pub struct Metadata {
/// ```no_run /// ```no_run
/// use ctru::services::fs::{Fs, OpenOptions}; /// use ctru::services::fs::{Fs, OpenOptions};
/// ///
/// let fs = Fs::init().unwrap(); /// let fs = Fs::new().unwrap();
/// let sdmc_archive = fs.sdmc().unwrap(); /// let sdmc_archive = fs.sdmc().unwrap();
/// let file = OpenOptions::new() /// let file = OpenOptions::new()
/// .read(true) /// .read(true)
@ -224,7 +224,7 @@ pub struct Metadata {
/// ```no_run /// ```no_run
/// use ctru::services::fs::{Fs, OpenOptions}; /// use ctru::services::fs::{Fs, OpenOptions};
/// ///
/// let fs = Fs::init().unwrap(); /// let fs = Fs::new().unwrap();
/// let sdmc_archive = fs.sdmc().unwrap(); /// let sdmc_archive = fs.sdmc().unwrap();
/// let file = OpenOptions::new() /// let file = OpenOptions::new()
/// .read(true) /// .read(true)
@ -298,7 +298,7 @@ impl Fs {
/// ctrulib services are reference counted, so this function may be called /// ctrulib services are reference counted, so this function may be called
/// as many times as desired and the service will not exit until all /// as many times as desired and the service will not exit until all
/// instances of Fs drop out of scope. /// instances of Fs drop out of scope.
pub fn init() -> crate::Result<Fs> { pub fn new() -> crate::Result<Fs> {
unsafe { unsafe {
let r = ctru_sys::fsInit(); let r = ctru_sys::fsInit();
if r < 0 { if r < 0 {
@ -351,7 +351,7 @@ impl File {
/// ```no_run /// ```no_run
/// use ctru::services::fs::{Fs, File}; /// use ctru::services::fs::{Fs, File};
/// ///
/// let fs = Fs::init().unwrap(); /// let fs = Fs::new().unwrap();
/// let sdmc_archive = fs.sdmc().unwrap(); /// let sdmc_archive = fs.sdmc().unwrap();
/// let mut f = File::open(&sdmc_archive, "/foo.txt").unwrap(); /// let mut f = File::open(&sdmc_archive, "/foo.txt").unwrap();
/// ``` /// ```
@ -380,7 +380,7 @@ impl File {
/// ```no_run /// ```no_run
/// use ctru::services::fs::{Fs, File}; /// use ctru::services::fs::{Fs, File};
/// ///
/// let fs = Fs::init().unwrap(); /// let fs = Fs::new().unwrap();
/// let sdmc_archive = fs.sdmc().unwrap(); /// let sdmc_archive = fs.sdmc().unwrap();
/// let mut f = File::create(&sdmc_archive, "/foo.txt").unwrap(); /// let mut f = File::create(&sdmc_archive, "/foo.txt").unwrap();
/// ``` /// ```

6
ctru-rs/src/services/gfx.rs

@ -131,7 +131,7 @@ impl Gfx {
/// Initialize the Gfx module with the chosen framebuffer formats for the top and bottom /// Initialize the Gfx module with the chosen framebuffer formats for the top and bottom
/// screens /// screens
/// ///
/// Use `Gfx::init()` instead of this function to initialize the module with default parameters /// Use `Gfx::new()` instead of this function to initialize the module with default parameters
pub fn with_formats( pub fn with_formats(
top_fb_fmt: FramebufferFormat, top_fb_fmt: FramebufferFormat,
bottom_fb_fmt: FramebufferFormat, bottom_fb_fmt: FramebufferFormat,
@ -158,7 +158,7 @@ impl Gfx {
/// Creates a new [Gfx] instance with default init values /// Creates a new [Gfx] instance with default init values
/// It's the same as calling: /// It's the same as calling:
/// `Gfx::with_formats(FramebufferFormat::Bgr8, FramebufferFormat::Bgr8, false)` /// `Gfx::with_formats(FramebufferFormat::Bgr8, FramebufferFormat::Bgr8, false)`
pub fn init() -> Result<Self> { pub fn new() -> Result<Self> {
Gfx::with_formats(FramebufferFormat::Bgr8, FramebufferFormat::Bgr8, false) Gfx::with_formats(FramebufferFormat::Bgr8, FramebufferFormat::Bgr8, false)
} }
@ -294,6 +294,6 @@ mod tests {
#[test] #[test]
fn gfx_duplicate() { fn gfx_duplicate() {
// We don't need to build a `Gfx` because the test runner has one already // We don't need to build a `Gfx` because the test runner has one already
assert!(matches!(Gfx::init(), Err(Error::ServiceAlreadyActive))); assert!(matches!(Gfx::new(), Err(Error::ServiceAlreadyActive)));
} }
} }

2
ctru-rs/src/services/hid.rs

@ -61,7 +61,7 @@ pub struct CirclePosition(ctru_sys::circlePosition);
/// Since this service requires no special or elevated permissions, errors are /// Since this service requires no special or elevated permissions, errors are
/// rare in practice. /// rare in practice.
impl Hid { impl Hid {
pub fn init() -> crate::Result<Hid> { pub fn new() -> crate::Result<Hid> {
unsafe { unsafe {
ResultCode(ctru_sys::hidInit())?; ResultCode(ctru_sys::hidInit())?;
Ok(Hid(())) Ok(Hid(()))

2
ctru-rs/src/services/ndsp/mod.rs

@ -80,7 +80,7 @@ impl Ndsp {
/// ///
/// This function will return an error if an instance of the `Ndsp` struct already exists /// This function will return an error if an instance of the `Ndsp` struct already exists
/// or if there are any issues during initialization. /// or if there are any issues during initialization.
pub fn init() -> crate::Result<Self> { pub fn new() -> crate::Result<Self> {
let _service_handler = ServiceReference::new( let _service_handler = ServiceReference::new(
&NDSP_ACTIVE, &NDSP_ACTIVE,
false, false,

4
ctru-rs/src/services/romfs.rs

@ -25,7 +25,7 @@ pub struct RomFS {
static ROMFS_ACTIVE: Mutex<usize> = Mutex::new(0); static ROMFS_ACTIVE: Mutex<usize> = Mutex::new(0);
impl RomFS { impl RomFS {
pub fn init() -> crate::Result<Self> { pub fn new() -> crate::Result<Self> {
let _service_handler = ServiceReference::new( let _service_handler = ServiceReference::new(
&ROMFS_ACTIVE, &ROMFS_ACTIVE,
true, true,
@ -50,7 +50,7 @@ mod tests {
#[test] #[test]
fn romfs_counter() { fn romfs_counter() {
let _romfs = RomFS::init().unwrap(); let _romfs = RomFS::new().unwrap();
let value = *ROMFS_ACTIVE.lock().unwrap(); let value = *ROMFS_ACTIVE.lock().unwrap();
assert_eq!(value, 1); assert_eq!(value, 1);

6
ctru-rs/src/services/soc.rs

@ -25,7 +25,7 @@ impl Soc {
/// # Errors /// # Errors
/// ///
/// This function will return an error if the `Soc` service is already initialized /// This function will return an error if the `Soc` service is already initialized
pub fn init() -> crate::Result<Self> { pub fn new() -> crate::Result<Self> {
Self::init_with_buffer_size(0x100000) Self::init_with_buffer_size(0x100000)
} }
@ -107,8 +107,8 @@ mod tests {
#[test] #[test]
fn soc_duplicate() { fn soc_duplicate() {
let _soc = Soc::init().unwrap(); let _soc = Soc::new().unwrap();
assert!(matches!(Soc::init(), Err(Error::ServiceAlreadyActive))) assert!(matches!(Soc::new(), Err(Error::ServiceAlreadyActive)))
} }
} }

2
ctru-rs/src/services/sslc.rs

@ -8,7 +8,7 @@ pub struct SslC(());
impl SslC { impl SslC {
/// Initialize the service /// Initialize the service
pub fn init() -> crate::Result<Self> { pub fn new() -> crate::Result<Self> {
unsafe { unsafe {
ResultCode(ctru_sys::sslcInit(0))?; ResultCode(ctru_sys::sslcInit(0))?;
Ok(SslC(())) Ok(SslC(()))

8
ctru-rs/src/test_runner.rs

@ -12,13 +12,13 @@ use crate::prelude::*;
/// runs all tests in series, "failing" on the first one to panic (really, the /// runs all tests in series, "failing" on the first one to panic (really, the
/// panic is just treated the same as any normal application panic). /// panic is just treated the same as any normal application panic).
pub(crate) fn run(tests: &[&TestDescAndFn]) { pub(crate) fn run(tests: &[&TestDescAndFn]) {
let gfx = Gfx::init().unwrap(); let gfx = Gfx::new().unwrap();
let mut hid = Hid::init().unwrap(); let mut hid = Hid::new().unwrap();
let apt = Apt::init().unwrap(); let apt = Apt::new().unwrap();
let mut top_screen = gfx.top_screen.borrow_mut(); let mut top_screen = gfx.top_screen.borrow_mut();
top_screen.set_wide_mode(true); top_screen.set_wide_mode(true);
let _console = Console::init(top_screen); let _console = Console::new(top_screen);
let opts = TestOpts { let opts = TestOpts {
force_run_in_process: true, force_run_in_process: true,

Loading…
Cancel
Save