int wiiuse_os_read(struct wiimote_t* wm, byte* buf, int len) { int rc; int i; rc = read(wm->in_sock, buf, len); if (rc == -1) { /* error reading data */ WIIUSE_ERROR("Receiving wiimote data (id %i).", wm->unid); perror("Error Details"); if (errno == ENOTCONN) { /* this can happen if the bluetooth dongle is disconnected */ WIIUSE_ERROR("Bluetooth appears to be disconnected. Wiimote unid %i will be disconnected.", wm->unid); wiiuse_os_disconnect(wm); wiiuse_disconnected(wm); } } else if (rc == 0) { /* remote disconnect */ wiiuse_disconnected(wm); } else { /* read successful */ /* on *nix we ignore the first byte */ memmove(buf, buf + 1, len - 1); /* log the received data */ #ifdef WITH_WIIUSE_DEBUG { int i; printf("[DEBUG] (id %i) RECV: (%.2x) ", wm->unid, buf[0]); for (i = 1; i < rc; i++) { printf("%.2x ", buf[i]); } printf("\n"); } #endif } return rc; }
/** * @brief Disconnect a wiimote. * * @param wm Pointer to a wiimote_t structure. * * @see wiiuse_connect() * @see wiiuse_os_disconnect() * * Note that this will not free the wiimote structure. * * This function only delegates to the platform-specific implementation * wiiuse_os_disconnect. * * This function is declared in wiiuse.h */ void wiiuse_disconnect(struct wiimote_t* wm) { wiiuse_os_disconnect(wm); }