17#ifndef LD2410_BAUD_RATE
18#define LD2410_BAUD_RATE 256000
20#define LD2410_BUFFER_SIZE 0x40
21#define LD2410_LATEST_FIRMWARE "2.44"
30 LIGHT_BELOW_THRESHOLD,
78 for (
byte i = 0; i <= N; i++)
79 values[i] = other.values[i];
83 template <
typename ByteHandler>
84 void forEach(ByteHandler func)
const
86 for (
byte i = 0; i <= N; i++)
93 unsigned long timestamp;
94 unsigned long mTargetDistance;
96 unsigned long sTargetDistance;
98 unsigned long distance;
109 byte noOne_window = 0;
112 byte lightThreshold = 0;
116 unsigned long version = 0;
117 unsigned long bufferSize = 0;
118 unsigned long dataFrames = 0;
121 String firmware =
"";
122 byte firmwareMajor = 0;
123 byte firmwareMinor = 0;
125 bool isEnhanced =
false;
126 bool isConfig =
false;
127 byte inBuf[LD2410_BUFFER_SIZE];
135 bool sendCommand(
const byte *command);
146 MyLD2410(Stream &serial,
bool debug =
false);
489 bool setGateParameters(
byte gate,
byte movingThreshold,
byte stationaryThreshold);
528 bool setMaxGate(
byte movingGate,
byte stationaryGate,
byte noOneWindow = 5);
OutputControl
The auxiliary output control status.
Definition MyLD2410.h:38
AutoStatus
The status of the auto-thresholds routine.
Definition MyLD2410.h:48
LightControl
The auxiliary light control status.
Definition MyLD2410.h:27
byte getLightLevel()
Get the Light Level.
Definition MyLD2410.cpp:793
bool inEnhancedMode()
Check whether the device is in enhanced mode (continuously sends enhanced presence data)
Definition MyLD2410.cpp:332
bool setMovingThreshold(byte gate, byte movingThreshold)
Set the moving target threshold for a particular gate.
Definition MyLD2410.cpp:601
bool requestParameters()
Request the sensor parameters: range, motion thresholds, stationary thresholds, no-one window.
Definition MyLD2410.cpp:570
byte getLightThreshold()
Get the Light Threshold.
Definition MyLD2410.cpp:805
unsigned long getFrameCount()
Get the number of data frames received so far.
Definition MyLD2410.cpp:352
byte getMaxMovingGate()
Get the maximum moving gate.
Definition MyLD2410.cpp:692
bool requestReboot()
Request reboot.
Definition MyLD2410.cpp:713
byte getFirmwareMajor()
Get the Firmware Major.
Definition MyLD2410.cpp:433
bool requestFirmware()
Request the Firmware.
Definition MyLD2410.cpp:549
bool enhancedMode(bool enable=true)
Request enhanced mode.
Definition MyLD2410.cpp:504
bool setMaxMovingGate(byte movingGate)
Set the maximum moving gate.
Definition MyLD2410.cpp:666
bool setMaxStationaryGate(byte stationaryGate)
Set the maximum stationary gate.
Definition MyLD2410.cpp:679
bool autoThresholds(byte _timeout=10)
Begin the automatic threshold detection routine (firmware >= 2.44)
Definition MyLD2410.cpp:519
bool configMode(bool enable=true)
Request config mode.
Definition MyLD2410.cpp:495
void debugOn()
Set the debug flag.
Definition MyLD2410.cpp:312
Response check()
Call this function in the main loop.
Definition MyLD2410.cpp:73
bool requestResolution()
Request the resolution (gate-width)
Definition MyLD2410.cpp:556
bool inBasicMode()
Check whether the device is in basic mode (continuously sends basic presence data)
Definition MyLD2410.cpp:327
bool requestAuxConfig()
Request the current auxiliary configuration.
Definition MyLD2410.cpp:512
byte getStatus()
Get the status of the sensor: 0 - No presence; 1 - Moving only; 2 - Stationary only; 3 - Both moving ...
Definition MyLD2410.cpp:337
bool setAuxControl(LightControl light_control, byte light_threshold, OutputControl output_control)
Set the Auxiliary Control parameters.
Definition MyLD2410.cpp:819
bool setGateParameters(byte gate, byte movingThreshold, byte stationaryThreshold)
Set the gate parameters for a particular gate, or for all gates at once.
Definition MyLD2410.cpp:577
MyLD2410(Stream &serial, bool debug=false)
Construct a new MyLD2410 object.
Definition MyLD2410.cpp:281
String getMACstr()
Get the Bluetooth MAC address as a String.
Definition MyLD2410.cpp:419
bool setBaud(byte baud)
Reset the serial baud rate. The sensor reboots at the new rate on success.
Definition MyLD2410.cpp:764
bool requestReset()
Request reset to factory default parameters.
Definition MyLD2410.cpp:706
bool setMaxGate(byte movingGate, byte stationaryGate, byte noOneWindow=5)
Set the detection range for moving targets, stationary targets, as well as the no-one window.
Definition MyLD2410.cpp:619
unsigned long getRange_cm()
Get the maximum detection range in [cm].
Definition MyLD2410.cpp:483
AutoStatus getAutoStatus()
Get the status of the automatic threshold detection routine (firmware >= 2.44)
Definition MyLD2410.cpp:530
byte stationaryTargetSignal()
Get the signal from the stationary target.
Definition MyLD2410.cpp:377
void debugOff()
Reset the debug flag.
Definition MyLD2410.cpp:317
const ValuesArray & getStationarySignals()
Get the Stationary Signals object, if in enhanced mode.
Definition MyLD2410.cpp:382
byte getMaxStationaryGate()
Get the maximum stationary gate.
Definition MyLD2410.cpp:699
byte getRange()
Get the maximum detection gate.
Definition MyLD2410.cpp:476
bool begin()
Call this function in setup() to ascertain whether the device is responding.
Definition MyLD2410.cpp:287
bool setBTpassword(const char *passwd)
Set a new BT password.
Definition MyLD2410.cpp:734
bool setResolution(bool fine=false)
Set the resolution of the sensor.
Definition MyLD2410.cpp:563
bool setStationaryThreshold(byte gate, byte stationaryThreshold)
Set the stationary target threshold for a particular gate.
Definition MyLD2410.cpp:610
bool presenceDetected()
Check whether presence was detected in the latest frame.
Definition MyLD2410.cpp:362
bool requestBTon()
Turn Bluetooth ON.
Definition MyLD2410.cpp:720
unsigned long detectedDistance()
Get the detected distance.
Definition MyLD2410.cpp:407
byte getResolution()
Get the sensor resolution (gate-width) in [cm].
Definition MyLD2410.cpp:776
byte getOutLevel()
Get the Light Level.
Definition MyLD2410.cpp:841
LightControl getLightControl()
Get the Light Control parameter.
Definition MyLD2410.cpp:798
bool resetBTpassword()
Reset the BT password.
Definition MyLD2410.cpp:757
unsigned long getTimestamp()
Get the time (in milliseconds) of the last successfully received data frame.
Definition MyLD2410.cpp:347
const ValuesArray & getMovingSignals()
Get the Moving Signals object, if in enhanced mode.
Definition MyLD2410.cpp:402
bool resetAuxControl()
Reset the Auxiliary Control parameters to their default values.
Definition MyLD2410.cpp:834
byte movingTargetSignal()
Get the signal from the moving target.
Definition MyLD2410.cpp:397
const SensorData & getSensorData()
Get the SensorData object.
Definition MyLD2410.cpp:457
unsigned long stationaryTargetDistance()
Get the distance to the stationary target in [cm].
Definition MyLD2410.cpp:372
bool requestBToff()
Turn Bluetooth OFF.
Definition MyLD2410.cpp:727
bool movingTargetDetected()
Check whether a moving target was detected in the latest frame.
Definition MyLD2410.cpp:387
byte getFirmwareMinor()
Get the Firmware Minor.
Definition MyLD2410.cpp:440
OutputControl getOutputControl()
Get the Output Control parameter.
Definition MyLD2410.cpp:812
void end()
Call this function to gracefully close the sensor. Useful for entering sleep mode.
Definition MyLD2410.cpp:306
const byte * getMAC()
Get the Bluetooth MAC address as an array byte[6].
Definition MyLD2410.cpp:412
bool requestMAC()
Request the Bluetooth MAC address.
Definition MyLD2410.cpp:542
bool inConfigMode()
Check whether the device is in config mode (accepts commands)
Definition MyLD2410.cpp:322
String getFirmware()
Get the Firmware as a String.
Definition MyLD2410.cpp:426
bool stationaryTargetDetected()
Check whether a stationary target was detected in the latest frame.
Definition MyLD2410.cpp:367
unsigned long getVersion()
Get the protocol version.
Definition MyLD2410.cpp:447
byte getNoOneWindow()
Get the time-lag of "no presence" in [s]. The sensor begins reporting "no presence" only after no mot...
Definition MyLD2410.cpp:488
const ValuesArray & getStationaryThresholds()
Get the detection thresholds for stationary targets.
Definition MyLD2410.cpp:469
bool setNoOneWindow(byte noOneWindow)
Set the no-one window parameter.
Definition MyLD2410.cpp:657
const char * statusString()
Get the presence status as a c-string.
Definition MyLD2410.cpp:342
const ValuesArray & getMovingThresholds()
Get the detection thresholds for moving targets.
Definition MyLD2410.cpp:462
unsigned long movingTargetDistance()
Get the distance to the moving target in [cm].
Definition MyLD2410.cpp:392