3
3
4
4
Based on BLESerial.cpp by Voita Molda
5
5
https://github.com/sandeepmistry/arduino-BLEPeripheral/blob/master/examples/serial/BLESerial.cpp
6
+
7
+ Last updated by Jeff Hoefs: February 28th, 2016
6
8
*/
7
9
8
10
#include " BLEStream.h"
@@ -21,7 +23,6 @@ BLEStream::BLEStream(unsigned char req, unsigned char rdy, unsigned char rst) :
21
23
this ->_txCount = 0 ;
22
24
this ->_rxHead = this ->_rxTail = 0 ;
23
25
this ->_flushed = 0 ;
24
- this ->_packetTxCount = 0 ;
25
26
BLEStream::_instance = this ;
26
27
27
28
addAttribute (this ->_uartService );
@@ -111,21 +112,9 @@ void BLEStream::flush(void)
111
112
{
112
113
if (this ->_txCount == 0 ) return ;
113
114
#ifndef _VARIANT_ARDUINO_101_X_
114
- long diff = millis () - this ->_flushed ;
115
- // flush() is called approximately every 1ms or less when sending multiple packets and
116
- // otherwise no more frequently than BLESTREAM_TXBUFFER_FLUSH_INTERVAL
117
- // TODO - determine if 2 is the best value or if something higher is necessary
118
- if (diff < 2 ) {
119
- // 2 is the max number of packets that can be sent in short succession
120
- // TODO - get the max packet value programatically
121
- if (++this ->_packetTxCount >= 2 ) {
122
- // delay after 2 packets have been sent in short succession
123
- // 100ms is the minimum necessary delay value
124
- delay (100 );
125
- this ->_packetTxCount = 0 ;
126
- }
127
- } else {
128
- this ->_packetTxCount = 0 ;
115
+ // ensure there are available packets before sending
116
+ while (!this ->_txCharacteristic .canNotify ()) {
117
+ BLEPeripheral::poll ();
129
118
}
130
119
#endif
131
120
this ->_txCharacteristic .setValue (this ->_txBuffer , this ->_txCount );
0 commit comments