Automatic shutdown on idle
What's new
- Added an option under [Settings->Power] that allows Flipper to be automatically turned off after a certain amount of time has passed without input from user ( the options are 15min, 30min, 1h, 2h, 6h, 12h, 24h, 48h).
Verification
- A submenu named [Shutdown on Idle] has been added under [Settings->Power]. Under that submenu is possible to set how long Flipper will be idle before shutting off on his own and to turn off this feature.
Checklist (For Reviewer)
- [ ] PR has description of feature/bug or link to Confluence/Jira task
- [ ] Description contains actions to verify feature/bugfix
- [ ] I've built this code, uploaded it to the device and verified feature/bugfix
@hedger
Looks good to me, but introducing a new file in /int will take up at least 4Kb of internal storage - and we're running short on it for debug builds. We'll discuss this feature internally and may merge it after releasing v.0.65.
Good to know this. I've been looking at adding a setting to the Power application for optionally limiting the battery charging voltage, and that would've required creating a new /int file as well.
If this idle shutdown PR gets merged, I can base my battery charge limit configuration efforts atop this so there will be two settings stored in /int/.power.settings, not just one. That might make the 4 Kb minimum filesystem cost more palatable?
Hi flipper team, how about to merge this? We are at 0.66 already.
Hi @azaitsev, will be included in next release. Sorry for delay.
@SHxKenzuto May I ask you to merge dev?
@SHxKenzuto May I ask you to merge dev?
Ok, doing it right now
@skotopes merge completed
Thanks. This RC is already packed with more features than our QA can test, so I'll merge it after this release.
@skotopes could you merge for the next release?
Most likely after: reading file every second doesn't looks good. I'd rather provide some API on power service level.
Most likely after: reading file every second doesn't looks good. I'd rather provide some API on power service level.
@skotopes Maybe I can create a custom event that is fired when the setting is modified and activates a callback that updates the timer in the data structure.
Best option is to implement it in a same way as notification service do
Please let mw know if you need any help.
@skotopes could you review the changes, please?
Hi @SHxKenzuto, I built the custom firmware that included your patch and used it for a while. Seems flipper shutdowns after no key is pressed by idle time regardless of running any application or not. Could you please add the check to prevent shutdown if any application is running? Or add the option to keep the flipper on for exact list of applications.
UPD: It would be good to add 2 hours interval. I added it, and seems it's has been the optimal compromise.
Hi @SHxKenzuto, I built the custom firmware that included your patch and used it for a while. Seems flipper shutdowns after no key is pressed by idle time regardless of running any application or not. Could you please add the check to prevent shutdown if any application is running? Or add the option to keep the flipper on for exact list of applications.
UPD: It would be good to add 2 hours interval. I added it, and seems it's has been the optimal compromise.
Hi, in order to do what you're asking there should be a system to make my service aware of running tasks and stop the timer in such cases. I don't really know if there's already such system or if it has to be designed. In the latter case, it wouldn't be so simple. A simpler way would be checking if the current view is the home with flipper's sprite and activate the timer only when the device is in that state. Right now I'll add the 2 hours interval. What do you think?
Would it make sense to be consistent with auto lock feature, auto shutdown in the same conditions when auto lock happens?
Would it make sense to be consistent with auto lock feature, auto shutdown in the same conditions when auto lock happens?
That's a good idea, I'll check it out
@SHxKenzuto can I help you somehow on this PR? The idea is awesome, would be great to implement it.
@SHxKenzuto can I help you somehow on this PR? The idea is awesome, would be great to implement it.
Hi, there's a lot going on right now in my life, so a little help would be very appreciated. Thank you!
From an initial look, suspending the auto-shutdown timer when inside an app requires hooking into DesktopGlobalBeforeAppStarted and DesktopGlobalAfterAppFinished from applications/services/desktop/desktop.c.
I'm unsure if the global events broadcast by desktop.c in desktop_events.h can be subscribed to from other services. If not, my next guess would be mimicking how the dolphin deed/level-up system works since that can receive events from any app/service.
With commit 400558acfd4e6c7f62339b59646ea7af1bd8b582 I've added a hook to LoaderEventTypeApplicationStarted and LoaderEventTypeApplicationStopped events. That should stop the shutdown timer when an application is running. Thanks to @digitalcircuit for the tip.
@skotopes or @hedger I'd be glad if you could review again the changes.
Un-draft when ready.
I've built from the most recent set of commits (2022-12-18) and tested it. Overall, this is a nice feature!
Testing - ⚠️ potential issues
This pull request functions as is. However, there are two changes I'd recommend making, noted in tests B and F.
Setup
- Compile and install firmware
- Set
Settings→Power→Shutdown on Idle→Set Timeto15min - Return to desktop
- Unplug Flipper from USB connection
A: Unplugged, auto-shutoff at desktop when idle - ✅ pass
- Make sure the Flipper desktop is showing
- Wait 15 or so minutes
- Ensure the Flipper has powered off
B: Plugged in, auto-shutoff at desktop when idle - ⚠️ potential issues
- Plug Flipper into USB charger and/or computer
- Make sure the Flipper desktop is showing
- Wait 15 or so minutes
- Ensure the Flipper remains turned on
- Unplug the Flipper from the USB charger
- Ensure the Flipper remains turned on
- Wait 15 or so minutes
- Ensure the Flipper has powered off
Current situation
The Flipper will immediately shut off without warning when unplugged from USB.
While this could be intentional, it feels unintuitive to me.
ℹ Recommended changes
- When connected to USB power, pause the auto-shutdown timer
- When disconnected from USB power, re-enable and reset the auto-shutdown timer if it is configured
- This needs to avoid conflicting with the app launch/quit event handling so if either an app is open or USB is connected it won't auto-shutdown
- Consider how charging is inhibited for the battery charging chip - every request to pause increments a counter, request to resume decrements it, and only when the counter is at zero does charging turn back on
- Test: plug into USB, launch an app, then unplug USB - auto-shutdown should still be paused
This might mimic the app launch/quit event handling.
C: Remains on in internal app - ✅ pass
- Open SubGhz app
- Wait 15 or so minutes
- Ensure the Flipper remains turned on
D: Remains on in external app - ✅ pass
- Navigate to
Plugins→Toolsand launchWeather Station - Wait 15 or so minutes
- Ensure the Flipper remains turned on
E: Unlocked, auto-shutoff timer reset on desktop key press - ✅ pass
- Make sure auto-lock is disabled
- Navigate to the Flipper desktop
- Wait 10 minutes
- Press the Back button once
- Wait 10 more minutes
- Ensure the Flipper remains on
- Wait 5 more minutes (15 total minutes since last button press)
- Ensure the Flipper has powered off
F: Locked, must unlock to reset auto-shutoff timer - ❌ fail
- Navigate to the Flipper desktop
- Lock the Flipper with Up button,
Lock(or use auto-lock) - Wait 10 minutes
- Press the Back button only once, do not unlock the Flipper
- Wait 5 more minutes (15 total minutes since last Flipper unlock)
- Ensure the Flipper has powered off
- Currently, the Flipper remains on at this point
- Power on the Flipper by holding the Back button
- Lock the Flipper with Up button,
Lock(or use auto-lock) - Wait 10 minutes
- Press the Back button three times to unlock the Flipper
- Wait 10 more minutes
- Ensure the Flipper remains powered on
- Wait 5 more minutes (15 total minutes since last Flipper unlock)
- Ensure the Flipper has powered off
Current situation
The Flipper will not shut off at step 6 (after pressing Back once without actually unlocking the Flipper).
ℹ Recommended changes
Don't reset the idle shutdown timer via key events when the desktop is locked.
- When handling key events, check if the desktop is locked and ignore the event if so
- Listen for the unlock event and reset the idle shutdown timer at that point
This ensures the Flipper will auto-shutdown even if in a backpack or such with occasional button presses.
We'll include this PR in next release(0.78).
I need more time with this code, moving to next release.
I think the next priority it making sure the butthurt_max xp system works off of what the clock app runs off of. Ive had issues with the butthurt_max xp not resetting properly if you turn off the flipper fully instead of locking it. If we do that, it would make this feature much more favorable in terms of preserving power by shutting it off after some time.
Otherwise I think this option in the settings to auto-shutoff would be very useful if the butthurt thing resets when the battery isnt under regular load
Considering the recent success of a deeper power-saving mode for the Flipper for 1 month of idle time, I think the selectable auto-shutdown delays could be adjusted.
Instead of… {"OFF", "15min", "30min", "1h", "2h", "6h", "12h", "24h", "48h"}
Perhaps… {"OFF", "1h", "2h", "6h", "12h", "24h", "48h", "1wk", "2wk"}, or similar.
Alternatively, if auto-off is no longer desired, I'd still like to make use of the Power app's settings code to add the configurable battery charge voltage limit - which with longer idle time reduces the risk of someone overdischarging.
Seeing the recent dev merge commits, I'm happy to help with retesting or other things to get this refined and merged.
I'm still both interested in auto-shutdown (especially if increasing the upper bound, so the Flipper shuts off after a week of not interacting with it), and in the Power application having a settings file (to build charge voltage limit settings on top of).
@digitalcircuit I'm currently refactoring power service, I'll update this PR and then merge it.