Skip to content

Commit

Permalink
added filter_negative to HX711
Browse files Browse the repository at this point in the history
  • Loading branch information
JavanXD committed Oct 26, 2021
1 parent b4e6f7e commit d542fd5
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions read_hx711.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,23 +328,21 @@ def measure_hx711(weight_sensor, ts_fields, hx=None):
channel = weight_sensor["channel"]
except Exception as e:
logger.error("HX711 missing param: " + str(e))
pass

try:
weight = measure_weight(weight_sensor, hx=None)

if 'ts_field_uncompensated' in weight_sensor and type(weight) in (float, int):
fields[weight_sensor["ts_field_uncompensated"]] = float("{0:.3f}".format(weight/1000)) # float only 3 decimals
weight = compensate_temperature(weight_sensor, weight, ts_fields)
if 'ts_field' in weight_sensor and type(weight) in (float, int):
fields[weight_sensor["ts_field"]] = float("{0:.3f}".format(weight/1000)) # float only 3 decimals


if 'filter_negative' in weight_sensor and weight_sensor['filter_negative'] and weight < -1: # filter negative measurements
weight = None

if 'ts_field' in weight_sensor and type(weight) in (float, int):
fields[weight_sensor["ts_field"]] = float("{0:.3f}".format(weight/1000)) # float only 3 decimals

except Exception as e:
logger.error('Measure HX711 DT: ' + str(pin_dt) + ' SCK: ' + str(pin_sck) + ' Channel: ' + channel + ': failed: ' + str(e))
finally:
pass

return fields

0 comments on commit d542fd5

Please sign in to comment.