Skip to content

Commit f0a1075

Browse files
Merge pull request #4990 from akosthekiss/ble-uart-flush
Add flush to the BLE UART Service
2 parents 5a01858 + 8035ddc commit f0a1075

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

features/FEATURE_BLE/ble/services/UARTService.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,19 @@ class UARTService {
140140
return write(str, strlen(str));
141141
}
142142

143+
/**
144+
* Flush sendBuffer, i.e., forcefully write its contents to the UART RX
145+
* characteristic even if the buffer is not full.
146+
*/
147+
void flush() {
148+
if (ble.getGapState().connected) {
149+
if (sendBufferIndex != 0) {
150+
ble.gattServer().write(getRXCharacteristicHandle(), static_cast<const uint8_t *>(sendBuffer), sendBufferIndex);
151+
sendBufferIndex = 0;
152+
}
153+
}
154+
}
155+
143156
/**
144157
* Override for Stream::_putc().
145158
* @param c

0 commit comments

Comments
 (0)