Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to support latest versions of libnx and bindgen #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
23 changes: 9 additions & 14 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
24 changes: 17 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down