diff --git a/selfdrive/frogpilot/frogpilot_process.py b/selfdrive/frogpilot/frogpilot_process.py index d28aae5..32ab957 100644 --- a/selfdrive/frogpilot/frogpilot_process.py +++ b/selfdrive/frogpilot/frogpilot_process.py @@ -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") diff --git a/selfdrive/ui/qt/offroad/software_settings.cc b/selfdrive/ui/qt/offroad/software_settings.cc index ef38f6f..7a5e162 100644 --- a/selfdrive/ui/qt/offroad/software_settings.cc +++ b/selfdrive/ui/qt/offroad/software_settings.cc @@ -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); diff --git a/selfdrive/updated/updated.py b/selfdrive/updated/updated.py old mode 100755 new mode 100644 index dfd2ae9..bd16024 --- a/selfdrive/updated/updated.py +++ b/selfdrive/updated/updated.py @@ -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")