@@ -61,8 +61,11 @@ static BluetoothManager* bluetoothManager;
61
61
62
62
Gps gps;
63
63
64
- static const uint32_t BLUETOOTH_INTERVAL_MILLIS = 100 ;
65
- static uint32_t lastBluetoothInterval = 0 ;
64
+ static const long BLUETOOTH_INTERVAL_MILLIS = 150 ;
65
+ static long lastBluetoothInterval = 0 ;
66
+
67
+ static const long DISPLAY_INTERVAL_MILLIS = 20 ;
68
+ static long lastDisplayInterval = 0 ;
66
69
67
70
float TemperatureValue = -1 ;
68
71
@@ -328,7 +331,7 @@ void setup() {
328
331
while (!gps.hasFix (displayTest)) {
329
332
currentTimeMillis = millis ();
330
333
gps.handle ();
331
- sensorManager->getDistances ();
334
+ sensorManager->pollDistancesParallel ();
332
335
reportBluetooth ();
333
336
gps.showWaitStatus (displayTest);
334
337
buttonState = digitalRead (PushButton_PIN);
@@ -353,7 +356,7 @@ void setup() {
353
356
void serverLoop () {
354
357
gps.handle ();
355
358
configServerHandle ();
356
- sensorManager->getDistancesNoWait ();
359
+ sensorManager->pollDistancesParallel ();
357
360
handleButtonInServerMode ();
358
361
}
359
362
@@ -415,10 +418,9 @@ void loop() {
415
418
currentSet->isInsidePrivacyArea = gps.isInsidePrivacyArea ();
416
419
currentSet->gpsRecord = gps.getCurrentGpsRecord ();
417
420
421
+ lastMeasurements = sensorManager->m_sensors [confirmationSensorID].numberOfTriggers ;
418
422
sensorManager->reset ();
419
423
420
- int measurements = 0 ;
421
-
422
424
// if the detected minimum was measured more than 5s ago, it is discarded and cannot be confirmed
423
425
int timeDelta = (int ) (currentTimeMillis - timeOfMinimum);
424
426
if (datasetToConfirm != nullptr &&
@@ -428,24 +430,44 @@ void loop() {
428
430
datasetToConfirm = nullptr ;
429
431
}
430
432
433
+ int loops = 0 ;
431
434
// do this for the time specified by measureInterval, e.g. 1s
432
435
while ((currentTimeMillis - startTimeMillis) < measureInterval) {
436
+ loops++;
433
437
434
438
currentTimeMillis = millis ();
435
- sensorManager->getDistances ();
439
+ if (sensorManager->pollDistancesParallel ()) {
440
+ // if a new minimum on the selected sensor is detected, the value and the time of detection will be stored
441
+ const uint16_t reading = sensorManager->sensorValues [confirmationSensorID];
442
+ if (reading > 0 && reading < minDistanceToConfirm) {
443
+ minDistanceToConfirm = reading;
444
+ minDistanceToConfirmIndex = sensorManager->getCurrentMeasureIndex ();
445
+ // if there was no measurement of this sensor for this index, it is the
446
+ // one before. This happens with fast confirmations.
447
+ while (minDistanceToConfirmIndex > 0
448
+ && sensorManager->m_sensors [confirmationSensorID].echoDurationMicroseconds [minDistanceToConfirmIndex] <= 0 ) {
449
+ minDistanceToConfirmIndex--;
450
+ }
451
+ datasetToConfirm = currentSet;
452
+ timeOfMinimum = currentTimeMillis;
453
+ }
454
+ }
436
455
gps.handle ();
437
456
438
- displayTest->showValues (
439
- sensorManager->m_sensors [LEFT_SENSOR_ID],
440
- sensorManager->m_sensors [RIGHT_SENSOR_ID],
441
- minDistanceToConfirm,
442
- voltageMeter->readPercentage (),
443
- (int16_t ) TemperatureValue,
444
- lastMeasurements,
445
- currentSet->isInsidePrivacyArea ,
446
- gps.getSpeed (),
447
- gps.getValidSatellites ()
448
- );
457
+ if (lastDisplayInterval != (currentTimeMillis / DISPLAY_INTERVAL_MILLIS)) {
458
+ lastDisplayInterval = currentTimeMillis / DISPLAY_INTERVAL_MILLIS;
459
+ displayTest->showValues (
460
+ sensorManager->m_sensors [LEFT_SENSOR_ID],
461
+ sensorManager->m_sensors [RIGHT_SENSOR_ID],
462
+ minDistanceToConfirm,
463
+ voltageMeter->readPercentage (),
464
+ (int16_t ) TemperatureValue,
465
+ lastMeasurements,
466
+ currentSet->isInsidePrivacyArea ,
467
+ gps.getSpeed (),
468
+ gps.getValidSatellites ()
469
+ );
470
+ }
449
471
450
472
reportBluetooth ();
451
473
buttonState = digitalRead (PushButton_PIN);
@@ -478,23 +500,9 @@ void loop() {
478
500
lastButtonState = buttonState;
479
501
}
480
502
481
- // if a new minimum on the selected sensor is detected, the value and the time of detection will be stored
482
- const uint16_t reading = sensorManager->sensorValues [confirmationSensorID];
483
- if (reading > 0 && reading < minDistanceToConfirm) {
484
- minDistanceToConfirm = reading;
485
- minDistanceToConfirmIndex = sensorManager->getCurrentMeasureIndex ();
486
- // if there was no measurement of this sensor for this index, it is the
487
- // one before. This happens with fast confirmations.
488
- while (minDistanceToConfirmIndex > 0
489
- && sensorManager->m_sensors [confirmationSensorID].echoDurationMicroseconds [minDistanceToConfirmIndex] <= 0 ) {
490
- minDistanceToConfirmIndex--;
491
- }
492
- datasetToConfirm = currentSet;
493
- timeOfMinimum = currentTimeMillis;
494
- }
495
- measurements++;
503
+ if (BMP280_active == true ) TemperatureValue = bmp280.readTemperature ();
496
504
497
- if (BMP280_active == true ) TemperatureValue = bmp280. readTemperature ();
505
+ yield (); //
498
506
} // end measureInterval while
499
507
500
508
// Write the minimum values of the while-loop to a set
@@ -510,15 +518,12 @@ void loop() {
510
518
&(sensorManager->startOffsetMilliseconds ), currentSet->measurements * sizeof (uint16_t ));
511
519
512
520
#ifdef DEVELOP
513
- Serial.write (" min. distance: " );
514
- Serial.print (currentSet->sensorValues [confirmationSensorID]) ;
515
- Serial.write (" cm," );
516
- Serial.print (measurements);
517
- Serial.write (" measurements \n " );
521
+ log_i (" min. distance: %dcm, loops %d" ,
522
+ currentSet->sensorValues [confirmationSensorID],
523
+ loops);
518
524
#endif
519
525
520
526
dataBuffer.push (currentSet);
521
- lastMeasurements = measurements;
522
527
// convert all data that does not wait for confirmation.
523
528
while ((!dataBuffer.isEmpty () && dataBuffer.first () != datasetToConfirm) || dataBuffer.isFull ()) {
524
529
DataSet* dataset = dataBuffer.shift ();
@@ -552,8 +557,8 @@ void loop() {
552
557
displayTest->normalDisplay ();
553
558
}
554
559
}
555
-
556
- log_i ( " Time elapsed in loop: %lu milliseconds " , currentTimeMillis - startTimeMillis);
560
+ log_i ( " Time in loop: %lums %d inner loops, %d measures " ,
561
+ currentTimeMillis - startTimeMillis, loops, lastMeasurements );
557
562
// synchronize to full measureIntervals
558
563
startTimeMillis = (currentTimeMillis / measureInterval) * measureInterval;
559
564
}
0 commit comments