Example #1
0
uint8_t BTD::Poll() {
	if (!bPollEnable)
		return 0;
    if (qNextPollTime <= millis()) { // Don't poll if shorter than polling interval
        qNextPollTime = millis() + pollInterval; // Set new poll time
        HCI_event_task(); // poll the HCI event pipe
        ACL_event_task(); // start polling the ACL input pipe too, though discard data until connected        
    }    
	return 0;
}
Example #2
0
uint8_t BTD::Poll() {
        if(!bPollEnable)
                return 0;
        if(qNextPollTime <= millis()) { // Don't poll if shorter than polling interval
                qNextPollTime = millis() + pollInterval; // Set new poll time
                HCI_event_task(); // Poll the HCI event pipe
                HCI_task(); // HCI state machine
                ACL_event_task(); // Poll the ACL input pipe too
        }
        return 0;
}
void WiiRemote::HCI_task(void) {
    HCI_event_task();

    switch (hci_state_) {
      case HCI_INIT_STATE:
        // wait until we have looped 10 times to clear any old events
        if (hci_timeout) {
            hci_reset();
            hci_state_ = HCI_RESET_STATE;
            hci_counter_ = 1000;
        }
        break;

      case HCI_RESET_STATE:
        if (hci_command_complete) {
            DEBUG_PRINT_P( PSTR("\r\nHCI Reset complete") );
            switch (bdaddr_acquisition_mode_) {
              case BD_ADDR_FIXED:
                hci_state_ = HCI_READY_CONNECT_STATE;
                hci_counter_ = 10000;
                break;

              case BD_ADDR_INQUIRY:
                hci_inquiry();
                hci_state_ = HCI_INQUIRY_STATE;
                hci_counter_ = 10000;
                break;

              default:
                break;
            }
        }
        if (hci_timeout) {
            DEBUG_PRINT_P( PSTR("\r\nNo response to HCI Reset") );
            hci_state_ = HCI_INIT_STATE;
            hci_counter_ = 10;
        }
        break;

      case HCI_INQUIRY_STATE:
        if (hci_inquiry_result) {
            DEBUG_PRINT_P( PSTR("\r\nHCI Inquiry responded") );
            hci_inquiry_cancel();
            hci_state_ = HCI_READY_CONNECT_STATE;
            hci_counter_ = 10000;
        }
        break;

      case HCI_READY_CONNECT_STATE:
        if (hci_command_complete) {
            if (hci_inquiry_result) {
                DEBUG_PRINT_P( PSTR("\r\nHCI Inquiry complete") );
            }
            hci_connect(wiiremote_bdaddr_); // connect to Wiimote
            hci_state_ = HCI_CONNECT_OUT_STATE;
            hci_counter_ = 10000;
        }
        break;

      case HCI_CONNECT_OUT_STATE:
        if (hci_connect_complete) {
            if(hci_connect_ok) {
                DEBUG_PRINT_P( PSTR("\r\nConnected to Wiimote") );
                hci_state_ = HCI_CONNECTED_STATE;
                l2cap_state_ = L2CAP_INIT_STATE;
                wiiremote_status_ |= WIIREMOTE_STATE_CONNECTED;
            }
            else {
                hci_connect(wiiremote_bdaddr_); // try again to connect to Wiimote
                hci_counter_ = 10000;
            }
        }
        if (hci_timeout) {
            hci_connect(wiiremote_bdaddr_); // try again to connect to Wiimote
            hci_counter_ = 10000;
        }
        break;

      case HCI_CONNECTED_STATE:
        if (hci_disconn_complete) {
            DEBUG_PRINT_P( PSTR("\r\nWiimote Disconnected") );
            hci_state_ = HCI_INIT_STATE;
            hci_counter_ = 10;
            l2cap_state_ = L2CAP_DOWN_STATE;
            wiiremote_status_ &= ~WIIREMOTE_STATE_CONNECTED;
        }
        break;

      default:
        break;
    }   // switch (hci_state_)

    return;
} // HCI_task