diff --git a/Cargo.toml b/Cargo.toml index f9b0333..d7bff07 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ lto = true [dependencies] rlibc = "*" -panic-abort = "0.3.1" +panic-abort = "0.3.2" [build-dependencies] -bindgen = "0.37.0" +bindgen = "0.65.1" diff --git a/build.rs b/build.rs index 3a54693..aeca613 100644 --- a/build.rs +++ b/build.rs @@ -23,24 +23,19 @@ pub fn main() { .clang_arg(format!("-I{}/libnx/include", devkitpro_path)) .clang_arg(format!("-I{}/devkitA64/aarch64-none-elf/include", devkitpro_path)) - .bitfield_enum("HidMouseButton") - .bitfield_enum("HidKeyboardModifier") - .rustified_enum("HidKeyboardScancode") - .bitfield_enum("HidControllerType") - .rustified_enum("HidControllerLayoutType") - .bitfield_enum("HidControllerColorDescription") - .bitfield_enum("HidControllerKeys") - .rustified_enum("HidControllerJoystick") - .bitfield_enum("HidControllerConnectionState") - .rustified_enum("HidControllerID") + .rustified_enum("HidNpadStyleTag") + .rustified_enum("HidNpadIdType") + .rustified_enum("HidNpadButton") .generate_inline_functions(true) - .blacklist_type("u8") - .blacklist_type("u16") - .blacklist_type("u32") - .blacklist_type("u64") + .blocklist_type("u8") + .blocklist_type("u16") + .blocklist_type("u32") + .blocklist_type("u64") + .derive_default(true) + // Finish the builder and generate the bindings. .generate() // Unwrap the Result and panic on failure. diff --git a/src/lib.rs b/src/lib.rs index 28be4dd..6923584 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,28 +15,38 @@ pub extern "C" fn main() { unsafe { consoleInit(null()); - let mut k_held_old = HidControllerKeys(0); + // Configure our supported input layout: a single player with standard controller styles + padConfigureInput(1, HidNpadStyleTag::HidNpadStyleSet_NpadStandard as u32); + + // Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller) + let mut pad: PadState = Default::default(); + let mut padMask: u64 = 0; + padMask |= (1 as u64) << HidNpadIdType::HidNpadIdType_No1 as u32; + padMask |= (1 as u64) << HidNpadIdType::HidNpadIdType_Handheld as u32; + padInitializeWithMask(&mut pad, padMask); + + let mut kHeldOld: u64 = 0; printf("\x1b[1;1HPress PLUS to exit.\n".as_ptr() as *const i8); printf("\x1b[2;1HOr any other key to see its value.\n".as_ptr() as *const i8); while appletMainLoop() { - hidScanInput(); - let k_held = HidControllerKeys(hidKeysHeld(HidControllerID::CONTROLLER_P1_AUTO) as u32); + padUpdate(&mut pad); - if k_held == HidControllerKeys::KEY_PLUS { + let kHeld = pad.buttons_cur; + if (kHeld & (HidNpadButton::HidNpadButton_Plus as u64)) != 0 { break; } - if k_held != k_held_old { + if kHeld != kHeldOld { consoleClear(); printf("\x1b[1;1HPress PLUS to exit.\n".as_ptr() as *const i8); printf("\x1b[2;1HOr any other key to see its value.\n".as_ptr() as *const i8); - printf("\x1b[3;1HThis key is currently pressed: %d\n".as_ptr() as *const i8, k_held); + printf("\x1b[3;1HThis key is currently pressed: %d\n".as_ptr() as *const i8, kHeld); } - k_held_old = k_held; + kHeldOld = kHeld; consoleUpdate(null()); }