Homebrew Pawnshop Joysticks on wii don't span all the way from 0 to 255

dreadpirate

New Member
OP
Newbie
Joined
May 23, 2012
Messages
4
Trophies
0
XP
58
Country
United States
Hey, this is my first post here. I noticed that while doing research gbatemp.net turned up quite a few useful threads so I figured I'd register here, but I'm not totally sure this is the right section so feel free to move it arround.

data.nunchuk.js.pos.x registers as 22 when all the way left and 220 when all the way right. Is this normal? I was thinking of setting up a game to register how far they are moving the joystick based on the distance of the joystick from origin.

My code would look something like this (I have a devkitpro environment):
Code:
joystickHandleing(){
struct expansion_t data;
WPAD_Expansion(WPAD_CHAN_0, &data); // Get expansion info from the first wiimote

joy_x = data.nunchuk.js.pos.x - 128;
joy_y = data.nunchuk.js.pos.y - 128;

double dist = getDistanceOfJoystickFromOrigin(joy_x, joy_y);
int runSpeed = setRunspeedTo(dist);
.
.
.
}


double getDistanceOfJoystickFromOrigin(int joy_x, int joy_y){
double result = sqrt(pow(joy_x, 2) + pow(joy_y, 2));
if (result > 127){ // cap it for dolphin emulation which goes beyond 127 when holding 'w' and 'd'
return 127;
}
return result;
}

But this is an icky situation since the pawnshop remote I have handy basically only goes from -108 to 92.

So if the left side of some (or most???) joysticks doesn't span as far as the right side, then I need to spend some more time on this function, don't I? So are all wii joysticks this finicky? Anyone know what the best practice is for determining the extent to which a joystick is being held so that it works symetrically?

Thanks so much.
 

tueidj

I R Expert
Member
Joined
Jan 8, 2009
Messages
2,569
Trophies
0
Website
Visit site
XP
999
Country
If you access the data via WPAD_Expansion() you are getting the "raw" values. This means the wiiuse library hasn't corrected them using either the built-in calibration data or the minimum/maximum values seen so far. Check the other values in the nunchuk struct (called min/max/center).
 
  • Like
Reactions: 1 person

dreadpirate

New Member
OP
Newbie
Joined
May 23, 2012
Messages
4
Trophies
0
XP
58
Country
United States
Thanks for the reply. I wish I had looked at that struct more closely a couple days ago before I coded all these functions. I never would have thought that the nunchuck would calibrate itself over transparently throughout runtime.

Anyway, thank god for version control, I better get to work modifying.

Btw, does this code look good for deadzone detection:

Code:
bool inDeadzone(joystick_t joy_data){
if (abs(joy_data.pos.x - joy_data.center.x) < 10 && abs(joy_data.pos.y - joy_data.center.y) < 10)
return true;
return false;
}
 

tueidj

I R Expert
Member
Joined
Jan 8, 2009
Messages
2,569
Trophies
0
Website
Visit site
XP
999
Country
For the nunchuk stick that's probably ok, if it is meant to handle the classic controller joysticks as well you might want to compare to a percentage of the min/max values instead of 10.
The reason is the classic controller sticks have much less accuracy/use a smaller range, the left stick returns values between -32:31 and the right stick is -16:15 (Nintendo really skimped out on them).
 

You may also like...

General chit-chat
Help Users
    M4x1mumReZ @ M4x1mumReZ: Didn't know a Mini one is out.