eyal0 / OctoPrint-TimeToFilament

Display time until next filament change and other time-until-whatever info in OctoPrint
3 stars 1 forks source link

Count the number of matches #35

Open eyal0 opened 2 years ago

eyal0 commented 2 years ago

The gcode is ridiculously simple. As per the regex in my previous post, the layer change line simply looks like: ;LAYER_CHANGE

Part of the reason I suggested a feature request to track the number of matches as of the current position is so that one could add a layer number to the layer detection since Prusa slicer default layer change comment doesn't include the layer number.

Originally posted by @puterboy in https://github.com/eyal0/OctoPrint-TimeToFilament/issues/30#issuecomment-1234895285

eyal0 commented 2 years ago

In order to keep it from missing one, I would need to have the search start not at the current file position, rather, continue from where we left off last time. That shouldn't be too bad. It probably won't add all that much processing.

We'll maintain a count per file, that's easy, we already have a cache of the last match location.

We'll provide another variable for user. Easy enough.

When the file changes, we start over by clearing the cache, which we already do, but also we'll start from the beginning of the file.

If TTF is enabled in the middle of printing a file, it will be a lot of processing for the catch up! We might want to limit the processing to perhaps just 100ms per invocation. So it'll eventually get there but it won't big down OctoPrint with too much processing.

eyal0 commented 2 years ago

@puterboy if I make this, are you able to test it?

I would send you a link to download and you'd install that link into OctoPrint. You don't have to uninstall anything. Assuming that it works, you can just keep using it or you can re-install the original, no problems.

For testing:

  1. Print something and look at the count and see if it looks about right.
  2. Disable TimeToFilament, start printing something, wait a few layers, and then enable it and see if it shows the right number. (It should show the correct layer number and not start counting from 1!)

I think that would be it. Of course, if you notice any trouble along the way, you should let me know.

puterboy commented 2 years ago

Sure!

eyal0 commented 2 years ago

Oh boy this is proving difficult. I don't want to automatically enable counting on each regex because counting is potentially expensive. And it's possible to enable or disable counting in the middle of a print, that's complicating it, too. Hmm. Perhaps if I made the enabling of counting part of the regex, so that a counted regex is counted as a brand new regex, maybe that'll simplify the code. I'll think about it.