Wiggle a GPIO line on shutdown
Dave Higton (1515) 3525 posts |
I’d like to run an arbitrary action on machine shutdown, when everythings is guaranteed safe so I can cut the power. Specifically, I’d like to change the state of a GPIO line. The line I’m thinking of would actually cut the power. |
Andrew Conroy (370) 740 posts |
Can you not put a file into Boot:Choices.PostDesk to do this? |
Dave Higton (1515) 3525 posts |
I don’t know, Andrew. Can I? Will the filing systems all be shut down, so that power can be safely removed – and if they are, how can a file be executed? |
Chris Hall (132) 3554 posts |
There wouldn’t be much point in having a directory Boot:Choices.PostDesk if the filing systems were shut down before the OS tried to run something there. Presumably the PreQuit message has already been sent around so that filing systems will have flushed any open but unwritten files (although RISC OS is not necessarily reliable in this matter, see other posts), and acknowledged so that users will have been asked about any unsaved files and replied. If you then twiddle the GPIO line to power off you will have to have some criterion in your mind about what might not have been done that can be tested for next time you power on. If you tell us what this is it would make answering simpler. Not sure at what point the OS presents the message ‘it is now safe to shut down’ (presumably after PostDesk) or the message ‘are you sure that you want to shut the computer down?’ (presumably just before PostDesk) and you will have to find a way of discriminating between the answers ‘off’ and ‘shutdown’ in PostDesk. Not sure how these alternative answers are communicated to PostDesk. |
Rick Murray (539) 13840 posts |
Shut down is a rather loose term with RISC OS. I wrote some power off code a while back. It does a shutdown itself, then it waits for a few seconds. This is to allow SD cards and SSDs that might have cached information time to write it to the flash. |
Leo Smiers (245) 56 posts |
What is normal in industrial automation is to keep the output high. When the device then is shutdown the output goes low. This is with the precondition that RISCOS / Pi does indeed changed the output to low when the OS is stopped. Otherwise maybe the GPIO module should do this on shutdown itself. |
Rick Murray (539) 13840 posts | |
Rick Murray (539) 13840 posts |
If the shutdown is a physical power off, you don’t need GPIO. Just use the +3.3V… If a soft shutdown (no power off), things are more complicated. |
Chris Evans (457) 1614 posts |
Dave you could look at the Iyonix shutdown code for what is presumable the official way to do it. We also do it on the PandaRO & RapidO ig. The source code of which has been submitted to ROOL but needs some changes before ROOL will make it public. |