Skip to content

hid: Add return type to GetNpadStates - #73

Open
MonsterDruide1 wants to merge 1 commit into
open-ead:masterfrom
MonsterDruide1:getnpadstates-return
Open

hid: Add return type to GetNpadStates#73
MonsterDruide1 wants to merge 1 commit into
open-ead:masterfrom
MonsterDruide1:getnpadstates-return

Conversation

@MonsterDruide1

@MonsterDruide1 MonsterDruide1 commented Jul 30, 2026

Copy link
Copy Markdown

When checking the SDK binary, it gets obvious that GetNpadStates should return an integer. According to my understanding, GetNpadStates can fetch multiple states at once (mSamplingNumber tells them apart), so the first parameter is a buffer of potentially multiple states, the second parameter is the buffer size and the third is the port. The return type might be the number of entries that were added to the buffer, but I'm not fully sure about that. Odyssey works with hardcoded buffer size of 16, but ignores the return value of this function.


This change is Reviewable

@MonsterDruide1 MonsterDruide1 self-assigned this Jul 30, 2026

@german77 german77 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally sdk functions return the nn::Result of the operation. In this overload the error triggers an abort and instead it returns the number of valid entries. When you just start the game the input ring buffer is empty and won't be able to provide the 16 requested entries. This period is very brief so most games asume the ring buffer is always full.

@german77 reviewed 1 file and all commit messages, and made 2 comments.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on MonsterDruide1).


include/nn/hid.h line 521 at r1 (raw file):

void GetNpadState(NpadJoyRightState*, const u32& port);

s32 GetNpadStates(NpadFullKeyState*, s32, const u32& port);

Your assumption is correct for the parameters. Although the port is actually the NpadId. Same for the others.

Libnx has this function documented although the parameters are in different order https://github.com/switchbrew/libnx/blob/master/nx/include/switch/services/hid.h#L1709

Suggestion:

s32 GetNpadStates(NpadFullKeyState* states, s32 count, const u32& id);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants