13
13
*********************************************************************/
14
14
15
15
/* This sketch demonstrates the "Image Upload" feature of Bluefruit Mobile App.
16
- * FeatherWing OLED is used to display uploaded image
16
+ * Either 2.4" or 3.5" TFT FeatherWing is used to display uploaded image
17
17
* - https://www.adafruit.com/product/3315
18
+ * - https://www.adafruit.com/product/3651
18
19
*/
19
20
21
+ // if USE_35_TFT_FEATHERWING = 0 then the 2.4" TFT will be used instead
22
+ #define USE_35_TFT_FEATHERWING 1
23
+
20
24
#include < bluefruit.h>
21
25
#include < SPI.h>
22
26
#include < Adafruit_GFX.h>
23
- #include < Adafruit_ILI9341.h>
27
+
28
+ #ifdef ARDUINO_NRF52832_FEATHER
29
+ #define TFT_DC 11
30
+ #define TFT_CS 31
31
+ #endif
32
+
33
+ #ifdef ARDUINO_NRF52840_FEATHER
34
+ #define TFT_DC 10
35
+ #define TFT_CS 9
36
+ #endif
37
+
38
+ #ifdef ARDUINO_NRF52840_CIRCUITPLAY
39
+ #define TFT_DC A7
40
+ #define TFT_CS A6
41
+ #endif
42
+
43
+ #if USE_35_TFT_FEATHERWING
44
+ #include " Adafruit_HX8357.h"
45
+ Adafruit_HX8357 tft = Adafruit_HX8357(TFT_CS, TFT_DC);
46
+ #else
47
+ #include < Adafruit_ILI9341.h>
48
+ Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
49
+ #endif
50
+
51
+ #define COLOR_WHITE 0xFFFF
52
+ #define COLOR_BLACK 0x0000
53
+ #define COLOR_YELLOW 0xFFE0
54
+ #define COLOR_GREEN 0x07E0
24
55
25
56
// Uart over BLE with large buffer to hold image data
26
57
BLEUart bleuart (1024 *10 );
@@ -50,31 +81,14 @@ uint16_t color_buf[2048];
50
81
uint32_t rxStartTime = 0 ;
51
82
uint32_t rxLastTime = 0 ;
52
83
53
- #ifdef ARDUINO_NRF52832_FEATHER
54
- #define TFT_DC 11
55
- #define TFT_CS 31
56
- #endif
57
-
58
- #ifdef ARDUINO_NRF52840_FEATHER
59
- #define TFT_DC 10
60
- #define TFT_CS 9
61
- #endif
62
-
63
- #ifdef ARDUINO_NRF52840_CIRCUITPLAY
64
- #define TFT_DC A7
65
- #define TFT_CS A6
66
- #endif
67
-
68
-
69
- Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
70
84
71
85
void setup ()
72
86
{
73
87
Serial.begin (115200 );
74
88
75
89
tft.begin ();
76
- tft.fillScreen (ILI9341_BLACK );
77
- tft.setTextColor (ILI9341_WHITE );
90
+ tft.fillScreen (COLOR_BLACK );
91
+ tft.setTextColor (COLOR_WHITE );
78
92
tft.setTextSize (1 );
79
93
80
94
// Config the peripheral connection with maximum bandwidth
@@ -135,7 +149,7 @@ void loop()
135
149
if ( !bleuart.available () ) return ;
136
150
137
151
// all pixel data is received
138
- if ( totalPixel == imageWidth*imageHeight )
152
+ if ( ( totalPixel != 0 ) && (totalPixel == imageWidth*imageHeight) )
139
153
{
140
154
uint8_t crc = bleuart.read ();
141
155
// do checksum later
@@ -193,37 +207,37 @@ void connect_callback(uint16_t conn_handle)
193
207
conn->requestMtuExchange (247 );
194
208
tft.println (" Exchanging MTU" );
195
209
196
- tft.setTextColor (ILI9341_GREEN );
210
+ tft.setTextColor (COLOR_GREEN );
197
211
tft.println (" Ready to receive new image" );
198
- tft.setTextColor (ILI9341_WHITE );
212
+ tft.setTextColor (COLOR_WHITE );
199
213
}
200
214
201
215
void print_speed (uint32_t count, uint32_t ms)
202
216
{
203
217
tft.setCursor (0 , imageHeight+5 );
204
218
tft.print (" Received " );
205
219
206
- tft.setTextColor (ILI9341_YELLOW );
220
+ tft.setTextColor (COLOR_YELLOW );
207
221
tft.print (count);
208
- tft.setTextColor (ILI9341_WHITE );
222
+ tft.setTextColor (COLOR_WHITE );
209
223
210
224
tft.print (" bytes in " );
211
225
212
- tft.setTextColor (ILI9341_YELLOW );
226
+ tft.setTextColor (COLOR_YELLOW );
213
227
tft.print (ms / 1000 .0F , 2 );
214
- tft.setTextColor (ILI9341_WHITE );
228
+ tft.setTextColor (COLOR_WHITE );
215
229
216
230
tft.println (" seconds" );
217
231
218
232
tft.print (" Speed: " );
219
- tft.setTextColor (ILI9341_YELLOW );
233
+ tft.setTextColor (COLOR_YELLOW );
220
234
tft.print ( (count / 1000 .0F ) / (ms / 1000 .0F ), 2 );
221
- tft.setTextColor (ILI9341_WHITE );
235
+ tft.setTextColor (COLOR_WHITE );
222
236
tft.println (" KB/s" );
223
237
224
- tft.setTextColor (ILI9341_GREEN );
238
+ tft.setTextColor (COLOR_GREEN );
225
239
tft.println (" Ready to receive new image" );
226
- tft.setTextColor (ILI9341_WHITE );
240
+ tft.setTextColor (COLOR_WHITE );
227
241
}
228
242
229
243
void bleuart_rx_callback (uint16_t conn_hdl)
@@ -249,7 +263,7 @@ void bleuart_rx_callback(uint16_t conn_hdl)
249
263
PRINT_INT (imageWidth);
250
264
PRINT_INT (imageHeight);
251
265
252
- tft.fillScreen (ILI9341_BLACK );
266
+ tft.fillScreen (COLOR_BLACK );
253
267
tft.setCursor (0 , 0 );
254
268
imageX = imageY = 0 ;
255
269
}
@@ -264,9 +278,11 @@ void disconnect_callback(uint16_t conn_handle, uint8_t reason)
264
278
{
265
279
(void ) reason;
266
280
267
- tft.fillScreen (ILI9341_BLACK );
281
+ tft.fillScreen (COLOR_BLACK );
268
282
tft.setCursor (0 , 0 );
269
283
tft.println (" Advertising ..." );
270
284
271
285
totalPixel = imageWidth = imageHeight = 0 ;
286
+
287
+ bleuart.flush ();
272
288
}
0 commit comments