FrogPilot features - Automatic updates

This commit is contained in:
FrogAi 2024-05-15 09:38:37 -07:00
parent c25749b752
commit 37265f8241
3 changed files with 31 additions and 3 deletions

View File

@ -27,10 +27,26 @@ def github_pinged(url="https://github.com", timeout=5):
except (urllib.error.URLError, socket.timeout, http.client.RemoteDisconnected):
return False
def time_checks(deviceState, now, params, params_memory):
def automatic_update_check(params):
update_available = params.get_bool("UpdaterFetchAvailable")
update_ready = params.get_bool("UpdateAvailable")
update_state_idle = params.get("UpdaterState", encoding='utf8') == "idle"
if update_ready:
HARDWARE.reboot()
elif update_available:
os.system("pkill -SIGHUP -f selfdrive.updated.updated")
elif update_state_idle:
os.system("pkill -SIGUSR1 -f selfdrive.updated.updated")
def time_checks(automatic_updates, deviceState, now, params, params_memory):
screen_off = deviceState.screenBrightnessPercent == 0
wifi_connection = deviceState.networkType == WIFI
if screen_off and wifi_connection:
if automatic_updates:
automatic_update_check(params)
def frogpilot_thread(frogpilot_toggles):
config_realtime_process(5, Priority.CTRL_LOW)
@ -71,9 +87,9 @@ def frogpilot_thread(frogpilot_toggles):
if not time_validated:
continue
if now.second == 0 or first_run:
if now.second == 0 or first_run or params_memory.get_bool("ManualUpdateInitiated"):
if not started and github_pinged():
time_checks(deviceState, now, params, params_memory)
time_checks(frogpilot_toggles.automatic_updates, deviceState, now, params, params_memory)
if now.day != current_day:
params.remove("FingerprintLogged")

View File

@ -29,6 +29,12 @@ SoftwarePanel::SoftwarePanel(QWidget* parent) : ListWidget(parent), scene(uiStat
versionLbl = new LabelControl(tr("Current Version"), "");
addItem(versionLbl);
// automatic updates toggle
ParamControl *automaticUpdatesToggle = new ParamControl("AutomaticUpdates", tr("Automatically Update FrogPilot"),
tr("FrogPilot will automatically update itself and it's assets when you're offroad and connected to Wi-Fi."), "");
connect(automaticUpdatesToggle, &ToggleControl::toggleFlipped, this, updateFrogPilotToggles);
addItem(automaticUpdatesToggle);
// download update btn
downloadBtn = new ButtonControl(tr("Download"), tr("CHECK"));
connect(downloadBtn, &ButtonControl::clicked, [=]() {
@ -38,6 +44,7 @@ SoftwarePanel::SoftwarePanel(QWidget* parent) : ListWidget(parent), scene(uiStat
} else {
std::system("pkill -SIGHUP -f selfdrive.updated.updated");
}
paramsMemory.putBool("ManualUpdateInitiated", true);
});
addItem(downloadBtn);

5
selfdrive/updated/updated.py Executable file → Normal file
View File

@ -471,11 +471,16 @@ def main() -> None:
params.put("InstallDate", datetime.datetime.now().astimezone(ZoneInfo('America/Phoenix')).strftime("%B %d, %Y - %I:%M%p").encode('utf8'))
install_date_set = True
if not (params.get_bool("AutomaticUpdates") or params_memory.get_bool("ManualUpdateInitiated")):
wait_helper.sleep(60*60*24*365*100)
continue
update_failed_count += 1
# check for update
params.put("UpdaterState", "checking...")
updater.check_for_update()
params_memory.put_bool("ManualUpdateInitiated", False)
# download update
last_fetch = read_time_from_param(params, "UpdaterLastFetchTime")