From 24b277ad92d1f769551cb9bf5f07633e2f24950f Mon Sep 17 00:00:00 2001 From: copercini Date: Sun, 6 Oct 2019 11:28:53 -0300 Subject: [PATCH] Add readFloat to BLE (#3321) * Add readFloat * Add readFloat to BLE --- libraries/BLE/src/BLERemoteCharacteristic.cpp | 11 +++++++++++ libraries/BLE/src/BLERemoteCharacteristic.h | 1 + 2 files changed, 12 insertions(+) diff --git a/libraries/BLE/src/BLERemoteCharacteristic.cpp b/libraries/BLE/src/BLERemoteCharacteristic.cpp index 840076f8..fe455919 100644 --- a/libraries/BLE/src/BLERemoteCharacteristic.cpp +++ b/libraries/BLE/src/BLERemoteCharacteristic.cpp @@ -389,6 +389,17 @@ uint8_t BLERemoteCharacteristic::readUInt8() { return 0; } // readUInt8 +/** + * @brief Read a float value. + * @return the float value. + */ +float BLERemoteCharacteristic::readFloat() { + std::string value = readValue(); + if (value.length() >= 4) { + return *(float*)(value.data()); + } + return 0.0; +} // readFloat /** * @brief Read the value of the remote characteristic. diff --git a/libraries/BLE/src/BLERemoteCharacteristic.h b/libraries/BLE/src/BLERemoteCharacteristic.h index fbcafe8d..1d0db1c3 100644 --- a/libraries/BLE/src/BLERemoteCharacteristic.h +++ b/libraries/BLE/src/BLERemoteCharacteristic.h @@ -45,6 +45,7 @@ public: uint8_t readUInt8(); uint16_t readUInt16(); uint32_t readUInt32(); + float readFloat(); void registerForNotify(notify_callback _callback, bool notifications = true); void writeValue(uint8_t* data, size_t length, bool response = false); void writeValue(std::string newValue, bool response = false);