Merge pull request #488 from adrianca88/SIM808_bt_support
First SIM808 bluetooth support commit. Template class and basic functionality
This commit is contained in:
57
src/TinyGsmBluetooth.tpp
Normal file
57
src/TinyGsmBluetooth.tpp
Normal file
@@ -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 modemType>
|
||||
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<const modemType&>(*this);
|
||||
}
|
||||
inline modemType& thisModem() {
|
||||
return static_cast<modemType&>(*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_
|
@@ -12,9 +12,11 @@
|
||||
|
||||
#include "TinyGsmClientSIM800.h"
|
||||
#include "TinyGsmGPS.tpp"
|
||||
#include "TinyGsmBluetooth.tpp"
|
||||
|
||||
class TinyGsmSim808 : public TinyGsmSim800, public TinyGsmGPS<TinyGsmSim808> {
|
||||
class TinyGsmSim808 : public TinyGsmSim800, public TinyGsmGPS<TinyGsmSim808>, public TinyGsmBluetooth<TinyGsmSim808> {
|
||||
friend class TinyGsmGPS<TinyGsmSim808>;
|
||||
friend class TinyGsmBluetooth<TinyGsmSim808>;
|
||||
|
||||
public:
|
||||
explicit TinyGsmSim808(Stream& stream) : TinyGsmSim800(stream) {}
|
||||
@@ -127,6 +129,40 @@ class TinyGsmSim808 : public TinyGsmSim800, public TinyGsmGPS<TinyGsmSim808> {
|
||||
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_
|
||||
|
Reference in New Issue
Block a user