UncleRus / esp-idf-lib

Component library for ESP32-xx and ESP8266
https://esp-idf-lib.readthedocs.io/en/latest/
1.37k stars 426 forks source link

Driver for HX711 uses unsigned division for signed average read #486

Closed gaialucas closed 1 year ago

gaialucas commented 1 year ago

The issue

The function hx711_read_average from the HX711 driver computes the average by dividing the accumulate value data by the average times, which is of type size_t (unsigned). For positive values the average value is as expected but for negative values the dividend is considered unsigned and the readings loop to large values (850604851). Simply casting times as unsigned fixes the issue. Currently building for ESP32-C3.

Which SDK are you using?

esp-idf

Which version of SDK are you using?

master (fca4578cf5aca8a9d0947343a570f563d26afe3c)

Which build target have you used?

Component causing the issue

hx711

Anything in the logs that might be useful for us?

No response

Additional information or context

No response

Confirmation