My Project 1
Yet another Wii Balance Board Driver
|
Header file for core definitions and utility functions used in the YAWiiBBD project. More...
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stdbool.h>
#include <sys/socket.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/l2cap.h>
#include <bluetooth/hci.h>
#include <bluetooth/hci_lib.h>
#include <pthread.h>
#include <ctype.h>
Go to the source code of this file.
Classes | |
struct | WiiBalanceBoard |
Represents the Wii Balance Board connection and status. More... | |
Macros | |
#define | WII_BALANCE_BOARD_ADDR "00:23:CC:43:DC:C2" |
#define | BUFFER_SIZE 24 |
Enumerations | |
enum | LogLevel { RAW , DECODE , DEBUG , VERBOSE } |
Specifies the level of detail for logging output. More... | |
Functions | |
void | print_info (const LogLevel *is_debug_level, const char *message, const unsigned char *buffer, int length, const WiiBalanceBoard *board) |
Logs messages with different verbosity levels, providing diagnostics and raw data output. More... | |
int | find_wii_balance_board (WiiBalanceBoard *board) |
Finds the Wii Balance Board by scanning nearby Bluetooth devices. More... | |
void | send_command (int sock, const unsigned char *command, int length) |
Sends a command to the Wii Balance Board over the control socket. More... | |
int | connect_l2cap (const char *bdaddr_str, uint16_t psm) |
Establishes a L2CAP connection with the Wii Balance Board. More... | |
void | process_received_data (int bytes_read, unsigned char *buffer, WiiBalanceBoard *board) |
Processes received data from the Wii Balance Board. More... | |
void * | threadFunction (void *arg) |
Thread function for monitoring user input to control the Wii Balance Board. More... | |
void | createThread (WiiBalanceBoard *board, pthread_t *threadId) |
Creates a new thread and starts the threadFunction to monitor user control. More... | |
int | is_valid_mac (int argc, char *argv[]) |
Validates a given MAC address for format and content. More... | |
void | handle_status (WiiBalanceBoard *board) |
Processes sending a status command to the Wii Balance Board. More... | |
void | handle_calibration (WiiBalanceBoard *board) |
Processes sending a calibration command to the Wii Balance Board. More... | |
void | handle_led_on (WiiBalanceBoard *board) |
Processes sending an LED on command to the Wii Balance Board. More... | |
void | handle_activation (WiiBalanceBoard *board) |
Processes sending an activation command to the Wii Balance Board. More... | |
void | handle_data_dump (WiiBalanceBoard *board) |
Processes sending a data dump command (continous report of readings) to the Wii Balance Board. More... | |
void | process_calibration_data (int *bytes_read, unsigned char *buffer, WiiBalanceBoard *board) |
Processes the calibration data from the Wii Balance Board. More... | |
uint16_t | bytes_to_int_big_endian (const unsigned char *buffer, size_t position, int *max) |
Converts two consecutive bytes in the buffer from Big-Endian representation to a decimal integer. More... | |
uint16_t | calc_mass (const WiiBalanceBoard *board, uint16_t raw, int pos) |
Calculates the weight in grams from the raw data of the Wii Balance Board. More... | |
void | print_calibration_data (const WiiBalanceBoard *board) |
Displays the stored calibration data. More... | |
Variables | |
const LogLevel | debug_level |
Default logging level for output verbosity, dependent on compilation mode. More... | |
unsigned char | buffer [BUFFER_SIZE] |
Buffer for storing responses from the Wii Balance Board. More... | |
const unsigned char | status_command [] |
const unsigned char | activate_command [] |
const unsigned char | calibration_command [] |
const unsigned char | led_on_command [] |
const unsigned char | data_dump_command [] |
Header file for core definitions and utility functions used in the YAWiiBBD project.
This header file provides essential definitions, data structures, and function declarations that support core functionality for the YAWiiBBD (Yet Another Wii Balance Board Driver) project. It serves as a foundational component, defining the main interfaces and constants required for interacting with a Wii Balance Board over Bluetooth.
Originally, the project aimed to split core (essentials
) and extended (extended
) functionality across separate files. However, as an intermediate programmer, I encountered challenges in managing memory access violations when handling this separation. After considerable testing, I integrated the extended functionality directly within YAWiiBBessentials.h
, within an EXTENDED
section, for stability and to simplify memory management.
This integrated approach ensures that both core and additional features operate seamlessly, although it may require restructuring in the future if modularity is prioritized or memory handling becomes more robust.
This file depends on the bluez
library for Bluetooth communication, which provides the essential functions and structures required to connect and interact with the Wii Balance Board. Ensure the following libraries are available and correctly linked:
bluez
(Bluetooth library for Linux, required for L2CAP connections)stdlib.h
, stdio.h
, unistd.h
) for basic operations and system-level interactions.This file should be included in any source files that need direct access to the core functionality of YAWiiBBD. By isolating these definitions and functions, YAWiiBBessentials.h
promotes modularity and ensures that key components of the application can be maintained and extended independently.
essentials
and extended
functionality, separating them into distinct files once memory handling and stability are manageable, allowing for a clearer modular structure. #define BUFFER_SIZE 24 |
Buffer size for data reception - for the Wii Balance Board 24 byte is enough
#define WII_BALANCE_BOARD_ADDR "00:23:CC:43:DC:C2" |
Default MAC address for the Wii Balance Board
enum LogLevel |
Specifies the level of detail for logging output.
This enumeration allows the user to choose between different verbosity levels when displaying information.
|
extern |
Buffer for storing responses from the Wii Balance Board.
This buffer holds incoming data from the Balance Board, with a fixed maximum length of bytes, as defined in BUFFER_SIZE
|
extern |
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.
YAWIIBB_EXTENDED
flag, the logging level is set to the only available option RAW
, limiting output to raw, uninterpreted data.YAWIIBB_EXTENDED
flag, the logging level defaults to DEBUG
, allowing the selection between multiple verbosity levels (RAW
, DECODE
, DEBUG
, and optionally VERBOSE
).