kontakt / Octoprint-Filament-Reloaded

GNU General Public License v3.0
44 stars 109 forks source link

Spurious GPIO changed callbacks. #57

Open sillyfunnypedro opened 3 years ago

sillyfunnypedro commented 3 years ago

Great job on this. I noticed that the GPIO library is calling the sensor_callback more frequently than when the sensor value changes. The code as written assumes that the callback system is 100% reliable. It is not. The solution is to check the value of the pin in the call back and compare it with the expected state. This allows us to detect whether the GPIO call back is spurious or not.

I added a cache value for the pin that is monitoring the sensor and then check the value when the call back is called. If it is obvious that we are being spuriously called. Its a simple 5 line change that i have included here init.py.zip. I have been running this version on my OctoPrint for 6 months now. I just finished a massive print with 4 filament changes and am thus confident that this is working as required.

Disttrack commented 3 years ago

Great job on this. I noticed that the GPIO library is calling the sensor_callback more frequently than when the sensor value changes. The code as written assumes that the callback system is 100% reliable. It is not. The solution is to check the value of the pin in the call back and compare it with the expected state. This allows us to detect whether the GPIO call back is spurious or not.

I added a cache value for the pin that is monitoring the sensor and then check the value when the call back is called. If it is obvious that we are being spuriously called. Its a simple 5 line change that i have included here init.py.zip. I have been running this version on my OctoPrint for 6 months now. I just finished a massive print with 4 filament changes and am thus confident that this is working as required.

I had a problem and that is that sometimes the filament sensor did not work, I had to throw away a piece of 0.5KG of PLA and tired I came to look and I have seen this post. I have uninstalled the plugin and reinstalled it with these fixes, I have done several tests on the same print and now it seems to work great. Thank you very much! Great job!