astyle on the library.

This commit is contained in:
Ryan Pavlik
2012-12-10 14:13:58 -06:00
parent 82080f9f37
commit a86f33afa5
23 changed files with 1168 additions and 1056 deletions

205
src/io.c
View File

@@ -62,7 +62,7 @@
* This function is declared in wiiuse.h
*/
int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout) {
return wiiuse_os_find(wm, max_wiimotes, timeout);
return wiiuse_os_find(wm, max_wiimotes, timeout);
}
/**
@@ -87,7 +87,7 @@ int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout) {
* This function is declared in wiiuse.h
*/
int wiiuse_connect(struct wiimote_t** wm, int wiimotes) {
return wiiuse_os_connect(wm, wiimotes);
return wiiuse_os_connect(wm, wiimotes);
}
/**
@@ -106,10 +106,10 @@ int wiiuse_connect(struct wiimote_t** wm, int wiimotes) {
* This function is declared in wiiuse.h
*/
void wiiuse_disconnect(struct wiimote_t* wm) {
wiiuse_os_disconnect(wm);
wiiuse_os_disconnect(wm);
}
/**
/**
* @brief Wait until specified report arrives and return it
*
* @param wm Pointer to a wiimote_t structure.
@@ -120,12 +120,10 @@ void wiiuse_disconnect(struct wiimote_t* wm) {
* report from the Wiimote.
*
*/
void wiiuse_wait_report(struct wiimote_t *wm, int report, byte *buffer, int bufferLength)
{
for(;;)
{
if(wiiuse_os_read(wm, buffer, bufferLength) > 0) {
if(buffer[0] == report) {
void wiiuse_wait_report(struct wiimote_t *wm, int report, byte *buffer, int bufferLength) {
for (;;) {
if (wiiuse_os_read(wm, buffer, bufferLength) > 0) {
if (buffer[0] == report) {
break;
} else {
WIIUSE_WARNING("(id %i) dropping report 0x%x, waiting for 0x%x", wm->unid, buffer[0], report);
@@ -147,8 +145,7 @@ void wiiuse_wait_report(struct wiimote_t *wm, int report, byte *buffer, int buff
* amount of data from the Wiimote.
*
*/
void wiiuse_read_data_sync(struct wiimote_t *wm, byte memory, unsigned addr, unsigned short size, byte *data)
{
void wiiuse_read_data_sync(struct wiimote_t *wm, byte memory, unsigned addr, unsigned short size, byte *data) {
byte pkt[6];
byte buf[MAX_PAYLOAD];
unsigned n_full_reports;
@@ -164,10 +161,10 @@ void wiiuse_read_data_sync(struct wiimote_t *wm, byte memory, unsigned addr, uns
/* read from registers or memory */
pkt[0] = (memory != 0) ? 0x00 : 0x04;
/* length in big endian */
to_big_endian_uint16_t(pkt + 4, size);
/* send */
wiiuse_send(wm, WM_CMD_READ_DATA, pkt, sizeof(pkt));
@@ -176,16 +173,14 @@ void wiiuse_read_data_sync(struct wiimote_t *wm, byte memory, unsigned addr, uns
last_report = size % 16;
output = data;
for(i = 0; i < n_full_reports; ++i)
{
for (i = 0; i < n_full_reports; ++i) {
wiiuse_wait_report(wm, WM_RPT_READ, buf, MAX_PAYLOAD);
memmove(output, buf + 6, 16);
output += 16;
}
/* read the last incomplete packet */
if(last_report)
{
if (last_report) {
wiiuse_wait_report(wm, WM_RPT_READ, buf, MAX_PAYLOAD);
memmove(output, buf + 6, last_report);
}
@@ -207,8 +202,7 @@ void wiiuse_read_data_sync(struct wiimote_t *wm, byte memory, unsigned addr, uns
#ifdef WIIUSE_SYNC_HANDSHAKE
void wiiuse_handshake(struct wiimote_t* wm, byte* data, uint16_t len)
{
void wiiuse_handshake(struct wiimote_t* wm, byte* data, uint16_t len) {
/* send request to wiimote for accelerometer calibration */
byte buf[MAX_PAYLOAD];
@@ -254,118 +248,113 @@ void wiiuse_handshake(struct wiimote_t* wm, byte* data, uint16_t len)
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE);
/* now enable IR if it was set before the handshake completed */
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR))
{
WIIUSE_DEBUG("Handshake finished, enabling IR.");
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR);
wiiuse_set_ir(wm, 1);
}
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) {
WIIUSE_DEBUG("Handshake finished, enabling IR.");
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR);
wiiuse_set_ir(wm, 1);
}
WIIUSE_DEBUG("Asking for status ...\n");
wm->event = WIIUSE_CONNECT;
wiiuse_status(wm);
WIIUSE_DEBUG("Asking for status ...\n");
wm->event = WIIUSE_CONNECT;
wiiuse_status(wm);
}
}
#else
static void wiiuse_disable_motion_plus1(struct wiimote_t *wm,byte *data,unsigned short len);
static void wiiuse_disable_motion_plus2(struct wiimote_t *wm,byte *data,unsigned short len);
static void wiiuse_disable_motion_plus1(struct wiimote_t *wm, byte *data, unsigned short len);
static void wiiuse_disable_motion_plus2(struct wiimote_t *wm, byte *data, unsigned short len);
void wiiuse_handshake(struct wiimote_t* wm, byte* data, uint16_t len) {
if (!wm) return;
if (!wm) {
return;
}
switch (wm->handshake_state) {
case 0:
{
byte* buf;
case 0: {
byte* buf;
/* continous reporting off, report to buttons only */
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE);
wiiuse_set_leds(wm, WIIMOTE_LED_NONE);
/* continous reporting off, report to buttons only */
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE);
wiiuse_set_leds(wm, WIIMOTE_LED_NONE);
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_ACC);
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR);
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_RUMBLE);
WIIMOTE_DISABLE_FLAG(wm, WIIUSE_CONTINUOUS);
wiiuse_set_report_type(wm);
/* send request to wiimote for accelerometer calibration */
buf = (byte*)malloc(sizeof(byte) * 8);
wiiuse_read_data_cb(wm, wiiuse_handshake, buf, WM_MEM_OFFSET_CALIBRATION, 7);
wm->handshake_state++;
wiiuse_set_leds(wm, WIIMOTE_LED_NONE);
break;
}
case 1:
{
struct read_req_t* req = wm->read_req;
struct accel_t* accel = &wm->accel_calib;
byte val;
/* received read data */
accel->cal_zero.x = req->buf[0];
accel->cal_zero.y = req->buf[1];
accel->cal_zero.z = req->buf[2];
accel->cal_g.x = req->buf[4] - accel->cal_zero.x;
accel->cal_g.y = req->buf[5] - accel->cal_zero.y;
accel->cal_g.z = req->buf[6] - accel->cal_zero.z;
/* done with the buffer */
free(req->buf);
/* handshake is done */
WIIUSE_DEBUG("Handshake finished. Calibration: Idle: X=%x Y=%x Z=%x\t+1g: X=%x Y=%x Z=%x",
accel->cal_zero.x, accel->cal_zero.y, accel->cal_zero.z,
accel->cal_g.x, accel->cal_g.y, accel->cal_g.z);
/* M+ off */
val = 0x55;
wiiuse_write_data_cb(wm, WM_EXP_MEM_ENABLE1, &val, 1, wiiuse_disable_motion_plus1);
break;
}
case 2:
{
/* request the status of the wiimote to check for any expansion */
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE);
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE_COMPLETE);
wm->handshake_state++;
/* now enable IR if it was set before the handshake completed */
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) {
WIIUSE_DEBUG("Handshake finished, enabling IR.");
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_ACC);
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR);
wiiuse_set_ir(wm, 1);
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_RUMBLE);
WIIMOTE_DISABLE_FLAG(wm, WIIUSE_CONTINUOUS);
wiiuse_set_report_type(wm);
/* send request to wiimote for accelerometer calibration */
buf = (byte*)malloc(sizeof(byte) * 8);
wiiuse_read_data_cb(wm, wiiuse_handshake, buf, WM_MEM_OFFSET_CALIBRATION, 7);
wm->handshake_state++;
wiiuse_set_leds(wm, WIIMOTE_LED_NONE);
break;
}
wm->event = WIIUSE_CONNECT;
wiiuse_status(wm);
case 1: {
struct read_req_t* req = wm->read_req;
struct accel_t* accel = &wm->accel_calib;
byte val;
break;
}
/* received read data */
accel->cal_zero.x = req->buf[0];
accel->cal_zero.y = req->buf[1];
accel->cal_zero.z = req->buf[2];
default:
{
break;
}
accel->cal_g.x = req->buf[4] - accel->cal_zero.x;
accel->cal_g.y = req->buf[5] - accel->cal_zero.y;
accel->cal_g.z = req->buf[6] - accel->cal_zero.z;
/* done with the buffer */
free(req->buf);
/* handshake is done */
WIIUSE_DEBUG("Handshake finished. Calibration: Idle: X=%x Y=%x Z=%x\t+1g: X=%x Y=%x Z=%x",
accel->cal_zero.x, accel->cal_zero.y, accel->cal_zero.z,
accel->cal_g.x, accel->cal_g.y, accel->cal_g.z);
/* M+ off */
val = 0x55;
wiiuse_write_data_cb(wm, WM_EXP_MEM_ENABLE1, &val, 1, wiiuse_disable_motion_plus1);
break;
}
case 2: {
/* request the status of the wiimote to check for any expansion */
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE);
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE_COMPLETE);
wm->handshake_state++;
/* now enable IR if it was set before the handshake completed */
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) {
WIIUSE_DEBUG("Handshake finished, enabling IR.");
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR);
wiiuse_set_ir(wm, 1);
}
wm->event = WIIUSE_CONNECT;
wiiuse_status(wm);
break;
}
default: {
break;
}
}
}
static void wiiuse_disable_motion_plus1(struct wiimote_t *wm,byte *data,unsigned short len)
{
static void wiiuse_disable_motion_plus1(struct wiimote_t *wm, byte *data, unsigned short len) {
byte val = 0x00;
wiiuse_write_data_cb(wm, WM_EXP_MEM_ENABLE1, &val, 1, wiiuse_disable_motion_plus2);
}
static void wiiuse_disable_motion_plus2(struct wiimote_t *wm,byte *data,unsigned short len)
{
static void wiiuse_disable_motion_plus2(struct wiimote_t *wm, byte *data, unsigned short len) {
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP_FAILED);
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP_HANDSHAKE);
wiiuse_set_ir_mode(wm);