Skip to content

Commit ed953a0

Browse files
gohaime-no-dev
authored andcommitted
BluetoothSerial: check return value and return number of bytes written (#1538)
1 parent 93566a4 commit ed953a0

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

Diff for: libraries/BluetoothSerial/src/BluetoothSerial.cpp

+12-9
Original file line numberDiff line numberDiff line change
@@ -220,21 +220,24 @@ int BluetoothSerial::read(void)
220220

221221
size_t BluetoothSerial::write(uint8_t c)
222222
{
223-
if (_spp_client){
224-
uint8_t buffer[1];
225-
buffer[0] = c;
226-
esp_spp_write(_spp_client, 1, buffer);
227-
return 1;
223+
if (!_spp_client){
224+
return 0;
228225
}
229-
return -1;
226+
227+
uint8_t buffer[1];
228+
buffer[0] = c;
229+
esp_err_t err = esp_spp_write(_spp_client, 1, buffer);
230+
return (err == ESP_OK) ? 1 : 0;
230231
}
231232

232233
size_t BluetoothSerial::write(const uint8_t *buffer, size_t size)
233234
{
234-
if (_spp_client){
235-
esp_spp_write(_spp_client, size, (uint8_t *)buffer);
235+
if (!_spp_client){
236+
return 0;
236237
}
237-
return size;
238+
239+
esp_err_t err = esp_spp_write(_spp_client, size, (uint8_t *)buffer);
240+
return (err == ESP_OK) ? size : 0;
238241
}
239242

240243
void BluetoothSerial::flush()

0 commit comments

Comments
 (0)