Skip to content

Commit 2f7894d

Browse files
committed
better example
1 parent d082202 commit 2f7894d

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/lib.rs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,34 @@ pub const fn null<T>() -> *mut T { 0 as *mut T }
1414
pub extern "C" fn main() -> ! {
1515
unsafe {
1616
consoleInit(null());
17-
gfxInitDefault();
1817

19-
printf("\x1b[16;16HPress PLUS to exit.".as_ptr() as *const i8);
18+
let mut k_held_old = HidControllerKeys(0);
19+
20+
printf("\x1b[1;1HPress PLUS to exit.\n".as_ptr() as *const i8);
21+
printf("\x1b[2;1HOr any other key to see its value.\n".as_ptr() as *const i8);
2022

2123
while appletMainLoop() {
2224
hidScanInput();
25+
let k_held = HidControllerKeys(hidKeysHeld(HidControllerID::CONTROLLER_P1_AUTO) as u32);
2326

24-
let k_down = HidControllerKeys(hidKeysDown(HidControllerID::CONTROLLER_P1_AUTO) as u32);
25-
26-
if k_down == HidControllerKeys::KEY_PLUS {
27+
if k_held == HidControllerKeys::KEY_PLUS {
2728
break;
2829
}
2930

30-
printf("This key is pressed: %d\n".as_ptr() as *const i8, k_down);
31+
if k_held != k_held_old {
32+
consoleClear();
33+
34+
printf("\x1b[1;1HPress PLUS to exit.\n".as_ptr() as *const i8);
35+
printf("\x1b[2;1HOr any other key to see its value.\n".as_ptr() as *const i8);
36+
printf("\x1b[3;1HThis key is currently pressed: %d\n".as_ptr() as *const i8, k_held);
37+
}
38+
39+
k_held_old = k_held;
3140

32-
gfxFlushBuffers();
33-
gfxSwapBuffers();
34-
gfxWaitForVsync();
41+
consoleUpdate(null());
3542
}
3643

37-
gfxExit();
44+
consoleExit(null());
3845
panic!("Success. We shall however think on a way of exiting cleanly.");
3946
}
4047
}

0 commit comments

Comments
 (0)