Treehopper C# API
WiiNunchuk Class Reference

Nintendo Wii Nunchuk More...

Inheritance diagram for WiiNunchuk:
IAccelerometer IPolledEvents IPollable IPollable

Classes

class  JoystickEventArgs
 

Public Member Functions

delegate void JoystickChangedDelegate (object sender, JoystickEventArgs e)
 
 WiiNunchuk (I2C i2c)
 
async Task UpdateAsync ()
 Fetch an update from the Nunchuk and push it to all the properties. More...
 

Properties

Vector2 Joystick [get]
 Gets a two-dimensional normalized vector representing the joystick state More...
 
Button C [get]
 Gets the "C" button More...
 
Button Z [get]
 Gets the "Z" button More...
 
Vector3 Accelerometer [get]
 Gets a three-dimensional normalized vector representing the accelerometer state More...
 
bool AutoUpdateWhenPropertyRead = true [get, set]
 Whether reading from one of the data properties should trigger a call to UpdateAsync() to fetch the latest state from the device. More...
 
int AwaitPollingInterval = 25 [get, set]
 The interval, in milliseconds, that "AwaitValueChanged"-type functions should use when polling this Nunchuk for updates. More...
 

Events

JoystickChangedDelegate JoystickChanged
 
PropertyChangedEventHandler PropertyChanged
 

Detailed Description

Nintendo Wii Nunchuk

This library implements an IAccelerometer-, DigitalIn-, and IPollable-compatible input device that exposes the joystick, accelerometer, C button, and Z button on a Nintendo Wii (or compatible) Nunchuk controller.

Just like all IPollable devices, there are different options for getting the data out of the peripheral. By default, AutoUpdateWhenPropertyRead will be true, so the library will automatically fetch updates from the device on-the-fly whenever you read one of the object's properties — this is a great method when you only need to grab the state of the device infrequently, as it doesn't tie up the I2C bus constantly. If your application is going to constantly read the input (say, in a game), you should change AutoUpdateWhenPropertyRead to false, and poll the sensor manually (with UpdateAsync()) whenever you want an update. Or, if you're hooking into events for the device, you can wrap this class inside a Poller<TPollable> to automatically run the polling loop for you.

Constructor & Destructor Documentation

◆ WiiNunchuk()

WiiNunchuk ( I2C  i2c)

Member Function Documentation

◆ JoystickChangedDelegate()

delegate void JoystickChangedDelegate ( object  sender,
JoystickEventArgs  e 
)

◆ UpdateAsync()

async Task UpdateAsync ( )

Fetch an update from the Nunchuk and push it to all the properties.

Returns
An awaitable task that completes upon success.

Implements IPollable.

Property Documentation

◆ Joystick

Vector2 Joystick
get

Gets a two-dimensional normalized vector representing the joystick state

◆ C

Button C
get

Gets the "C" button

◆ Z

Button Z
get

Gets the "Z" button

◆ Accelerometer

Vector3 Accelerometer
get

Gets a three-dimensional normalized vector representing the accelerometer state

◆ AutoUpdateWhenPropertyRead

bool AutoUpdateWhenPropertyRead = true
getset

Whether reading from one of the data properties should trigger a call to UpdateAsync() to fetch the latest state from the device.

If false, the user should periodically call UpdateAsync() to poll the device.

◆ AwaitPollingInterval

int AwaitPollingInterval = 25
getset

The interval, in milliseconds, that "AwaitValueChanged"-type functions should use when polling this Nunchuk for updates.

Event Documentation

◆ JoystickChanged

JoystickChangedDelegate JoystickChanged

◆ PropertyChanged

PropertyChangedEventHandler PropertyChanged

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