From 34eea17ebc9640f317d7bd07145869dd6fade99e Mon Sep 17 00:00:00 2001 From: Ashcon Mohseninia Date: Sat, 24 Aug 2024 10:25:11 +0100 Subject: [PATCH] Fix output sensor not being initialized --- src/main.cpp | 6 +++--- src/sensors.cpp | 10 +++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index d319167c..9c0f6958 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -68,11 +68,11 @@ SPEAKER_POST_CODE setup_tcm() if (ret == SPEAKER_POST_CODE::INIT_OK) { spkr = new Speaker(pcb_gpio_matrix->spkr_pin); - if (ESP_OK == Sensors::init_sensors()) + if (ESP_OK == EEPROM::init_eeprom()) { - if (ESP_OK == Solenoids::init_all_solenoids()) + if (ESP_OK == Sensors::init_sensors()) { - if (ESP_OK == EEPROM::init_eeprom()) + if (ESP_OK == Solenoids::init_all_solenoids()) { // Read device mode! CURRENT_DEVICE_MODE = EEPROM::read_device_mode(); diff --git a/src/sensors.cpp b/src/sensors.cpp index fe94944f..c759f150 100644 --- a/src/sensors.cpp +++ b/src/sensors.cpp @@ -266,9 +266,13 @@ esp_err_t Sensors::init_sensors(void){ ESP_RETURN_ON_ERROR(configure_pcnt("N3", pcb_gpio_matrix->n3_pin, &PCNT_HANDLE_N3, &PCNT_C_HANDLE_N3, &n3_avg_buffer), "SENSORS", "N3 PCNT Setup failed"); // Enable output RPM reading if needed - if (VEHICLE_CONFIG.io_0_usage == 1 && VEHICLE_CONFIG.input_sensor_pulses_per_rev != 0) { - ESP_LOGI("SENSORS", "Will init OUTPUT RPM sensor"); - if (ESP_OK == configure_output_pcnt(pcb_gpio_matrix->io_pin, &PCNT_HANDLE_OUTPUT, &PCNT_C_HANDLE_OUTPUT)) { + if (VEHICLE_CONFIG.io_0_usage == 1) { + if (VEHICLE_CONFIG.input_sensor_pulses_per_rev == 0) { + ESP_LOGE("SENSORS", "Cannot init output sensor with 0 pulses/rev specified"); + return ESP_ERR_INVALID_ARG; + } else { + ESP_LOGI("SENSORS", "Will init OUTPUT RPM sensor"); + ESP_RETURN_ON_ERROR(configure_output_pcnt(pcb_gpio_matrix->io_pin, &PCNT_HANDLE_OUTPUT, &PCNT_C_HANDLE_OUTPUT), "SENSORS", "Output PCNT Setup failed"); output_rpm_ok = true; } }