Skip to content

Commit ee58a58

Browse files
committed
improved documentation of template types
1 parent d50681c commit ee58a58

File tree

6 files changed

+37
-24
lines changed

6 files changed

+37
-24
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ int main() {
107107

108108
## Upcoming features:
109109
- methods to get status of peripherals, characteristics, etc
110-
- better error logging
111110
- Windows support
112111

113112
## Help & bug reports

docs/demo/demo.rst

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -248,20 +248,7 @@ thread-safe, this applies to both member and non-member functions.
248248

249249
.. _supported-template-types:
250250

251-
Supported template types
252-
========================
253-
254-
Primitive:
255-
256-
- uint8_t
257-
- int
258-
- float
259-
- double
260-
261-
Non Primitive:
262-
263-
- std::string
264-
- std::vector<std::byte>
251+
.. include:: ../template_types.rst
265252

266253

267254

docs/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
:maxdepth: 4
2424
:hidden:
2525

26-
API/API
2726
API/central
2827
API/peripheral
2928
API/service
30-
API/characteristic
29+
API/characteristic
30+
template_types

docs/template_types.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Supported Template Types
2+
========================
3+
4+
Primitive:
5+
6+
- uint8_t
7+
- int
8+
- float
9+
- double
10+
11+
Non Primitive:
12+
13+
- std::string
14+
- std::vector<std::byte>

include/characteristic.h

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,15 @@ namespace bluetooth {
3333

3434
/**
3535
* Read the characteristic.
36+
* Compatible template types are listed at `supported template types` section.
3637
*
38+
* Recommended default usage to return a vector of bytes:
39+
* `std::vector<std::byte> bytes = some_char->read<std::vector<std::byte>>();`
40+
*
41+
* You can also return an int if you know your characteristic value is a 4-byte integer in little-endian order:
42+
* `int x = some_char->read<int>();`
3743
* @tparam T the type your want the data to be read as.
3844
*
39-
* @note blocking.
4045
* @return a byte vector.
4146
*/
4247
template<typename T>
@@ -46,6 +51,12 @@ namespace bluetooth {
4651
/**
4752
* Write to characteristic using a vector of bytes. Will not print error if write fails.
4853
* You can transmit more data with this method than write_with_response().
54+
* Compatible template types are listed at `supported template types` section.
55+
*
56+
* examples:
57+
* `std::vector<std::byte> data = {...};`
58+
* `some_char->write_without_response<std::byte>(data);`
59+
* `some_char->write_without_response<int>(1);`
4960
*
5061
* @note asynchronous.
5162
* @param data byte vector of your data.
@@ -60,8 +71,14 @@ namespace bluetooth {
6071
/**
6172
* Write to characteristic with response. If the write_without_response fails and verbose mode is on,
6273
* the console will print an error and the program will continue running.
74+
* Compatible template types are listed at `supported template types` section.
6375
*
64-
* @param byte vector of your data.
76+
* examples:
77+
* `std::vector<std::byte> data = {...};`
78+
* `some_char->write_with_response<std::byte>(data);`
79+
* `some_char->write_with_response<int>(1);`
80+
*
81+
* @param data byte vector of your data.
6582
*/
6683
template<typename T>
6784
void write_with_response(T data);

macOS/src/model/characteristic_impl.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,7 @@ namespace bluetooth {
6767
};
6868
///@endcond
6969

70-
/**
71-
* Creates instance of specialized template to return either T or vector<T>.
72-
* @tparam T type.
73-
* @return T or vector<T>
74-
*/
70+
7571
template<typename T>
7672
T read() {
7773
return Getter<T>(this).get();

0 commit comments

Comments
 (0)