LuckyX182 / Filament_sensor_simplified

OctoPrint Filament sensor simplified plugin repository
Apache License 2.0
29 stars 41 forks source link

Add multiline gcode configuration #56

Open CMR-DEV opened 2 years ago

CMR-DEV commented 2 years ago

Allows #54 by changing the G-code input field to textarea in the settings template.

LuckyX182 commented 2 years ago

I don't get how this should work - should the user put one gcode per line? Should the user put semicolons on each line? There's no indication to user that tells him how it works. Also I tested this on my test Raspberry and it did not seem to work.

CMR-DEV commented 2 years ago

I don't get how this should work - should the user put one gcode per line? Should the user put semicolons on each line? There's no indication to user that tells him how it works. Also I tested this on my test Raspberry and it did not seem to work.

Correct! One G-Code per line. Semicolons induce a comment. Sending multiline G-Code already seems possible by providing a string that is wrapped by \n line breaks to self._printer.commands. Your backend does not validate the user input of the G-Code field at all. So there is no barrier to injecting \n characters on that side. Only the current text-type settings input trims \n line breaks. Honestly I am unsure whether the behavior of self._printer.commands in terms of handling multiline strings is expected like that but at least it worked for me. Docs are quite imprecise about that. Alternatively one could split the G-Code user input by \n and pass each single line or convert it to a list. What G-Codes did you use for testing on your Pi? My attempts on an Ender 3 resulted as expected with

M117 Hello World
M300 S300 P1000

Both have been processed all fine. M117 is an LCD message and M300 is a beep for one second. See [here].(https://www.reprap.org/wiki/G-code) You may link this documentation if you are worried about the user's comprehension.