Skip to content

Commit d8f91cd

Browse files
committed
increase color_buf to prevent bleuart buffer overflow
Able to draw 240x240
1 parent 454db84 commit d8f91cd

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

libraries/Bluefruit52Lib/examples/Peripheral/image_upload/image_upload.ino

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ BLEUart bleuart(1024*10);
2727

2828
/* The Image Transfer module sends the image of your choice to Bluefruit LE over UART.
2929
* Each image sent begins with
30-
* - A single byte char '!' (0x21)
30+
* - A single byte char '!' (0x21) followed by 'I' helper for image
3131
* - Image width (uint16 little endian, 2 bytes)
3232
* - Image height (uint16 little endian, 2 bytes)
3333
* - Pixel data encoded as RGB 24-bit and suffixed by a single byte CRC.
3434
*
35-
* Format: [ '!' ] [ uint16 width ] [ uint16 height ] [ r g b ] [ r g b ] [ r g b ] … [ CRC ]
35+
* Format: [ '!' ] [ 'I' ] [ uint16 width ] [ uint16 height ] [ r g b ] [ r g b ] [ r g b ] … [ CRC ]
3636
*/
3737

3838
uint16_t imageWidth = 0;
@@ -42,7 +42,9 @@ uint16_t imageY = 0;
4242

4343
uint32_t totalPixel = 0; // received pixel
4444

45-
uint16_t color_buf[512];
45+
// color buf must be large enough to consume incoming data fast enough
46+
// otherwise bleuart fifo could be overflow and start dropping data
47+
uint16_t color_buf[2048];
4648

4749
// Statistics for speed testing
4850
uint32_t rxStartTime = 0;
@@ -81,7 +83,7 @@ void setup()
8183
Bluefruit.configPrphBandwidth(BANDWIDTH_MAX);
8284

8385
Bluefruit.begin();
84-
Bluefruit.setTxPower(4); // Check bluefruit.h for supported values
86+
Bluefruit.setTxPower(8); // Check bluefruit.h for supported values
8587
Bluefruit.setName("Bluefruit52");
8688
Bluefruit.Periph.setConnectCallback(connect_callback);
8789
Bluefruit.Periph.setDisconnectCallback(disconnect_callback);
@@ -235,11 +237,11 @@ void bleuart_rx_callback(uint16_t conn_hdl)
235237
{
236238
rxStartTime = millis();
237239

238-
// Skip all data until '!' is found
240+
// Skip all data until '!I' is found
239241
while( bleuart.available() && bleuart.read() != '!' ) { }
240-
if ( !bleuart.available() ) return;
242+
if (bleuart.read() != 'I') return;
241243

242-
bleuart.read(); // skip unicode extra byte following '!'
244+
if ( !bleuart.available() ) return;
243245

244246
imageWidth = bleuart.read16();
245247
imageHeight = bleuart.read16();

libraries/Bluefruit52Lib/examples/Peripheral/throughput/throughput.ino

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ void bleuart_rx_callback(uint16_t conn_hdl)
162162
rxCount += count;
163163
bleuart.flush(); // empty rx fifo
164164

165-
Serial.printf("RX %d bytes\n", count);
165+
// Serial.printf("RX %d bytes\n", count);
166166
}
167167

168168
void bleuart_notify_callback(uint16_t conn_hdl, bool enabled)
@@ -232,9 +232,6 @@ void loop(void)
232232
print_speed("Received ", rxCount, rxLastTime-rxStartTime);
233233
rxCount = 0;
234234
}
235-
236-
// Bluefruit.disconnect(0);
237-
// delay(2000);
238235
}
239236
}
240237

0 commit comments

Comments
 (0)