Your code has trouble with timing the communication with the HX711 and you make a heroic effort to clean up the dirty readings. Timing is a tricky problem to solve but it has been solved very well in the pigpio library which can be used directly from c but also via a daemon and from other languages. There's even a an example HX711 reader written in python.
When I used your code it mostly worked but gave quite slow and erratic readings. When I used the pigpio code it was absolutely rock solid - and fast (frequent completion of readings) too.
So the issue: can you modify your code to use the pigpio library? It'll provide the timing-sensitive functions while your code already does the higher-level work.
Your code has trouble with timing the communication with the HX711 and you make a heroic effort to clean up the dirty readings. Timing is a tricky problem to solve but it has been solved very well in the pigpio library which can be used directly from c but also via a daemon and from other languages. There's even a an example HX711 reader written in python.
When I used your code it mostly worked but gave quite slow and erratic readings. When I used the pigpio code it was absolutely rock solid - and fast (frequent completion of readings) too.
So the issue: can you modify your code to use the pigpio library? It'll provide the timing-sensitive functions while your code already does the higher-level work.