Skip to content

Add readFloat to BLE #3321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions libraries/BLE/src/BLERemoteCharacteristic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions libraries/BLE/src/BLERemoteCharacteristic.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class BLERemoteCharacteristic {
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);
Expand Down