Skip to content

Commit

Permalink
Merge pull request #146 from facchinm/writeWithoutResponse
Browse files Browse the repository at this point in the history
Overload writeValue to allow forced write without response
  • Loading branch information
Paolo Calao authored Dec 18, 2020
2 parents 953f973 + 8a167ad commit be365c9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 33 deletions.
36 changes: 18 additions & 18 deletions src/BLECharacteristic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,65 +234,65 @@ int BLECharacteristic::readValue(int32_t& value)
return readValue((uint8_t*)&value, sizeof(value));
}

int BLECharacteristic::writeValue(const uint8_t value[], int length)
int BLECharacteristic::writeValue(const uint8_t value[], int length, bool withResponse)
{
if (_local) {
return _local->writeValue(value, length);
}

if (_remote) {
return _remote->writeValue(value, length);
return _remote->writeValue(value, length, withResponse);
}

return 0;
}

int BLECharacteristic::writeValue(const void* value, int length)
int BLECharacteristic::writeValue(const void* value, int length, bool withResponse)
{
return writeValue((const uint8_t*)value, length);
return writeValue((const uint8_t*)value, length, withResponse);
}

int BLECharacteristic::writeValue(const char* value)
int BLECharacteristic::writeValue(const char* value, bool withResponse)
{
if (_local) {
return _local->writeValue(value);
}

if (_remote) {
return _remote->writeValue(value);
return _remote->writeValue(value, withResponse);
}

return 0;
}

int BLECharacteristic::writeValue(uint8_t value)
int BLECharacteristic::writeValue(uint8_t value, bool withResponse)
{
return writeValue((uint8_t*)&value, sizeof(value));
return writeValue((uint8_t*)&value, sizeof(value), withResponse);
}

int BLECharacteristic::writeValue(int8_t value)
int BLECharacteristic::writeValue(int8_t value, bool withResponse)
{
return writeValue((uint8_t*)&value, sizeof(value));
return writeValue((uint8_t*)&value, sizeof(value), withResponse);
}

int BLECharacteristic::writeValue(uint16_t value)
int BLECharacteristic::writeValue(uint16_t value, bool withResponse)
{
return writeValue((uint8_t*)&value, sizeof(value));
return writeValue((uint8_t*)&value, sizeof(value), withResponse);
}

int BLECharacteristic::writeValue(int16_t value)
int BLECharacteristic::writeValue(int16_t value, bool withResponse)
{
return writeValue((uint8_t*)&value, sizeof(value));
return writeValue((uint8_t*)&value, sizeof(value), withResponse);
}

int BLECharacteristic::writeValue(uint32_t value)
int BLECharacteristic::writeValue(uint32_t value, bool withResponse)
{
return writeValue((uint8_t*)&value, sizeof(value));
return writeValue((uint8_t*)&value, sizeof(value), withResponse);
}

int BLECharacteristic::writeValue(int32_t value)
int BLECharacteristic::writeValue(int32_t value, bool withResponse)
{
return writeValue((uint8_t*)&value, sizeof(value));
return writeValue((uint8_t*)&value, sizeof(value), withResponse);
}

int BLECharacteristic::broadcast()
Expand Down
18 changes: 9 additions & 9 deletions src/BLECharacteristic.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ class BLECharacteristic {
int readValue(uint32_t& value);
int readValue(int32_t& value);

int writeValue(const uint8_t value[], int length);
int writeValue(const void* value, int length);
int writeValue(const char* value);
int writeValue(uint8_t value);
int writeValue(int8_t value);
int writeValue(uint16_t value);
int writeValue(int16_t value);
int writeValue(uint32_t value);
int writeValue(int32_t value);
int writeValue(const uint8_t value[], int length, bool withResponse = true);
int writeValue(const void* value, int length, bool withResponse = true);
int writeValue(const char* value, bool withResponse = true);
int writeValue(uint8_t value, bool withResponse = true);
int writeValue(int8_t value, bool withResponse = true);
int writeValue(uint16_t value, bool withResponse = true);
int writeValue(int16_t value, bool withResponse = true);
int writeValue(uint32_t value, bool withResponse = true);
int writeValue(int32_t value, bool withResponse = true);

// deprecated, use writeValue(...)
int setValue(const uint8_t value[], int length) { return writeValue(value, length); }
Expand Down
8 changes: 4 additions & 4 deletions src/remote/BLERemoteCharacteristic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ uint8_t BLERemoteCharacteristic::operator[] (int offset) const
return 0;
}

int BLERemoteCharacteristic::writeValue(const uint8_t value[], int length)
int BLERemoteCharacteristic::writeValue(const uint8_t value[], int length, bool withResponse)
{
if (!ATT.connected(_connectionHandle)) {
return false;
Expand All @@ -104,7 +104,7 @@ int BLERemoteCharacteristic::writeValue(const uint8_t value[], int length)
return 0;
}

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

Expand Down Expand Up @@ -133,9 +133,9 @@ int BLERemoteCharacteristic::writeValue(const uint8_t value[], int length)
return 0;
}

int BLERemoteCharacteristic::writeValue(const char* value)
int BLERemoteCharacteristic::writeValue(const char* value, bool withResponse)
{
return writeValue((uint8_t*)value, strlen(value));
return writeValue((uint8_t*)value, strlen(value), withResponse);
}

bool BLERemoteCharacteristic::valueUpdated()
Expand Down
4 changes: 2 additions & 2 deletions src/remote/BLERemoteCharacteristic.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class BLERemoteCharacteristic : public BLERemoteAttribute {
int valueLength() const;
uint8_t operator[] (int offset) const;

int writeValue(const uint8_t value[], int length);
int writeValue(const char* value);
int writeValue(const uint8_t value[], int length, bool withResponse = true);
int writeValue(const char* value, bool withResponse = true);

bool valueUpdated();
bool updatedValueRead();
Expand Down

0 comments on commit be365c9

Please sign in to comment.