Skip to content

Commit 73efcc6

Browse files
committed
extend write method to typed characteristics
1 parent e358f2d commit 73efcc6

5 files changed

+60
-0
lines changed

src/BLECharacteristic.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,41 @@ int BLECharacteristic::write(const uint8_t value[], int length, bool withRespons
262262
return 0;
263263
}
264264

265+
int BLECharacteristic::write(const void* value, int length, bool withResponse)
266+
{
267+
return write((const uint8_t*)value, length, withResponse);
268+
}
269+
270+
int BLECharacteristic::write(uint8_t value, bool withResponse)
271+
{
272+
return write((uint8_t*)&value, sizeof(value), withResponse);
273+
}
274+
275+
int BLECharacteristic::write(int8_t value, bool withResponse)
276+
{
277+
return write((uint8_t*)&value, sizeof(value), withResponse);
278+
}
279+
280+
int BLECharacteristic::write(uint16_t value, bool withResponse)
281+
{
282+
return write((uint8_t*)&value, sizeof(value), withResponse);
283+
}
284+
285+
int BLECharacteristic::write(int16_t value, bool withResponse)
286+
{
287+
return write((uint8_t*)&value, sizeof(value), withResponse);
288+
}
289+
290+
int BLECharacteristic::write(uint32_t value, bool withResponse)
291+
{
292+
return write((uint8_t*)&value, sizeof(value), withResponse);
293+
}
294+
295+
int BLECharacteristic::write(int32_t value, bool withResponse)
296+
{
297+
return write((uint8_t*)&value, sizeof(value), withResponse);
298+
}
299+
265300
int BLECharacteristic::writeValue(const uint8_t value[], int length, bool withResponse)
266301
{
267302
if (_local) {

src/BLECharacteristic.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ class BLECharacteristic {
7979
int writeValue(int32_t value, bool withResponse = true);
8080
int write(const uint8_t value[], int length, bool withResponse = true);
8181
int write(const char* value, bool withResponse = true);
82+
int write(const void* value, int length, bool withResponse = true);
83+
int write(uint8_t value, bool withResponse = true);
84+
int write(int8_t value, bool withResponse = true);
85+
int write(uint16_t value, bool withResponse = true);
86+
int write(int16_t value, bool withResponse = true);
87+
int write(uint32_t value, bool withResponse = true);
88+
int write(int32_t value, bool withResponse = true);
8289

8390

8491
// deprecated, use writeValue(...)

src/BLEStringCharacteristic.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ BLEStringCharacteristic::BLEStringCharacteristic(const char* uuid, unsigned char
2424
{
2525
}
2626

27+
int BLEStringCharacteristic::write(const char *value)
28+
{
29+
return BLECharacteristic::write(value);
30+
}
31+
32+
int BLEStringCharacteristic::write(const String &value)
33+
{
34+
return BLECharacteristic::write(value.c_str());
35+
}
36+
2737
int BLEStringCharacteristic::writeValue(const String& value)
2838
{
2939
return BLECharacteristic::writeValue(value.c_str());

src/BLEStringCharacteristic.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class BLEStringCharacteristic : public BLECharacteristic
2929
public:
3030
BLEStringCharacteristic(const char* uuid, unsigned char properties, int valueSize);
3131

32+
int write(const char * value);
33+
int write(const String& value);
3234
int writeValue(const String& value);
3335
int setValue(const String& value) { return writeValue(value); }
3436
String value(void);

src/BLETypedCharacteristic.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ template<typename T> class BLETypedCharacteristic : public BLECharacteristic
2727
public:
2828
BLETypedCharacteristic(const char* uuid, unsigned int permissions);
2929

30+
int write(T value);
3031
int writeValue(T value);
3132
int setValue(T value) { return writeValue(value); }
3233
T value(void);
@@ -52,6 +53,11 @@ template<typename T> BLETypedCharacteristic<T>::BLETypedCharacteristic(const cha
5253
writeValue(value);
5354
}
5455

56+
template<typename T> int BLETypedCharacteristic<T>::write(T value)
57+
{
58+
return BLECharacteristic::write((uint8_t*)&value, sizeof(T));
59+
}
60+
5561
template<typename T> int BLETypedCharacteristic<T>::writeValue(T value)
5662
{
5763
return BLECharacteristic::writeValue((uint8_t*)&value, sizeof(T));

0 commit comments

Comments
 (0)