File syn_sensor.c¶
FileList > sensor > syn_sensor.c
Go to the source code of this file
Sensor polling framework implementation.
#include "../util/syn_assert.h"#include "syn_sensor.h"#include <string.h>
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 | apply_filter (SYN_Sensor * sensor, int16_t raw) Apply the configured filter to a raw sample. |
| void | do_read (SYN_Sensor * sensor) Perform one sensor read cycle (read + filter + threshold). |
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 apply_filter¶
Apply the configured filter to a raw sample.
Parameters:
sensorSensor instance.rawRaw reading.
Returns:
Filtered value.
function do_read¶
Perform one sensor read cycle (read + filter + threshold).
Parameters:
sensorSensor instance.
The documentation for this class was generated from the following file src/syntropic/sensor/syn_sensor.c