Embedded Artistry C Interfaces
A reference collection of abstract interfaces in C.
Classes | Typedefs
barometric_sensor.h File Reference

Example barometric pressure sensor interfaces that also support altitude calculations. More...

#include <stdbool.h>
#include <stdint.h>
Include dependency graph for barometric_sensor.h:

Go to the source code of this file.

Classes

struct  BarometricSensor
 Virtual Barometric Pressure/Altimeter Sensor Interface. More...
 
struct  BarometricSensor_withCb
 Virtual Barometric Pressure/Altimeter Interface (with callback support) More...
 
struct  BarometricSensor_asyncWithCb
 Virtual Barometric Pressure/Altimeter Interface (asynchronous mode) More...
 

Typedefs

typedef void(* NewBarometricSampleCb) (uint32_t pressure, int32_t altitude)
 Callback function prototype for processing new barometric samples. More...
 
typedef void(* BarometricErrorCb) (void)
 Callback function prototype for barometric sensor errors. More...
 

Detailed Description

Example barometric pressure sensor interfaces that also support altitude calculations.

This header defines three variations of a barometric sensor:

Note that there are differences in fundamental assumptions and function behaviors across the variations. Even small changes in an interface can impact expected behaviors.

Modifying the Interfaces

There are a number of ways you might modify this interface to suit your needs:

Definition in file barometric_sensor.h.

Typedef Documentation

◆ BarometricErrorCb

typedef void(* BarometricErrorCb) (void)

Callback function prototype for barometric sensor errors.

When an error in the virtual barometric device occurs, this callback function will be invoked. The virtual device itself does not support error handling capabilities, so we recommend using this callback in tightly-coupled system code to take the appropriate recovery action (restart the device, restart the system, etc.).

The callback is not guaranteed to run on its own thread of control. We recommend keeping the implementation small. Your function implementation could take the new sample and perform some dispatching operation (e.g., add the value to a queue), ensuring that any "heavy" processing happens on a new thread.

Definition at line 151 of file barometric_sensor.h.

◆ NewBarometricSampleCb

typedef void(* NewBarometricSampleCb) (uint32_t pressure, int32_t altitude)

Callback function prototype for processing new barometric samples.

When a new (and valid) barometric pressure/altitude sample is available, this callback function will be invoked.

The callback is not guaranteed to run on its own thread of control. We recommend keeping the implementation small. Your function implementation could take the new sample and perform some dispatching operation (e.g., add the value to a queue), ensuring that any "heavy" processing happens on a new thread.

Parameters
[in]pressureThe latest pressure sample.

Pressure will be formatted as a 32-bit fixed-point integer with format UQ22.10, giving a resolution of 0.001 hPa.

Parameters
[in]altitudeThe latest altitude sample.

Altitude will be formatted as a signed 32-bit fixed-point number in format Q21.10.

Definition at line 136 of file barometric_sensor.h.