提交 ed953a0d 编写于 作者: G Gottfried Haider 提交者: Me No Dev

BluetoothSerial: check return value and return number of bytes written (#1538)

上级 93566a4f
...@@ -220,21 +220,24 @@ int BluetoothSerial::read(void) ...@@ -220,21 +220,24 @@ int BluetoothSerial::read(void)
size_t BluetoothSerial::write(uint8_t c) size_t BluetoothSerial::write(uint8_t c)
{ {
if (_spp_client){ if (!_spp_client){
uint8_t buffer[1]; return 0;
buffer[0] = c;
esp_spp_write(_spp_client, 1, buffer);
return 1;
} }
return -1;
uint8_t buffer[1];
buffer[0] = c;
esp_err_t err = esp_spp_write(_spp_client, 1, buffer);
return (err == ESP_OK) ? 1 : 0;
} }
size_t BluetoothSerial::write(const uint8_t *buffer, size_t size) size_t BluetoothSerial::write(const uint8_t *buffer, size_t size)
{ {
if (_spp_client){ if (!_spp_client){
esp_spp_write(_spp_client, size, (uint8_t *)buffer); return 0;
} }
return size;
esp_err_t err = esp_spp_write(_spp_client, size, (uint8_t *)buffer);
return (err == ESP_OK) ? size : 0;
} }
void BluetoothSerial::flush() void BluetoothSerial::flush()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册