From 90f2f5ccdf27e2d846edb6eba8c23a8fca62e01f Mon Sep 17 00:00:00 2001 From: tGecko Date: Thu, 12 Sep 2024 20:34:01 +0200 Subject: [PATCH] detect rtc --- static/build/.tmp_update/runtime.sh | 12 ++++++++++-- website/docs/07-apps/01-included-in-onion/clock.md | 3 +-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/static/build/.tmp_update/runtime.sh b/static/build/.tmp_update/runtime.sh index 4e2194f1b..dad6643f7 100644 --- a/static/build/.tmp_update/runtime.sh +++ b/static/build/.tmp_update/runtime.sh @@ -763,14 +763,22 @@ save_settings() { } update_time() { - # Give hardware modders an option to disable time restore - if [ -f $sysdir/config/.noTimeRestore ]; then + # Detect RTC, if available, do not restore time + rtc_treshold=15 # usually around 3-5 at this point + current_time=$(date +%s) + + if [ "$current_time" -gt "$rtc_treshold" ]; then + log "RTC available, not restoring time. Current time: $current_time" return + else + log "RTC not available, restoring time. Current time: $current_time" fi + timepath=/mnt/SDCARD/Saves/CurrentProfile/saves/currentTime.txt currentTime=0 # Load current time if [ -f $timepath ]; then + log "Restoring time" currentTime=$(cat $timepath) fi date +%s -s @$currentTime diff --git a/website/docs/07-apps/01-included-in-onion/clock.md b/website/docs/07-apps/01-included-in-onion/clock.md index af59b2fb4..1876354fd 100644 --- a/website/docs/07-apps/01-included-in-onion/clock.md +++ b/website/docs/07-apps/01-included-in-onion/clock.md @@ -9,8 +9,7 @@ description: Set your Onion's time ## Presentation Simple clock app which allows you to manually set the clock of your device. Especially useful for the Miyoo Mini which doesn't have an internal RTC (which means that the time is reset at each boot). By default, Onion preserves the current time during shutdown, and upon the subsequent boot, it is restored with 4 hours added. - -If you don't want the device to restore the time on boot (e.g. you have modded your device to have hardware RTC), you can create the file `SDCARD\.tmp_update\config\.noTimeRestore`. Doing so will prevent the time restore. +If RTC is present, which is the case with newer Miyoo Mini+, or if it is modded in, the time is not restored or advanced but will instead be set by RTC. ![](./assets/clock.png)