Characteristic¶
A characteristic holds a value. This value is represented by a std::vector<std::byte>
byte vector.
A characteristic can also be set with properties to read, write, and notify. feeling-blue provides
the tools to read, write, and be notified from characteristics.
-
class
bluetooth
::
Characteristic
¶ Represents a characteristic.
Public Functions
-
template<typename
T
>
Tread
()¶ Read the characteristic. Compatible template types are listed at
supported template types
section.Recommended default usage to return a vector of bytes:
std::vector<std::byte> bytes = some_char->read<std::vector<std::byte>>();
You can also return an int if you know your characteristic value is a 4-byte integer in little-endian order:
int x = some_char->read<int>();
- Return
a byte vector.
- Template Parameters
T
: the type your want the data to be read as.
-
template<typename
T
>
voidwrite_without_response
(T data)¶ Write to characteristic using a vector of bytes. Will not print error if write fails. You can transmit more data with this method than write_with_response(). Compatible template types are listed at
supported template types
section.examples:
std::vector<std::byte> data = {...};
some_char->write_without_response<std::byte>(data);
some_char->write_without_response<int>(1);
- Note
asynchronous.
- Parameters
data
: byte vector of your data.
-
template<typename
T
>
voidwrite_with_response
(T data)¶ Write to characteristic with response. If the write_without_response fails and verbose mode is on, the console will print an error and the program will continue running. Compatible template types are listed at
supported template types
section.examples:
std::vector<std::byte> data = {...};
some_char->write_with_response<std::byte>(data);
some_char->write_with_response<int>(1);
- Parameters
data
: byte vector of your data.
-
void
notify
(const std::function<void(std::vector<std::byte>)> &callback)¶ Enable notifications from the characteristic and set callback function to do something with the data when the device notifies.
- Note
this method returns when the callback is successfully set. Your callback is asynchronously called whenever a notification is triggered.
- Parameters
callback
: function to do something with notification data.
-
template<typename