build: the libavr pin advances past the audit sweep, and the numbers get names

The pin crosses libavr's phase-6 close and the guideline sweep behind it;
the image is byte-identical in both modes at 8206 bytes.

The port's own sweep, against the same rules. Every mutable `static inline`
takes `m_` - uptime's counter, the sampler's window, the controller's five,
the statistics histogram and the terminal's line state (rule 46; a private
`static constexpr` is a constant rather than state and keeps its bare name).
The command table is `std::to_array` and the serial config breaks one member
per line (rules 36, 40). And three numbers get the name they already had
somewhere: duty goes through `percent_t::of()` rather than a hand-built
basis-point count, the ADC's top count is `thermistor::adc_full_scale`
instead of 1023 in four places, and the two `0xffffffff` are `open_circuit`
- which was already declared five lines away - and `never_written`, which
replaces a comment explaining the literal (rules 5, 6, 41).

Measured, not assumed: rendering `adc_full_scale` into the `show` line
instead of leaving it in the message string cost 6 bytes, so the display
text stays text.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-12 14:40:33 +02:00
parent 1489f4c3a0
commit 837b832bc7
7 changed files with 102 additions and 90 deletions

View File

@@ -9,7 +9,7 @@
// Temperature histogram: one uint32 bucket per C 0..99, sampled once a
// second, written back to EEPROM every 30 minutes (update() only touches
// changed bytes). Erased EEPROM reads back as 0xffffffff - treated as 0.
// changed bytes).
namespace app {
class statistics {
@@ -17,11 +17,15 @@ class statistics {
static constexpr std::uint32_t sample_delay_ms = 1'000;
static constexpr std::uint32_t writeback_delay_ms = 1'800'000;
// What an erased cell reads back as, so a bucket nobody has written yet
// counts as no samples rather than four billion.
static constexpr std::uint32_t never_written = ~std::uint32_t{0};
using stored = avr::eeprom::var<std::array<std::uint32_t, range>, 0>;
static inline std::array<std::uint32_t, range> histogram{};
static inline std::uint64_t last_sample = 0;
static inline std::uint64_t last_writeback = 0;
static inline std::array<std::uint32_t, range> m_histogram{};
static inline std::uint64_t m_last_sample = 0;
static inline std::uint64_t m_last_writeback = 0;
static constexpr std::uint8_t clamp(std::int8_t t)
{
@@ -33,9 +37,9 @@ class statistics {
static void init()
{
histogram = stored::read();
for (auto &bucket : histogram) {
if (bucket == 0xffffffff) {
m_histogram = stored::read();
for (auto &bucket : m_histogram) {
if (bucket == never_written) {
bucket = 0;
}
}
@@ -44,31 +48,31 @@ class statistics {
static void record(std::int8_t celsius)
{
auto now = uptime::millis();
if (now >= last_sample + sample_delay_ms) {
++histogram[clamp(celsius)];
last_sample = now;
if (now >= m_last_sample + sample_delay_ms) {
++m_histogram[clamp(celsius)];
m_last_sample = now;
}
if (now >= last_writeback + writeback_delay_ms) {
if (now >= m_last_writeback + writeback_delay_ms) {
save();
last_writeback = now;
m_last_writeback = now;
}
}
static void save()
{
stored::update(histogram);
stored::update(m_histogram);
}
static void reset()
{
histogram = {};
stored::update(histogram);
m_histogram = {};
stored::update(m_histogram);
}
static std::uint8_t min_temperature()
{
for (std::uint8_t i = 0; i < range; ++i) {
if (histogram[i]) {
if (m_histogram[i]) {
return i;
}
}
@@ -78,7 +82,7 @@ class statistics {
static std::uint8_t max_temperature()
{
for (std::uint8_t i = range; i > 0; --i) {
if (histogram[i - 1]) {
if (m_histogram[i - 1]) {
return i - 1;
}
}
@@ -88,7 +92,7 @@ class statistics {
static std::uint64_t total_samples()
{
std::uint64_t total = 0;
for (auto bucket : histogram) {
for (auto bucket : m_histogram) {
total += bucket;
}
return total;
@@ -97,7 +101,7 @@ class statistics {
static std::uint32_t highest_bucket()
{
std::uint32_t highest = 0;
for (auto bucket : histogram) {
for (auto bucket : m_histogram) {
if (bucket > highest) {
highest = bucket;
}
@@ -107,7 +111,7 @@ class statistics {
static std::uint32_t bucket(std::uint8_t celsius)
{
return histogram[clamp(static_cast<std::int8_t>(celsius))];
return m_histogram[clamp(static_cast<std::int8_t>(celsius))];
}
};