Ejemplo n.º 1
0
void WiiRemote::task(void (*pFunc)(void)) {
    Max.Task();
    Usb.Task();
    delay(1);

    // re-initialize
    if (Usb.getUsbTaskState() == USB_DETACHED_SUBSTATE_INITIALIZE) {
        /* TODO */
        wiiremote_status_ = 0;
    }

    // wait for addressing state
    if (Usb.getUsbTaskState() == USB_STATE_CONFIGURING) {
        initBTController();

        if (wiiremote_status_ & WIIREMOTE_STATE_USB_CONFIGURED) {
            hci_state_ = HCI_INIT_STATE;
            hci_counter_ = 10;
            l2cap_state_ = L2CAP_DOWN_STATE;

            Usb.setUsbTaskState(USB_STATE_RUNNING);
        }
    }

    if (Usb.getUsbTaskState() == USB_STATE_RUNNING) {
        HCI_task();     // poll the HCI event pipe
        L2CAP_task();   // start polling the ACL input pipe too, though discard
                        // data until connected
    }
    //if (l2cap_state_ == L2CAP_READY_STATE) {
    if (wiiremote_status_ & WIIREMOTE_STATE_RUNNING) {
        if (pFunc) { pFunc(); }
    }
} // task