5 * DECLARE_SMEAN(temperature, uint8_t, uint16_t);
6 * for (i = 0; i < TEMP_MEANS; ++i)
7 * SMEAN_ADD(temperature, adc_get(), TEMP_MEANS);
8 * printf("mean temperature = %d\n", SMEAN_GET(temperature));
12 * Instantiate a mean instance
14 #define DECLARE_SMEAN(name, Type, SumType) \
22 * Insert a new sample into the mean.
24 * \note \a mean and \a max_samples are evaluated multiple times
26 #define SMEAN_ADD(mean, sample, max_samples) \
28 (mean).sum += (sample); \
29 if ((mean).count++ >= (max_samples)) \
31 (mean).result = (mean).sum / (max_samples); \
38 * Return current mean value.
40 #define SMEAN_GET(mean) ((mean).result)