#pragma once #include #include #include "auto_ctrl_thresholds.h" #include "esp_err.h" #ifdef __cplusplus extern "C" { #endif typedef enum { AUTO_ALERT_METRIC_SOIL_MOISTURE = 1, AUTO_ALERT_METRIC_LIGHT_INTENSITY = 2, } auto_alert_metric_t; typedef enum { AUTO_ALERT_STATE_NORMAL = 0, AUTO_ALERT_STATE_ALARM = 1, } auto_alert_state_t; typedef struct { auto_alert_metric_t metric; auto_alert_state_t state; float value; float threshold; int64_t timestamp_ms; } auto_alert_event_t; typedef void (*auto_alert_callback_t)(const auto_alert_event_t *event, void *user_ctx); // Reset internal state at boot. void auto_alerts_init(void); // Register callback sink (e.g. MQTT publisher). Passing NULL clears callback. esp_err_t auto_alerts_register_callback(auto_alert_callback_t callback, void *user_ctx); // Evaluate current sensor values and emit edge-triggered alert events. void auto_alerts_evaluate(bool soil_valid, float soil_moisture_pct, bool light_valid, float light_lux, const auto_ctrl_thresholds_t *thresholds); #ifdef __cplusplus } #endif