Skip to content
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
3 changes: 3 additions & 0 deletions gc/wiiuse/wpad.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ void WPAD_Expansion(int chan, struct expansion_t *exp);
void WPAD_PadStatus(int chan);
bool WPAD_IsBatteryCritical(int chan);

s32 WPAD_HasMotionPlus(s32 chan);
#define WPAD_EXP_MOTION_PLUS 5
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

unused define?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The #define WPAD_EXP_MOTION_PLUS 5 is important because it exposes Motion Plus as an official public API constant. Now that Motion Plus actually works, external code needs to know what the value 5 represents. Without it in the header, 5 stays an undocumented magic number. The constant makes Motion Plus a discoverable, documented part of the API.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please don't add this: we already have EXP_MOTION_PLUS defined in a public header, and there's a way of checking if the motion plus is available, using the currently public API: just check the exp.type field of the WPADData structure.

If you really want to make it even more convenient, you could add this to the wpad.h header:

static inline bool WPAD_HasMotionPlus(s32 chan) {
     return WPAD_Data(chan)->exp.type == EXP_MOTION_PLUS;
}

Copy link
Copy Markdown
Author

@gitman123323 gitman123323 Mar 24, 2026

Choose a reason for hiding this comment

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

Hi mardy,

Just to clarify what my new code actually does: it ensures that the Wii MotionPlus can be reliably detected as physically present using libogc. Before these changes, detection wasn’t consistent, and the gyroscope values from MotionPlus were all zeros, so motion data wasn’t accessible at all. With my fixes, the MotionPlus now responds correctly to motion, and developers can safely detect and use it.

That’s why I added the new header — it’s directly tied to these fixes and makes the feature work reliably in practice.

Thanks for taking a look.


#ifdef __cplusplus
}
#endif /* __cplusplus */
Expand Down
4 changes: 2 additions & 2 deletions wiiuse/motion_plus.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static void wiiuse_probe_motion_plus_check2(struct wiimote_t *wm, ubyte *data, u

static void wiiuse_probe_motion_plus_check1(struct wiimote_t *wm, ubyte *data, uword len)
{
if (data[1] != 0x05)
if (data[5] != 0x05)
{
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_MPLUS_PRESENT);
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP_HANDSHAKE);
Expand All @@ -45,7 +45,7 @@ static void wiiuse_probe_motion_plus_check1(struct wiimote_t *wm, ubyte *data, u
void wiiuse_probe_motion_plus(struct wiimote_t *wm)
{
ubyte *buf = __lwp_wkspace_allocate(MAX_PAYLOAD);
wiiuse_read_data(wm, buf, WM_EXP_MOTION_PLUS_MODE, 2, wiiuse_probe_motion_plus_check1);
wiiuse_read_data(wm, buf, WM_EXP_ID, 6, wiiuse_probe_motion_plus_check1);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I haven't test this very code in libogc, but when I ported it in my wpad2 branch I followed the same logic and it was working fine. Are you sure that the old code is not working?

Also, according to the documentation, the old code is correct, because the motion plus, until you activate it, is found at 0xA60000: https://wiibrew.org/wiki/Wiimote/Extension_Controllers/Wii_Motion_Plus

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Hey, just to make sure we're talking about the same thing — if you mean Motion Plus connectivity, yeah that might be fine. What I'm fixing here is actually reading the gyro data, because right now the values just come back as 0.00 no matter what even when Motion Plus is attached and active. That's the bug I ran into and what this PR addresses. Maybe we were just confused about which problem we were each referring to?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Because i mean, could you clarify what you were talking about? because what my new code fixes is the following: wii motion plus can now be detected as wheter it is physically present or not using libogc and it also now allow access to the wii motion plus gyros which weren't accessible at all before because the values returned all zeros and now they actually respond to motion correctly.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi! Let's try to address one issue at a time, since your PR seems to relate to several different issues.

With the unmodified libogc, is the motion plus detected correctly? I mean, what is the value of WPAD_Data(chan)->exp.type, if you connect the Motion plus? And does this change, if you call WPAD_SetMotionPlus(chan, true)?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

the value of WPAD_Data(chan)->exp.type returns nothing because i don't know, somehow it doesn't work right, and also yes directly setting WPAD_SetMotionPlus(chan, true) does do something but it's just forcefully telling the system that there is a motion plus present when there isn't one, not actually detecting wheter it got connected to the wiimote or not. Does that help you?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Mmm... Are you calling WPAD_ScanPads() at every frame? This is the function responsible for updating the wiimotes structures.

Copy link
Copy Markdown
Author

@gitman123323 gitman123323 Mar 25, 2026

Choose a reason for hiding this comment

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

Yes, I am calling WPAD_ScanPads() every frame as expected, and all standard input handling works correctly (Wiimote buttons, Nunchuk detection, etc.).

The issue seems to be specific to Wii MotionPlus. Before applying my changes, MotionPlus could not be reliably detected or used, even though the rest of the input system behaved normally.

From my testing, this appears to be unrelated to how often PAD_ScanPads() is called, and more likely tied to how MotionPlus data or registers are currently handled in libogc. After patching the relevant parts, MotionPlus detection and usage started working as expected.

I really appreciate you taking the time to look into this.

Copy link
Copy Markdown
Author

@gitman123323 gitman123323 Mar 26, 2026

Choose a reason for hiding this comment

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

Here are some showcase videos demonstrating the fix working in real time:

https://youtube.com/shorts/dbdM1a0HkyI?feature=share

https://youtube.com/shorts/va6WUNGnWXY?feature=share

}

void wiiuse_motion_plus_check(struct wiimote_t *wm,ubyte *data,uword len)
Expand Down
9 changes: 8 additions & 1 deletion wiiuse/wpad.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ static vs32 __wpads_bonded = 0;
static u32 __wpad_idletimeout = 300;
static vu32 __wpads_active = 0;
static vu32 __wpads_used = 0;
static wiimote **__wpads = NULL;
wiimote **__wpads = NULL;
static wiimote_listen __wpads_listen[WPAD_MAX_DEVICES] = {0};
static WPADData wpaddata[WPAD_MAX_DEVICES] = {0};
static struct _wpad_cb __wpdcb[WPAD_MAX_DEVICES] = {0};
Expand Down Expand Up @@ -2046,3 +2046,10 @@ bool WPAD_IsBatteryCritical(int chan)
if(chan<0 || chan>=WPAD_MAX_DEVICES) return false;
return WIIMOTE_IS_SET(__wpads[chan],WIIMOTE_STATE_BATTERY_CRITICAL);
}

int WPAD_HasMotionPlus(s32 chan) {
if (__wpads && __wpads[chan]) __wpads[chan]->state &= ~0x000020;
if (__wpads == NULL) return 0;
if (__wpads[chan] == NULL) return 0;
return (__wpads[chan]->state & 0x100000) ? 1 : 0;
}
Loading