firmware/src/ambientlight.c
// ---------------- simple moving average ----------------
//   for dampening of the ambient light sensor readings
simple moving average
for dampening of the ambient light sensor readings
simple moving average for dampening of the ambient light sensor readings
uint16_t moving_average(moving_average_t *avg, uint16_t next) {
  avg->buf[avg->pos] = next;
  avg->pos = (avg->pos + 1) % AVERAGE_POINTS;
  uint32_t sum = 0;
  for (unsigned i = 0; i < AVERAGE_POINTS; i++) {
    sum += avg->buf[i];
  }
  return sum / AVERAGE_POINTS;
}
uint16_t moving_average ( moving_average_t * avg , uint16_t next ) { avg -> buf [ avg -> pos ] = next ; avg -> pos = ( avg -> pos + 1 ) % AVERAGE_POINTS ; uint32_t sum = 0 ; for ( unsigned i = 0 ; i < AVERAGE_POINTS ; i ++ ) { sum += avg -> buf [ i ] ; } return sum / AVERAGE_POINTS ; }
simple moving average
for dampening of the ambient light sensor readings
simple moving average for dampening of the ambient light sensor readings
// TODO: there's a more efficient algorithm than summing every time