bool Adafruit_BluefruitLE_UART::setMode(uint8_t new_mode)
{
  // invalid mode
  if ( !(new_mode == BLUEFRUIT_MODE_COMMAND || new_mode == BLUEFRUIT_MODE_DATA) ) return false;

  bool isOK;

  if ( _mode_pin >= 0 )
  {
    // Switch mode using hardware pin
    digitalWrite(_mode_pin, new_mode);
    delay(1);
    isOK = true;
  } else
  {
    // Switch mode using +++ command, at worst switch 2 times
    int32_t updated_mode;

    isOK = sendCommandWithIntReply(F("+++"), &updated_mode);

    if ( isOK )
    {
      // Ahhh, we are already in the wanted mode before sending +++
      // Switch again. This is required to make sure it is always correct
      if ( updated_mode != new_mode )
      {
        isOK = sendCommandWithIntReply(F("+++"), &updated_mode);
        // Still does not match -> give up
        if ( updated_mode != new_mode ) return false;
      }
    }
  }

  return isOK;
}
예제 #2
0
bool Adafruit_BLE::isConnected(void)
{
  int32_t connected = 0;
  sendCommandWithIntReply(F("AT+GAPGETCONN"), &connected);
  return connected;
}