void wii_mouse_init() { if (!mouse_initialized) { if (!mousequeue) { mousequeue = (lwp_queue*)malloc(sizeof(lwp_queue)); __lwp_queue_initialize(mousequeue,0,0,0); } if (wii_find_mouse()!=0) return; if (USB_OpenDevice("oh0",mouse_vid,mouse_pid,&mousefd)<0) { return; } if (!mousedata) { mousedata = (signed char*)memalign(32, 20); } //set boot protocol USB_WriteCtrlMsg(mousefd,USB_REQTYPE_SET,USB_REQ_SETPROTOCOL,0,0,0,0); USB_ReadIntrMsgAsync(mousefd, 0x81 ,4, mousedata, mousecallback, 0); mouse_initialized = 1; } }
s32 mousecallback(s32 result,void *usrdata) { if (result>0) { u8 button = mousedata[0]; int x = mousedata[1]; int y = mousedata[2]; //int w = (-1)<<(data[3]-1); MOUSE_addEvent(button, x, y); USB_ReadIntrMsgAsync(mousefd, 0x81 ,4, mousedata, mousecallback, 0); } else { mouse_initialized = 0; mousefd =0; } return 0; }
static void wiiusb_hid_poll_thread(void *data) { wiiusb_hid_t *hid = (wiiusb_hid_t*)data; struct wiiusb_adapter *adapter = NULL; if (!hid) return; while (!hid->poll_thread_quit) { /* first check for new devices */ if (hid->device_detected) { /* turn off the detection flag */ hid->device_detected = false; /* search for new pads and add them as needed */ wiiusb_hid_scan_for_devices(hid); } /* process each active adapter */ for (adapter = hid->adapters_head; adapter; adapter=adapter->next) { if (adapter->busy) continue; /* lock itself while writing or reading */ adapter->busy = true; if (adapter->send_control_type) wiiusb_hid_process_control_message(adapter); USB_ReadIntrMsgAsync(adapter->handle, adapter->endpoint_in, adapter->endpoint_in_max_size, adapter->data, wiiusb_hid_read_cb, adapter); } /* Wait 10 milliseconds to process again */ usleep(10000); } }