feat: 添加电容式土壤湿度传感器支持,更新相关命令和初始化逻辑
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "esp_adc/adc_oneshot.h"
|
||||
#include "esp_err.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// 你当前接在 GPIO0(ESP32-C3 对应 ADC1_CH0),这里作为默认值。
|
||||
#define CAP_SOIL_SENSOR_DEFAULT_UNIT ADC_UNIT_1
|
||||
#define CAP_SOIL_SENSOR_DEFAULT_CHANNEL ADC_CHANNEL_0
|
||||
|
||||
typedef enum {
|
||||
CAP_SOIL_LEVEL_DRY = 0,
|
||||
CAP_SOIL_LEVEL_MOIST,
|
||||
CAP_SOIL_LEVEL_WET,
|
||||
} cap_soil_level_t;
|
||||
|
||||
typedef struct {
|
||||
adc_unit_t unit;
|
||||
adc_channel_t channel;
|
||||
adc_atten_t atten;
|
||||
adc_bitwidth_t bitwidth;
|
||||
|
||||
// 标定值:空气中读数(干)通常更大,水中读数(湿)通常更小。
|
||||
int air_raw;
|
||||
int water_raw;
|
||||
} cap_soil_sensor_config_t;
|
||||
|
||||
typedef struct {
|
||||
int raw;
|
||||
int voltage_mv;
|
||||
float moisture_percent;
|
||||
cap_soil_level_t level;
|
||||
} cap_soil_sensor_data_t;
|
||||
|
||||
esp_err_t cap_soil_sensor_init(const cap_soil_sensor_config_t *config);
|
||||
esp_err_t cap_soil_sensor_read(cap_soil_sensor_data_t *out_data);
|
||||
esp_err_t cap_soil_sensor_set_calibration(int air_raw, int water_raw);
|
||||
esp_err_t cap_soil_sensor_deinit(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user