wiiuse
Macros | Functions
example.c File Reference

Example using the wiiuse API. More...

#include <stdio.h>
#include "wiiuse.h"
#include <unistd.h>
Include dependency graph for example.c:

Macros

#define MAX_WIIMOTES   4
 
#define WIIUSE_ACCEL_10BIT_BUILD   0
 

Functions

void handle_event (struct wiimote_t *wm)
 Callback that handles an event. More...
 
void handle_read (struct wiimote_t *wm, byte *data, unsigned short len)
 Callback that handles a read event. More...
 
void handle_ctrl_status (struct wiimote_t *wm)
 Callback that handles a controller status event. More...
 
void handle_disconnect (wiimote *wm)
 Callback that handles a disconnection event. More...
 
void test (struct wiimote_t *wm, byte *data, unsigned short len)
 
short any_wiimote_connected (wiimote **wm, int wiimotes)
 
int main (int argc, char **argv)
 main() More...
 

Detailed Description

Example using the wiiuse API.

This file is an example of how to use the wiiuse library.

Function Documentation

◆ handle_ctrl_status()

void handle_ctrl_status ( struct wiimote_t *  wm)

Callback that handles a controller status event.

Parameters
wmPointer to a wiimote_t structure.
attachmentIs there an attachment? (1 for yes, 0 for no)
speakerIs the speaker enabled? (1 for yes, 0 for no)
irIs the IR support enabled? (1 for yes, 0 for no)
ledWhat LEDs are lit.
battery_levelBattery level, between 0.0 (0%) and 1.0 (100%).

This occurs when either the controller status changed or the controller status was requested explicitly by wiiuse_status().

One reason the status can change is if the nunchuk was inserted or removed from the expansion port.

◆ handle_disconnect()

void handle_disconnect ( wiimote *  wm)

Callback that handles a disconnection event.

Parameters
wmPointer to a wiimote_t structure.

This can happen if the POWER button is pressed, or if the connection is interrupted.

◆ handle_event()

void handle_event ( struct wiimote_t *  wm)

Callback that handles an event.

Parameters
wmPointer to a wiimote_t structure.

Like WITH_BT_EMBEDDED, this macro is not propagated via wiiuse.pc's Cflags; a consumer must independently define WIIUSE_ACCEL_10BIT when it builds to interpret the widened field as extended precision. See ACCELEROMETER_PRECISION.md for background.

  • The historically mislabeled WIIMOTE_BUTTON_ZACCEL_BIT4/5/6/7 macros (only 2 of the 4 actually related to the Z axis) are renamed to WIIMOTE_BUTTON_XACCEL_LSB0/LSB1/YACCEL_LSB/ZACCEL_LSB, which accurately describe what each bit represents. Breaking for any code referencing the old names directly; no deprecated aliases are kept.
  • When WITH_ACCEL_10BIT is enabled, the Wii Remote's and Nunchuk's calibrated gforce/orient output reflects the accelerometer's full extended precision instead of being silently narrowed back down to 8-bit-equivalent before calibration runs (the MotionPlus-Nunchuk- passthrough path, which never decodes extra precision bits, is unaffected either way). With the flag off, output is unchanged.
  • wiiuse_set_accel_threshold()/wiiuse_set_nunchuk_accel_threshold() keep roughly the same real-world sensitivity whether or not WITH_ACCEL_10BIT is enabled: the internal accel-change comparison now rescales the threshold per axis to match each device/path's own decode shift, instead of silently becoming more sensitive under the flag as it did before. The public threshold value/units are unchanged - still a plain int at 8-bit-equivalent scale. * This function is called automatically by the wiiuse library when an event occurs on the specified wiimote.

◆ handle_read()

void handle_read ( struct wiimote_t *  wm,
byte *  data,
unsigned short  len 
)

Callback that handles a read event.

Parameters
wmPointer to a wiimote_t structure.
dataPointer to the filled data block.
lenLength in bytes of the data block.

This function is called automatically by the wiiuse library when the wiimote has returned the full data requested by a previous call to wiiuse_read_data().

You can read data on the wiimote, such as Mii data, if you know the offset address and the length.

The data pointer was specified on the call to wiiuse_read_data(). At the time of this function being called, it is not safe to deallocate this buffer.

◆ main()

int main ( int  argc,
char **  argv 
)

main()

Connect to up to two wiimotes and print any events that occur on either device.