Seeed-Studio / Seeed_Arduino_DopplerRadar

Arduino library for DopplerRader
MIT License
3 stars 6 forks source link

implement single query getInfo call #13

Closed x29a closed 1 year ago

x29a commented 1 year ago

so that target detection and speed can be evaluated with one serial send (since the answer provides both already).

This reduces the load on the UART port and ensures that the received data is from the same sampling frame. Otherwise it could be that between getTargetState() and getSpeed() the module updated its values.

Example usage:

  uint16_t state = 0;
  uint16_t speed = 0;

  if (BGT.getInfo(&state, &speed)) {
    if (state == 2) {
      digitalWrite(5, HIGH);
      ShowSerial.print("target approach");
    } else if (state == 1) {
      digitalWrite(5, LOW);
      ShowSerial.print("target leave   ");
    } else {
      ShowSerial.println("no target");
      return;
    }

    ShowSerial.print(" - target speed: ");
    ShowSerial.println(speed);
  }

Tested on a Sparkfun ESP32 Thing with the real hardware module. Arduino IDE with espressif 2.0.6.

Old functions are left for backwards compatibility.