Skip to content

Commit 1ce065e

Browse files
committed
add BLEUuid toString()
1 parent f152527 commit 1ce065e

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

libraries/Bluefruit52Lib/src/BLEUuid.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,25 @@ bool BLEUuid::begin(void)
151151
return true;
152152
}
153153

154+
String BLEUuid::toString(void) const
155+
{
156+
if (_str) return _str;
157+
158+
char result[38];
159+
if (this->size() == 16)
160+
{
161+
sprintf(result, "%02X:%02X", _uuid.uuid);
162+
}else
163+
{
164+
// uuid is little endian
165+
sprintf(result, "%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X",
166+
_uuid128[15], _uuid128[14], _uuid128[13], _uuid128[12], _uuid128[11], _uuid128[10], _uuid128[ 9], _uuid128[ 8],
167+
_uuid128[ 7], _uuid128[ 6], _uuid128[ 5], _uuid128[ 4], _uuid128[ 3], _uuid128[ 2], _uuid128[ 1], _uuid128[ 0]);
168+
}
169+
170+
return result;
171+
}
172+
154173
//--------------------------------------------------------------------+
155174
// Set & Get
156175
//--------------------------------------------------------------------+

libraries/Bluefruit52Lib/src/BLEUuid.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ class BLEUuid
6666
// Add UUID128 if needed, in case of UUID16, no actions is required
6767
bool begin(void);
6868

69+
String toString(void) const;
70+
6971
bool operator==(const BLEUuid& uuid) const;
7072
bool operator!=(const BLEUuid& uuid) const;
7173
bool operator==(const ble_uuid_t uuid) const;

0 commit comments

Comments
 (0)