From 48764a62025fcec5aae4d7a8b3f046fd6650f07f Mon Sep 17 00:00:00 2001 From: Alayan <25536748+Alayan-stk-2@users.noreply.github.com> Date: Tue, 21 May 2024 13:53:57 +0200 Subject: [PATCH] Update Wiiuse to 0.15.6 STK-specific patches are kept, CI related changes are not included --- lib/wiiuse/CHANGELOG.mkd | 10 ++++++++ lib/wiiuse/README.mkd | 12 ++++++--- lib/wiiuse/src/include/wiiuse.h | 3 +-- lib/wiiuse/src/io.c | 4 ++- lib/wiiuse/src/os_nix.c | 27 +++++++++++++++------ lib/wiiuse/src/wiiboard.c | 43 +++++++++++++++++++++++++++++++-- 6 files changed, 83 insertions(+), 16 deletions(-) diff --git a/lib/wiiuse/CHANGELOG.mkd b/lib/wiiuse/CHANGELOG.mkd index 22c757bf6..f7dcebebd 100644 --- a/lib/wiiuse/CHANGELOG.mkd +++ b/lib/wiiuse/CHANGELOG.mkd @@ -14,6 +14,16 @@ Original project (0.12 and earlier): most recent archive from 2010 (looks identical on homepage to 2011 snapshot above) +v0.15.6 -- 18-Feb-2024 +-------------------- + +Fixed: + +- Linux - Fixed hang with kernels 6.6.x and newer +- Corrected historical record about Wiiuse origins +- Require CMake > 3.6.x to avoid deprecation warnings +- Support for Balance Board calibration + v0.15.5 -- 24-Nov-2019 -------------------- diff --git a/lib/wiiuse/README.mkd b/lib/wiiuse/README.mkd index 54de753de..689d0f735 100644 --- a/lib/wiiuse/README.mkd +++ b/lib/wiiuse/README.mkd @@ -68,6 +68,12 @@ Additional Contributors: - Chadwick Boulay - Florian Baumgartl - Philipp Hartl +Bryan Quigley +Bart Ribbers +Samuel Hackbeil +Jean-Michaƫl Celerier +Dave Murphy +Forrest Cahoon ## License @@ -253,10 +259,10 @@ greatly appreciated. ### Forks not yet fully integrated -- [libogc/WPAD/DevKitPro](http://wiibrew.org/wiki/Libogc) - - Started before the disappearance of the original upstream +- [libogc/wiiuse](https://github.com/devkitPro/libogc/tree/master/wiiuse) + - wii port created by Shagkur and contributed upstream - Focused on Wiimote use with Wii hardware - - Functions renamed, copyright statements removed + - code unfortunately diverged - Additional functionality unknown? - git-svn mirror found here: - [fwiine](http://sourceforge.net/projects/fwiine/files/wiiuse/0.13/) diff --git a/lib/wiiuse/src/include/wiiuse.h b/lib/wiiuse/src/include/wiiuse.h index 883eff542..8c52fd085 100644 --- a/lib/wiiuse/src/include/wiiuse.h +++ b/lib/wiiuse/src/include/wiiuse.h @@ -73,7 +73,7 @@ #define WIIUSE_MAJOR 0 #define WIIUSE_MINOR 15 -#define WIIUSE_MICRO 5 +#define WIIUSE_MICRO 6 #define WIIUSE_VERSION_TRANSFORM(MAJ, MIN, MICRO) (MAJ * 1000000 + MIN * 1000 + MICRO) #define WIIUSE_HAS_VERSION(MAJ, MIN, MICRO) \ @@ -953,7 +953,6 @@ WIIUSE_EXPORT extern void wiiuse_set_nunchuk_orient_threshold(struct wiimote_t * WIIUSE_EXPORT extern void wiiuse_set_nunchuk_accel_threshold(struct wiimote_t *wm, int threshold); /* wiiboard.c */ -/* this function not currently implemented... */ WIIUSE_EXPORT extern void wiiuse_set_wii_board_calib(struct wiimote_t *wm); WIIUSE_EXPORT extern void wiiuse_set_motion_plus(struct wiimote_t *wm, int status); diff --git a/lib/wiiuse/src/io.c b/lib/wiiuse/src/io.c index d81fa999a..7a0a4cbe6 100644 --- a/lib/wiiuse/src/io.c +++ b/lib/wiiuse/src/io.c @@ -150,8 +150,10 @@ int wiiuse_wait_report(struct wiimote_t *wm, int report, byte *buffer, int buffe if (elapsed > timeout_ms && timeout_ms > 0) { result = -1; + WIIUSE_DEBUG("(id %i) timeout waiting for report 0x%x, aborting!", wm->unid, report); break; } + wiiuse_millisleep(10); } return result; @@ -328,7 +330,7 @@ void wiiuse_handshake(struct wiimote_t *wm, byte *data, uint16_t len) wiiuse_status(wm); rc = wiiuse_wait_report(wm, WM_RPT_CTRL_STATUS, buf, MAX_PAYLOAD, WIIUSE_READ_TIMEOUT); - if (buf[3] != 0) + if (rc && buf[3] != 0) break; wiiuse_millisleep(500); diff --git a/lib/wiiuse/src/os_nix.c b/lib/wiiuse/src/os_nix.c index 8d69cbb0a..a27c24fc2 100644 --- a/lib/wiiuse/src/os_nix.c +++ b/lib/wiiuse/src/os_nix.c @@ -374,21 +374,32 @@ int wiiuse_os_read(struct wiimote_t *wm, byte *buf, int len) { int rc; - rc = read(wm->in_sock, buf, len); + rc = recv(wm->in_sock, buf, len, MSG_DONTWAIT); if (rc == -1) { - /* error reading data */ - WIIUSE_ERROR("Receiving wiimote data (id %i).", wm->unid); - perror("Error Details"); - - if (errno == ENOTCONN) + switch(errno) { + case ENOTCONN: /* this can happen if the bluetooth dongle is disconnected */ + WIIUSE_ERROR("Receiving wiimote data (id %i).", wm->unid); + perror("Error Details"); + WIIUSE_ERROR("Bluetooth appears to be disconnected. Wiimote unid %i will be disconnected.", wm->unid); wiiuse_os_disconnect(wm); wiiuse_disconnected(wm); + break; + + case EAGAIN: + /* no data available yet */ + break; + + default: + /* error reading data */ + WIIUSE_ERROR("Receiving wiimote data (id %i).", wm->unid); + perror("Error Details"); + break; } } else if (rc == 0) { @@ -406,7 +417,7 @@ int wiiuse_os_read(struct wiimote_t *wm, byte *buf, int len) { /* hack for chatty Balance Boards that flood the logs with useless button reports */ int i; printf("[DEBUG] (id %i) RECV: (%.2x) ", wm->unid, buf[0]); - for (i = 1; i < rc; i++) + for (i = 1; i < rc - 1; i++) { printf("%.2x ", buf[i]); } @@ -427,7 +438,7 @@ int wiiuse_os_write(struct wiimote_t *wm, byte report_type, byte *buf, int len) write_buffer[1] = report_type; memcpy(write_buffer + 2, buf, len); - rc = write(wm->in_sock, write_buffer, len + 2); + rc = send(wm->in_sock, write_buffer, len + 2, 0); if (rc < 0) { diff --git a/lib/wiiuse/src/wiiboard.c b/lib/wiiuse/src/wiiboard.c index 1c54938fe..289b579e2 100644 --- a/lib/wiiuse/src/wiiboard.c +++ b/lib/wiiuse/src/wiiboard.c @@ -161,6 +161,45 @@ void wii_board_event(struct wii_board_t *wb, byte *msg) } /** - @todo not implemented! +* @brief Calib wii board +* +* @param wm Pointer to a wiimote_t struct the calib values are used. */ -void wiiuse_set_wii_board_calib(struct wiimote_t *wm) {} +void wiiuse_set_wii_board_calib(struct wiimote_t *wm) +{ + byte pkt[21]; + uint16_t test = 1; + memset(pkt, 0, sizeof(pkt)); + + /* + * address in big endian first, the leading byte will + * be overwritten (only 3 bytes are sent) + */ + to_big_endian_uint32_t(pkt, WM_EXP_MEM_CALIBR + 4); + + pkt[0] = 0x04; //write register + pkt[4] = 0x0f; //size of data + + to_big_endian_uint16_t(&pkt[5], wm->exp.wb.ctr[0]); + to_big_endian_uint16_t(&pkt[7], wm->exp.wb.cbr[0]); + to_big_endian_uint16_t(&pkt[9], wm->exp.wb.ctl[0]); + to_big_endian_uint16_t(&pkt[11], wm->exp.wb.cbl[0]); + to_big_endian_uint16_t(&pkt[13], wm->exp.wb.ctr[1]); + to_big_endian_uint16_t(&pkt[15], wm->exp.wb.cbr[1]); + to_big_endian_uint16_t(&pkt[17], wm->exp.wb.ctl[1]); + to_big_endian_uint16_t(&pkt[19], wm->exp.wb.cbl[1]); + if (wiiuse_send(wm, WM_CMD_WRITE_DATA, pkt, sizeof(pkt)) < 0) + return; + wiiuse_millisleep(100); + + to_big_endian_uint32_t(pkt, WM_EXP_MEM_CALIBR + 20); + pkt[0] = 0x04; //write register + pkt[4] = 0x08; //size of data + + to_big_endian_uint16_t(&pkt[5], wm->exp.wb.ctr[2]); + to_big_endian_uint16_t(&pkt[7], wm->exp.wb.cbr[2]); + to_big_endian_uint16_t(&pkt[9], wm->exp.wb.ctl[2]); + to_big_endian_uint16_t(&pkt[11], wm->exp.wb.cbl[2]); + wiiuse_send(wm, WM_CMD_WRITE_DATA, pkt, sizeof(pkt)); + wiiuse_millisleep(100); +} \ No newline at end of file