Browse Source

Fix examples after thorough testing

pull/134/head
Andrea Ciliberti 1 year ago
parent
commit
2af0268f89
  1. 2
      ctru-rs/examples/camera-image.rs
  2. 6
      ctru-rs/examples/gfx-3d-mode.rs
  3. 9
      ctru-rs/examples/gfx-bitmap.rs
  4. 12
      ctru-rs/examples/network-sockets.rs
  5. 5
      ctru-rs/examples/software-keyboard.rs
  6. 13
      ctru-rs/examples/time-rtc.rs
  7. 4
      ctru-rs/examples/title-info.rs
  8. 6
      ctru-rs/examples/touch-screen.rs
  9. 4
      ctru-rs/src/console.rs

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

@ -61,7 +61,7 @@ fn main() { @@ -61,7 +61,7 @@ fn main() {
let mut buf = vec![0u8; BUF_SIZE];
println!("\nPress R to take a new picture");
println!("\x1b[29;16HPress Start to exit");
println!("Press Start to exit");
while apt.main_loop() {
hid.scan_input();

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

@ -10,7 +10,6 @@ use ctru::services::gfx::{Flush, Screen, Side, Swap, TopScreen3D}; @@ -10,7 +10,6 @@ use ctru::services::gfx::{Flush, Screen, Side, Swap, TopScreen3D};
//
// WARNING: this example uses 3D mode in a rather unnatural way, and should
// probably not be viewed for too long or at all if you are photosensitive.
const IMAGE: &[u8] = include_bytes!("assets/ferris.rgb");
static ZERO: &[u8] = &[0; IMAGE.len()];
@ -22,8 +21,9 @@ fn main() { @@ -22,8 +21,9 @@ fn main() {
let apt = Apt::new().expect("Couldn't obtain APT controller");
let _console = Console::new(gfx.bottom_screen.borrow_mut());
println!("Press A to switch sides (be sure to have set the 3D slider correctly).");
println!("\x1b[29;16HPress Start to exit");
println!("Press A to switch sides.");
println!("Make sure to have set the 3D slider correctly");
println!("\x1b[29;12HPress Start to exit");
gfx.top_screen.borrow_mut().set_double_buffering(true);

9
ctru-rs/examples/gfx-bitmap.rs

@ -64,6 +64,15 @@ fn main() { @@ -64,6 +64,15 @@ fn main() {
} else {
IMAGE
};
let frame_buffer = bottom_screen.raw_framebuffer();
// We render the newly switched image to the framebuffer.
unsafe {
frame_buffer
.ptr
.copy_from(image_bytes.as_ptr(), image_bytes.len());
}
}
// Flush framebuffers. Since we're not using double buffering,

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

@ -12,12 +12,9 @@ fn main() { @@ -12,12 +12,9 @@ fn main() {
ctru::use_panic_handler();
let gfx = Gfx::new().unwrap();
let _console = Console::new(gfx.top_screen.borrow_mut());
let mut hid = Hid::new().unwrap();
let apt = Apt::new().unwrap();
println!("\nlibctru sockets demo\n");
// Owning a living handle to the `Soc` service is required to use network functionalities.
let soc = Soc::new().unwrap();
@ -25,8 +22,12 @@ fn main() { @@ -25,8 +22,12 @@ fn main() {
let server = TcpListener::bind("0.0.0.0:80").unwrap();
server.set_nonblocking(true).unwrap();
println!("Point your browser to http://{}/\n", soc.host_address());
println!("\x1b[29;16HPress Start to exit");
let _bottom_console = Console::new(gfx.bottom_screen.borrow_mut());
println!("Point your browser at:\nhttp://{}/\n", soc.host_address());
println!("\x1b[29;12HPress Start to exit");
let _top_console = Console::new(gfx.top_screen.borrow_mut());
while apt.main_loop() {
hid.scan_input();
@ -34,6 +35,7 @@ fn main() { @@ -34,6 +35,7 @@ fn main() {
break;
};
// Receive any incoming connections.
match server.accept() {
Ok((mut stream, socket_addr)) => {
println!("Got connection from {socket_addr}");

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

@ -13,8 +13,7 @@ fn main() { @@ -13,8 +13,7 @@ fn main() {
let gfx = Gfx::new().unwrap();
let _console = Console::new(gfx.top_screen.borrow_mut());
println!("Press A to enter some text.");
println!("\x1b[29;16HPress Start to exit");
println!("Press A to enter some text or press Start to exit.");
while apt.main_loop() {
hid.scan_input();
@ -23,7 +22,7 @@ fn main() { @@ -23,7 +22,7 @@ fn main() {
break;
}
// If the user request to write some input.
// Check if the user request to write some input.
if hid.keys_down().contains(KeyPad::A) {
// Prepares a software keyboard with two buttons: One to cancel input and one
// to accept it. You can also use `SoftwareKeyboard::new()` to launch the keyboard in different

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

@ -27,8 +27,17 @@ fn main() { @@ -27,8 +27,17 @@ fn main() {
// since the 3DS doesn't seem to support timezones.
let cur_time = time::OffsetDateTime::now_utc();
// Display the retrieved information.
println!("\x1b[1;1H{cur_time}");
let hours = cur_time.hour();
let minutes = cur_time.minute();
let seconds = cur_time.second();
let weekday = cur_time.weekday().to_string();
let month = cur_time.month().to_string();
let day = cur_time.day();
let year = cur_time.year();
println!("\x1b[1;1H{hours:0>2}:{minutes:0>2}:{seconds:0>2}");
println!("{weekday} {month} {day} {year}");
gfx.wait_for_vblank();
}

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

@ -88,7 +88,8 @@ fn main() { @@ -88,7 +88,8 @@ fn main() {
// Clear the bottom screen and write the properties of selected title to it.
bottom_screen.select();
println!("\x1b[2J");
bottom_screen.clear();
println!("Press Start to exit");
// Move cursor to top left.
println!("\x1b[1;1");
@ -97,7 +98,6 @@ fn main() { @@ -97,7 +98,6 @@ fn main() {
println!("Version: 0x{:x}", selected_title.version());
println!("Product code: \"{}\"", selected_title.product_code());
println!("\x1b[29;16HPress Start to exit");
if use_nand {
println!("Press SELECT to choose SD Card");
println!("Current medium: NAND");

6
ctru-rs/examples/touch-screen.rs

@ -32,6 +32,9 @@ fn main() { @@ -32,6 +32,9 @@ fn main() {
// We only want to print the position when it's different
// from what it was on the previous frame.
if touch != old_touch {
// Move the cursor back to the top of the screen and print the coordinates.
print!("\x1b[1;1HTouch Screen position: {:#?}", touch);
// Special case for when the user lifts the stylus/finger from the screen.
// This is done to avoid some screen tearing.
if touch == (0, 0) {
@ -40,9 +43,6 @@ fn main() { @@ -40,9 +43,6 @@ fn main() {
// Print again because we just cleared the screen.
println!("\x1b[29;16HPress Start to exit");
}
// Move the cursor back to the top of the screen and print the coordinates.
print!("\x1b[1;1HTouch Screen position: {:#?}", touch);
}
// Save our current touch position for the next frame.

4
ctru-rs/src/console.rs

@ -21,7 +21,9 @@ static mut EMPTY_CONSOLE: PrintConsole = unsafe { const_zero::const_zero!(PrintC @@ -21,7 +21,9 @@ static mut EMPTY_CONSOLE: PrintConsole = unsafe { const_zero::const_zero!(PrintC
///
/// # Notes
///
/// The console will take full possession of the screen handed to it as long as it stays alive. It also supports ANSI codes.
/// The [`Console`] will take full possession of the screen handed to it as long as it stays alive. It also supports ANSI codes.
/// The [`Console`]'s window will have a size of 40x30 on the bottom screen, 50x30 on the normal top screen and
/// 100x30 on the top screen when wide mode is enabled.
///
/// # Alternatives
///

Loading…
Cancel
Save