rudetrooper / Octoprint-Chituboard

Added basic support chituboard based printers(Elegoo Mars, Anycubic Photon, Phrozen, etc.) to octoprint.
GNU Affero General Public License v3.0
81 stars 18 forks source link

Refresh USB-OTG g_mass_storage after file upload/delete #20

Open bwright86 opened 2 years ago

bwright86 commented 2 years ago

Could support be added to refresh the USB-OTG "piusb.bin" file after certain events?

I'm wondering if there are hooks in Octoprint that could run system commands after events occur?

Step 10 of this article shares steps to "unplug/Plug" the media, so the printer can pickup the new files: https://magpi.raspberrypi.com/articles/pi-zero-w-smart-usb-flash-drive

Essentially the steps are:

It would be nice to have some blocking in place, if a file is being printed. Exposing some configuration settings, so this could be disabled if it cause issues, could be helpful.

But i'm also not sure what happens to a resin printer when the drive is pulled during a print. Does it pause? Does it cancel? I might have to try this and see...

bwright86 commented 2 years ago

It would probably help to share my printer model and software version, to help snapshot this issue. I think some resin printers do refreshes the USB Drive contents automatically.

Printer Model: Anycubic Photon Mono X Printer Firmware: v3.5.4 octopi_version: 0.18.0 octopiuptodate_build: 0.18.0-1.7.3-20220120112925 python.pip: 20.3.3 python.version: 3.7.3

bwright86 commented 2 years ago

I've found that OctoPrint has an Event Manager section in the settings. I am currently leveraging this to run a System command.

It appears the have some decent events to trigger on, like: FileAdded, FileRemoved, Upload, UpdatedFiles

Based on debug logging, it appears UpdatedFiles event is triggered during both Upload and FileRemoved. So this seems to cover both or all scenarios of file changes.

I am currently using the following command to refresh the USB Drive contents: sleep 5 && sudo modprobe -r g_mass_storage && sudo modprobe g_mass_storage file=/piusb.bin stall=0 ro=1

Currently, the debug shows that sleep commands are removed. I will have to play around with getting some delay introduced. Right now, Upload needs about 2 seconds for the filesystem to stabilize, and FileRemoved needs about 5-10 seconds, as it is triggered before the system removes the file.

rudetrooper commented 2 years ago

I don't do this in the plugin because its generally bad practice to run sudo commands within a python application.

bwright86 commented 2 years ago

Fair point, I’ve been looking to see if there are projects to do this “as a user”. There appears to be python-FunctionFS project that might be able to do this.

The hardest part is figuring out when to “unplug/plug” for a refresh. I wouldn't want to do this during a print. So knowing whether a print is in progress would be helpful to block the “unplug/plug” function.

I want to say there is a way to block “uploads” during a print. I’m not in a good place to check this right now.