Skip to content

Commit 62f276c

Browse files
committed
Overload writeValue to allow forced write without response
When a characteristic is declared (Write | WriteWithoutResponse) the code always creates a request and expects a response. By setting withResponse=false the user can bypass the request and write a responseless command. Reworks and supersedes #72
1 parent 840501e commit 62f276c

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

src/BLECharacteristic.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,22 +234,22 @@ int BLECharacteristic::readValue(int32_t& value)
234234
return readValue((uint8_t*)&value, sizeof(value));
235235
}
236236

237-
int BLECharacteristic::writeValue(const uint8_t value[], int length)
237+
int BLECharacteristic::writeValue(const uint8_t value[], int length, bool withResponse)
238238
{
239239
if (_local) {
240240
return _local->writeValue(value, length);
241241
}
242242

243243
if (_remote) {
244-
return _remote->writeValue(value, length);
244+
return _remote->writeValue(value, length, withResponse);
245245
}
246246

247247
return 0;
248248
}
249249

250-
int BLECharacteristic::writeValue(const void* value, int length)
250+
int BLECharacteristic::writeValue(const void* value, int length, bool withResponse)
251251
{
252-
return writeValue((const uint8_t*)value, length);
252+
return writeValue((const uint8_t*)value, length, withResponse);
253253
}
254254

255255
int BLECharacteristic::writeValue(const char* value)

src/BLECharacteristic.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ class BLECharacteristic {
6868
int readValue(uint32_t& value);
6969
int readValue(int32_t& value);
7070

71-
int writeValue(const uint8_t value[], int length);
72-
int writeValue(const void* value, int length);
71+
int writeValue(const uint8_t value[], int length, bool withResponse = true);
72+
int writeValue(const void* value, int length, bool withResponse = true);
7373
int writeValue(const char* value);
7474
int writeValue(uint8_t value);
7575
int writeValue(int8_t value);

src/remote/BLERemoteCharacteristic.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ uint8_t BLERemoteCharacteristic::operator[] (int offset) const
8585
return 0;
8686
}
8787

88-
int BLERemoteCharacteristic::writeValue(const uint8_t value[], int length)
88+
int BLERemoteCharacteristic::writeValue(const uint8_t value[], int length, bool withResponse)
8989
{
9090
if (!ATT.connected(_connectionHandle)) {
9191
return false;
@@ -104,7 +104,7 @@ int BLERemoteCharacteristic::writeValue(const uint8_t value[], int length)
104104
return 0;
105105
}
106106

107-
if (_properties & BLEWrite) {
107+
if ((_properties & BLEWrite) && withResponse) {
108108
uint8_t resp[4];
109109
int respLength = ATT.writeReq(_connectionHandle, _valueHandle, value, length, resp);
110110

src/remote/BLERemoteCharacteristic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class BLERemoteCharacteristic : public BLERemoteAttribute {
3838
int valueLength() const;
3939
uint8_t operator[] (int offset) const;
4040

41-
int writeValue(const uint8_t value[], int length);
41+
int writeValue(const uint8_t value[], int length, bool withResponse = true);
4242
int writeValue(const char* value);
4343

4444
bool valueUpdated();

0 commit comments

Comments
 (0)