software:firmware
MakAir Firmware
pressure_utl.h File Reference

Pressure computing utility function. More...

#include <stdint.h>

Go to the source code of this file.

Functions

int16_t convertSensor2Pressure (uint32_t sensorValue)
 Convert the analog value from sensor to a pressure value. More...
 
void resetFilteredRawPressure ()
 Reset the value of void filteredRawPressure to 0. More...
 

Detailed Description

Pressure computing utility function.

Author
Makers For Life

Definition in file pressure_utl.h.

Function Documentation

◆ convertSensor2Pressure()

int16_t convertSensor2Pressure ( uint32_t  sensorValue)

Convert the analog value from sensor to a pressure value.

Parameters
sensorValueValue read from the analog input connected to the sensor
Returns
The pressure in mmH2O

Definition at line 51 of file pressure_utl.cpp.

51  {
52  int32_t rawPressure = static_cast<int32_t>(sensorValue);
53  int32_t delta = rawPressure - filteredRawPressure;
54 
55  // Adjust delta so that the division result will be rounded away from zero.
56  // This is needed to guaranty that filteredRawPressure will reach
57  // rawPressure when it is constant.
58  int32_t rounding = RAW_PRESSURE_FILTER_DIVIDER - 1;
59  delta += (delta > 0) ? rounding : -rounding;
61 
62  int16_t scaledRawPressure =
64  return scaledRawPressure - RAW_PRESSURE_TO_MMH20_CONSTANT;
65 }
static int32_t filteredRawPressure
static const int32_t RAW_PRESSURE_FILTER_DIVIDER
static const int32_t RAW_PRESSURE_TO_MMH20_DEN
static const int32_t RAW_PRESSURE_TO_MMH20_NUM
static const int16_t RAW_PRESSURE_TO_MMH20_CONSTANT

◆ resetFilteredRawPressure()

void resetFilteredRawPressure ( )

Reset the value of void filteredRawPressure to 0.

Note
Mainly for testing purpose

Definition at line 68 of file pressure_utl.cpp.

68 { filteredRawPressure = 0; }