Files
iot-bedroom-environment-con…/main/sensors.h
Wang Beihong f0ac50642d refactor(display): migrate from ST7735S to ST7789 driver
- Rename component directory from lvgl_st7735s_use to lvgl_st7789_use
- Update CMakeLists.txt to register new source files
- Add comprehensive README documentation for ST7789 configuration
- Add time_alarm module with SNTP synchronization and alarm management
- Add sensors header for sensor abstraction layer
2026-03-29 02:31:29 +08:00

66 lines
1.4 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#ifndef SENSORS_H
#define SENSORS_H
#include "esp_err.h"
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#include "driver/i2c_master.h"
#ifdef __cplusplus
extern "C" {
#endif
// 默认 I2C 引脚/参数(如果上层未定义,则使用这些默认值)
#ifndef I2C_MASTER_SCL_IO
#define I2C_MASTER_SCL_IO 5
#endif
#ifndef I2C_MASTER_SDA_IO
#define I2C_MASTER_SDA_IO 4
#endif
#ifndef I2C_MASTER_NUM
#define I2C_MASTER_NUM I2C_NUM_0
#endif
#ifndef I2C_MASTER_FREQ_HZ
#define I2C_MASTER_FREQ_HZ 100000
#endif
// 传感器数据结构体(从 main.c 抽取)
typedef struct
{
float temperature;
float humidity;
float lux;
uint16_t co2_ppm;
uint16_t tvoc_ppb;
bool ahtxx_valid;
bool bh1750_valid;
bool sgp30_valid;
} sensor_data_t;
// 全局传感器数据(在 sensors.c 定义)
extern sensor_data_t g_sensor_data;
// 互斥锁(由 main.c 创建sensors 使用 extern 引用)
extern SemaphoreHandle_t xSensorDataMutex;
// I2C 句柄(在 sensors.c 中定义)
extern i2c_master_bus_handle_t bus_handle;
extern i2c_master_dev_handle_t dev_handle;
// 模块对外接口
esp_err_t sensors_init(void);
esp_err_t sensors_read(void);
// 低层接口 / 任务
esp_err_t i2c_master_init(void);
void i2c0_ahtxx_task(void *pvParameters);
void i2c0_bh1750_task(void *pvParameters);
void i2c0_sgp30_task(void *pvParameters);
void get_sensor_data(sensor_data_t *data);
void print_sensor_data(void);
#ifdef __cplusplus
}
#endif
#endif // SENSORS_H