Zoltan Hudak / UsbHostMAX3421E

Dependents:   UsbHostMAX3421E_Hello

Embed: (wiki syntax)

« Back to documentation index

WII Class Reference

This BluetoothService class implements support for the Wiimote including the Nunchuck and Motion Plus extension. More...

#include <Wii.h>

Inherits BluetoothService.

Public Member Functions

 WII (BTD *p, bool pair=false)
 Constructor for the WII class.
void attachOnInit (void(*funcOnInit)(void))
 Used to call your own function when the device is successfully initialized.
Wii Controller functions
bool getButtonPress (ButtonEnum b)
 getButtonPress(Button b) will return true as long as the button is held down.
bool getButtonClick (ButtonEnum b)
void pair (void)
 Call this to start the pairing sequence with a controller.
uint8_t getAnalogHat (HatEnum a)
 Used to read the joystick of the Nunchuck.
uint16_t getAnalogHat (AnalogHatEnum a)
 Used to read the joystick of the Wii U Pro Controller.
float getPitch ()
 Pitch calculated from the Wiimote.
float getRoll ()
 Roll calculated from the Wiimote.
float getYaw ()
 This is the yaw calculated by the gyro.
void setAllOff ()
 Used to set all LEDs and rumble off.
void setRumbleOff ()
 Turn off rumble.
void setRumbleOn ()
 Turn on rumble.
void setRumbleToggle ()
 Toggle rumble.
void setLedRaw (uint8_t value)
 Set LED value without using the LEDEnum.
void setLedOff ()
 Turn all LEDs off.
void setLedOff (LEDEnum a)
 Turn the specific LEDEnum off.
void setLedOn (LEDEnum a)
 Turn the specific LEDEnum on.
void setLedToggle (LEDEnum a)
 Toggle the specific LEDEnum.
void setLedStatus ()
 This will set the LEDs, so the user can see which connections are active.
uint8_t getBatteryLevel ()
 Return the battery level of the Wiimote.
uint8_t getWiiState ()
 Return the Wiimote state.
float getWiimotePitch ()
 Pitch and roll calculated from the accelerometer inside the Wiimote.
float getNunchuckPitch ()
 Pitch and roll calculated from the accelerometer inside the Nunchuck.
Wii Balance Board functions
float getWeight (BalanceBoardEnum pos)
 Used to get the weight at the specific position on the Wii Balance Board.
float getTotalWeight ()
 Used to get total weight on the Wii Balance Board.
uint16_t getWeightRaw (BalanceBoardEnum pos)
 Used to get the raw reading at the specific position on the Wii Balance Board.
Wiimote IR camera functions

You will have to set ENABLE_WII_IR_CAMERA in settings.h to 1 in order use the IR camera.

void IRinitialize ()
 Initialises the camera as per the steps from: http://wiibrew.org/wiki/Wiimote#IR_Camera.
uint16_t getIRx1 ()
 IR object 1 x-position read from the Wii IR camera.
uint16_t getIRy1 ()
 IR object 1 y-position read from the Wii IR camera.
uint8_t getIRs1 ()
 IR object 1 size read from the Wii IR camera.
uint16_t getIRx2 ()
 IR object 2 x-position read from the Wii IR camera.
uint16_t getIRy2 ()
 IR object 2 y-position read from the Wii IR camera.
uint8_t getIRs2 ()
 IR object 2 size read from the Wii IR camera.
uint16_t getIRx3 ()
 IR object 3 x-position read from the Wii IR camera.
uint16_t getIRy3 ()
 IR object 3 y-position read from the Wii IR camera.
uint8_t getIRs3 ()
 IR object 3 size read from the Wii IR camera.
uint16_t getIRx4 ()
 IR object 4 x-position read from the Wii IR camera.
uint16_t getIRy4 ()
 IR object 4 y-position read from the Wii IR camera.
uint8_t getIRs4 ()
 IR object 4 size read from the Wii IR camera.
bool isIRCameraEnabled ()
 Use this to check if the camera is enabled or not.

Data Fields

float gyroPitch
 This is the pitch calculated by the gyro - use this to tune WII::pitchGyroScale.
float gyroRoll
 This is the roll calculated by the gyro - use this to tune WII::rollGyroScale.
float gyroYaw
 This is the yaw calculated by the gyro - use this to tune WII::yawGyroScale.
bool wiimoteConnected
 Variable used to indicate if a Wiimote is connected.
bool nunchuckConnected
 Variable used to indicate if a Nunchuck controller is connected.
bool motionPlusConnected
 Variable used to indicate if a Nunchuck controller is connected.
bool wiiUProControllerConnected
 Variable used to indicate if a Wii U Pro controller is connected.
bool wiiBalanceBoardConnected
 Variable used to indicate if a Wii Balance Board is connected.
int16_t accXwiimote
 Accelerometer values used to calculate pitch and roll.
float pitchGyroSpeed
 The speed in deg/s from the gyro.
uint16_t pitchGyroScale
 You might need to fine-tune these values.
int16_t gyroYawRaw
 Raw value read directly from the Motion Plus.
int16_t gyroYawZero
 These values are set when the controller is first initialized.

Protected Member Functions

bool checkHciHandle (uint8_t *buf, uint16_t handle)
 Used to check if the incoming L2CAP data matches the HCI Handle.

Protected Attributes

void(* pFuncOnInit )(void)
 Pointer to function called in onInit().
BTDpBtd
 Pointer to BTD instance.
uint16_t hci_handle
 The HCI Handle for the connection.
uint32_t l2cap_event_flag
 L2CAP flags of received Bluetooth events.
uint8_t identifier
 Identifier for L2CAP commands.

BluetoothService implementation

void disconnect ()
 Used this to disconnect any of the controllers.
void ACLData (uint8_t *ACLData)
 Used to pass acldata to the services.
void Run ()
 Used to run part of the state machine.
void Reset ()
 Use this to reset the service.
void onInit ()
 Called when the controller is successfully initialized.

Detailed Description

This BluetoothService class implements support for the Wiimote including the Nunchuck and Motion Plus extension.

It also support the Wii U Pro Controller.

Definition at line 56 of file Wii.h.


Constructor & Destructor Documentation

WII ( BTD p,
bool  pair = false 
)

Constructor for the WII class.

Parameters:
pPointer to BTD class instance.
pairSet this to true in order to pair with the Wiimote. If the argument is omitted then it won't pair with it. One can use PAIR to set it to true.

Definition at line 85 of file Wii.cpp.


Member Function Documentation

void ACLData ( uint8_t *  ACLData ) [protected, virtual]

Used to pass acldata to the services.

Parameters:
ACLDataIncoming acldata.

Implements BluetoothService.

Definition at line 133 of file Wii.cpp.

void attachOnInit ( void(*)(void)  funcOnInit ) [inherited]

Used to call your own function when the device is successfully initialized.

Parameters:
funcOnInitFunction to call.

Definition at line 592 of file BTD.h.

bool checkHciHandle ( uint8_t *  buf,
uint16_t  handle 
) [protected, inherited]

Used to check if the incoming L2CAP data matches the HCI Handle.

Definition at line 605 of file BTD.h.

void disconnect (  ) [virtual]

Used this to disconnect any of the controllers.

Implements BluetoothService.

Definition at line 116 of file Wii.cpp.

uint8_t getAnalogHat ( HatEnum  a )

Used to read the joystick of the Nunchuck.

Parameters:
aEither HatX or HatY.
Returns:
Return the analog value in the range from approximately 25-230.

Definition at line 1115 of file Wii.cpp.

uint16_t getAnalogHat ( AnalogHatEnum  a )

Used to read the joystick of the Wii U Pro Controller.

Parameters:
aEither LeftHatX, LeftHatY, RightHatX or RightHatY.
Returns:
Return the analog value in the range from approximately 800-3200.

Definition at line 1127 of file Wii.cpp.

uint8_t getBatteryLevel (  )

Return the battery level of the Wiimote.

Returns:
The battery level in the range 0-255.

Definition at line 968 of file Wii.cpp.

bool getButtonPress ( ButtonEnum  b )

getButtonPress(Button b) will return true as long as the button is held down.

While getButtonClick(Button b) will only return it once.

So you instance if you need to increase a variable once you would use getButtonClick(Button b), but if you need to drive a robot forward you would use getButtonPress(Button b).

Parameters:
bButtonEnum to read.
Returns:
getButtonPress(ButtonEnum b) will return a true as long as a button is held down, while getButtonClick(ButtonEnum b) will return true once for each button press.

Definition at line 1097 of file Wii.cpp.

uint8_t getIRs1 (  )

IR object 1 size read from the Wii IR camera.

Returns:
The size of the object in the range 0-15.

Definition at line 327 of file Wii.h.

uint8_t getIRs2 (  )

IR object 2 size read from the Wii IR camera.

Returns:
The size of the object in the range 0-15.

Definition at line 351 of file Wii.h.

uint8_t getIRs3 (  )

IR object 3 size read from the Wii IR camera.

Returns:
The size of the object in the range 0-15.

Definition at line 375 of file Wii.h.

uint8_t getIRs4 (  )

IR object 4 size read from the Wii IR camera.

Returns:
The size of the object in the range 0-15.

Definition at line 399 of file Wii.h.

uint16_t getIRx1 (  )

IR object 1 x-position read from the Wii IR camera.

Returns:
The x-position of the object in the range 0-1023.

Definition at line 311 of file Wii.h.

uint16_t getIRx2 (  )

IR object 2 x-position read from the Wii IR camera.

Returns:
The x-position of the object in the range 0-1023.

Definition at line 335 of file Wii.h.

uint16_t getIRx3 (  )

IR object 3 x-position read from the Wii IR camera.

Returns:
The x-position of the object in the range 0-1023.

Definition at line 359 of file Wii.h.

uint16_t getIRx4 (  )

IR object 4 x-position read from the Wii IR camera.

Returns:
The x-position of the object in the range 0-1023.

Definition at line 383 of file Wii.h.

uint16_t getIRy1 (  )

IR object 1 y-position read from the Wii IR camera.

Returns:
The y-position of the object in the range 0-767.

Definition at line 319 of file Wii.h.

uint16_t getIRy2 (  )

IR object 2 y-position read from the Wii IR camera.

Returns:
The y-position of the object in the range 0-767.

Definition at line 343 of file Wii.h.

uint16_t getIRy3 (  )

IR object 3 y-position read from the Wii IR camera.

Returns:
The y-position of the object in the range 0-767.

Definition at line 367 of file Wii.h.

uint16_t getIRy4 (  )

IR object 4 y-position read from the Wii IR camera.

Returns:
The y-position of the object in the range 0-767.

Definition at line 391 of file Wii.h.

float getNunchuckPitch (  )

Pitch and roll calculated from the accelerometer inside the Nunchuck.

Definition at line 224 of file Wii.h.

float getPitch (  )

Pitch calculated from the Wiimote.

A complimentary filter is used if the Motion Plus is connected.

Returns:
Pitch in the range from 0-360.

Definition at line 110 of file Wii.h.

float getRoll (  )

Roll calculated from the Wiimote.

A complimentary filter is used if the Motion Plus is connected.

Returns:
Roll in the range from 0-360.

Definition at line 120 of file Wii.h.

float getTotalWeight (  )

Used to get total weight on the Wii Balance Board.

Returns:
Returns the weight in kg.

Definition at line 1163 of file Wii.cpp.

float getWeight ( BalanceBoardEnum  pos )

Used to get the weight at the specific position on the Wii Balance Board.

Parameters:
posBalanceBoardEnum to read from.
Returns:
Returns the weight in kg.

Definition at line 1150 of file Wii.cpp.

uint16_t getWeightRaw ( BalanceBoardEnum  pos )

Used to get the raw reading at the specific position on the Wii Balance Board.

Parameters:
posBalanceBoardEnum to read from.
Returns:
Returns the raw reading.

Definition at line 295 of file Wii.h.

float getWiimotePitch (  )

Pitch and roll calculated from the accelerometer inside the Wiimote.

Definition at line 212 of file Wii.h.

uint8_t getWiiState (  )

Return the Wiimote state.

Returns:
See: http://wiibrew.org/wiki/Wiimote#0x20:_Status.

Definition at line 189 of file Wii.h.

float getYaw (  )

This is the yaw calculated by the gyro.

NOTE: This angle will drift a lot and is only available if the Motion Plus extension is connected.

Returns:
The angle calculated using the gyro.

Definition at line 132 of file Wii.h.

void IRinitialize (  )

Initialises the camera as per the steps from: http://wiibrew.org/wiki/Wiimote#IR_Camera.

Definition at line 1173 of file Wii.cpp.

bool isIRCameraEnabled (  )

Use this to check if the camera is enabled or not.

If not call WII::IRinitialize to initialize the IR camera.

Returns:
True if it's enabled, false if not.

Definition at line 408 of file Wii.h.

void onInit (  ) [protected, virtual]

Called when the controller is successfully initialized.

Use attachOnInit(void (*funcOnInit)(void)) to call your own function. This is useful for instance if you want to set the LEDs in a specific way.

Implements BluetoothService.

Definition at line 1139 of file Wii.cpp.

void pair ( void   )

Call this to start the pairing sequence with a controller.

Definition at line 89 of file Wii.h.

void Reset (  ) [protected, virtual]

Use this to reset the service.

Implements BluetoothService.

Definition at line 101 of file Wii.cpp.

void Run (  ) [protected, virtual]

Used to run part of the state machine.

Implements BluetoothService.

Definition at line 725 of file Wii.cpp.

void setAllOff (  )

Used to set all LEDs and rumble off.

Definition at line 903 of file Wii.cpp.

void setLedOff ( LEDEnum  a )

Turn the specific LEDEnum off.

Parameters:
aThe LEDEnum to turn off.

Definition at line 933 of file Wii.cpp.

void setLedOff (  )

Turn all LEDs off.

Definition at line 152 of file Wii.h.

void setLedOn ( LEDEnum  a )

Turn the specific LEDEnum on.

Parameters:
aThe LEDEnum to turn on.

Definition at line 939 of file Wii.cpp.

void setLedRaw ( uint8_t  value )

Set LED value without using the LEDEnum.

Parameters:
valueSee: LEDEnum.

Definition at line 927 of file Wii.cpp.

void setLedStatus (  )

This will set the LEDs, so the user can see which connections are active.

The first LEDEnum indicate that the Wiimote is connected, the second LEDEnum indicate indicate that a Motion Plus is also connected the third LEDEnum will indicate that a Nunchuck controller is also connected.

Definition at line 955 of file Wii.cpp.

void setLedToggle ( LEDEnum  a )

Toggle the specific LEDEnum.

Parameters:
aThe LEDEnum to toggle.

Definition at line 949 of file Wii.cpp.

void setRumbleOff (  )

Turn off rumble.

Definition at line 909 of file Wii.cpp.

void setRumbleOn (  )

Turn on rumble.

Definition at line 915 of file Wii.cpp.

void setRumbleToggle (  )

Toggle rumble.

Definition at line 921 of file Wii.cpp.


Field Documentation

int16_t accXwiimote

Accelerometer values used to calculate pitch and roll.

Definition at line 230 of file Wii.h.

float gyroPitch

This is the pitch calculated by the gyro - use this to tune WII::pitchGyroScale.

Definition at line 241 of file Wii.h.

float gyroRoll

This is the roll calculated by the gyro - use this to tune WII::rollGyroScale.

Definition at line 243 of file Wii.h.

float gyroYaw

This is the yaw calculated by the gyro - use this to tune WII::yawGyroScale.

Definition at line 245 of file Wii.h.

int16_t gyroYawRaw

Raw value read directly from the Motion Plus.

Definition at line 263 of file Wii.h.

int16_t gyroYawZero

These values are set when the controller is first initialized.

Definition at line 270 of file Wii.h.

uint16_t hci_handle [protected, inherited]

The HCI Handle for the connection.

Definition at line 616 of file BTD.h.

uint8_t identifier [protected, inherited]

Identifier for L2CAP commands.

Definition at line 622 of file BTD.h.

uint32_t l2cap_event_flag [protected, inherited]

L2CAP flags of received Bluetooth events.

Definition at line 619 of file BTD.h.

Variable used to indicate if a Nunchuck controller is connected.

Definition at line 200 of file Wii.h.

Variable used to indicate if a Nunchuck controller is connected.

Definition at line 198 of file Wii.h.

BTD* pBtd [protected, inherited]

Pointer to BTD instance.

Definition at line 613 of file BTD.h.

void(* pFuncOnInit)(void) [protected, inherited]

Pointer to function called in onInit().

Definition at line 610 of file BTD.h.

uint16_t pitchGyroScale

You might need to fine-tune these values.

Definition at line 256 of file Wii.h.

The speed in deg/s from the gyro.

Definition at line 249 of file Wii.h.

Variable used to indicate if a Wii Balance Board is connected.

Definition at line 204 of file Wii.h.

Variable used to indicate if a Wiimote is connected.

Definition at line 191 of file Wii.h.

Variable used to indicate if a Wii U Pro controller is connected.

Definition at line 202 of file Wii.h.