USB Host Shield 2.0
Public Member Functions | Public Attributes | List of all members
WII Class Reference

#include <Wii.h>

Inheritance diagram for WII:
Inheritance graph
[legend]
Collaboration diagram for WII:
Collaboration graph
[legend]

Public Member Functions

 WII (BTD *p, bool pair=false)
 
Wii Controller functions
bool getButtonPress (ButtonEnum b)
 
bool getButtonClick (ButtonEnum b)
 
void pair (void)
 
uint8_t getAnalogHat (HatEnum a)
 
uint16_t getAnalogHat (AnalogHatEnum a)
 
float getPitch ()
 
float getRoll ()
 
float getYaw ()
 
void setAllOff ()
 
void setRumbleOff ()
 
void setRumbleOn ()
 
void setRumbleToggle ()
 
void setLedRaw (uint8_t value)
 
void setLedOff ()
 
void setLedOff (LEDEnum a)
 
void setLedOn (LEDEnum a)
 
void setLedToggle (LEDEnum a)
 
void setLedStatus ()
 
uint8_t getBatteryLevel ()
 
uint8_t getWiiState ()
 
float getWiimotePitch ()
 
float getWiimoteRoll ()
 
float getNunchuckPitch ()
 
float getNunchuckRoll ()
 
Wii Balance Board functions
float getWeight (BalanceBoardEnum pos)
 
float getTotalWeight ()
 
uint16_t getWeightRaw (BalanceBoardEnum pos)
 
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 ()
 
uint16_t getIRx1 ()
 
uint16_t getIRy1 ()
 
uint8_t getIRs1 ()
 
uint16_t getIRx2 ()
 
uint16_t getIRy2 ()
 
uint8_t getIRs2 ()
 
uint16_t getIRx3 ()
 
uint16_t getIRy3 ()
 
uint8_t getIRs3 ()
 
uint16_t getIRx4 ()
 
uint16_t getIRy4 ()
 
uint8_t getIRs4 ()
 
bool isIRCameraEnabled ()
 
- Public Member Functions inherited from BluetoothService
 BluetoothService (BTD *p)
 
void attachOnInit (void(*funcOnInit)(void))
 

Public Attributes

float gyroPitch
 
float gyroRoll
 
float gyroYaw
 
bool wiimoteConnected
 
bool nunchuckConnected
 
bool motionPlusConnected
 
bool wiiUProControllerConnected
 
bool wiiBalanceBoardConnected
 
int16_t accXwiimote
 
int16_t accYwiimote
 
int16_t accZwiimote
 
int16_t accXnunchuck
 
int16_t accYnunchuck
 
int16_t accZnunchuck
 
float pitchGyroSpeed
 
float rollGyroSpeed
 
float yawGyroSpeed
 
uint16_t pitchGyroScale
 
uint16_t rollGyroScale
 
uint16_t yawGyroScale
 
int16_t gyroYawRaw
 
int16_t gyroRollRaw
 
int16_t gyroPitchRaw
 
int16_t gyroYawZero
 
int16_t gyroRollZero
 
int16_t gyroPitchZero
 

BluetoothService implementation

void disconnect ()
 
void ACLData (uint8_t *ACLData)
 
void Run ()
 
void Reset ()
 
void onInit ()
 

Additional Inherited Members

- Protected Member Functions inherited from BluetoothService
bool checkHciHandle (uint8_t *buf, uint16_t handle)
 
- Protected Attributes inherited from BluetoothService
void(* pFuncOnInit )(void)
 
BTDpBtd
 
uint16_t hci_handle
 
uint32_t l2cap_event_flag
 
uint8_t identifier
 

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()

WII::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

◆ disconnect()

void WII::disconnect ( )
virtual

Used this to disconnect any of the controllers.

Implements BluetoothService.

Definition at line 116 of file Wii.cpp.

◆ getButtonPress()

bool WII::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 1109 of file Wii.cpp.

◆ getButtonClick()

bool WII::getButtonClick ( 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 1120 of file Wii.cpp.

◆ pair()

void WII::pair ( void  )
inline

Call this to start the pairing sequence with a controller

Definition at line 89 of file Wii.h.

◆ getAnalogHat() [1/2]

uint8_t WII::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 1135 of file Wii.cpp.

◆ getAnalogHat() [2/2]

uint16_t WII::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 1147 of file Wii.cpp.

◆ getPitch()

float WII::getPitch ( )
inline

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.

◆ getRoll()

float WII::getRoll ( )
inline

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.

◆ getYaw()

float WII::getYaw ( )
inline

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.

◆ setAllOff()

void WII::setAllOff ( )

Used to set all LEDs and rumble off.

Definition at line 903 of file Wii.cpp.

◆ setRumbleOff()

void WII::setRumbleOff ( )

Turn off rumble.

Definition at line 909 of file Wii.cpp.

◆ setRumbleOn()

void WII::setRumbleOn ( )

Turn on rumble.

Definition at line 915 of file Wii.cpp.

◆ setRumbleToggle()

void WII::setRumbleToggle ( )

Toggle rumble.

Definition at line 921 of file Wii.cpp.

◆ setLedRaw()

void WII::setLedRaw ( uint8_t  value)

Set LED value without using the LEDEnum.

Parameters
valueSee: LEDEnum.

Definition at line 927 of file Wii.cpp.

◆ setLedOff() [1/2]

void WII::setLedOff ( )
inline

Turn all LEDs off.

Definition at line 152 of file Wii.h.

◆ setLedOff() [2/2]

void WII::setLedOff ( LEDEnum  a)

Turn the specific LEDEnum off.

Parameters
aThe LEDEnum to turn off.

Definition at line 933 of file Wii.cpp.

◆ setLedOn()

void WII::setLedOn ( LEDEnum  a)

Turn the specific LEDEnum on.

Parameters
aThe LEDEnum to turn on.

Definition at line 939 of file Wii.cpp.

◆ setLedToggle()

void WII::setLedToggle ( LEDEnum  a)

Toggle the specific LEDEnum.

Parameters
aThe LEDEnum to toggle.

Definition at line 949 of file Wii.cpp.

◆ setLedStatus()

void WII::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.

◆ getBatteryLevel()

uint8_t WII::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.

◆ getWiiState()

uint8_t WII::getWiiState ( )
inline

Return the Wiimote state.

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

Definition at line 189 of file Wii.h.

◆ getWiimotePitch()

float WII::getWiimotePitch ( )
inline

Pitch and roll calculated from the accelerometer inside the Wiimote.

Definition at line 212 of file Wii.h.

◆ getWiimoteRoll()

float WII::getWiimoteRoll ( )
inline

Pitch and roll calculated from the accelerometer inside the Wiimote.

Definition at line 216 of file Wii.h.

◆ getNunchuckPitch()

float WII::getNunchuckPitch ( )
inline

Pitch and roll calculated from the accelerometer inside the Nunchuck.

Definition at line 224 of file Wii.h.

◆ getNunchuckRoll()

float WII::getNunchuckRoll ( )
inline

Pitch and roll calculated from the accelerometer inside the Nunchuck.

Definition at line 228 of file Wii.h.

◆ getWeight()

float WII::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 1170 of file Wii.cpp.

◆ getTotalWeight()

float WII::getTotalWeight ( )

Used to get total weight on the Wii Balance Board.

Returns
Returns the weight in kg.

Definition at line 1183 of file Wii.cpp.

◆ getWeightRaw()

uint16_t WII::getWeightRaw ( BalanceBoardEnum  pos)
inline

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.

◆ IRinitialize()

void WII::IRinitialize ( )

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

Definition at line 1193 of file Wii.cpp.

◆ getIRx1()

uint16_t WII::getIRx1 ( )
inline

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.

◆ getIRy1()

uint16_t WII::getIRy1 ( )
inline

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.

◆ getIRs1()

uint8_t WII::getIRs1 ( )
inline

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.

◆ getIRx2()

uint16_t WII::getIRx2 ( )
inline

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.

◆ getIRy2()

uint16_t WII::getIRy2 ( )
inline

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.

◆ getIRs2()

uint8_t WII::getIRs2 ( )
inline

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.

◆ getIRx3()

uint16_t WII::getIRx3 ( )
inline

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.

◆ getIRy3()

uint16_t WII::getIRy3 ( )
inline

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.

◆ getIRs3()

uint8_t WII::getIRs3 ( )
inline

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.

◆ getIRx4()

uint16_t WII::getIRx4 ( )
inline

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.

◆ getIRy4()

uint16_t WII::getIRy4 ( )
inline

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.

◆ getIRs4()

uint8_t WII::getIRs4 ( )
inline

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.

◆ isIRCameraEnabled()

bool WII::isIRCameraEnabled ( )
inline

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.

◆ ACLData()

void WII::ACLData ( uint8_t *  ACLData)
protectedvirtual

Used to pass acldata to the services.

Parameters
ACLDataIncoming acldata.

Implements BluetoothService.

Definition at line 133 of file Wii.cpp.

◆ Run()

void WII::Run ( )
protectedvirtual

Used to run part of the state machine.

Implements BluetoothService.

Definition at line 725 of file Wii.cpp.

◆ Reset()

void WII::Reset ( )
protectedvirtual

Use this to reset the service.

Implements BluetoothService.

Definition at line 101 of file Wii.cpp.

◆ onInit()

void WII::onInit ( )
protectedvirtual

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 1159 of file Wii.cpp.

Member Data Documentation

◆ wiimoteConnected

bool WII::wiimoteConnected

Variable used to indicate if a Wiimote is connected.

Definition at line 196 of file Wii.h.

◆ nunchuckConnected

bool WII::nunchuckConnected

Variable used to indicate if a Nunchuck controller is connected.

Definition at line 198 of file Wii.h.

◆ motionPlusConnected

bool WII::motionPlusConnected

Variable used to indicate if a Nunchuck controller is connected.

Definition at line 200 of file Wii.h.

◆ wiiUProControllerConnected

bool WII::wiiUProControllerConnected

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

Definition at line 202 of file Wii.h.

◆ wiiBalanceBoardConnected

bool WII::wiiBalanceBoardConnected

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

Definition at line 204 of file Wii.h.

◆ accXwiimote

int16_t WII::accXwiimote

Accelerometer values used to calculate pitch and roll.

Definition at line 235 of file Wii.h.

◆ accYwiimote

int16_t WII::accYwiimote

Accelerometer values used to calculate pitch and roll.

Definition at line 235 of file Wii.h.

◆ accZwiimote

int16_t WII::accZwiimote

Accelerometer values used to calculate pitch and roll.

Definition at line 235 of file Wii.h.

◆ accXnunchuck

int16_t WII::accXnunchuck

Accelerometer values used to calculate pitch and roll.

Definition at line 236 of file Wii.h.

◆ accYnunchuck

int16_t WII::accYnunchuck

Accelerometer values used to calculate pitch and roll.

Definition at line 236 of file Wii.h.

◆ accZnunchuck

int16_t WII::accZnunchuck

Accelerometer values used to calculate pitch and roll.

Definition at line 236 of file Wii.h.

◆ gyroPitch

float WII::gyroPitch

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

Definition at line 241 of file Wii.h.

◆ gyroRoll

float WII::gyroRoll

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

Definition at line 243 of file Wii.h.

◆ gyroYaw

float WII::gyroYaw

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

Definition at line 245 of file Wii.h.

◆ pitchGyroSpeed

float WII::pitchGyroSpeed

The speed in deg/s from the gyro.

Definition at line 249 of file Wii.h.

◆ rollGyroSpeed

float WII::rollGyroSpeed

The speed in deg/s from the gyro.

Definition at line 250 of file Wii.h.

◆ yawGyroSpeed

float WII::yawGyroSpeed

The speed in deg/s from the gyro.

Definition at line 251 of file Wii.h.

◆ pitchGyroScale

uint16_t WII::pitchGyroScale

You might need to fine-tune these values.

Definition at line 256 of file Wii.h.

◆ rollGyroScale

uint16_t WII::rollGyroScale

You might need to fine-tune these values.

Definition at line 257 of file Wii.h.

◆ yawGyroScale

uint16_t WII::yawGyroScale

You might need to fine-tune these values.

Definition at line 258 of file Wii.h.

◆ gyroYawRaw

int16_t WII::gyroYawRaw

Raw value read directly from the Motion Plus.

Definition at line 263 of file Wii.h.

◆ gyroRollRaw

int16_t WII::gyroRollRaw

Raw value read directly from the Motion Plus.

Definition at line 264 of file Wii.h.

◆ gyroPitchRaw

int16_t WII::gyroPitchRaw

Raw value read directly from the Motion Plus.

Definition at line 265 of file Wii.h.

◆ gyroYawZero

int16_t WII::gyroYawZero

These values are set when the controller is first initialized.

Definition at line 270 of file Wii.h.

◆ gyroRollZero

int16_t WII::gyroRollZero

These values are set when the controller is first initialized.

Definition at line 271 of file Wii.h.

◆ gyroPitchZero

int16_t WII::gyroPitchZero

These values are set when the controller is first initialized.

Definition at line 272 of file Wii.h.


The documentation for this class was generated from the following files: