@@ -58,7 +58,6 @@ static uint16_t score = 0, time_to_wait = 70;
5858static uint8_t gameMode = MENU;
5959static float tofOldDistance = 0 ;
6060static bool mute = false ;
61- static int localRecord = 0 ;
6261
6362byte frame[8 ][12 ] = {
6463 { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
@@ -74,8 +73,11 @@ byte frame[8][12] = {
7473
7574#ifdef BLE_SYNC
7675/* BT Service and properties */
77- BleSync ble (" FlappyLed" , " d4d1cb67-d83e-41b6-bfc9-95d25ca6a91d" , 2 );
76+ BleSync ble (" FlappyLed" , " d4d1cb67-d83e-41b6-bfc9-95d25ca6a91d" , 5 );
7877BleSyncValue bleRecordEncoder (" a3cd7bd3-4d6e-492f-9f18-f9bf181be541" , BLERead | BLEWrite);
78+ BleSyncValue bleGamesEncoder (" 59802c1a-c0d8-4b35-9c6c-b258304e078b" , BLERead | BLEWrite);
79+ BleSyncValue bleRecordTof (" 2380e50e-562d-4e46-aeaf-d73b9d258f73" , BLERead | BLEWrite);
80+ BleSyncValue bleGamesTof (" a8dd61cd-02b9-465b-8f6d-a185aa65bce0" , BLERead | BLEWrite);
7981BleSyncValue bleCounter (" 17a8a342-41bd-4dc0-98af-62d30a0d4432" , BLERead | BLEWrite);
8082#endif
8183
@@ -136,6 +138,10 @@ void setup() {
136138
137139 ble.addValue (&bleRecordEncoder);
138140 ble.addValue (&bleCounter);
141+ ble.addValue (&bleGamesEncoder);
142+ ble.addValue (&bleRecordTof);
143+ ble.addValue (&bleGamesTof);
144+ ble.addValue (&bleCounter);
139145 ble.initBLE ();
140146
141147 #endif
@@ -319,6 +325,11 @@ void distanceLoop() {
319325
320326 #if !defined(BUTTONS)
321327
328+ if (!distanceSensor.available ()){
329+ delay (1 );
330+ continue ;
331+ }
332+
322333 float d = distanceSensor.get ();
323334 unsigned long m = millis ();
324335
@@ -351,6 +362,11 @@ void distanceLoop() {
351362 delay (1 );
352363 }
353364
365+ if (!distanceSensor.available ()){
366+ delay (1 );
367+ return ;
368+ }
369+
354370 float distance = distanceSensor.get ();
355371
356372 if (isnan (distance)){
@@ -537,6 +553,23 @@ void clear_text()
537553void resetGameState ()
538554{
539555
556+ #ifdef BLE_SYNC
557+ /* Store local record */
558+
559+ if (gameMode == ENCODER) {
560+ if (score > bleRecordEncoder.getValue ()){
561+ bleRecordEncoder.setValue (score);
562+ }
563+ bleGamesEncoder.setValue (bleGamesEncoder.getValue ()+1 );
564+ } else if (gameMode == TOF) {
565+ if (score > bleRecordTof.getValue ()){
566+ bleRecordTof.setValue (score);
567+ }
568+ bleGamesTof.setValue (bleGamesTof.getValue ()+1 );
569+ }
570+ bleCounter.setValue (bleCounter.getValue ()+1 );
571+ #endif
572+
540573 /* Reset game mode*/
541574 gameMode = MENU;
542575
@@ -568,16 +601,6 @@ void resetGameState()
568601 buttons.setLeds (false , mute, false );
569602 #endif
570603
571- #ifdef BLE_SYNC
572- /* Store local record */
573- if (score > localRecord){
574- localRecord = score;
575- bleRecordEncoder.setValue (localRecord);
576- }
577-
578- bleCounter.setValue (bleCounter.getValue ()+1 );
579- #endif
580-
581604 print_score (score);
582605 score = 0 ;
583606 wall_pos_x = WIDTH-1 ;
0 commit comments