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

Example temperature sensor interface. More...

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

Go to the source code of this file.

Classes

struct  TemperatureSensor
 Virtual Temperature Sensor Interface. More...
 
struct  TemperatureSensor_withCb
 Virtual Temperature Sensor Interface with Callback Support. More...
 

Typedefs

typedef void(* NewTemperatureSampleCb) (int16_t temperature)
 Callback function prototype for processing new temperature samples. More...
 
typedef void(* TemperatureErrorCb) (void)
 Callback function prototype for temperature sensor errors. More...
 

Detailed Description

Example temperature sensor interface.

This header defines the core interfaces for a virtual temperature sensor. Two samples are provided:

  1. A basic interface for reading temperature (TemperatureSensor)
  2. An interface expanded with support for callbacks (TemperatureSensor_withCb)

Modifying the Interfaces

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

Possible Humidity Specifications

For the data format, we can consider a few options:

Definition in file temperature_sensor.h.

Typedef Documentation

◆ NewTemperatureSampleCb

typedef void(* NewTemperatureSampleCb) (int16_t temperature)

Callback function prototype for processing new temperature samples.

When a new (and valid) temperature 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]temperatureThe latest temperature sample.

Temperature readings will be provided as a signed 16-bit fixed point integer in format Q7.8.

Definition at line 98 of file temperature_sensor.h.

◆ TemperatureErrorCb

typedef void(* TemperatureErrorCb) (void)

Callback function prototype for temperature sensor errors.

When an error in the virtual temperature 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 113 of file temperature_sensor.h.