feat: init

This commit is contained in:
yangzhijia
2026-07-22 11:27:37 +08:00
commit 49e3abbb34
23 changed files with 4388 additions and 0 deletions

61
include/sensor_manager.h Normal file
View File

@@ -0,0 +1,61 @@
/**
* @file sensor_manager.h
* @brief 传感器管理器 - DHT11温湿度 + 水浸检测
*/
#ifndef SENSOR_MANAGER_H
#define SENSOR_MANAGER_H
#include <Arduino.h>
#include <DHT.h>
#include "config.h"
#define DHT_TYPE DHT11
typedef void (*SensorCallback)(void); // 数据变化通知
class SensorManager {
public:
SensorManager();
~SensorManager();
/** 初始化 */
bool begin();
/** 读取所有传感器 (定时调用) */
void read();
/** 获取温度 */
float getTemp() const { return _temp; }
/** 获取湿度 */
float getHumi() const { return _humi; }
/** DHT11 有效性 */
bool isDhtValid() const { return _dhtValid; }
/** DHT 是否持续故障 */
bool isDhtFault() const { return _dhtErrorCnt >= 10; }
/** 获取水浸状态 */
bool getRainDO() const { return _rainDO; }
/** 水浸传感器有效性 */
bool isRainValid() const { return _rainValid; }
/** 设置数据变化回调 */
void onChange(SensorCallback cb);
private:
DHT* _dht;
float _temp;
float _humi;
bool _dhtValid;
uint8_t _dhtErrorCnt; // 连续失败计数
bool _rainDO; // 1=正常 0=水浸
bool _rainValid;
bool _lastRainRaw;
uint32_t _rainChangeTime;
SensorCallback _callback;
uint32_t _lastReadTime;
};
#endif // SENSOR_MANAGER_H