26#ifndef DETERMINISTICESPASYNCWEBSERVER_LD2410_H
27#define DETERMINISTICESPASYNCWEBSERVER_LD2410_H
33#define LD2410_MAX_GATES 9
36#define LD2410_FRAME_MAX 72
bool ld2410_present(const Ld2410Report *r)
true if r shows any target (moving or stationary).
size_t ld2410_cmd_restart(uint8_t *buf, size_t cap)
Restart the module (word 0x00A3).
const Ld2410Report * ld2410_last()
The most recently decoded report, or nullptr before the first one arrives.
bool ld2410_restart()
Restart the module (brackets the command with enable/end).
size_t ld2410_cmd_engineering(uint8_t *buf, size_t cap, bool on)
Enable (0x0062) or disable (0x0063) engineering mode.
uint16_t ld2410_distance_cm(const Ld2410Report *r)
Best available target distance (cm): the moving distance if moving, else stationary.
bool ld2410_stream_push(Ld2410Stream *s, uint8_t byte, Ld2410Report *out)
Feed one received byte. When it completes a valid report frame, fills out and returns true; otherwise...
bool ld2410_parse_report(const uint8_t *frame, size_t len, Ld2410Report *out)
Decode one whole LD2410 report frame (header F4 F3 F2 F1 .. footer F8 F7 F6 F5). Pure - no I/O....
#define LD2410_MAX_GATES
Range gates the LD2410 reports energy for in engineering mode (gate 0..8).
bool ld2410_begin(int rx_pin, int tx_pin)
Open UART2 at DETWS_LD2410_BAUD on rx_pin / tx_pin.
size_t ld2410_cmd_config_enable(uint8_t *buf, size_t cap)
"Enable configuration" (word 0x00FF, value 0x0001).
#define LD2410_FRAME_MAX
Largest assembled frame: header(4) + len(2) + payload(<=60) + footer(4), rounded up.
bool ld2410_poll()
Pump the UART through the stream.
bool ld2410_set_engineering(bool on)
Enable/disable engineering mode (brackets the command with enable/end).
size_t ld2410_cmd_config_end(uint8_t *buf, size_t cap)
"End configuration" (word 0x00FE).
void ld2410_stream_reset(Ld2410Stream *s)
Reset a stream to the syncing state.
A decoded LD2410 target report. Engineering fields are 0 unless engineering.
uint16_t detect_cm
overall detection distance (cm)
uint8_t static_gate_energy[LD2410_MAX_GATES]
per-gate stationary energy (0-100)
uint16_t moving_cm
moving target distance (cm)
uint8_t out_pin
OUT pin level (0/1)
uint8_t max_static_gate
highest configured stationary gate
uint8_t state
one of LD2410_STATE_*
uint8_t static_energy
stationary target energy (0-100)
uint8_t engineering
1 if this was an engineering-mode frame (per-gate energies valid)
uint8_t moving_gate_energy[LD2410_MAX_GATES]
per-gate moving energy (0-100)
uint8_t moving_energy
moving target energy (0-100)
uint8_t max_moving_gate
highest configured moving gate
uint8_t light
photosensor level (0-255)
uint16_t static_cm
stationary target distance (cm)
Target presence state (report payload byte 2).
static constexpr uint8_t LD2410_STATE_NONE
no target
static constexpr uint8_t LD2410_STATE_BOTH
both a moving and a stationary target
static constexpr uint8_t LD2410_STATE_STATIC
stationary target only
static constexpr uint8_t LD2410_STATE_MOVING
moving target only
Byte-by-byte report-frame reassembler (fixed buffer, resyncs on noise).
uint16_t pos
bytes collected so far
uint8_t hdr_match
header bytes matched while syncing (phase = pos<4)
uint16_t total
expected full-frame length (known after the length field)
uint8_t buf[LD2410_FRAME_MAX]
frame under construction
uint8_t phase
0 sync, 1 length, 2 body