Skip to content

Commit c37292f

Browse files
temp fix for config query issue
1 parent 1b61d8f commit c37292f

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

utility/BLEStream.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ BLEStream::BLEStream(unsigned char req, unsigned char rdy, unsigned char rst) :
2121
this->_txCount = 0;
2222
this->_rxHead = this->_rxTail = 0;
2323
this->_flushed = 0;
24+
this->_packetTxCount = 0;
2425
BLEStream::_instance = this;
2526

2627
addAttribute(this->_uartService);
@@ -109,6 +110,24 @@ int BLEStream::read(void)
109110
void BLEStream::flush(void)
110111
{
111112
if (this->_txCount == 0) return;
113+
#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;
129+
}
130+
#endif
112131
this->_txCharacteristic.setValue(this->_txBuffer, this->_txCount);
113132
this->_flushed = millis();
114133
this->_txCount = 0;

utility/BLEStream.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#if defined(_VARIANT_ARDUINO_101_X_)
2222
#define BLESTREAM_TXBUFFER_FLUSH_INTERVAL 30
2323
#else
24-
#define BLESTREAM_TXBUFFER_FLUSH_INTERVAL 50
24+
#define BLESTREAM_TXBUFFER_FLUSH_INTERVAL 80
2525
#endif
2626

2727
class BLEStream : public BLEPeripheral, public Stream
@@ -53,6 +53,8 @@ class BLEStream : public BLEPeripheral, public Stream
5353
size_t _txCount;
5454
unsigned char _txBuffer[_MAX_ATTR_DATA_LEN_];
5555

56+
uint8_t _packetTxCount;
57+
5658
BLEService _uartService = BLEService("6E400001-B5A3-F393-E0A9-E50E24DCCA9E");
5759
BLEDescriptor _uartNameDescriptor = BLEDescriptor("2901", "UART");
5860
BLECharacteristic _rxCharacteristic = BLECharacteristic("6E400002-B5A3-F393-E0A9-E50E24DCCA9E", BLEWriteWithoutResponse, _MAX_ATTR_DATA_LEN_);

0 commit comments

Comments
 (0)