diff options
author | chegewara <imperiaonline4@gmail.com> | 2018-11-30 10:59:14 +0100 |
---|---|---|
committer | chegewara <imperiaonline4@gmail.com> | 2018-11-30 10:59:14 +0100 |
commit | 934702b6169b92c71cbc850876fd17fb9ee3236d (patch) | |
tree | 048df4f7106cd4a574b609a13e62a36567f5a322 /src/BLERemoteDescriptor.cpp | |
parent | Upload of 0.4.16 (diff) | |
download | thermostat-934702b6169b92c71cbc850876fd17fb9ee3236d.tar.gz thermostat-934702b6169b92c71cbc850876fd17fb9ee3236d.tar.bz2 thermostat-934702b6169b92c71cbc850876fd17fb9ee3236d.zip |
Changes, bugfixes and updgrades. Library is ready to work with arduino-esp32 v1.0.1.
Diffstat (limited to 'src/BLERemoteDescriptor.cpp')
-rw-r--r-- | src/BLERemoteDescriptor.cpp | 42 |
1 files changed, 19 insertions, 23 deletions
diff --git a/src/BLERemoteDescriptor.cpp b/src/BLERemoteDescriptor.cpp index 4d14ba8..96a8a57 100644 --- a/src/BLERemoteDescriptor.cpp +++ b/src/BLERemoteDescriptor.cpp @@ -9,12 +9,15 @@ #include <sstream> #include "BLERemoteDescriptor.h" #include "GeneralUtils.h" -#include <esp_log.h> -#ifdef ARDUINO_ARCH_ESP32 +#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG) #include "esp32-hal-log.h" +#define LOG_TAG "" +#else +#include "esp_log.h" +static const char* LOG_TAG = "BLERemoteDescriptor"; #endif -static const char* LOG_TAG = "BLERemoteDescriptor"; + BLERemoteDescriptor::BLERemoteDescriptor( @@ -55,7 +58,7 @@ BLEUUID BLERemoteDescriptor::getUUID() { } // getUUID -std::string BLERemoteDescriptor::readValue(void) { +std::string BLERemoteDescriptor::readValue() { ESP_LOGD(LOG_TAG, ">> readValue: %s", toString().c_str()); // Check to see that we are connected. @@ -87,28 +90,28 @@ std::string BLERemoteDescriptor::readValue(void) { } // readValue -uint8_t BLERemoteDescriptor::readUInt8(void) { +uint8_t BLERemoteDescriptor::readUInt8() { std::string value = readValue(); if (value.length() >= 1) { - return (uint8_t)value[0]; + return (uint8_t) value[0]; } return 0; } // readUInt8 -uint16_t BLERemoteDescriptor::readUInt16(void) { +uint16_t BLERemoteDescriptor::readUInt16() { std::string value = readValue(); if (value.length() >= 2) { - return *(uint16_t*)(value.data()); + return *(uint16_t*) value.data(); } return 0; } // readUInt16 -uint32_t BLERemoteDescriptor::readUInt32(void) { +uint32_t BLERemoteDescriptor::readUInt32() { std::string value = readValue(); if (value.length() >= 4) { - return *(uint32_t*)(value.data()); + return *(uint32_t*) value.data(); } return 0; } // readUInt32 @@ -118,7 +121,7 @@ uint32_t BLERemoteDescriptor::readUInt32(void) { * @brief Return a string representation of this BLE Remote Descriptor. * @retun A string representation of this BLE Remote Descriptor. */ -std::string BLERemoteDescriptor::toString(void) { +std::string BLERemoteDescriptor::toString() { std::stringstream ss; ss << "handle: " << getHandle() << ", uuid: " << getUUID().toString(); return ss.str(); @@ -131,10 +134,7 @@ std::string BLERemoteDescriptor::toString(void) { * @param [in] length The length of the data to send. * @param [in] response True if we expect a response. */ -void BLERemoteDescriptor::writeValue( - uint8_t* data, - size_t length, - bool response) { +void BLERemoteDescriptor::writeValue(uint8_t* data, size_t length, bool response) { ESP_LOGD(LOG_TAG, ">> writeValue: %s", toString().c_str()); // Check to see that we are connected. if (!getRemoteCharacteristic()->getRemoteService()->getClient()->isConnected()) { @@ -148,7 +148,7 @@ void BLERemoteDescriptor::writeValue( getHandle(), length, // Data length data, // Data - ESP_GATT_WRITE_TYPE_NO_RSP, + response ? ESP_GATT_WRITE_TYPE_RSP : ESP_GATT_WRITE_TYPE_NO_RSP, ESP_GATT_AUTH_REQ_NONE ); if (errRc != ESP_OK) { @@ -163,10 +163,8 @@ void BLERemoteDescriptor::writeValue( * @param [in] newValue The data to send to the remote descriptor. * @param [in] response True if we expect a response. */ -void BLERemoteDescriptor::writeValue( - std::string newValue, - bool response) { - writeValue(newValue.data(), newValue.length()); +void BLERemoteDescriptor::writeValue(std::string newValue, bool response) { + writeValue((uint8_t*) newValue.data(), newValue.length(), response); } // writeValue @@ -175,9 +173,7 @@ void BLERemoteDescriptor::writeValue( * @param [in] The single byte to write. * @param [in] True if we expect a response. */ -void BLERemoteDescriptor::writeValue( - uint8_t newValue, - bool response) { +void BLERemoteDescriptor::writeValue(uint8_t newValue, bool response) { writeValue(&newValue, 1, response); } // writeValue |