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
void loop() {
    Usb.Task();

    if (!adk.isReady()) {
        return;
    }
    
    readMessage();
}
Beispiel #3
0
void processUsb()
{
    uint8_t rcode;

    g_usb.Task();
    if (g_adk.isReady() == false)
    {
        digitalWrite(LED_PIN, 0);
        return;
    }
    digitalWrite(LED_PIN, g_storage_buffer_index);
    rcode = g_adk.SndData(STORAGE_SIZE, g_storage_space[g_storage_index]);
    if (rcode) 
    {
        Serial.print("USB send: ");
        Serial.println(rcode);
    }
}