Compare commits

..

No commits in common. "main" and "v1.0.0" have entirely different histories.
main ... v1.0.0

View File

@ -58,13 +58,15 @@
#define AP_MAX_CONN 4
#define AP_CHANNEL 6
#define SENSOR_CHAN ADC_CHANNEL_4 // D32 on esp32
#define ADC_CHAN0 ADC_CHANNEL_4
#define ADC_CHAN1 ADC_CHANNEL_5
#define ADC_ATTEN_DB ADC_ATTEN_DB_12
#define THRESHOLD_UP_NVS_NAME "threshold_up"
#define THRESHOLD_LOW_NVS_NAME "threshold_low"
#define NVS_PARTITION "nvs"
#define SENSOR_ADC_CHAN 0
#define MAX_JSON_CONTENT 512
#define FILTER_SAMPLES 5
@ -277,7 +279,8 @@ static app_error_t adc_init(void) {
.atten = ADC_ATTEN_DB,
.bitwidth = ADC_BITWIDTH_DEFAULT,
};
CHECK_ERROR(adc_oneshot_config_channel(adc_handle, SENSOR_CHAN, &config), APP_ERR_ADC_INIT_FAIL);
CHECK_ERROR(adc_oneshot_config_channel(adc_handle, ADC_CHAN0, &config), APP_ERR_ADC_INIT_FAIL);
CHECK_ERROR(adc_oneshot_config_channel(adc_handle, ADC_CHAN1, &config), APP_ERR_ADC_INIT_FAIL);
adc_cali_line_fitting_config_t cali_config = {
.unit_id = ADC_UNIT_1,
@ -299,8 +302,17 @@ static app_error_t adc_init(void) {
return ERR_OK;
}
static int adc_read_raw() {
adc_channel_t adc_channel = SENSOR_CHAN;
static int adc_read_raw(uint8_t channel) {
adc_channel_t adc_channel;
if (channel == 0) {
adc_channel = ADC_CHAN0;
} else if (channel == 1) {
adc_channel = ADC_CHAN1;
} else {
ESP_LOGE(TAG, "Invalid ADC channel: %d", channel);
return -1;
}
CHECK_PTR(adc_handle, APP_ERR_ADC_INIT_FAIL);
@ -309,8 +321,8 @@ static int adc_read_raw() {
return raw_value;
}
static int adc_read_voltage() {
int raw_value = adc_read_raw();
static int adc_read_voltage(uint8_t channel) {
int raw_value = adc_read_raw(channel);
if (raw_value < 0) return -1;
if (is_calibrated) {
@ -325,7 +337,7 @@ static int adc_read_voltage() {
static int read_voltage_filtered(void) {
int sum = 0;
for (int i = 0; i < FILTER_SAMPLES; i++) {
int voltage = adc_read_voltage();
int voltage = adc_read_voltage(SENSOR_ADC_CHAN);
if (voltage < 0) return -1;
sum += voltage;
vTaskDelay(pdMS_TO_TICKS(10));