diff --git a/src/TinyGsmBluetooth.tpp b/src/TinyGsmBluetooth.tpp new file mode 100644 index 0000000..ca1cb4e --- /dev/null +++ b/src/TinyGsmBluetooth.tpp @@ -0,0 +1,57 @@ +/** + * @file TinyGsmGPS.tpp + * @author Adrian Cervera Andes + * @license LGPL-3.0 + * @copyright Copyright (c) 2021 Adrian Cervera Andes + * @date Jan 2021 + */ + +#ifndef SRC_TINYGSMBLUETOOTH_H_ +#define SRC_TINYGSMBLUETOOTH_H_ + +#include "TinyGsmCommon.h" + +#define TINY_GSM_MODEM_HAS_BLUETOOTH + +template +class TinyGsmBluetooth { + public: + /* + * Bluetooth functions + */ + bool enableBluetooth() { + return thisModem().enableBluetoothImpl(); + } + bool disableBluetooth() { + return thisModem().disableBluetoothImpl(); + } + bool setBluetoothVisibility(bool visible) { + return thisModem().setBluetoothVisibilityImpl(visible); + } + bool setBluetoothHostName(const char* name) { + return thisModem().setBluetoothHostNameImpl(name); + } + + /* + * CRTP Helper + */ + protected: + inline const modemType& thisModem() const { + return static_cast(*this); + } + inline modemType& thisModem() { + return static_cast(*this); + } + + /* + * Bluetooth functions + */ + + bool enableBluetoothImpl() TINY_GSM_ATTR_NOT_IMPLEMENTED; + bool disableBluetoothImpl() TINY_GSM_ATTR_NOT_IMPLEMENTED; + bool setBluetoothVisibilityImpl(bool visible) TINY_GSM_ATTR_NOT_IMPLEMENTED; + bool setBluetoothHostNameImpl(const char* name) TINY_GSM_ATTR_NOT_IMPLEMENTED; +}; + + +#endif // SRC_TINYGSMBLUETOOTH_H_ diff --git a/src/TinyGsmClientSIM808.h b/src/TinyGsmClientSIM808.h index ab699d1..7398bfa 100644 --- a/src/TinyGsmClientSIM808.h +++ b/src/TinyGsmClientSIM808.h @@ -12,9 +12,11 @@ #include "TinyGsmClientSIM800.h" #include "TinyGsmGPS.tpp" +#include "TinyGsmBluetooth.tpp" -class TinyGsmSim808 : public TinyGsmSim800, public TinyGsmGPS { +class TinyGsmSim808 : public TinyGsmSim800, public TinyGsmGPS, public TinyGsmBluetooth { friend class TinyGsmGPS; + friend class TinyGsmBluetooth; public: explicit TinyGsmSim808(Stream& stream) : TinyGsmSim800(stream) {} @@ -127,6 +129,40 @@ class TinyGsmSim808 : public TinyGsmSim800, public TinyGsmGPS { waitResponse(); return false; } + + /* + * Bluetooth functions + */ + + bool enableBluetoothImpl() { + sendAT(GF("+BTPOWER=1")); + if (waitResponse() != 1) { return false; } + return true; + } + + bool disableBluetoothImpl() { + sendAT(GF("+BTPOWER=0")); + if (waitResponse() != 1) { return false; } + return true; + } + + bool setBluetoothVisibilityImpl(bool visible) { + sendAT(GF("+BTVIS="), visible); + if (waitResponse() != 1) { + return false; + } + + return true; + } + + bool setBluetoothHostNameImpl(const char* name) { + sendAT(GF("+BTHOST="), name); + if (waitResponse() != 1) { + return false; + } + + return true; + } }; #endif // SRC_TINYGSMCLIENTSIM808_H_