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);
Comment thread
gitman123323 marked this conversation as resolved.
}

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;
Comment thread
gitman123323 marked this conversation as resolved.
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;
Comment thread
gitman123323 marked this conversation as resolved.
if (__wpads == NULL) return 0;
if (__wpads[chan] == NULL) return 0;
return (__wpads[chan]->state & 0x100000) ? 1 : 0;
}
Loading