Browse Source

Update examples

pull/10/head
Fenrir 7 years ago committed by FenrirWolf
parent
commit
d46f9f4565
  1. 3
      examples/src/bin/buttons.rs
  2. 3
      examples/src/bin/hello-both-screens.rs
  3. 10
      examples/src/bin/hello-world.rs

3
examples/src/bin/buttons.rs

@ -9,7 +9,7 @@ fn main() {
// Setup services // Setup services
let apt = Apt::init().unwrap(); let apt = Apt::init().unwrap();
let hid = Hid::init().unwrap(); let hid = Hid::init().unwrap();
let mut gfx = Gfx::default(); let gfx = Gfx::default();
let console = Console::default(); let console = Console::default();
println!("Hi there! Try pressing a button"); println!("Hi there! Try pressing a button");
@ -71,5 +71,6 @@ fn main() {
// Flush and swap framebuffers // Flush and swap framebuffers
gfx.flush_buffers(); gfx.flush_buffers();
gfx.swap_buffers(); gfx.swap_buffers();
gfx.wait_for_vblank();
} }
} }

3
examples/src/bin/hello-both-screens.rs

@ -9,7 +9,7 @@ fn main() {
// Initialize services // Initialize services
let apt = Apt::init().unwrap(); let apt = Apt::init().unwrap();
let hid = Hid::init().unwrap(); let hid = Hid::init().unwrap();
let mut gfx = Gfx::default(); let gfx = Gfx::default();
// Start a console on the top screen // Start a console on the top screen
let top_screen = Console::init(Screen::Top); let top_screen = Console::init(Screen::Top);
@ -33,6 +33,7 @@ fn main() {
while apt.main_loop() { while apt.main_loop() {
gfx.flush_buffers(); gfx.flush_buffers();
gfx.swap_buffers(); gfx.swap_buffers();
gfx.wait_for_vblank();
hid.scan_input(); hid.scan_input();
if hid.keys_down().contains(KeyPad::KEY_START) { if hid.keys_down().contains(KeyPad::KEY_START) {

10
examples/src/bin/hello-world.rs

@ -10,15 +10,15 @@ fn main() {
// Service handles are internally reference-counted. When all instances of a // Service handles are internally reference-counted. When all instances of a
// service handle go out of scope, the service will be closed. // service handle go out of scope, the service will be closed.
// The APT service handles application management functions, such as // The APT service handles application management functions, such as enabling sleep
// syncing our main loop with the graphics hardware. // mode and jumping to the home menu or to other applications
let apt = Apt::init().unwrap(); let apt = Apt::init().unwrap();
// The HID service handles button and touch screen inputs. // The HID service handles button and touch screen inputs.
let hid = Hid::init().unwrap(); let hid = Hid::init().unwrap();
// The GFX service manages the framebuffers for the top and bottom screens. // The GFX service manages the framebuffers for the top and bottom screens.
let mut gfx = Gfx::default(); let gfx = Gfx::default();
// Initialize a ctrulib console and direct standard output to it. // Initialize a ctrulib console and direct standard output to it.
// Consoles can be initialized on both the top and bottom screens. // Consoles can be initialized on both the top and bottom screens.
@ -41,8 +41,12 @@ fn main() {
gfx.flush_buffers(); gfx.flush_buffers();
gfx.swap_buffers(); gfx.swap_buffers();
// Wait for the next frame to begin
gfx.wait_for_vblank();
// Scan for user input. // Scan for user input.
hid.scan_input(); hid.scan_input();
// Check if the user has pressed the given button on this frame. // Check if the user has pressed the given button on this frame.
// If so, break out of the loop. // If so, break out of the loop.
if hid.keys_down().contains(KeyPad::KEY_START) { if hid.keys_down().contains(KeyPad::KEY_START) {

Loading…
Cancel
Save