Skip to content

Commit aa55beb

Browse files
committed
clean up
1 parent e23c63f commit aa55beb

File tree

1 file changed

+36
-12
lines changed

1 file changed

+36
-12
lines changed

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

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ BLEUart bleuart; // uart over ble
3636

3737
uint16_t imageWidth = 0;
3838
uint16_t imageHeight = 0;
39+
uint16_t imageX = 0;
40+
uint16_t imageY = 0;
41+
42+
uint16_t color_buf[256];
3943

4044
// Statistics for speed testing
4145
uint32_t rxCount = 0;
@@ -47,9 +51,7 @@ uint32_t rxLastTime = 0;
4751
#define TFT_CS 31
4852
#define STMPE_CS 30
4953
#define SD_CS 27
50-
#endif
51-
52-
#ifdef ARDUINO_NRF52840_FEATHER
54+
#else
5355
#define TFT_DC 10
5456
#define TFT_CS 9
5557
#define STMPE_CS 6
@@ -86,10 +88,6 @@ void setup()
8688
// Set up and start advertising
8789
startAdv();
8890

89-
// splash screen effect
90-
delay(100);
91-
92-
9391
tft.println("Advertising ... ");
9492
}
9593

@@ -124,6 +122,30 @@ void startAdv(void)
124122

125123
void loop()
126124
{
125+
if ( !Bluefruit.connected() ) return;
126+
if ( !bleuart.notifyEnabled() ) return;
127+
128+
// extract pixel data and display on TFT
129+
uint16_t pixelNum = 0;
130+
while ( bleuart.available() >= 3 )
131+
{
132+
uint8_t red = bleuart.read();
133+
uint8_t green = bleuart.read();
134+
uint8_t blue = bleuart.read();
135+
136+
color_buf[pixelNum++] = ((red & 0xF8) << 8) | ((green & 0xFC) << 3) | ( blue >> 3);
137+
138+
rxCount += 3;
139+
}
140+
141+
if ( pixelNum )
142+
{
143+
tft.drawRGBBitmap(imageX, imageY, color_buf, imageWidth, imageHeight);
144+
145+
imageX += (imageX + pixelNum) % imageWidth;
146+
imageY += pixelNum/imageHeight;
147+
}
148+
127149
// 3 seconds has passed and there is no data received
128150
// then reset rx count
129151
if ( (rxCount > 0) && (rxLastTime + 1000 < millis()) )
@@ -170,21 +192,23 @@ void bleuart_rx_callback(uint16_t conn_hdl)
170192

171193
rxLastTime = millis();
172194

173-
// first packet
195+
// first packet: reset time, extract Image Width & Height
174196
if ( rxCount == 0 )
175197
{
176198
rxStartTime = millis();
177199

178200
// Incorrect format, possibly corrupted data
179201
if ( bleuart.read() != '!' ) bleuart.flush();
180-
rxCount++;
202+
203+
imageWidth = bleuart.read16();
204+
imageHeight = bleuart.read16();
205+
206+
rxCount += 5;
181207

182208
tft.fillScreen(ILI9341_BLACK);
183209
tft.setCursor(0, 0);
210+
imageX = imageY = 0;
184211
}
185-
186-
rxCount += bleuart.available();
187-
bleuart.flush(); // empty rx fifo
188212
}
189213

190214
/**

0 commit comments

Comments
 (0)