User:Goofster1020/Code Tutorials/Tutorial 1 - Basic Wiimote Usage: Difference between revisions
Goofster1020 (talk | contribs) No edit summary |
Goofster1020 (talk | contribs) No edit summary |
||
(13 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
==Introduction== | |||
Over the last couple of years, many new programs have been designed for Wii homebrew. But, haven't you ever wondered how these programs were created? The following tutorial shows how the programmers behind the Wii scene develop the simplest and the hardest programs. | |||
<br><br> | <br><br> | ||
'''[[#Useful Codes | Useful Codes]] | |||
*[[#Wiimote Channels | Wiimote Channels]] | |||
*[[#Wiimote Buttons | Wiimote Buttons]] | |||
**[[#Wiimote Codes | Wiimote Codes]] | |||
**[[#Nunchuk Codes | Nunchuk Codes]] | |||
**[[#Classic Controller Codes | Classic Controller Codes]] | |||
**[[#Guitar Codes | Guitar Codes]] | |||
*[[#Wiimote Expansions | Wiimote Expansions]] | |||
*[[#Wiimote Errors | Wiimote Errors]] | |||
'''[[#Basic Usage | Basic Usage]]''' | '''[[#Basic Usage | Basic Usage]]''' | ||
*[[#Initializing the Wiimote | Initiallizing the Wiimote]] | *[[#Initializing the Wiimote | Initiallizing the Wiimote]] | ||
Line 23: | Line 33: | ||
*[[#Wiimote Callbacks | Wiimote Callbacks]] | *[[#Wiimote Callbacks | Wiimote Callbacks]] | ||
<br> | <br> | ||
==Useful Codes== | |||
===Wiimote Channels=== | |||
When programming, the Wiimote channels start from 0 and go to 3. So: | |||
*Wiimote 1 = Channel 0 | |||
*Wiimote 2 = Channel 1 | |||
*Wiimote 3 = Channel 2 | |||
*Wiimote 4 = Channel 3 | |||
<br> | |||
Furthermore, there are preprocessor (macro) codes to make life a little simpler: | |||
<source lang="c"> | |||
WPAD_CHAN_0 | |||
// For the first Wiimote. (equals 0) | |||
WPAD_CHAN_1 | |||
// For the second Wiimote. (equals 1) | |||
WPAD_CHAN_2 | |||
// For the third Wiimote. (equals 2) | |||
WPAD_CHAN_3 | |||
// For the fourth Wiimote. (equals 3) | |||
</source> | |||
Additionally, there is a code for all Wiimotes that can be used as well: | |||
<source lang="c"> | |||
WPAD_CHAN_ALL | |||
// For every Wiimote. (equals -1) | |||
</source> | |||
===Wiimote Buttons=== | |||
In order to detect a button press, you need to define the button. Thankfully, Wiiuse defines these, otherwise you would have to type codes such as: | |||
<source lang="c"> | |||
(0x0001<<16) | |||
// Z button on the Nunchuk. (Defined as WPAD_NUNCHUK_BUTTON_Z) | |||
</source> | |||
Instead, you only have to type the name of the button. | |||
====Wiimote Codes==== | |||
The definitions for the buttons on the Wiimote follow: | |||
<source lang="c"> | |||
WPAD_BUTTON_2 | |||
// 2 Button. | |||
WPAD_BUTTON_1 | |||
// 1 Button. | |||
WPAD_BUTTON_B | |||
// B Button. | |||
WPAD_BUTTON_A | |||
// A Button. | |||
WPAD_BUTTON_MINUS | |||
// Minus Button. | |||
WPAD_BUTTON_HOME | |||
// Home Button. | |||
WPAD_BUTTON_PLUS | |||
// Plus Button. | |||
WPAD_BUTTON_LEFT | |||
// Left Button. | |||
WPAD_BUTTON_RIGHT | |||
// Right Button. | |||
WPAD_BUTTON_DOWN | |||
// Down Button. | |||
WPAD_BUTTON_UP | |||
// Up Button. | |||
</source> | |||
====Nunchuk Codes==== | |||
The definitions for the buttons on the Nunchuk follow: | |||
<source lang="c"> | |||
WPAD_NUNCHUK_BUTTON_Z | |||
// Nunchuk Z Button. | |||
WPAD_NUNCHUK_BUTTON_C | |||
// Nunchuk C Button. | |||
</source> | |||
====Classic Controller Codes==== | |||
The definitions for the buttons on the Classic Controller follow: | |||
<source lang="c"> | |||
WPAD_CLASSIC_BUTTON_UP | |||
// Classic Controller Up Button. | |||
WPAD_CLASSIC_BUTTON_LEFT | |||
// Classic Controller Left Button. | |||
WPAD_CLASSIC_BUTTON_ZR | |||
// Classic Controller ZR Button. | |||
WPAD_CLASSIC_BUTTON_X | |||
// Classic Controller X Button. | |||
WPAD_CLASSIC_BUTTON_A | |||
// Classic Controller A Button. | |||
WPAD_CLASSIC_BUTTON_Y | |||
// Classic Controller Y Button. | |||
WPAD_CLASSIC_BUTTON_B | |||
// Classic Controller B Button. | |||
WPAD_CLASSIC_BUTTON_ZL | |||
// Classic Controller ZL Button. | |||
WPAD_CLASSIC_BUTTON_FULL_R | |||
// Classic Controller R Button. (when fully pressed) | |||
WPAD_CLASSIC_BUTTON_PLUS | |||
// Classic Controller Plus Button. | |||
WPAD_CLASSIC_BUTTON_HOME | |||
// Classic Controller Home Button. | |||
WPAD_CLASSIC_BUTTON_MINUS | |||
// Classic Controller Minus Button. | |||
WPAD_CLASSIC_BUTTON_FULL_L | |||
// Classic Controller L Button. (when fully pressed) | |||
WPAD_CLASSIC_BUTTON_DOWN | |||
// Classic Controller Down Button. | |||
WPAD_CLASSIC_BUTTON_RIGHT | |||
// Classic Controller Right Button. | |||
</source> | |||
====Guitar Codes==== | |||
The definitions for the buttons on the Guitar follow: | |||
'''NOTE:''' This only works for the Guitar Hero 3 Controller. | |||
<source lang="c"> | |||
WPAD_GUITAR_HERO_3_BUTTON_STRUM_UP | |||
// Guitar Strum Up. | |||
WPAD_GUITAR_HERO_3_BUTTON_YELLOW | |||
// Guitar Fret Yellow. | |||
WPAD_GUITAR_HERO_3_BUTTON_GREEN | |||
// Guitar Fret Green. | |||
WPAD_GUITAR_HERO_3_BUTTON_BLUE | |||
// Guitar Fret Blue. | |||
WPAD_GUITAR_HERO_3_BUTTON_RED | |||
// Guitar Fret Red. | |||
WPAD_GUITAR_HERO_3_BUTTON_ORANGE | |||
// Guitar Fret Orange. | |||
WPAD_GUITAR_HERO_3_BUTTON_PLUS | |||
// Guitar Plus Button. | |||
WPAD_GUITAR_HERO_3_BUTTON_MINUS | |||
// Guitar Minus Button. | |||
WPAD_GUITAR_HERO_3_BUTTON_STRUM_DOWN | |||
// Guitar Strum Up. | |||
</source> | |||
===Wiimote Expansions=== | |||
When you use expansions within your code, it is easier just to type out the name of the expansion. The definitions for the expansions available in Wiiuse follow: | |||
<source lang="c"> | |||
WPAD_EXP_NONE | |||
// No expansion is connected. (equals 0) | |||
WPAD_EXP_NUNCHUK | |||
// The Nunchuk is connected. (equals 1) | |||
WPAD_EXP_CLASSIC | |||
// The Classic Controller is connected. (equals 2) | |||
WPAD_EXP_GUITARHERO3 | |||
// The Guitar is connected. (equals 3) | |||
WPAD_EXP_WIIBOARD | |||
// The Wii Balance Board is connected on that channel. (equals 4) | |||
</source> | |||
If a expansion is unknown, it is defined as: | |||
<source lang="c"> | |||
WPAD_EXP_UNKNOWN | |||
// An unknown expansion is connected. (equals 255) | |||
// This could be because it is a new expansion or | |||
// Wiiuse has no compatibility for it yet. | |||
</source> | |||
===Wiimote Errors=== | |||
When using a function, such as the [[#Wiimote Detection | WPAD_Probe(s32,u32)]] function, it will return a error code. These include: | |||
<source lang="c"> | |||
WPAD_ERR_NONE | |||
// There are no errors with the Wiimote. | |||
WPAD_ERR_NO_CONTROLLER | |||
// There is no Wiimote connected. | |||
WPAD_ERR_NOT_READY | |||
// The Wiimote is not ready. | |||
WPAD_ERR_TRANSFER | |||
// There was a problem with data transfer. | |||
WPAD_ERR_NONEREGISTERED | |||
// The Wiimote is not registered on the Wii. (synchronization) | |||
WPAD_ERR_UNKNOWN | |||
// An unknown error has occurred. | |||
WPAD_ERR_BAD_CHANNEL | |||
// The channel that the Wiimote is connected to is bad. (radio interference?) | |||
WPAD_ERR_QUEUE_EMPTY | |||
// The queue is empty. | |||
WPAD_ERR_BADVALUE | |||
// The Wiimote value is bad. | |||
WPAD_ERR_BADCONF | |||
// The configuration for the Wiimote is bad. | |||
</source> | |||
==Basic Usage== | ==Basic Usage== | ||
''The following section includes the very basic usage of the Wiimote.'' | ''The following section includes the very basic usage of the Wiimote.'' | ||
Line 41: | Line 225: | ||
===Disconnecting the Wiimote=== | ===Disconnecting the Wiimote=== | ||
If you want to, you can disconnect the Wiimote when you are done using it. This can be done by: | |||
<source lang="c"> | |||
WPAD_Flush(WPAD_CHAN_ALL); | |||
// This will write all pending data to the wiimote. (not required) | |||
WPAD_Disconnect(WPAD_CHAN_ALL); | |||
// This will turn off all connected Wiimotes. | |||
</source> | |||
==Wiimote Features== | ==Wiimote Features== |
Latest revision as of 03:48, 16 January 2010
Introduction
Over the last couple of years, many new programs have been designed for Wii homebrew. But, haven't you ever wondered how these programs were created? The following tutorial shows how the programmers behind the Wii scene develop the simplest and the hardest programs.
Useful Codes
Useful Codes
Wiimote Channels
When programming, the Wiimote channels start from 0 and go to 3. So:
- Wiimote 1 = Channel 0
- Wiimote 2 = Channel 1
- Wiimote 3 = Channel 2
- Wiimote 4 = Channel 3
Furthermore, there are preprocessor (macro) codes to make life a little simpler:
WPAD_CHAN_0
// For the first Wiimote. (equals 0)
WPAD_CHAN_1
// For the second Wiimote. (equals 1)
WPAD_CHAN_2
// For the third Wiimote. (equals 2)
WPAD_CHAN_3
// For the fourth Wiimote. (equals 3)
Additionally, there is a code for all Wiimotes that can be used as well:
WPAD_CHAN_ALL
// For every Wiimote. (equals -1)
Wiimote Buttons
In order to detect a button press, you need to define the button. Thankfully, Wiiuse defines these, otherwise you would have to type codes such as:
(0x0001<<16)
// Z button on the Nunchuk. (Defined as WPAD_NUNCHUK_BUTTON_Z)
Instead, you only have to type the name of the button.
Wiimote Codes
The definitions for the buttons on the Wiimote follow:
WPAD_BUTTON_2
// 2 Button.
WPAD_BUTTON_1
// 1 Button.
WPAD_BUTTON_B
// B Button.
WPAD_BUTTON_A
// A Button.
WPAD_BUTTON_MINUS
// Minus Button.
WPAD_BUTTON_HOME
// Home Button.
WPAD_BUTTON_PLUS
// Plus Button.
WPAD_BUTTON_LEFT
// Left Button.
WPAD_BUTTON_RIGHT
// Right Button.
WPAD_BUTTON_DOWN
// Down Button.
WPAD_BUTTON_UP
// Up Button.
Nunchuk Codes
The definitions for the buttons on the Nunchuk follow:
WPAD_NUNCHUK_BUTTON_Z
// Nunchuk Z Button.
WPAD_NUNCHUK_BUTTON_C
// Nunchuk C Button.
Classic Controller Codes
The definitions for the buttons on the Classic Controller follow:
WPAD_CLASSIC_BUTTON_UP
// Classic Controller Up Button.
WPAD_CLASSIC_BUTTON_LEFT
// Classic Controller Left Button.
WPAD_CLASSIC_BUTTON_ZR
// Classic Controller ZR Button.
WPAD_CLASSIC_BUTTON_X
// Classic Controller X Button.
WPAD_CLASSIC_BUTTON_A
// Classic Controller A Button.
WPAD_CLASSIC_BUTTON_Y
// Classic Controller Y Button.
WPAD_CLASSIC_BUTTON_B
// Classic Controller B Button.
WPAD_CLASSIC_BUTTON_ZL
// Classic Controller ZL Button.
WPAD_CLASSIC_BUTTON_FULL_R
// Classic Controller R Button. (when fully pressed)
WPAD_CLASSIC_BUTTON_PLUS
// Classic Controller Plus Button.
WPAD_CLASSIC_BUTTON_HOME
// Classic Controller Home Button.
WPAD_CLASSIC_BUTTON_MINUS
// Classic Controller Minus Button.
WPAD_CLASSIC_BUTTON_FULL_L
// Classic Controller L Button. (when fully pressed)
WPAD_CLASSIC_BUTTON_DOWN
// Classic Controller Down Button.
WPAD_CLASSIC_BUTTON_RIGHT
// Classic Controller Right Button.
Guitar Codes
The definitions for the buttons on the Guitar follow: NOTE: This only works for the Guitar Hero 3 Controller.
WPAD_GUITAR_HERO_3_BUTTON_STRUM_UP
// Guitar Strum Up.
WPAD_GUITAR_HERO_3_BUTTON_YELLOW
// Guitar Fret Yellow.
WPAD_GUITAR_HERO_3_BUTTON_GREEN
// Guitar Fret Green.
WPAD_GUITAR_HERO_3_BUTTON_BLUE
// Guitar Fret Blue.
WPAD_GUITAR_HERO_3_BUTTON_RED
// Guitar Fret Red.
WPAD_GUITAR_HERO_3_BUTTON_ORANGE
// Guitar Fret Orange.
WPAD_GUITAR_HERO_3_BUTTON_PLUS
// Guitar Plus Button.
WPAD_GUITAR_HERO_3_BUTTON_MINUS
// Guitar Minus Button.
WPAD_GUITAR_HERO_3_BUTTON_STRUM_DOWN
// Guitar Strum Up.
Wiimote Expansions
When you use expansions within your code, it is easier just to type out the name of the expansion. The definitions for the expansions available in Wiiuse follow:
WPAD_EXP_NONE
// No expansion is connected. (equals 0)
WPAD_EXP_NUNCHUK
// The Nunchuk is connected. (equals 1)
WPAD_EXP_CLASSIC
// The Classic Controller is connected. (equals 2)
WPAD_EXP_GUITARHERO3
// The Guitar is connected. (equals 3)
WPAD_EXP_WIIBOARD
// The Wii Balance Board is connected on that channel. (equals 4)
If a expansion is unknown, it is defined as:
WPAD_EXP_UNKNOWN
// An unknown expansion is connected. (equals 255)
// This could be because it is a new expansion or
// Wiiuse has no compatibility for it yet.
Wiimote Errors
When using a function, such as the WPAD_Probe(s32,u32) function, it will return a error code. These include:
WPAD_ERR_NONE
// There are no errors with the Wiimote.
WPAD_ERR_NO_CONTROLLER
// There is no Wiimote connected.
WPAD_ERR_NOT_READY
// The Wiimote is not ready.
WPAD_ERR_TRANSFER
// There was a problem with data transfer.
WPAD_ERR_NONEREGISTERED
// The Wiimote is not registered on the Wii. (synchronization)
WPAD_ERR_UNKNOWN
// An unknown error has occurred.
WPAD_ERR_BAD_CHANNEL
// The channel that the Wiimote is connected to is bad. (radio interference?)
WPAD_ERR_QUEUE_EMPTY
// The queue is empty.
WPAD_ERR_BADVALUE
// The Wiimote value is bad.
WPAD_ERR_BADCONF
// The configuration for the Wiimote is bad.
Basic Usage
The following section includes the very basic usage of the Wiimote.
If you are using the Wiimote, no matter what, you always need to have this line in your file:
#include <wiiuse/wpad.h>
//This simple line allows your program access to everything available (in LibWiiuse) for the Wiimote.
Initializing the Wiimote
In order to turn on and use the Wiimote, you need to add this line (at least once) in your program:
WPAD_Init();
// This will turn on and allow you to use the Wiimote.
Disconnecting the Wiimote
If you want to, you can disconnect the Wiimote when you are done using it. This can be done by:
WPAD_Flush(WPAD_CHAN_ALL);
// This will write all pending data to the wiimote. (not required)
WPAD_Disconnect(WPAD_CHAN_ALL);
// This will turn off all connected Wiimotes.