/// © MiroZ 2024 #ifndef __SENSORS_H__ #define __SENSORS_H__ #include #include #include #include "Bme68x.h" #include "Bmp280.h" #include "LD2410.h" #include #include "../AppIF.h" class SensorService { protected: TaskHandle_t m_i2c1_task = nullptr; TaskHandle_t m_i2c2_task = nullptr; void run_i2c_1(); void run_uart(); Bmp280 * m_bmp280 = nullptr; Bme68x * m_bme68x = nullptr; LD2410 * m_ld2410 = nullptr; AppIF & m_app_if; void postBme68xData(float pressure, float temp); void processLight(int light_value); void processPressure(float pressure); uint16_t m_light_value = 0; public: SensorService(AppIF & app_if); void start(); private: static const size_t MAX_LIGHT_SAMPLES = 200; struct LightMeasurement { uint16_t samples[MAX_LIGHT_SAMPLES]; size_t sample_count; uint64_t window_start; bool leds_were_controlled; }; LightMeasurement m_light_measurement; static const uint64_t LIGHT_WINDOW_MS = 2000; static const uint32_t LIGHT_SYNC_INTERVAL_MS = 100; // Sync every 100ms void synchronizedLightMeasurement(uint16_t light_value); double calculateMovingAverage(const uint16_t* samples, size_t count, size_t avg_count = 10); uint16_t findMinimum(const uint16_t* samples, size_t count); }; #endif