Skip to content

Commit 3d28336

Browse files
committed
Adding all BLE properties
1 parent 4b05330 commit 3d28336

File tree

1 file changed

+35
-12
lines changed

1 file changed

+35
-12
lines changed

FlappyLED.ino

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ static uint8_t gameMode = MENU;
5757
static float oldDistance = 0;
5858
static bool firstAnimationsRun = true;
5959
static bool mute = false;
60-
static int localRecord = 0;
6160

6261
byte frame[8][12] = {
6362
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
@@ -73,8 +72,11 @@ byte frame[8][12] = {
7372

7473
#ifdef BLE_SYNC
7574
/* BT Service and properties */
76-
BleSync ble("FlappyLed", "d4d1cb67-d83e-41b6-bfc9-95d25ca6a91d", 2);
75+
BleSync ble("FlappyLed", "d4d1cb67-d83e-41b6-bfc9-95d25ca6a91d", 5);
7776
BleSyncValue bleRecordEncoder("a3cd7bd3-4d6e-492f-9f18-f9bf181be541", BLERead | BLEWrite);
77+
BleSyncValue bleGamesEncoder("59802c1a-c0d8-4b35-9c6c-b258304e078b", BLERead | BLEWrite);
78+
BleSyncValue bleRecordTof("2380e50e-562d-4e46-aeaf-d73b9d258f73", BLERead | BLEWrite);
79+
BleSyncValue bleGamesTof("a8dd61cd-02b9-465b-8f6d-a185aa65bce0", BLERead | BLEWrite);
7880
BleSyncValue bleCounter("17a8a342-41bd-4dc0-98af-62d30a0d4432", BLERead | BLEWrite);
7981
#endif
8082

@@ -127,6 +129,10 @@ void setup() {
127129

128130
ble.addValue(&bleRecordEncoder);
129131
ble.addValue(&bleCounter);
132+
ble.addValue(&bleGamesEncoder);
133+
ble.addValue(&bleRecordTof);
134+
ble.addValue(&bleGamesTof);
135+
ble.addValue(&bleCounter);
130136
ble.initBLE();
131137

132138
#endif
@@ -310,6 +316,11 @@ void distanceLoop() {
310316

311317
#if !defined(BUTTONS)
312318

319+
if(!distanceSensor.available()){
320+
delay(1);
321+
continue;
322+
}
323+
313324
float d = distanceSensor.get();
314325
unsigned long m = millis();
315326

@@ -342,6 +353,11 @@ void distanceLoop() {
342353
delay(1);
343354
}
344355

356+
if(!distanceSensor.available()){
357+
delay(1);
358+
return;
359+
}
360+
345361
float distance = distanceSensor.get();
346362

347363
if(isnan(distance)){
@@ -528,6 +544,23 @@ void clear_text()
528544
void reset_global_variables()
529545
{
530546

547+
#ifdef BLE_SYNC
548+
/* Store local record */
549+
550+
if(gameMode == ENCODER) {
551+
if(score > bleRecordEncoder.getValue()){
552+
bleRecordEncoder.setValue(score);
553+
}
554+
bleGamesEncoder.setValue(bleGamesEncoder.getValue()+1);
555+
} else if(gameMode == TOF) {
556+
if(score > bleRecordTof.getValue()){
557+
bleRecordTof.setValue(score);
558+
}
559+
bleGamesTof.setValue(bleGamesTof.getValue()+1);
560+
}
561+
bleCounter.setValue(bleCounter.getValue()+1);
562+
#endif
563+
531564
/* Reset game mode*/
532565
gameMode = MENU;
533566

@@ -559,16 +592,6 @@ void reset_global_variables()
559592
buttons.setLeds(false, mute, false);
560593
#endif
561594

562-
#ifdef BLE_SYNC
563-
/* Store local record */
564-
if(score > localRecord){
565-
localRecord = score;
566-
bleRecordEncoder.setValue(localRecord);
567-
}
568-
569-
bleCounter.setValue(bleCounter.getValue()+1);
570-
#endif
571-
572595
print_score(score);
573596
/* Reset score after crash */
574597
score = 0;

0 commit comments

Comments
 (0)