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

Add emulated stick values for Nunchuk and Classic Controller #114

Merged
merged 7 commits into from
Jan 20, 2020

Conversation

Crayon2000
Copy link
Contributor

@Crayon2000 Crayon2000 commented Dec 31, 2019

Hello, I have added emulated stick values for the Nunchuk and the Classic Controller.

For the Classic Controller is was simply adding new values at the end of the WPADClassicButton enum.

For the Nunchuk extension I added new properties to the struct.

To help me understand the union used for extensions, I have created this table:

Nunchuk Classic Controller Classic Controller Pro
0x60 stick.x (KPADVec2D) hold (uint32_t) hold (uint32_t)
0x64 stick.y trigger (uint32_t) trigger (uint32_t)
0x68 acc.x (KPADVec3D) release (uint32_t) release (uint32_t)
0x6C acc.y leftStick.x (KPADVec2D) leftStick.x (KPADVec2D)
0x70 acc.z leftStick.y leftStick.y
0x74 accValue (float) rightStick.x (KPADVec2D) rightStick.x (KPADVec2D)
0x78 accSpeed (float) rightStick.y rightStick.y
0x7C hold (uint32_t) leftTrigger (float) charging (int32_t)
0x80 trigger (uint32_t) rightTrigger (float) wired (int32_t)
0x84 release (uint32_t)

By the way, there is an error in the word Nunchuk, there is no C before the K:

      struct
      {
         KPADVec2D stick;
      } nunchuck;

I did not changed it, because it would break compatibility with all homebrews using this.

@Crayon2000
Copy link
Contributor Author

Crayon2000 commented Dec 31, 2019

I just did another commit, I have also added acceleration sensor data to KPADStatus.

Again, to help me, I have done a table:

Wii Remote
0x00 hold (uint32_t)
0x04 trigger (uint32_t)
0x08 release (uint32_t)
0x0C acc.x (KPADVec3D)
0x10 acc.y
0x14 acc.z
0x18 accMagnitude (float)
0x1C accVariation (float)
0x20 pos.x (KPADVec2D)
0x24 pos.y
0x28 ?
0x2C ?
0x30 ?
0x34 angle.x (KPADVec2D)
0x38 angle.y
0x3C ?
0x40 ?
0x44 ?
0x48 ?
0x4C ?
0x50 ?
0x54 ?
0x58 ?
0x5C extensionType (uint8_t)
error (int8_t)
posValid (int8_t)
format (uint8_t)
0x60 Extension data

For the acceleration variable names, I'm using names similar to the ones from this structure:

struct VPADAccStatus
{
   VPADVec3D acc;
   float magnitude;
   float variation;
   VPADVec2D vertical;
};

Copy link
Contributor

@ashquarky ashquarky left a comment

Choose a reason for hiding this comment

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

Looks good to me! I threw together a quick demo using the accelerometer data and it looks perfect. I did check what C and Z are, so you should probably add them to the enum.

include/padscore/wpad.h Show resolved Hide resolved
@Crayon2000
Copy link
Contributor Author

Looks good to me! I threw together a quick demo using the accelerometer data and it looks perfect. I did check what C and Z are, so you should probably add them to the enum.

I did a commit to add the missing mask for C and Z.

I did some test and you are right about mask values 😃

@ashquarky
Copy link
Contributor

I did a bit more testing, and it appears all the buttons can be read from the nunchuck.hold property; with the Wii Remote's buttons getting OR'd in. (yes, this does result in the wiimote dpad setting the nunchuck direction too. it seems the only way to tell them apart is to check both the wii remote and nunchuck masks and compare).
I'm not 100% sure how to represent or document this, though it does lead me to believe that the WPADNunchukButton enum is probably not needed at all, and apps should instead use the regular WPADButton stuff for nunchuck.hold; with Doxygen notes explaining how the two relate.
Sorry for being a pain about this.

@exjam
Copy link
Contributor

exjam commented Jan 17, 2020

I think its best to keep the enums separate, I like this change as it is now unless you really object. Even if it does look like the wii remote buttons are being or'd into the nunchuk buttons, i think it is best that people use only the nunchuk specific enums with the nunchuk button field, and use the other enums with their respective fields.

@ashquarky
Copy link
Contributor

I guess my key issue is that there aren't really any buttons specific to the nunchuk field (the nunchuk-specific buttons like C and Z are available through both) other than the emulated directions; and since those share a bitmask with the Wii Remote's d-pad it leads to a situation where stat.nunchuck.hold & WPAD_NUNCHUK_STICK_EMULATION_LEFT is true when the Wii Remote d-pad left is being pressed, even if the nunchuk stick is centred. This is very odd and would seem like a bug to the casual observer.
On the other hand, by not having a nunchuk enum at all (what I'm now suggesting), someone who wants to use the stick emulation has to have at least basic knowledge of the relationship between the wiimote button fields and the nunchuk button fields, understanding the limits (you can't tell if the situation is "wiimote left" or "wiimote left and nunchuk left", for example) and the cross-referencing to the wiimote field one has to do for these values to be meaningful.
I'm not going to lose my mind if we end up adding this enum anyway, because it does make sense to access nunchuk buttons through nunchuk fields, I just feel like it may give people a false impression about what this field actually is.

I have also changed the posValid type from uint8_t to int8_t because the value can be negative.
A negative value means that the result validity is not really good.
The same mask applies to WPADButton and WPADNunchukButton.
Most of the comments are pretty obvious but at least it's a start.
I have also added comments for VPADGetTPCalibrationParam and VPADSetTPCalibrationParam.
@Crayon2000
Copy link
Contributor Author

Hello, I have added a lot of new comments. I didn't change the enum for the Wii Remote buttons (WPADButton) and the Nunchuk buttons (WPADNunchukButton) since my last commits (except for comments).

I don't care if someone propose changes, I will accept them.

There is currently more than 300 new lines of code, mostly comments, in this PR. I just want the emulated stick values for the Nunchuk and the Classic Controller to work in wut. Please help me achieve that 😃

Copy link
Contributor

@ashquarky ashquarky left a comment

Choose a reason for hiding this comment

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

Doxygen! Absolutely someone after my own heart. I guess we'll leave WPADNunchuckButton as-is for now.

@ashquarky ashquarky merged commit 78ee1c5 into devkitPro:master Jan 20, 2020
@Crayon2000 Crayon2000 deleted the feature-kpad branch January 20, 2020 19:35
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.

3 participants