From cb7294f73a4de03dcbe52fa010fd5d797bb4f57c Mon Sep 17 00:00:00 2001 From: nobodyguy <4577368+nobodyguy@users.noreply.github.com> Date: Mon, 8 Jul 2024 20:12:45 +0200 Subject: [PATCH] CONFIG_HX711_SAMPLE_FETCH_TIMEOUT_MS config option --- drivers/sensor/hx711/Kconfig | 6 ++++++ drivers/sensor/hx711/hx711.c | 8 +++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/sensor/hx711/Kconfig b/drivers/sensor/hx711/Kconfig index 9e58678..c6a4c5b 100644 --- a/drivers/sensor/hx711/Kconfig +++ b/drivers/sensor/hx711/Kconfig @@ -77,6 +77,12 @@ config HX711_GAIN default 2 if HX711_GAIN_32X default 3 if HX711_GAIN_64X +config HX711_SAMPLE_FETCH_TIMEOUT_MS + int "HX711 sampling timeout" + default 1000 + help + Max waiting time (ms) for data ready state. + config HX711_ENABLE_MEDIAN_FILTER bool "Apply median filter to output" depends on MINIMAL_LIBC # int types, qsort() diff --git a/drivers/sensor/hx711/hx711.c b/drivers/sensor/hx711/hx711.c index 0e0e10a..0607923 100644 --- a/drivers/sensor/hx711/hx711.c +++ b/drivers/sensor/hx711/hx711.c @@ -16,8 +16,6 @@ #include "hx711.h" -#define SAMPLE_FETCH_TIMEOUT_MS 600 - LOG_MODULE_REGISTER(HX711, CONFIG_SENSOR_LOG_LEVEL); static struct hx711_data hx711_data = { @@ -91,7 +89,7 @@ static int hx711_cycle(struct hx711_data *data) * * @retval 0 on success, * @retval -EACCES error if module is not powered up. - * @retval -EIO error if SAMPLE_FETCH_TIMEOUT_MS elapsed with no data available. + * @retval -EIO error if CONFIG_HX711_SAMPLE_FETCH_TIMEOUT_MS elapsed with no data available. * */ static int hx711_sample_fetch(const struct device *dev, enum sensor_channel chan) @@ -108,8 +106,8 @@ static int hx711_sample_fetch(const struct device *dev, enum sensor_channel chan return -EACCES; } - if (k_sem_take(&data->dout_sem, K_MSEC(SAMPLE_FETCH_TIMEOUT_MS))) { - LOG_ERR("Weight data not ready within %d ms", SAMPLE_FETCH_TIMEOUT_MS); + if (k_sem_take(&data->dout_sem, K_MSEC(CONFIG_HX711_SAMPLE_FETCH_TIMEOUT_MS))) { + LOG_ERR("Weight data not ready within %d ms", CONFIG_HX711_SAMPLE_FETCH_TIMEOUT_MS); ret = -EIO; goto exit; }