@@ -110,6 +110,96 @@ BLECharacteristic metaTxChar (UUID_GEN("4002") , BLERead
110110uint8_t *newModelFileData = nullptr ;
111111int newModelFileLength = 0 ;
112112
113+ /* ***********************************************************************
114+ * Labels for local display
115+ ************************************************************************/
116+
117+ // Currently there is no set Labels, this used actual data matched with 2 examples
118+ // "Air Snare" and "Finger User Interface" to display TFT locally
119+
120+ // from ARCADA color
121+ #define COLOR_BLACK 0x0000 // /< 0, 0, 0
122+ #define COLOR_BLUE 0x001F // /< 0, 0, 255
123+ #define COLOR_GREEN 0x07E0 // /< 0, 255, 0
124+ #define COLOR_CYAN 0x07FF // /< 0, 255, 255
125+ #define COLOR_RED 0xF800 // /< 255, 0, 0
126+ #define COLOR_MAGENTA 0xF81F // /< 255, 0, 255
127+ #define COLOR_YELLOW 0xFFE0 // /< 255, 255, 0
128+ #define COLOR_WHITE 0xFFFF // /< 255, 255, 255
129+ #define COLOR_ORANGE 0xFD20 // /< 255, 165, 0
130+ #define COLOR_PINK 0xFC18 // /< 255, 130, 198
131+
132+ const char * labelAirSnare[] = {
133+ " Side" , " Down" , " Up"
134+ };
135+
136+ const char * labelFingerUserInterface[] = {
137+ " Left" , " Right" , " Poke" , " Twirl" , " Pluck"
138+ };
139+
140+ const char ** modelLabel = NULL ;
141+
142+ // detect model label
143+ const char ** detectModelLabel (int file_length) {
144+ uint8_t const numClasses = numClassesRxChar.read8 ();
145+
146+ if ( (numClasses == 3 ) && ( (file_length / 1000 ) == 17 ) ) {
147+ return labelAirSnare;
148+ }
149+
150+ if ( (numClasses == 5 ) && ( (file_length / 1000 ) == 35 ) ) {
151+ return labelFingerUserInterface;
152+ }
153+
154+ return NULL ;
155+ }
156+
157+ uint16_t const color_pallete[] = {
158+ COLOR_BLUE,
159+ COLOR_GREEN, // Green
160+ COLOR_YELLOW, // Yellow
161+ COLOR_CYAN, // Cyan
162+ COLOR_PINK, // Pink
163+ COLOR_MAGENTA, // MAGENTA
164+ COLOR_ORANGE, // Orange
165+ COLOR_RED, // Red
166+ };
167+
168+ #if defined(ARDUINO_NRF52840_CLUE)
169+
170+ // use arcada for display
171+ #include < Adafruit_Arcada.h>
172+
173+ Adafruit_Arcada arcada;
174+
175+ void displayInit (void ) {
176+ arcada.displayBegin ();
177+ arcada.setBacklight (255 );
178+
179+ Adafruit_SPITFT* tft = arcada.display ;
180+
181+ tft->fillScreen (COLOR_BLACK);
182+ tft->setRotation (3 );
183+ }
184+
185+ void displayText (const char * text, uint8_t size, uint16_t color) {
186+ Adafruit_SPITFT* tft = arcada.display ;
187+
188+ tft->fillScreen (COLOR_BLACK);
189+ tft->setTextColor (color);
190+ tft->setTextSize (size);
191+ tft->setCursor (60 , 100 );
192+ tft->print (text);
193+ }
194+
195+ #else
196+
197+ // stub for no-tft board
198+ void displayText (const char * text, uint8_t size, uint16_t color) { (void ) text; (void ) size; (void ) color; }
199+ void displayInit (void ) { }
200+
201+ #endif
202+
113203/* ***********************************************************************
114204* LED / State status functions
115205************************************************************************/
@@ -242,6 +332,11 @@ void setState(State state)
242332 break ;
243333 case FILE_TRANSFER:
244334 Serial.println (" state is now FILE_TRANSFER" );
335+ displayText (" Dwnloading" , 3 , COLOR_ORANGE);
336+ break ;
337+ case INFERENCE:
338+ Serial.println (" state is now INFERENCE" );
339+ displayText (" Ready" , 3 , COLOR_GREEN);
245340 break ;
246341 case IMU_DATA_PROVIDER:
247342 Serial.println (" state is now IMU_DATA_PROVIDER" );
@@ -359,6 +454,11 @@ void model_tester_onInference(unsigned char classIndex, unsigned char score, uns
359454 Serial.print (classIndex);
360455 Serial.print (" score: " );
361456 Serial.println (score);
457+
458+ if ( modelLabel ) {
459+ // display label on TFT use index as color id
460+ displayText (modelLabel[classIndex], 5 , color_pallete[classIndex]);
461+ }
362462}
363463
364464// called when calibration completes
@@ -369,6 +469,12 @@ void data_provider_calibrationComplete(){
369469// called on file transfer complete
370470void onBLEFileReceived (uint8_t *file_data, int file_length)
371471{
472+ Serial.print (" file length " );
473+ Serial.println (file_length);
474+
475+ // detect label of model for local display
476+ modelLabel = detectModelLabel (file_length);
477+
372478 switch (fileTransferType)
373479 {
374480 case MODEL_FILE:
@@ -425,6 +531,7 @@ void setup()
425531 pinMode (LED_BUILTIN, OUTPUT);
426532 neopixels.begin ();
427533 neopixels.setBrightness (0x20 );
534+ displayInit ();
428535
429536 // Start IMU / Data provider.
430537 if (!data_provider::setup ())
0 commit comments