Skip to content

Commit 48d1b3c

Browse files
committed
able draw 16x16 image, 32x32 has some tft noise
1 parent dddb437 commit 48d1b3c

File tree

2 files changed

+47
-22
lines changed

2 files changed

+47
-22
lines changed

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

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222
#include <Adafruit_GFX.h>
2323
#include <Adafruit_ILI9341.h>
2424

25-
BLEUart bleuart; // uart over ble
25+
// Uart over BLE with large buffer to hold image, image size is
26+
// size = width x height x 3 + 6
27+
//
28+
BLEUart bleuart(1024*10);
2629

2730
/* The Image Transfer module sends the image of your choice to Bluefruit LE over UART.
2831
* Each image sent begins with
@@ -39,7 +42,7 @@ uint16_t imageHeight = 0;
3942
uint16_t imageX = 0;
4043
uint16_t imageY = 0;
4144

42-
uint16_t color_buf[256];
45+
uint16_t color_buf[512];
4346

4447
// Statistics for speed testing
4548
uint32_t rxCount = 0;
@@ -128,35 +131,47 @@ void loop()
128131
{
129132
if ( !Bluefruit.connected() ) return;
130133
if ( !bleuart.notifyEnabled() ) return;
134+
if ( !bleuart.available() ) return;
131135

132-
// extract pixel data and display on TFT
133-
uint16_t pixelNum = 0;
134-
while ( bleuart.available() >= 3 )
135-
{
136-
uint8_t red = bleuart.read();
137-
uint8_t green = bleuart.read();
138-
uint8_t blue = bleuart.read();
136+
PRINT_INT(bleuart.available());
139137

140-
color_buf[pixelNum++] = ((red & 0xF8) << 8) | ((green & 0xFC) << 3) | ( blue >> 3);
138+
// all pixel data is received
139+
if ( rxCount == 1 + 5 + imageWidth*imageHeight*3 )
140+
{
141+
uint8_t crc = bleuart.read();
142+
rxCount++;
143+
// do checksum later
141144

142-
rxCount += 3;
145+
print_speed(rxCount, rxLastTime-rxStartTime);
146+
rxCount = 0;
143147
}
144148

149+
// extract pixel data and display on TFT
150+
uint16_t pixelNum = bleuart.available() / 3;
151+
152+
// draw up to 512 pixels since color_buf array size is 512
153+
// the rest will be drawn in the next invocation of loop()
154+
pixelNum = min(pixelNum, sizeof(color_buf)/2);
155+
145156
if ( pixelNum )
146157
{
158+
PRINT_INT(pixelNum);
159+
for ( uint16_t i=0; i < pixelNum; i++)
160+
{
161+
uint8_t red = bleuart.read();
162+
uint8_t green = bleuart.read();
163+
uint8_t blue = bleuart.read();
164+
165+
color_buf[i] = ((red & 0xF8) << 8) | ((green & 0xFC) << 3) | ( blue >> 3);
166+
167+
rxCount += 3;
168+
}
169+
147170
tft.drawRGBBitmap(imageX, imageY, color_buf, imageWidth, imageHeight);
148171

149172
imageX += (imageX + pixelNum) % imageWidth;
150173
imageY += pixelNum/imageHeight;
151174
}
152-
153-
// 3 seconds has passed and there is no data received
154-
// then reset rx count
155-
if ( (rxCount > 0) && (rxLastTime + 1000 < millis()) )
156-
{
157-
print_speed(rxCount, rxLastTime-rxStartTime);
158-
rxCount = 0;
159-
}
160175
}
161176

162177
void connect_callback(uint16_t conn_handle)
@@ -202,11 +217,21 @@ void bleuart_rx_callback(uint16_t conn_hdl)
202217
rxStartTime = millis();
203218

204219
// Incorrect format, possibly corrupted data
205-
if ( bleuart.read() != '!' ) bleuart.flush();
206-
220+
if ( bleuart.read() != '!' )
221+
{
222+
PRINT_LOCATION();
223+
bleuart.flush();
224+
return;
225+
}
226+
227+
bleuart.read(); rxCount++; // skip unicode extra byte following '!'
228+
207229
imageWidth = bleuart.read16();
208230
imageHeight = bleuart.read16();
209231

232+
PRINT_INT(imageWidth);
233+
PRINT_INT(imageHeight);
234+
210235
rxCount += 5;
211236

212237
tft.fillScreen(ILI9341_BLACK);

tools/build_all.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def build_examples(variant):
2727
build_result = subprocess.run("arduino --verify {}".format(sketch), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
2828
if build_result.returncode != 0:
2929
exit_status = build_result.returncode
30-
success = "\033[31mfailed\033[0m"
30+
success = "\033[31mfailed\033[0m "
3131
fail_count += 1
3232
else:
3333
success = "\033[32msucceeded\033[0m"

0 commit comments

Comments
 (0)