My Project 1
Yet another Wii Balance Board Driver
|
Functions for interpreting and displaying Wii Balance Board data. More...
Functions | |
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... | |
Functions for interpreting and displaying Wii Balance Board data.
These functions provide additional capabilities for interpreting and converting raw data from the Wii Balance Board into a human-readable format. While not essential for the primary operation, they enable a deeper understanding of data processing and assist in debugging.
Currently, these functions accept variables in some cases, though the goal is to refactor them to exclusively use pointers where possible to streamline memory management and improve efficiency. Additionally, they would ideally be organized in a separate file, but due to challenges in managing memory access and avoiding segmentation faults, they remain integrated within this file for now.
YAWIIBB_EXTENDED
flag. 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.
Interprets two bytes in the given buffer
starting from the provided position
as a 16-bit integer in Big-Endian format (most significant byte first). The function returns this integer so that it can be output in decimal form.
buffer | Pointer to the buffer that contains the bytes. |
position | The starting position of the most significant byte in the buffer. |
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.
This function uses calibration data from the Wii Balance Board to calculate a weight in grams based on the given raw data. The weight is interpolated within four calibration ranges or, if the value exceeds the highest calibration range, is linearly extrapolated.
board | A constant pointer to the Wii Balance Board structure that contains the calibration data. |
raw | The raw data value representing the weight, measured from one of the four sensor positions (Top-Right, Bottom-Right, etc.). |
pos | The position of the sensor (0 to 3) for the calibration data of the raw value. Must be within the range [0, 3]. |
uint16_t
.The calculation uses four cases based on the raw data:
void print_calibration_data | ( | const WiiBalanceBoard * | board | ) |
Displays the stored calibration data.
This function is solely for debugging purposes and is no longer used. If one wants to know whether the calibration data has been stored, they can implement it.
void process_calibration_data | ( | int * | bytes_read, |
unsigned char * | buffer, | ||
WiiBalanceBoard * | board | ||
) |
Processes the calibration data from the Wii Balance Board.
This function analyzes a data buffer with calibration information and extracts this into the calibration array of the passed WiiBalanceBoard
instance. The calibration data are 16-bit values stored in a big-endian format and consist of 4 pairs for each of the four corners (topright, topleft, bottomright, bottomleft).
bytes_read | Number of bytes actually read in the buffer. |
buffer | Pointer to a buffer containing the received bytes. The expected structure is:
|
board | Pointer to the WiiBalanceBoard instance where calibration data will be stored. |
buffer
contains at least 23 bytes in order to process the expected calibration data.The operation of the function is as follows:
calibration[0]
(Calibration set 0).calibration[1]
(Calibration set 1).calibration[2]
(Calibration set 2).Example:
board->calibration[0][0]
board->calibration[2][i]