29#define RADAR_RX_PIN 32
30#define RADAR_TX_PIN 33
31#define RADAR_BAUDRATE 256000
73 snprintf(buf,
sizeof(buf),
"%6lu", value);
89 default:
return "UNKNOWN";
105 switch (random(0, 4)) {
113 delayMs = random(0, 50) * 20 + 100;
116 delayMs = random(0, 70) * 100 + 1000;
122 Serial.print(
"Test ");
124 Serial.print(
" | Delay: ");
129 Serial.print(
" (Data cnt: ");
135 Serial.println(
" > enableConfigModeAsync could not be started (busy).");
164 Serial.print(
"Dur: ");
166 Serial.print(
" ms | Data Cnt:");
168 Serial.print(
" | Min: ");
170 Serial.print(
" ms | Max: ");
172 Serial.print(
" ms | Avg: ");
174 Serial.print(
" ms | Fails: ");
179 int cmd = random(0, 6);
188 Serial.println(
"Could not start disableConfigMode()");
195 Serial.print(
"enableConfigModeAsync failed: ");
197 Serial.print(
" Received ");
199 Serial.println(
" data frames while waiting for ACK");
214 Serial.print(
"Extra command failed ");
218 Serial.println(
"Could not start disableConfigMode()");
233 Serial.print(
"Disable config mode failed ");
251 int currentState = digitalRead(
LED_PIN);
252 digitalWrite(
LED_PIN, currentState == HIGH ? LOW : HIGH);
268 Serial.begin(115200);
270 Serial.println(
"=== LD2410Async enableConfigModeAsync measurement test ===");
278 Serial.println(
"Failed to start LD2410Async task!");
279 while (
true) delay(1000);
282 Serial.println(
"LD2410Async task started!");
Asynchronous driver class for the LD2410 human presence radar sensor.
bool begin()
Starts the background task that continuously reads data from the sensor.
AsyncCommandResult
Result of an asynchronous command execution.
@ TIMEOUT
No ACK received within the expected time window.
@ FAILED
Command failed (sensor responded with negative ACK).
@ SUCCESS
Command completed successfully and ACK was received.
@ CANCELED
Command was canceled by the user before completion.
bool requestAllStaticDataAsync(AsyncCommandCallback callback)
Requests all static information from the sensor.
bool disableConfigModeAsync(AsyncCommandCallback callback)
Disables config mode on the radar.
bool enableConfigModeAsync(AsyncCommandCallback callback)
Enables config mode on the radar.
void setAsyncCommandTimeoutMs(unsigned long timeoutMs)
Sets the timeout for async command callbacks.
bool requestDistanceResolutionAsync(AsyncCommandCallback callback)
Requests the current distance resolution setting from the sensor.
bool requestFirmwareAsync(AsyncCommandCallback callback)
Requests the firmware version of the sensor.
bool requestAllConfigSettingsAsync(AsyncCommandCallback callback)
Requests all configuration settings from the sensor.
bool requestAuxControlSettingsAsync(AsyncCommandCallback callback)
Requests the current auxiliary control settings.
void onDetectionDataReceived(DetectionDataCallback callback)
Registers a callback for new detection data.
unsigned long failureCount
Number of failed measurements.
const char * resultToString(LD2410Async::AsyncCommandResult result)
Convert AsyncCommandResult enum to human-readable text.
HardwareSerial RadarSerial(1)
HardwareSerial instance bound to UART1.
void setup()
Arduino setup function.
unsigned long delayMs
Delay before the tests.
void onDetectionDataReceived(LD2410Async *sender, bool presenceDetected)
Callback triggered when new detection data is received.
unsigned long measurementCount
Number of successful measurements.
void disableConfigModeCallback(LD2410Async *sender, LD2410Async::AsyncCommandResult result)
Callback for disableConfigModeAsync().
void enableConfigModeCallback(LD2410Async *sender, LD2410Async::AsyncCommandResult result)
Callback for enableConfigModeAsync().
#define RADAR_BAUDRATE
UART baudrate for radar sensor (default is 256000)
#define RADAR_RX_PIN
ESP32 pin receiving data from the radar (radar TX)
unsigned long enableStartMs
Timestamp when enableConfigModeAsync() was called.
LD2410Async ld2410(RadarSerial)
LD2410Async driver instance.
unsigned long maxEnableDurationMs
Maximum execution time measured so far.
Ticker delayTicker
Ticker for randomized delays.
#define LED_PIN
GPIO for internal LED (adjust if needed)
unsigned long totalEnableDurationMs
Sum of all measured durations.
void printPaddedNumber(unsigned long value)
Print a number padded to 6 characters width.
unsigned long minEnableDurationMs
Minimum execution time measured so far.
#define RADAR_TX_PIN
ESP32 pin transmitting data to the radar (radar RX)
void extraCommandCallback(LD2410Async *sender, LD2410Async::AsyncCommandResult result)
Callback for extra commands.
void scheduleNextSequence()
Schedule the next test sequence.
unsigned long dataCount
Used to count received data frames.
void loop()
Arduino loop function.