DeterministicESPAsyncWebServer v6.27.1
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
sen0192.h
Go to the documentation of this file.
1// Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4/**
5 * @file sen0192.h
6 * @brief DFRobot SEN0192 10.525 GHz microwave Doppler motion sensor (DETWS_ENABLE_SEN0192).
7 *
8 * The SEN0192 is a 3-pin part (V / G / digital OUT) whose OUT line asserts while it senses motion
9 * (Doppler shift) within its adjustable range. Unlike the framed serial of an LD2410, it carries no
10 * protocol - it is a single digital line - so the "driver" is a debounced presence tracker over that
11 * line: assert presence on an active sample and hold it for a configurable window after the last active
12 * sample, so brief gaps between Doppler returns don't make presence flap.
13 *
14 * The presence state machine (::Sen0192Motion) is pure and host-tested - it takes a sampled line level
15 * and a timestamp and needs no clock or GPIO. The ESP32 binding reads DETWS_SEN0192_PIN each poll (via
16 * detws_millis()) and feeds it in; only that read touches hardware. The OUT polarity and hold window come
17 * from ServerConfig (DETWS_SEN0192_ACTIVE_HIGH / DETWS_SEN0192_HOLD_MS / DETWS_SEN0192_PIN).
18 *
19 * @author Douglas Quigg (dstroy0)
20 * @date 2026
21 */
22
23#ifndef DETERMINISTICESPASYNCWEBSERVER_SEN0192_H
24#define DETERMINISTICESPASYNCWEBSERVER_SEN0192_H
25
26#include "ServerConfig.h"
27
28#if DETWS_ENABLE_SEN0192
29
30#include <stdint.h>
31
32/**
33 * @brief Debounced motion-presence tracker over a single digital line.
34 *
35 * Presence asserts on an active-level sample and is held for @c hold_ms after the last active sample; an
36 * inactive stretch longer than @c hold_ms clears it. Pure: time is passed in, so it is fully host-testable.
37 */
38struct Sen0192Motion
39{
40 bool present; ///< presence currently asserted (respecting the hold window)
41 bool seeded; ///< a first sample has been fed (so the hold timing is meaningful)
42 bool active_high; ///< the active (motion) state is a logic HIGH
43 uint32_t hold_ms; ///< presence is held this long after the last active sample
44 uint32_t last_active_ms; ///< timestamp of the last active-level sample
45 uint32_t motion_events; ///< count of clear -> present transitions (rising edges of presence)
46};
47
48/** @brief Initialize a tracker: @p active_high sets the motion polarity, @p hold_ms the presence hold. */
49void sen0192_motion_init(Sen0192Motion *m, uint32_t hold_ms, bool active_high);
50
51/**
52 * @brief Feed one sampled line level at @p now_ms.
53 * @return true iff this sample started a new presence (a clear -> present edge).
54 */
55bool sen0192_motion_update(Sen0192Motion *m, bool level_high, uint32_t now_ms);
56
57/**
58 * @brief Re-evaluate presence against the hold window at @p now_ms without a new sample (call each tick so
59 * presence clears on time even when no fresh sample arrives). @return the current presence.
60 */
61bool sen0192_motion_tick(Sen0192Motion *m, uint32_t now_ms);
62
63/** @brief Current presence (respecting the hold window). */
64bool sen0192_motion_present(const Sen0192Motion *m);
65
66/** @brief Number of clear -> present transitions since init. */
67uint32_t sen0192_motion_events(const Sen0192Motion *m);
68
69/** @brief Milliseconds since the last active-level sample (0 if none yet). */
70uint32_t sen0192_motion_active_age_ms(const Sen0192Motion *m, uint32_t now_ms);
71
72// --- ESP32 binding (GPIO poll; no-ops on a host build) ---------------------------------------
73
74/**
75 * @brief Configure DETWS_SEN0192_PIN as an input and start tracking (polarity / hold from ServerConfig).
76 * @return true on ESP32, false on a host build.
77 */
78bool sen0192_begin(void);
79
80/** @brief Sample the pin now (via detws_millis()). @return true iff a new presence just started. */
81bool sen0192_poll(void);
82
83/** @brief Current presence. */
84bool sen0192_present(void);
85
86/** @brief Count of motion events (clear -> present transitions) since sen0192_begin(). */
87uint32_t sen0192_motion_count(void);
88
89#endif // DETWS_ENABLE_SEN0192
90
91#endif // DETERMINISTICESPASYNCWEBSERVER_SEN0192_H
User-facing configuration for DeterministicESPAsyncWebServer.