software:firmware
MakAir Firmware
pressure_utl.cpp File Reference

Pressure computing utility function. More...

#include <algorithm>
#include "../includes/pressure_utl.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...
 

Variables

static int32_t filteredRawPressure = 0
 
static const int32_t RAW_PRESSURE_FILTER_DIVIDER = 5
 
static const int16_t RAW_PRESSURE_TO_MMH20_CONSTANT = 45
 
static const int32_t RAW_PRESSURE_TO_MMH20_NUM = 2238
 
static const int32_t RAW_PRESSURE_TO_MMH20_DEN = 10000
 

Detailed Description

Pressure computing utility function.

Author
Makers For Life

Definition in file pressure_utl.cpp.

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; }

Variable Documentation

◆ filteredRawPressure

int32_t filteredRawPressure = 0
static

Definition at line 16 of file pressure_utl.cpp.

◆ RAW_PRESSURE_FILTER_DIVIDER

const int32_t RAW_PRESSURE_FILTER_DIVIDER = 5
static

Definition at line 18 of file pressure_utl.cpp.

◆ RAW_PRESSURE_TO_MMH20_CONSTANT

const int16_t RAW_PRESSURE_TO_MMH20_CONSTANT = 45
static

Definition at line 45 of file pressure_utl.cpp.

◆ RAW_PRESSURE_TO_MMH20_DEN

const int32_t RAW_PRESSURE_TO_MMH20_DEN = 10000
static

Definition at line 47 of file pressure_utl.cpp.

◆ RAW_PRESSURE_TO_MMH20_NUM

const int32_t RAW_PRESSURE_TO_MMH20_NUM = 2238
static

Definition at line 46 of file pressure_utl.cpp.