Skip to content

Commit

Permalink
CONFIG_HX711_SAMPLE_FETCH_TIMEOUT_MS config option
Browse files Browse the repository at this point in the history
  • Loading branch information
nobodyguy committed Jul 8, 2024
1 parent b807259 commit cb7294f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 6 additions & 0 deletions drivers/sensor/hx711/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 3 additions & 5 deletions drivers/sensor/hx711/hx711.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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)
Expand All @@ -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;
}
Expand Down

0 comments on commit cb7294f

Please # to comment.