Hello coders :
I'm developing an add-on (including a RasPi shield) for OctoPrint. This shield embeds a microcontroller and manages power (among other features).
I'd like to know if OctoPrint can "hook" the OctoPi/Linux shutdown procedure so it could ask the user a confirmation before shutting down and powering off after pushing a button. I'd like to make the hardware push button act like the "Shutdown system" option in the system menu.
At this time the PCBs are populated. Everything is working fine on the bench. I routed a "reserved" trace between the MC (on the shield), and the Pi GPIO. So it can communicate with the Pi and OctoPrint. But I'd prefer an OS+Octoprint level solution.
The question is ; could OctoPrint hook a "shutdown procedure" ?
I didn't find an answer reading the OctoPrint APIs...
(not asking for a snippet, but I won't close my eyes and my ears )
There is a shutdown event that you can hook into, but it doesn't allow to block the process, it's more of a I need to do these things to clean up on shutdown. An approach that you would probably be better doing is implementing your own actions on press rather than trying to intercept the dtoverlay command.
Once the OS gets a signal to shutdown, it doesn't let anything interrupt it so you could do anything. By the time OctoPrint finds out it's being shutdown it's too late. I agree with a button that would do the confirmation process then tell the OS to shutdown.
Thanks for your quick answers.
So I'll will try this :
- short button push : send a signal to a GPIO pin OctoPrint polls or trigger an interrupt with, and initiate (or not...) a shutdown after answering to "Are you sure ? etc.". It will use the only "reserved" trace Wish I asked before I send the Gerbers to the manufacturer !
- long button push (like 3 seconds) : send a signal to the shutdown pin (unconditional clean shutdown, at least from a OS point of view)
Will provide a behaviour similar to a PC power button. Doable without any PCB hack, but firing my only round with my only single shot gun ! Should have routed more pins...