Example #1
0
static void BTTasks() {
    switch (state) {
    case STATE_DETACHED:
        if (USBHostBluetoothIsDeviceAttached()) {
            BTAttached();
            state = STATE_ATTACHED;
        }
        break;

    case STATE_ATTACHED:
        if (USBHostBluetoothIsDeviceAttached()) {
            hci_transport_mchpusb_tasks();

            if (rfcomm_channel_id && rfcomm_send_credit) {
                rfcomm_grant_credits(rfcomm_channel_id, 1);
                rfcomm_send_credit = 0;
            }
        } else {
            // Detached. We don't care about the state of btstack, since we're not
            // going to give it any context, and we'll reset it the next time a
            // dongle is attached. Just close the channel if it is open.
            log_printf("Bluetooth detached.");
            client_callback(NULL, 1, client_callback_arg);
            client_callback = DummyCallback;
            rfcomm_channel_id = 0;
            state = STATE_DETACHED;
        }
    }
}
Example #2
0
static void ConnBTTasks() {
  switch (bt_state) {
    case STATE_BT_DISCONNECTED:
      if (USBHostBluetoothIsDeviceAttached()) {
        BTInit(buf, BUF_SIZE);
        bt_state = STATE_BT_INITIALIZING;
      }
      break;

    case STATE_BT_INITIALIZING:
    case STATE_BT_INITIALIZED:
      if (!USBHostBluetoothIsDeviceAttached()) {
        // disconnected
        BTShutdown();
        bt_state = STATE_BT_DISCONNECTED;
      } else {
#ifndef USB_ENABLE_TRANSFER_EVENT
        USBHostBluetoothTasks();
#endif
        BTTasks();
        bt_state = BTAccepting() ? STATE_BT_INITIALIZED : STATE_BT_INITIALIZING;
      }
      break;
  }
}
Example #3
0
void USBHostBluetoothReset() {
  assert(USBHostBluetoothIsDeviceAttached());
  USBHostResetDevice(gc_BluetoothDevData.ID.deviceAddress);
  memset(&gc_BluetoothDevData, 0, sizeof gc_BluetoothDevData);
}