LD2410Async
Asynchronous Arduino ESP32 library for the LD2410 mmWave radar sensor
Loading...
Searching...
No Matches
LD2410CommandBuilder.h
Go to the documentation of this file.
1#pragma once
2#include "Arduino.h"
3#include "LD2410Async.h"
4#include "LD2410Defs.h"
5#include "LD2410Types.h"
6
8
9 inline bool buildMaxGateCommand(byte* out, byte maxMotionGate, byte maxStationaryGate, unsigned short noOneTimeout) {
10
11 if (maxMotionGate < 2 || maxMotionGate > 8) return false;
12 if (maxStationaryGate < 2 || maxStationaryGate > 8) return false;
13
15
16 out[6] = maxMotionGate;
17 out[12] = maxStationaryGate;
18
19 memcpy(&out[18], &noOneTimeout, 2);
20
21 return true;
22
23 }
24
25 inline bool buildGateSensitivityCommand(byte* out, byte gate, byte movingThreshold, byte stationaryThreshold) {
26
27 if (gate > 8 && gate != 0xFF) return false; // 0-8 allowed, or 0xFF (all gates)
28
31
32 if (gate > 8) {
33 out[6] = 0xFF;
34 out[7] = 0xFF;
35 }
36 else {
37 out[6] = gate;
38 out[7] = 0;
39 }
40
41 if (movingThreshold > 100) movingThreshold = 100;
42 if (stationaryThreshold > 100) stationaryThreshold = 100;
43
44 out[12] = movingThreshold;
45 out[18] = stationaryThreshold;
46 return true;
47 }
48
63
64 inline bool buildAuxControlCommand(byte* out, LD2410Types::LightControl lightControl, byte lightThreshold, LD2410Types::OutputControl outputControl) {
67
68 if (lightControl == LD2410Types::LightControl::NOT_SET) return false;
69 if (outputControl == LD2410Types::OutputControl::NOT_SET) return false;
70
71 out[4] = byte(lightControl);
72 out[5] = lightThreshold;
73 out[6] = byte(outputControl);
74 return true;
75 }
76
77 inline bool buildBaudRateCommand(byte* out, byte baudRateSetting) {
79 if (baudRateSetting < 1 || baudRateSetting > 8) return false;
80 out[4] = baudRateSetting;
81 return true;
82 }
83
84 inline bool buildBluetoothPasswordCommand(byte* out, const char* password) {
85 if (!password) return false;
86 size_t len = strlen(password);
87 if (len > 6) return false;
88
91
92 for (unsigned int i = 0; i < 6; i++) {
93 if (i < strlen(password))
94 out[4 + i] = byte(password[i]);
95 else
96 out[4 + i] = byte(' '); // pad with spaces
97 }
98 return true;
99 }
100
101}
bool buildMaxGateCommand(byte *out, byte maxMotionGate, byte maxStationaryGate, unsigned short noOneTimeout)
bool buildDistanceResolutionCommand(byte *out, LD2410Types::DistanceResolution resolution)
bool buildAuxControlCommand(byte *out, LD2410Types::LightControl lightControl, byte lightThreshold, LD2410Types::OutputControl outputControl)
bool buildGateSensitivityCommand(byte *out, byte gate, byte movingThreshold, byte stationaryThreshold)
bool buildBluetoothPasswordCommand(byte *out, const char *password)
bool buildBaudRateCommand(byte *out, byte baudRateSetting)
constexpr byte setAuxControlSettingCommandData[8]
Definition LD2410Defs.h:68
constexpr byte distanceGateSensitivityConfigCommandData[0x16]
Definition LD2410Defs.h:77
constexpr byte setBluetoothPasswordCommandData[10]
Definition LD2410Defs.h:53
constexpr byte setDistanceResolution20cmCommandData[6]
Definition LD2410Defs.h:35
constexpr byte maxGateCommandData[0x16]
Definition LD2410Defs.h:83
constexpr byte setBaudRateCommandData[6]
Definition LD2410Defs.h:38
constexpr byte setDistanceResolution75cmCommandData[6]
Definition LD2410Defs.h:34
OutputControl
Logic level behavior of the auxiliary output pin.
@ NOT_SET
Placeholder for the initial value. Do not use as a config value (it will cause the configuration comm...
DistanceResolution
Distance resolution per gate for detection.
@ RESOLUTION_20CM
Each gate is about 0.20 m, max range about 1.8 m.
@ RESOLUTION_75CM
Each gate is about 0.75 m, max range about 6 m.
LightControl
Light-dependent control status of the auxiliary output.
Definition LD2410Types.h:93
@ NOT_SET
Placeholder for the initial value. Do not use as a config value (it will cause the configuration comm...