First SIM808 support commit. Added template base class and some 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 "TinyGsmClientSIM800.h"
|
||||||
#include "TinyGsmGPS.tpp"
|
#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 TinyGsmGPS<TinyGsmSim808>;
|
||||||
|
friend class TinyGsmBluetooth<TinyGsmSim808>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit TinyGsmSim808(Stream& stream) : TinyGsmSim800(stream) {}
|
explicit TinyGsmSim808(Stream& stream) : TinyGsmSim800(stream) {}
|
||||||
@@ -127,6 +129,40 @@ class TinyGsmSim808 : public TinyGsmSim800, public TinyGsmGPS<TinyGsmSim808> {
|
|||||||
waitResponse();
|
waitResponse();
|
||||||
return false;
|
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_
|
#endif // SRC_TINYGSMCLIENTSIM808_H_
|
||||||
|
Reference in New Issue
Block a user