38 lines
617 B
C
38 lines
617 B
C
#pragma once
|
||
|
||
#include <stdbool.h>
|
||
#include <stdint.h>
|
||
|
||
#include "esp_err.h"
|
||
|
||
#ifdef __cplusplus
|
||
extern "C" {
|
||
#endif
|
||
|
||
// ESP32-S3: GPIO8 -> ADC1_CHANNEL_7
|
||
#define MQ2_ADC_GPIO 8
|
||
|
||
/**
|
||
* @brief 初始化 MQ-2 ADC 通道
|
||
*/
|
||
esp_err_t mq2_init(void);
|
||
|
||
/**
|
||
* @brief 读取 MQ-2 原始 ADC 值(0~4095)
|
||
*/
|
||
esp_err_t mq2_read_raw(int *raw_out);
|
||
|
||
/**
|
||
* @brief 读取 MQ-2 归一化百分比(0~100)
|
||
*/
|
||
esp_err_t mq2_read_percent(float *percent_out);
|
||
|
||
/**
|
||
* @brief 根据阈值判断是否疑似有害气体/烟雾超标
|
||
*/
|
||
bool mq2_is_alarm(float percent, float threshold_percent);
|
||
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif
|