| 1 | #include "Types.h" |
| 2 | #include "TemperatureFilter.h" |
| 3 | #include <math.h> |
| 4 | |
| 5 | static bool initialized; |
| 6 | static float temperatureInCelcius; |
| 7 | |
| 8 | void TemperatureFilter_Init(void) |
| 9 | { |
| 10 | initialized = FALSE; |
| 11 | temperatureInCelcius = -INFINITY; |
| 12 | } |
| 13 | |
| 14 | float TemperatureFilter_GetTemperatureInCelcius(void) |
| 15 | { |
| 16 | return temperatureInCelcius; |
| 17 | } |
| 18 | |
| 19 | void TemperatureFilter_ProcessInput(float temperature) |
| 20 | { |
| 21 | if (!initialized) |
| 22 | { |
| 23 | temperatureInCelcius = temperature; |
| 24 | initialized = TRUE; |
| 25 | } |
| 26 | else |
| 27 | { |
| 28 | if (temperature == +INFINITY || |
| 29 | temperature == -INFINITY || |
| 30 | temperature == +NAN || |
| 31 | temperature == -NAN) |
| 32 | { |
| 33 | initialized = FALSE; |
| 34 | temperature = -INFINITY; |
| 35 | } |
| 36 | |
| 37 | temperatureInCelcius = (temperatureInCelcius * 0.75f) + (temperature * 0.25); |
| 38 | } |
| 39 | } |