添加 JW01 传感器支持,包含初始化和数据读取功能,判断CO2值来判断实物状态。1000为初始阈值

This commit is contained in:
Wang Beihong
2026-04-21 01:47:39 +08:00
parent f0d8b7fe6e
commit cdc35d323a
5 changed files with 274 additions and 8 deletions

View File

@@ -0,0 +1,40 @@
#pragma once
#include <stdbool.h>
#include "esp_err.h"
#ifdef __cplusplus
extern "C" {
#endif
#define JW01_UART_PORT 0
#define JW01_UART_TX_GPIO 43
#define JW01_UART_RX_GPIO 44
#define JW01_UART_BAUDRATE 9600
typedef struct {
float tvoc;
float hcho;
float co2;
bool tvoc_valid;
bool hcho_valid;
bool co2_valid;
} jw01_data_t;
/**
* @brief 初始化 JW01 UART 传感器UART0, TX=43, RX=44
*/
esp_err_t jw01_init(void);
/**
* @brief 读取一帧 JW01 数据
*
* @param out_data 输出数据
* @param timeout_ms 超时时间(ms)
*/
esp_err_t jw01_read(jw01_data_t *out_data, int timeout_ms);
#ifdef __cplusplus
}
#endif