33
44 Based on BLESerial.cpp by Voita Molda
55 https://github.com/sandeepmistry/arduino-BLEPeripheral/blob/master/examples/serial/BLESerial.cpp
6+
7+ Last updated by Jeff Hoefs: February 28th, 2016
68 */
79
810#include " BLEStream.h"
@@ -21,7 +23,6 @@ BLEStream::BLEStream(unsigned char req, unsigned char rdy, unsigned char rst) :
2123 this ->_txCount = 0 ;
2224 this ->_rxHead = this ->_rxTail = 0 ;
2325 this ->_flushed = 0 ;
24- this ->_packetTxCount = 0 ;
2526 BLEStream::_instance = this ;
2627
2728 addAttribute (this ->_uartService );
@@ -111,21 +112,9 @@ void BLEStream::flush(void)
111112{
112113 if (this ->_txCount == 0 ) return ;
113114#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 ();
129118 }
130119#endif
131120 this ->_txCharacteristic .setValue (this ->_txBuffer , this ->_txCount );
0 commit comments