26inline bool elapsed(uint32_t now, uint32_t since, uint32_t limit)
28 return (now - since) >= limit;
32void pc_presence_core_init(PresenceCore *c, uint32_t debounce_ms, uint32_t hold_ms, uint32_t now)
38 c->debounce_ms = debounce_ms;
40 c->raw_since_ms = now;
41 c->last_high_ms = now;
48bool pc_presence_core_update(PresenceCore *c,
bool pin_high, uint32_t now)
54 const uint8_t lvl = pin_high ? 1u : 0u;
60 c->raw_since_ms = now;
64 if (elapsed(now, c->raw_since_ms, c->debounce_ms))
70 const uint8_t was = c->present;
73 c->last_high_ms = now;
76 else if (c->present && elapsed(now, c->last_high_ms, c->hold_ms))
81 if (c->present != was)
85 return c->present != 0;
88bool pc_presence_core_get(
const PresenceCore *c)
90 return c && c->present != 0;
93bool pc_presence_take_event(PresenceCore *c)
95 if (!c || !c->changed)
103void pc_rcwl0516_core_init(PresenceCore *c, uint32_t now)
105 pc_presence_core_init(c, PC_RCWL0516_DEBOUNCE_MS, PC_RCWL0516_HOLD_MS, now);
126bool pc_rcwl0516_begin(
int out_pin)
128 s_rcwl.pin = out_pin;
129 pinMode(out_pin, INPUT);
130 pc_rcwl0516_core_init(&s_rcwl.core, (uint32_t)millis());
134bool pc_rcwl0516_poll()
140 pc_presence_core_update(&s_rcwl.core, digitalRead(s_rcwl.pin) == HIGH, (uint32_t)millis());
141 return pc_presence_take_event(&s_rcwl.core);
144bool pc_rcwl0516_present()
146 return pc_presence_core_get(&s_rcwl.core);
151bool pc_rcwl0516_begin(
int)
156bool pc_rcwl0516_poll()
161bool pc_rcwl0516_present()
RCWL-0516 microwave Doppler presence sensor, and the shared one-GPIO presence facade (PC_ENABLE_RCWL0...