Sensor/SensorValue in components/sensors/include/sensor.h is modeled on Zephyr's sensor API: a fetch()/get() split so multi-channel sensors (e.g. BME280) pay the hardware read cost once, fixed-point SensorValue (no float/double -- ESP32-C6 has no hardware FPU), a fine-grained SensorChannel enum, and an optional interrupt-driven set_trigger() for the battery-first sleep/wake design. Adds components/sensors/test_apps/host, a self-contained ESP-IDF project building against the `linux` target so this logic is host-testable per AGENTS.md's testing philosophy -- verified in a clean run against the pinned espressif/idf:v6.0.2 image (builds, 4/4 tests pass). Replaces the earlier generic top-level test/README.md placeholder now that a real per-component pattern exists. Also fixes .gitignore's build/managed_components patterns to match nested paths, not just the repo root. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
13 lines
1.4 KiB
Markdown
13 lines
1.4 KiB
Markdown
# sensors
|
|
|
|
Turns raw `drivers` readings into typed sensor values (e.g. debounced contact state, calibrated analog readings). Knows values, not hardware. `REQUIRES drivers`.
|
|
|
|
Common interface: `include/sensor.h` defines `Sensor` and `SensorValue`, deliberately modeled on Zephyr's sensor API:
|
|
|
|
- **fetch()/get() split**: `fetch()` triggers one hardware read and caches it; `get(channel, out)` pulls a single channel out of that cache. Multi-channel sensors (e.g. BME280: temperature + humidity + pressure) pay the hardware cost once per `fetch()`, not once per channel.
|
|
- **Fixed-point `SensorValue`**: `val1 + val2 * 1e-6`, no `float`/`double`. ESP32-C6 has no hardware FPU, so this avoids software-emulated floating point on every sample.
|
|
- **Fine-grained `SensorChannel`** enum (`AmbientTemperature`, `Humidity`, `AccelX`, ...), mirroring Zephyr's `SENSOR_CHAN_*` granularity. `supports(channel)` lets `profiles` discover capabilities generically.
|
|
- **`set_trigger()`** for interrupt-driven sensors (data-ready pin, threshold, reed switch edge), so wake-on-event is possible instead of pure polling -- matters for the battery-first sleep/wake philosophy in `AGENTS.md`. Defaults to unsupported; polling-only sensors don't override it.
|
|
|
|
Every concrete sensor (reed switch, DS18B20, BME280, ...) implements `Sensor`, so `profiles` and `lua_runtime` can consume any of them uniformly.
|