My Project 1
Yet another Wii Balance Board Driver
Functions | Variables
YAWiiBBD.c File Reference

Core file for the YAWiiBBD application, facilitating interaction with a Wii Balance Board. More...

#include "YAWiiBBessentials.h"
Include dependency graph for YAWiiBBD.c:

Functions

void main_loop (WiiBalanceBoard *board)
 Main loop of the application. More...
 
int main (int argc, char *argv[])
 Main entry point of the application. More...
 

Variables

const LogLevel debug_level = DEBUG
 Default logging level for output verbosity, dependent on compilation mode. More...
 

Detailed Description

Core file for the YAWiiBBD application, facilitating interaction with a Wii Balance Board.

This file contains the main functionality of the application, including setup for Bluetooth connections, the primary loop for data handling, and thread management. The compilation flags control debug levels, which influence logging and application status reporting.

The application scans for the Wii Balance Board and attempts to establish two L2CAP connections: one for command transmission and one for receiving responses. Once connected, it enters a loop to process and output data continuously as long as the board remains active.

Termination

The main loop can be exited by pressing Enter in the terminal or by pressing the power button on the Wii Balance Board.

Compilation Instructions

Compile the application using the following commands based on the intended configuration:

Note
Ensure all required Bluetooth dependencies are installed and configured to allow successful connection and data handling from the Wii Balance Board.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Main entry point of the application.

This function initializes the WiiBalanceBoard, checks the validity of the provided MAC address, and establishes a Bluetooth connection to the Balance Board. If a valid MAC address is detected, a message is displayed to the user, suggesting a command line format for establishing an immediate connection on subsequent runs:

printf("YOU MAY USE \"%s %s\" FOR IMMEDIATE CONNECTION\n", argv[0], board.mac);

A background thread is started to handle user input. Currently, this thread only supports program termination commands, allowing the user to end the main loop. However, in future versions, this thread could be expanded to accept additional commands, such as status requests or calibration triggers, by setting corresponding flags in the WiiBalanceBoard object.

The main loop operates as long as the is_running flag remains set to true. Upon termination, the function performs cleanup by releasing all resources and closing the Bluetooth connection to the Balance Board.

Parameters
argcNumber of arguments passed to the program at startup.
argvArray of strings containing the arguments passed.
Returns
0 if the program completes successfully.

◆ main_loop()

void main_loop ( WiiBalanceBoard board)

Main loop of the application.

This function executes the core operations of the application, performing various actions based on the flags set within the WiiBalanceBoard object. These actions include status checks, calibration, activation, and toggling the LED on or off. The received data from the Balance Board is processed and handled within this loop.

The loop includes a 10-millisecond delay to reduce CPU load and ensure efficient processing of data. It runs continuously until a termination signal is received.

Parameters
boardA pointer to the WiiBalanceBoard object containing current status information and control flags.

Variable Documentation

◆ debug_level

const LogLevel debug_level = DEBUG

Default logging level for output verbosity, dependent on compilation mode.

The debug_level constant controls the verbosity of output logging for the Wii Balance Board.

  • When compiled without the YAWIIBB_EXTENDED flag, the logging level is set to the only available option RAW, limiting output to raw, uninterpreted data.
  • When compiled with the YAWIIBB_EXTENDED flag, the logging level defaults to DEBUG, allowing the selection between multiple verbosity levels (RAW, DECODE, DEBUG, and optionally VERBOSE).