17#define LD2410ASYNC_DEBUG_LEVEL 0
18#define LD2410ASYNC_DEBUG_DATA_LEVEL 0
1437 enum ReadFrameState {
1448 enum FrameReadResponse {
1454 int readFrameHeaderIndex = 0;
1455 int payloadSize = 0;
1456 ReadFrameState readFrameState = ReadFrameState::WAITING_FOR_HEADER;
1459 bool readFramePayloadSize(
byte b, ReadFrameState nextReadFrameState);
1462 FrameReadResponse readFramePayload(
byte b,
const byte* tailPattern, LD2410Async::FrameReadResponse successResponseType);
1465 FrameReadResponse readFrame();
1476 byte receiveBufferIndex = 0;
1484 static constexpr size_t MAX_COMMAND_SEQUENCE_LENGTH = 15;
1490 byte commandSequenceBufferCount = 0;
1493 unsigned long executeCommandSequenceStartMs = 0;
1501 bool executeCommandSequencePending =
false;
1505 Ticker executeCommandSequenceOnceTicker;
1508 int executeCommandSequenceIndex = 0;
1511 bool executeCommandSequenceInitialConfigModeState =
false;
1527 bool addCommandToSequence(
const byte* command);
1530 bool resetCommandSequence();
1540 bool inactivityHandlingEnabled =
true;
1541 unsigned long inactivityHandlingTimeoutMs = 60000;
1542 unsigned long lastSensorActivityTimestamp = 0;
1544 byte inactivityHandlingStep = 0;
1545 unsigned long lastInactivityHandlingTimestamp = 0;
1547 bool handleInactivityExitConfigModeDone =
false;
1550 void handleInactivity();
1571 unsigned long rebootAsyncWaitTimeoutMs = 5000;
1572 bool rebootAsyncDontWaitForNormalOperationAfterReboot =
false;
1573 bool rebootAsyncPending =
false;
1592 void executeConfigUpdateReceivedCallback();
1595 void executeConfigChangedCallback();
1604 void sendCommand(
const byte* command);
1611 TaskHandle_t taskHandle = NULL;
1612 bool taskStop =
false;
1621 unsigned long asyncCommandTimeoutMs = 4000;
1628 return sendCommandAsync(command, 0, callback);
1636 void sendCommandAsyncStoreDataForCallback(
const byte* command,
byte retries,
AsyncCommandCallback callback);
1639 void sendCommandAsyncHandleTimeout();
1645 unsigned long sendCommandAsyncStartMs = 0;
1646 byte sendCommandAsyncCommandCode = 0;
1647 bool sendCommandAsyncCommandPending =
false;
1649 byte sendCommandAsyncRetriesLeft = 0;
1655 void processReceivedData();
1662 return enableConfigModeInternalAsync(
false, callback);
1668 return disableConfigModeInternalAsync(
false, callback);
1671 Ticker configModeOnceTicker;
1677 bool configureAllConfigSettingsAsyncWriteFullConfig =
false;
1679 bool configureAllConfigSettingsAsyncConfigActive =
false;
1680 bool configureAllConfigSettingsAsyncConfigInitialConfigMode =
false;
1687 bool configureAllConfigSettingsAsyncWriteConfig();
1689 bool configureAllConfigSettingsAsyncRequestAllConfigData();
1692 bool configureAllConfigSettingsAsyncBuildSaveChangesCommandSequence();
Asynchronous driver class for the LD2410 human presence radar sensor.
bool configureAuxControlSettingsAsync(LD2410Types::LightControl light_control, byte light_threshold, LD2410Types::OutputControl output_control, AsyncCommandCallback callback)
Configures the auxiliary control parameters (light and output pin).
bool requestGateParametersAsync(AsyncCommandCallback callback)
Requests the current gate parameters from the sensor.
void asyncCancel()
Cancels any pending asynchronous command or sequence.
bool configureDistanceResolutionAsync(LD2410Types::DistanceResolution distanceResolution, AsyncCommandCallback callback)
Configures the distance resolution of the radar.
bool rebootAsync(AsyncCommandCallback callback)
Reboots the sensor.
LD2410Types::StaticData staticData
Static data of the radar.
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 configureMaxGateAndNoOneTimeoutAsync(byte maxMovingGate, byte maxStationaryGate, unsigned short noOneTimeout, AsyncCommandCallback callback)
Configures the maximum detection gates and "no-one" timeout on the sensor.
bool requestAllStaticDataAsync(AsyncCommandCallback callback)
Requests all static information from the sensor.
bool restoreFactorySettingsAsync(AsyncCommandCallback callback)
Restores factory settings of the sensor.
bool disableConfigModeAsync(AsyncCommandCallback callback)
Disables config mode on the radar.
bool isConfigModeEnabled() const
Detects if config mode is enabled.
void(*) AsyncCommandCallback(LD2410Async *sender, AsyncCommandResult result)
Callback signature for asynchronous command completion.
bool configureAllConfigSettingsAsync(const LD2410Types::ConfigData &configToWrite, bool writeAllConfigData, AsyncCommandCallback callback)
Applies a full ConfigData struct to the LD2410.
void enableInactivityHandling()
Convenience method: enables inactivity handling.
bool enableConfigModeAsync(AsyncCommandCallback callback)
Enables config mode on the radar.
void setInactivityTimeoutMs(unsigned long timeoutMs=60000)
Sets the timeout period for inactivity handling.
bool disableBluetoothAsync(AsyncCommandCallback callback)
Disables Bluetooth.
void setInactivityHandling(bool enable)
Enables or disables automatic inactivity handling of the sensor.
void onConfigDataReceived(GenericCallback callback)
Registers a callback for configuration data updates.
LD2410Types::ConfigData getConfigData() const
Returns a clone of the current configuration data of the radar.
LD2410Types::DetectionData getDetectionData() const
Returns a clone of the latest detection data from the radar.
void setAsyncCommandTimeoutMs(unsigned long timeoutMs)
Sets the timeout for async command callbacks.
bool configureDistanceResolution75cmAsync(AsyncCommandCallback callback)
Configures the distance resolution explicitly to 75 cm per gate.
LD2410Types::ConfigData configData
Current configuration parameters of the radar.
void disableInactivityHandling()
Convenience method: disables inactivity handling.
bool requestDistanceResolutionAsync(AsyncCommandCallback callback)
Requests the current distance resolution setting from the sensor.
bool asyncIsBusy()
Checks if an asynchronous command is currently pending.
unsigned long getInactivityTimeoutMs() const
Returns the current inactivity handling timeout period.
bool configModeEnabled
True if the sensor is currently in config mode.
bool configureBluetoothPasswordAsync(const char *password, AsyncCommandCallback callback)
Sets the password for Bluetooth access to the sensor.
void onConfigChanged(GenericCallback callback)
Registers a callback that is invoked whenever the sensor's configuration has been changed successfull...
unsigned long getAsyncCommandTimeoutMs() const
Returns the current async command timeout.
bool requestFirmwareAsync(AsyncCommandCallback callback)
Requests the firmware version of the sensor.
bool requestBluetoothMacAddressAsync(AsyncCommandCallback callback)
Requests the Bluetooth MAC address.
void(*) GenericCallback(LD2410Async *sender)
Generic callback signature used for simple notifications.
LD2410Types::DetectionData detectionData
Latest detection results from the radar.
LD2410Types::AutoConfigStatus autoConfigStatus
Current status of the auto-configuration routine.
bool requestAllConfigSettingsAsync(AsyncCommandCallback callback)
Requests all configuration settings from the sensor.
bool engineeringModeEnabled
True if the sensor is currently in engineering mode.
bool configureDefaultBluetoothPasswordAsync(AsyncCommandCallback callback)
Resets the password for Bluetooth access to the default value (HiLink)
bool configureDistanceGateSensitivityAsync(const byte movingThresholds[9], const byte stationaryThresholds[9], AsyncCommandCallback callback)
Configures sensitivity thresholds for all gates at once.
void(*) DetectionDataCallback(LD2410Async *sender, bool presenceDetected)
Callback type for receiving detection data events.
LD2410Async(Stream &serial)
Constructs a new LD2410Async instance bound to a given serial stream.
bool beginAutoConfigAsync(AsyncCommandCallback callback)
Starts the automatic configuration (auto-config) routine on the sensor.
bool requestAuxControlSettingsAsync(AsyncCommandCallback callback)
Requests the current auxiliary control settings.
bool isEngineeringModeEnabled() const
Detects if engineering mode is enabled.
void onDetectionDataReceived(DetectionDataCallback callback)
Registers a callback for new detection data.
bool enableEngineeringModeAsync(AsyncCommandCallback callback)
Enables engineering mode.
bool isInactivityHandlingEnabled() const
Returns whether inactivity handling is currently enabled.
const LD2410Types::DetectionData & getDetectionDataRef() const
Access the current detection data without making a copy.
bool disableEngineeringModeAsync(AsyncCommandCallback callback)
Disables engineering mode.
bool configureBaudRateAsync(byte baudRateSetting, AsyncCommandCallback callback)
Configures the UART baud rate of the sensor.
bool requestAutoConfigStatusAsync(AsyncCommandCallback callback)
Requests the current status of the auto-config routine.
bool end()
Stops the background task started by begin().
bool configuresDistanceResolution20cmAsync(AsyncCommandCallback callback)
Configures the distance resolution explicitly to 20 cm per gate.
const LD2410Types::ConfigData & getConfigDataRef() const
Access the current config data without making a copy.
bool enableBluetoothAsync(AsyncCommandCallback callback)
Enables Bluetooth.
constexpr size_t LD2410_Buffer_Size
AutoConfigStatus
State of the automatic threshold configuration routine.
@ NOT_SET
Status not yet retrieved.
OutputControl
Logic level behavior of the auxiliary output pin.
DistanceResolution
Distance resolution per gate for detection.
LightControl
Light-dependent control status of the auxiliary output.
Holds the most recent detection data reported by the radar.