Nunchuk Programming August 28, 2008 08:13PM | Admin Registered: 16 years ago Posts: 5,132 |
Re: Nunchuk Programming August 28, 2008 08:50PM | Registered: 16 years ago Posts: 114 |
Re: Nunchuk Programming August 28, 2008 11:39PM | Admin Registered: 16 years ago Posts: 5,132 |
#define WPAD_THRESH_DEFAULT_JOYSTICK 2 void WPAD_Orientation(int chan, struct orient_t *orient); void WPAD_GForce(int chan, struct gforce_t *gforce); void WPAD_Accel(int chan, struct vec3b_t *accel); void WPAD_Expansion(int chan, struct expansion_t *exp);
Re: Nunchuk Programming August 29, 2008 01:47AM | Registered: 16 years ago Posts: 114 |
// Assuming WPAD is all set up... struct expansion_t data; WPAD_Expansion(WPAD_CHAN_0, &data); // Get expansion info from the first wiimote if (data.type == WPAD_EXP_NUNCHUK) { // Ensure there's a nunchuk do something with data.nunchuk.joystick }
typedef struct joystick_t { struct vec2b_t max; /**< maximum joystick values */ struct vec2b_t min; /**< minimum joystick values */ struct vec2b_t center; /**< center joystick values */ struct vec2b_t pos; /**< raw position values */ float ang; /**< angle the joystick is being held */ float mag; /**< magnitude of the joystick (range 0-1) */ } joystick_t;
Re: Nunchuk Programming August 29, 2008 03:15PM | Admin Registered: 16 years ago Posts: 5,132 |
Re: Nunchuk Programming August 29, 2008 05:48PM | Registered: 16 years ago Posts: 114 |
Re: Nunchuk Programming August 29, 2008 07:41PM | Registered: 16 years ago Posts: 265 |
Re: Nunchuk Programming August 29, 2008 08:50PM | Registered: 16 years ago Posts: 114 |
True enough, so just use the pos field instead. Again, there's no instant way to check for a "down" press or not, but just pick a reasonable threshold for the X and Y values.Quote
henke37
Personally I think that the ang and mag properties are bloat. It's not that fircking hard to do it yourself, but only when needed.
I just want access to normal scaled X and Y values.
Re: Nunchuk Programming August 29, 2008 10:21PM | Admin Registered: 16 years ago Posts: 5,132 |
Re: Nunchuk Programming August 30, 2008 04:13AM | Registered: 16 years ago Posts: 211 |
Re: Nunchuk Programming August 30, 2008 04:52AM | Registered: 16 years ago Posts: 114 |
#includeCompile and run via wiiload/TP, plug in a nunchuk (before or after running it) and move the joystick around.#include #include #include static void *xfb = NULL; static GXRModeObj *rmode = NULL; //--------------------------------------------------------------------------------- int main(int argc, char **argv) { //--------------------------------------------------------------------------------- // Initialise the video system VIDEO_Init(); // This function initialises the attached controllers WPAD_Init(); // Obtain the preferred video mode from the system // This will correspond to the settings in the Wii menu rmode = VIDEO_GetPreferredMode(NULL); // Allocate memory for the display in the uncached region xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); // Initialise the console, required for printf console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ); // Set up the video registers with the chosen mode VIDEO_Configure(rmode); // Tell the video hardware where our display memory is VIDEO_SetNextFramebuffer(xfb); // Make the display visible VIDEO_SetBlack(FALSE); // Flush the video register changes to the hardware VIDEO_Flush(); // Wait for Video setup to complete VIDEO_WaitVSync(); if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); while (1) { // The console understands VT terminal escape codes // This positions the cursor on row 2, column 0 // we can use variables for this with format codes too // e.g. printf ("\x1b[%d;%dH", row, column ); printf("\x1b[2;0H"); printf("Hello World!\n"); // Call WPAD_ScanPads each loop, this reads the latest controller states WPAD_ScanPads(); // WPAD_ButtonsDown tells us which buttons were pressed in this loop // this is a "one shot" state which will not fire again until the button has been released u32 pressed = WPAD_ButtonsDown(0); // We return to the launcher application via exit if ( pressed & WPAD_BUTTON_HOME ) exit(0); struct expansion_t data; WPAD_Expansion(WPAD_CHAN_0, &data); // Get expansion info from the first wiimote if (data.type == WPAD_EXP_NUNCHUK) { // Ensure there's a nunchuk printf("Nunchuk X: %d\n Nunchuk Y: %d\n", data.nunchuk.js.pos.x, data.nunchuk.js.pos.y); } // Wait for the next frame VIDEO_WaitVSync(); } return 0; }
Re: Nunchuk Programming August 30, 2008 04:36PM | Admin Registered: 16 years ago Posts: 5,132 |
Re: Nunchuk Programming August 30, 2008 06:28PM | Registered: 16 years ago Posts: 114 |
vec2b_t center = data.nunchuk.js.center; printf("Nunchuk X: %d \n Nunchuk Y: %d \n", data.nunchuk.js.pos.x - center.x, data.nunchuk.js.pos.y - center.y);
Re: Nunchuk Programming August 30, 2008 10:47PM | Admin Registered: 16 years ago Posts: 5,132 |
Re: Nunchuk Programming September 01, 2008 11:08PM | Admin Registered: 16 years ago Posts: 5,132 |
//Nunchuck Up if((exp.nunchuk.js.ang>=315 || exp.nunchuk.js.ang<=45) && exp.nunchuk.js.mag>=0.9) //Nunchuck Right if((exp.nunchuk.js.ang>=90-45 && exp.nunchuk.js.ang<=90+45) && exp.nunchuk.js.mag>=0.9) //Nunchuck Down if((exp.nunchuk.js.ang>=180-45 && exp.nunchuk.js.ang<=180+45) && exp.nunchuk.js.mag>=0.9) //Nunchuck Left if((exp.nunchuk.js.ang>=270-45 && exp.nunchuk.js.ang<=270+45) && exp.nunchuk.js.mag>=0.9)
Re: Nunchuk Programming September 02, 2008 07:53AM | Registered: 16 years ago Posts: 265 |
Re: Nunchuk Programming September 02, 2008 02:42PM | Admin Registered: 16 years ago Posts: 5,132 |
Re: Nunchuk Programming September 03, 2008 03:00AM | Registered: 16 years ago Posts: 114 |
Re: Nunchuk Programming September 03, 2008 07:05AM | Registered: 16 years ago Posts: 265 |
Re: Nunchuk Programming September 03, 2008 02:02PM | Admin Registered: 16 years ago Posts: 5,132 |