Skip to content

Commit 24b277a

Browse files
copercinime-no-dev
authored andcommitted
Add readFloat to BLE (#3321)
* Add readFloat * Add readFloat to BLE
1 parent c2b3f2d commit 24b277a

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

Diff for: libraries/BLE/src/BLERemoteCharacteristic.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,17 @@ uint8_t BLERemoteCharacteristic::readUInt8() {
389389
return 0;
390390
} // readUInt8
391391

392+
/**
393+
* @brief Read a float value.
394+
* @return the float value.
395+
*/
396+
float BLERemoteCharacteristic::readFloat() {
397+
std::string value = readValue();
398+
if (value.length() >= 4) {
399+
return *(float*)(value.data());
400+
}
401+
return 0.0;
402+
} // readFloat
392403

393404
/**
394405
* @brief Read the value of the remote characteristic.

Diff for: libraries/BLE/src/BLERemoteCharacteristic.h

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class BLERemoteCharacteristic {
4545
uint8_t readUInt8();
4646
uint16_t readUInt16();
4747
uint32_t readUInt32();
48+
float readFloat();
4849
void registerForNotify(notify_callback _callback, bool notifications = true);
4950
void writeValue(uint8_t* data, size_t length, bool response = false);
5051
void writeValue(std::string newValue, bool response = false);

0 commit comments

Comments
 (0)