Files
xInfo/main/DashboardFetcher.h
T
2026-08-31 15:05:13 +08:00

67 lines
2.1 KiB
C++

/**
* @file DashboardFetcher.h
* @brief 本地环境数据聚合器。
*
* 无需后端服务器支持,直接从本地硬件传感器(DHT11 + UART 空气质量传感器)
* 以及 ESP32 本地系统时钟(NTP)采集环境数据并生成墨水屏展示数据。
*/
#ifndef DASHBOARD_FETCHER_H
#define DASHBOARD_FETCHER_H
#include "Dht11Driver.h"
#include "SensorDriver.h"
#include <optional>
#include <string>
/**
* @brief 墨水屏展示所需的环境数据结构体。
*/
struct DashboardData {
// 室内/本地环境传感器读数
std::string temperature; ///< 温度(℃),如 "24.5"
std::string humidity; ///< 湿度(%),如 "60.2"
std::string co2; ///< CO₂ 浓度(ppm),如 "450"
std::string tvoc; ///< TVOC 浓度(mg/m³),如 "0.08"
std::string ch2o; ///< 甲醛浓度(mg/m³),如 "0.01"
std::string lastReport; ///< 本地采集时间,如 "14:30"
/// 用于检测数据是否有变化,避免无意义的墨水屏全刷
bool operator==(const DashboardData &other) const {
return temperature == other.temperature &&
humidity == other.humidity &&
co2 == other.co2 &&
tvoc == other.tvoc &&
ch2o == other.ch2o &&
lastReport == other.lastReport;
}
bool operator!=(const DashboardData &other) const {
return !(*this == other);
}
};
/**
* @brief 负责从本地传感器与系统时钟聚合环境数据。
*/
class DashboardFetcher {
public:
/**
* @brief 构造函数。
* @param sensorDriver UART 空气质量传感器驱动引用
* @param dht11Driver DHT11 温湿度传感器驱动引用
*/
DashboardFetcher(SensorDriver &sensorDriver, Dht11Driver &dht11Driver);
~DashboardFetcher();
/**
* @brief 执行本地采样并聚合生成展示数据。
* @return 成功返回聚合好的 DashboardData
*/
std::optional<DashboardData> fetch();
private:
SensorDriver &sensorDriver_;
Dht11Driver &dht11Driver_;
};
#endif // DASHBOARD_FETCHER_H