File syn_sensor.h¶
FileList > sensor > syn_sensor.h
Go to the source code of this file
Sensor polling framework — periodic read → filter → threshold → event. More...
#include "../common/syn_defs.h"#include "../dsp/syn_filter.h"#include "../dsp/syn_signal.h"#include "../port/syn_port_system.h"#include "../util/syn_hysteresis.h"#include <stdbool.h>
Classes¶
| Type | Name |
|---|---|
| struct | SYN_Sensor Sensor descriptor — owns the full read→filter→threshold pipeline. |
Public Types¶
| Type | Name |
|---|---|
| enum | SYN_SensorFilterType Filter type selector for sensor pipeline. |
| typedef int16_t(* | SYN_SensorReadFunc Read function — returns the raw sensor value. |
| typedef void(* | SYN_SensorThresholdCallback Threshold callback — called when threshold is crossed. |
Public Functions¶
| Type | Name |
|---|---|
| void | syn_sensor_clear_filter (SYN_Sensor * sensor) Remove any attached filter. |
| void | syn_sensor_clear_threshold (SYN_Sensor * sensor) Disable threshold monitoring. |
| void | syn_sensor_enable (SYN_Sensor * sensor, bool enable) Enable or disable polling. |
| void | syn_sensor_init (SYN_Sensor * sensor, const char * name, SYN_SensorReadFunc read_func, void * ctx) Initialize a sensor. |
| int16_t | syn_sensor_read_now (SYN_Sensor * sensor) Force an immediate reading (ignoring interval). |
| void | syn_sensor_service (SYN_Sensor * sensors, size_t count) Service an array of sensors (calls syn_sensor_update on each). |
| void | syn_sensor_set_filter_ema (SYN_Sensor * sensor, SYN_FilterEMA * f) Attach an exponential moving-average filter. |
| void | syn_sensor_set_filter_ma (SYN_Sensor * sensor, SYN_FilterMA * f) Attach a moving-average filter. |
| void | syn_sensor_set_filter_median (SYN_Sensor * sensor, SYN_FilterMedian * f) Attach a median filter. |
| void | syn_sensor_set_interval (SYN_Sensor * sensor, uint32_t interval_ms) Set polling interval in milliseconds. |
| void | syn_sensor_set_stats (SYN_Sensor * sensor, SYN_Signal * stats) Attach a signal statistics window. |
| void | syn_sensor_set_threshold (SYN_Sensor * sensor, int32_t threshold, int32_t band, SYN_SensorThresholdCallback on_high, SYN_SensorThresholdCallback on_low, void * ctx) Set a threshold with hysteresis and callbacks. |
| bool | syn_sensor_update (SYN_Sensor * sensor) Update the sensor — poll if interval elapsed, filter, check threshold. |
Public Static Functions¶
| Type | Name |
|---|---|
| int16_t | syn_sensor_raw (const SYN_Sensor * sensor) Get the last raw value. |
| int16_t | syn_sensor_value (const SYN_Sensor * sensor) Get the last filtered value. |
Detailed Description¶
Wires up the full sensor pipeline: poll at an interval, filter the reading, compare against thresholds (with hysteresis), and fire callbacks or set event flags.
** **
static SYN_Sensor temp_sensor;
static SYN_FilterEMA temp_filter;
syn_filter_ema_init(&temp_filter, 64);
syn_sensor_init(&temp_sensor, "temp", read_temperature, NULL);
syn_sensor_set_interval(&temp_sensor, 1000); // poll every 1s
syn_sensor_set_filter_ema(&temp_sensor, &temp_filter);
syn_sensor_set_threshold(&temp_sensor, 8000, 500, // 80.00°C ± 5°C
on_temp_high, on_temp_low, NULL);
// In main loop:
syn_sensor_update(&temp_sensor);
Public Types Documentation¶
enum SYN_SensorFilterType¶
Filter type selector for sensor pipeline.
enum SYN_SensorFilterType {
SYN_SENSOR_FILTER_NONE = 0,
SYN_SENSOR_FILTER_MA = 1,
SYN_SENSOR_FILTER_EMA = 2,
SYN_SENSOR_FILTER_MEDIAN = 3
};
typedef SYN_SensorReadFunc¶
Read function — returns the raw sensor value.
Parameters:
ctxUser context pointer.
Returns:
Raw sensor reading.
typedef SYN_SensorThresholdCallback¶
Threshold callback — called when threshold is crossed.
Parameters:
sensorThe sensor that fired.valueCurrent filtered value.ctxUser context pointer.
Public Functions Documentation¶
function syn_sensor_clear_filter¶
Remove any attached filter.
Parameters:
sensorSensor.
function syn_sensor_clear_threshold¶
Disable threshold monitoring.
Parameters:
sensorSensor.
function syn_sensor_enable¶
Enable or disable polling.
Parameters:
sensorSensor.enabletrue to enable, false to disable.
function syn_sensor_init¶
Initialize a sensor.
void syn_sensor_init (
SYN_Sensor * sensor,
const char * name,
SYN_SensorReadFunc read_func,
void * ctx
)
Parameters:
sensorSensor instance.nameHuman-readable name (for logging).read_funcFunction that reads the sensor hardware.ctxContext passed to read_func.
function syn_sensor_read_now¶
Force an immediate reading (ignoring interval).
Parameters:
sensorSensor.
Returns:
The filtered value.
function syn_sensor_service¶
Service an array of sensors (calls syn_sensor_update on each).
Parameters:
sensorsArray of sensors.countNumber of sensors.
function syn_sensor_set_filter_ema¶
Attach an exponential moving-average filter.
Parameters:
sensorSensor.fInitialized EMA filter.
function syn_sensor_set_filter_ma¶
Attach a moving-average filter.
Parameters:
sensorSensor.fInitialized MA filter.
function syn_sensor_set_filter_median¶
Attach a median filter.
Parameters:
sensorSensor.fInitialized median filter.
function syn_sensor_set_interval¶
Set polling interval in milliseconds.
Parameters:
sensorSensor.interval_msPoll interval.
function syn_sensor_set_stats¶
Attach a signal statistics window.
Each update pushes the filtered value into the signal window, giving you min/max/mean/variance/delta automatically.
Parameters:
sensorSensor.statsInitialized SYN_Signal instance, or NULL to detach.
function syn_sensor_set_threshold¶
Set a threshold with hysteresis and callbacks.
void syn_sensor_set_threshold (
SYN_Sensor * sensor,
int32_t threshold,
int32_t band,
SYN_SensorThresholdCallback on_high,
SYN_SensorThresholdCallback on_low,
void * ctx
)
Parameters:
sensorSensor.thresholdCenter threshold value.bandHysteresis half-width.on_highCalled when value crosses above (threshold + band).on_lowCalled when value drops below (threshold - band).ctxContext for callbacks.
function syn_sensor_update¶
Update the sensor — poll if interval elapsed, filter, check threshold.
Call from your main loop or scheduler task.
Parameters:
sensorSensor.
Returns:
true if a new reading was taken this call.
Public Static Functions Documentation¶
function syn_sensor_raw¶
Get the last raw value.
Parameters:
sensorSensor.
Returns:
Raw reading.
function syn_sensor_value¶
Get the last filtered value.
Parameters:
sensorSensor.
Returns:
Filtered reading.
The documentation for this class was generated from the following file src/syntropic/sensor/syn_sensor.h