mborjesson / USB-Mouse-to-Serial

Connect a USB mouse to your retro computer using a Raspberry Pi
GNU General Public License v2.0
46 stars 3 forks source link

Feature Request: Power off the Raspi when the attached system is powered off #5

Closed texneus closed 1 year ago

texneus commented 3 years ago

Just a suggestion: Have the raspberry pi power down on it's own after some (perhaps user specified) delay. I'm thinking you already monitor the serial port and can suspend the mouse. The next logical step would be to power down the Raspberry Pi if the mouse is not reactivated within a period of time (i.e. because the main system was powered off).

mborjesson commented 3 years ago

I suppose it wouldn't be too difficult to add. I wonder if it might be better to add so that scripts can be run when it enters or leaves suspended mode so that the user can decide what to do when that happens.

In your use-case, are you going to power it up manually when you are about to use it again?

texneus commented 3 years ago

I like your idea better! More flexibility, but it can't be when the mouse suspends (I assume this is what you mean) as that feature does not seem to work with my mouse (I think your readme hints that not all mice support this). It could be triggered by the same event that would cause the mouse to be suspended, however.

I originally considered using +5V from the PSU so the Pi turns on/off with the PSU but after researching concluded the Pi needs a controlled shutdown otherwise the SD card can become corrupted.

My use scenario (although this could change...I tend to invent this stuff as I go) is the Pi would be powered from it's usual wall wart. I'm envisioning when I power off the PC the Pi does a controlled shutdown on it's own after some delay. A delay would be needed because I noticed during reboots the Pi can no longer "see" the PC until a driver (i.e. CuteMouse) activates it, so this would keep everything alive during this time.

If the system was indeed powered off the Pi eventually times out and does a controlled shutdown without any further user interaction. It can be rebooted when the power strip to the system is cycled.

mborjesson commented 3 years ago

Oh, yeah I meant when the mouse is in inactive mode. That mode is actually called mouse_suspend in the code so I understand if it can be confusing :)

Sounds like an interesting solution. I use my Pi for more than just a mouse emulator so it's always on, but I can see the usefulness of it shutting down.

I will think about how to implement it and take a look at it when I have the time.

mborjesson commented 3 years ago

There's a new branch now called idle_command you can try where I've added two parameters, --idlecommand and --idlecommanddelay. With these two you should be able to do what you want. The value for --idlecommand can be a script or a regular command, as long as it's executable. Delay is 300 seconds by default.

If the mouse is connected again the timer for the execution will be cancelled and will restart from 0 again when it's disconnected.

I hope it works as expected!

texneus commented 3 years ago

Wow! Thank you! You can probably tell I've moved to another project for the time being (I have way to many simultaneous things going on) but I'll try to check this out sometime soon.