return retval;
}
-float aqi_calc_pm10(uint16_t pm10){
- // precision is integer, so div 100
- // ex. 2543 / 100 = 25 (real value: 25)
- pm10 /= 100;
+int get_lookup_int_pm10(uint16_t pm10){
int i = 0;
while (i < 6){
if (pm10 < AQI_LOOKUP_TABLE[i].pm10_high ){
}
if (pm10 > AQI_LOOKUP_TABLE[i].pm10_high){
printf("pm10 too high for aqi lookup, this should never happen %d > %d\n", pm10, AQI_LOOKUP_TABLE[i].pm10_high );
- return 0.0;
+ return -1;
}
+ return i;
+}
+
+float aqi_calc_pm10(uint16_t pm10){
+ // precision is integer, so div 100
+ // ex. 2543 / 100 = 25 (real value: 25)
+ pm10 /= 100;
+ int i = get_lookup_int_pm10(pm10);
return linear_calc(pm10, AQI_LOOKUP_TABLE[i], LOOKUP_PM10);
}
-float aqi_calc_pm25(uint16_t pm25){
- // precision is one decimal, so div 10:
- // ex. 2543 / 10 = 254 (real value: 25.4)
- pm25 /= 10;
+int get_lookup_int_pm25(uint16_t pm25){
printf("modified pm25: %d\n", pm25);
int i = 0;
while (i < 6){
}
if (pm25 > AQI_LOOKUP_TABLE[i].pm25_high){
printf("pm25 too high for aqi lookup, this should never happen %d > %d\n", pm25, AQI_LOOKUP_TABLE[i].pm25_high );
- return 0.0;
+ return -1;
}
+ return i;
+}
+
+float aqi_calc_pm25(uint16_t pm25){
+ // precision is one decimal, so div 10:
+ // ex. 2543 / 10 = 254 (real value: 25.4)
+ pm25 /= 10;
+ int i = get_lookup_int_pm25(pm25);
return linear_calc(pm25, AQI_LOOKUP_TABLE[i], LOOKUP_PM25);
}
+
+int get_lookup_highest(int pm10, int pm25){
+ int pm10_lookup = get_lookup_int_pm10(pm10/100);
+ int pm25_lookup = get_lookup_int_pm25(pm25/10);
+ if (pm25_lookup > pm10_lookup){
+ return pm25_lookup;
+ } else {
+ return pm10_lookup;
+ }
+}
+