src/main.c
// points - number of last points to average
number of last points to average
number of last points to average
double pm1_0(int points){
  if (points > PMS_MA_BUFFER_SIZE){
    LOG(LL_ERROR, ("too many ma points"));
    return -1.0;
  };
  double sum = 0.0;
  int count=0;
  for(int i=top-1; count < points; count++, i-- ){
    if (i < 0){
      i = PMS_MA_BUFFER_SIZE-1;
    }
    int val = ma_buffer[i].env_pm10;
    if (val == 0xFFFF)
      break;
    else
      sum += val;
  };
  return count ? (sum / (double)count) : -1.0;
}
double pm1_0 ( int points ) { if ( points > PMS_MA_BUFFER_SIZE ) { LOG ( LL_ERROR , ( " " ) ) ; return -1.0 ; } ; double sum = 0.0 ; int count = 0 ; for ( int i = top - 1 ; count < points ; count ++ , i -- ) { if ( i < 0 ) { i = PMS_MA_BUFFER_SIZE - 1 ; } int val = ma_buffer [ i ] . env_pm10 ; if ( val == 0xFFFF ) break ; else sum += val ; } ; return count ? ( sum / ( double ) count ) : -1.0 ; }
points - number of last points to average
points - number of last points to average