Embedded Artistry C Interfaces
A reference collection of abstract interfaces in C.
|
Example temperature sensor interface. More...
#include <stdbool.h>
#include <stdint.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... | |
Example temperature sensor interface.
This header defines the core interfaces for a virtual temperature sensor. Two samples are provided:
There are a number of ways you might modify this interface to suit your needs:
For the data format, we can consider a few options:
Definition in file temperature_sensor.h.
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.
[in] | temperature | The 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.
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.