Window average on the greenhouse zone status line
C++ · C++ · beginner · modification
The zone status line used to show the last sensor reading, which jumps around by a degree from one sample to the next on these DHT11 sensors. It now shows the average over the zone's reading window, in tenths like the setpoint. `report.hpp` declares a new `average_tenths(std::span<const int>)` that returns `std::nullopt` for an empty window, `report.cpp` implements it by summing the window and uses it in `zone_line`, and `tests/report_test.cpp` replaces the last-reading test with tests for an empty window, a steady and a spread window, and the new line with and without readings.
Greenhouse climate controller in C++20, standard library only, built with CMake (build files unchanged) by Apple clang 17 locally and GCC 13 in CI with `-Wall -Wextra -Wconversion` treated as errors. `int` is 32 bits on every target. Single-threaded: the control loop copies each zone's window into a `ZoneStatus` and then formats it, so nothing else touches the vector during `zone_line`. Tests use the repo's existing helper `tests/check.hpp` (unchanged): `TEST(name)` registers a test, `CHECK(expr)` and `CHECK_EQ(a, b)` record a failure without stopping, and `tests/check_main.cpp` runs every registered test and exits non-zero on any failure.
Requirements
- `climate::zone_line` (existing, used by the controller's status page and its hourly log) shows the average temperature of the zone's current reading window instead of the last reading: `zone <id>: setpoint <S> C, avg <A> C`, with both temperatures written by `format_tenths` (one decimal), for example `zone 3: setpoint 21.5 C, avg 21.7 C`. A zone with an empty window shows `zone <id>: setpoint <S> C, avg --`.
- A new `climate::average_tenths(readings)` returns the arithmetic mean of the readings in tenths of a degree, rounded half up to the nearest tenth, and `std::nullopt` for no readings. Examples: `{21, 22}` gives 215 (21.5 C), `{21, 21, 22}` gives 213 (21.33 C), `{21, 22, 22}` gives 217 (21.67 C), `{20, 21, 22}` gives 210.
- Readings are whole degrees Celsius from DHT11 sensors, from 0 to 50 inclusive (the sensor driver drops anything else before it reaches the window). A window holds at most 360 readings (one every 10 seconds over the last hour), oldest first. `setpoint_tenths` is from 0 to 500 and `zone_id` from 1 to 16.
- Unchanged: `format_tenths` and the setpoint part of the line.
Files touched
- src/climate/report.hpp
- src/climate/report.cpp
- tests/report_test.cpp