Skip to content

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.

void syn_sensor_clear_filter (
    SYN_Sensor * sensor
) 

Parameters:

  • sensor Sensor.

function syn_sensor_clear_threshold

Disable threshold monitoring.

void syn_sensor_clear_threshold (
    SYN_Sensor * sensor
) 

Parameters:

  • sensor Sensor.

function syn_sensor_enable

Enable or disable polling.

void syn_sensor_enable (
    SYN_Sensor * sensor,
    bool enable
) 

Parameters:

  • sensor Sensor.
  • enable true 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:

  • sensor Sensor instance.
  • name Human-readable name (for logging).
  • read_func Function that reads the sensor hardware.
  • ctx Context passed to read_func.

function syn_sensor_read_now

Force an immediate reading (ignoring interval).

int16_t syn_sensor_read_now (
    SYN_Sensor * sensor
) 

Parameters:

  • sensor Sensor.

Returns:

The filtered value.


function syn_sensor_service

Service an array of sensors (calls syn_sensor_update on each).

void syn_sensor_service (
    SYN_Sensor * sensors,
    size_t count
) 

Parameters:

  • sensors Array of sensors.
  • count Number of sensors.

function syn_sensor_set_filter_ema

Attach an exponential moving-average filter.

void syn_sensor_set_filter_ema (
    SYN_Sensor * sensor,
    SYN_FilterEMA * f
) 

Parameters:

  • sensor Sensor.
  • f Initialized EMA filter.

function syn_sensor_set_filter_ma

Attach a moving-average filter.

void syn_sensor_set_filter_ma (
    SYN_Sensor * sensor,
    SYN_FilterMA * f
) 

Parameters:

  • sensor Sensor.
  • f Initialized MA filter.

function syn_sensor_set_filter_median

Attach a median filter.

void syn_sensor_set_filter_median (
    SYN_Sensor * sensor,
    SYN_FilterMedian * f
) 

Parameters:

  • sensor Sensor.
  • f Initialized median filter.

function syn_sensor_set_interval

Set polling interval in milliseconds.

void syn_sensor_set_interval (
    SYN_Sensor * sensor,
    uint32_t interval_ms
) 

Parameters:

  • sensor Sensor.
  • interval_ms Poll interval.

function syn_sensor_set_stats

Attach a signal statistics window.

void syn_sensor_set_stats (
    SYN_Sensor * sensor,
    SYN_Signal * stats
) 

Each update pushes the filtered value into the signal window, giving you min/max/mean/variance/delta automatically.

Parameters:

  • sensor Sensor.
  • stats Initialized 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:

  • sensor Sensor.
  • threshold Center threshold value.
  • band Hysteresis half-width.
  • on_high Called when value crosses above (threshold + band).
  • on_low Called when value drops below (threshold - band).
  • ctx Context for callbacks.

function syn_sensor_update

Update the sensor — poll if interval elapsed, filter, check threshold.

bool syn_sensor_update (
    SYN_Sensor * sensor
) 

Call from your main loop or scheduler task.

Parameters:

  • sensor Sensor.

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.

static int16_t apply_filter (
    SYN_Sensor * sensor,
    int16_t raw
) 

Parameters:

  • sensor Sensor instance.
  • raw Raw reading.

Returns:

Filtered value.


function do_read

Perform one sensor read cycle (read + filter + threshold).

static void do_read (
    SYN_Sensor * sensor
) 

Parameters:

  • sensor Sensor instance.


The documentation for this class was generated from the following file src/syntropic/sensor/syn_sensor.c