Sha256: 1c3c728921b9359fcc9189146120b6b602ec10480b96f879b1934af1844b56a2

Contents?: true

Size: 1.05 KB

Versions: 2

Compression:

Stored size: 1.05 KB

Contents

/* =========================================================================
    Ceedling - Test-Centered Build System for C
    ThrowTheSwitch.org
    Copyright (c) 2010-25 Mike Karlesky, Mark VanderVoord, & Greg Williams
    SPDX-License-Identifier: MIT
========================================================================= */

#include "Types.h"
#include "TemperatureFilter.h"
#include <math.h>

static bool initialized;
static float temperatureInCelcius;

void TemperatureFilter_Init(void)
{
  initialized = FALSE;
  temperatureInCelcius = -INFINITY;
}

float TemperatureFilter_GetTemperatureInCelcius(void)
{
  return temperatureInCelcius;
}

void TemperatureFilter_ProcessInput(float temperature)
{
  if (!initialized)
  {
    temperatureInCelcius = temperature;
    initialized = TRUE;
  }
  else
  {
    if (temperature == +INFINITY ||
        temperature == -INFINITY ||
        isnan(temperature))
    {
      initialized = FALSE;
      temperature = -INFINITY;
    }
    
    temperatureInCelcius = (temperatureInCelcius * 0.75f) + (temperature * 0.25);
  }
}

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ceedling-1.0.1 examples/temp_sensor/src/TemperatureFilter.c
ceedling-1.0.0 examples/temp_sensor/src/TemperatureFilter.c