diff --git a/selfdrive/manager.py b/selfdrive/manager.py index c5990f4fdf7aa3..f107b6cd7b86e6 100755 --- a/selfdrive/manager.py +++ b/selfdrive/manager.py @@ -93,6 +93,7 @@ def unblock_stdout(): import selfdrive.crash as crash from selfdrive.loggerd.config import ROOT +from selfdrive.ui.spinner.spinner_manager import Spinner # comment out anything you don't want to run managed_processes = { @@ -305,32 +306,38 @@ def cleanup_all_processes(signal, frame): # ****************** run loop ****************** def manager_init(should_register=True): - if should_register: - reg_res = register() - if reg_res: - dongle_id, dongle_secret = reg_res + params = Params() + spinner_text = "chffrplus" if params.get("Passive")=="1" else "openpilot" + init_text = "initializing {0}".format(spinner_text) + with Spinner() as spinner: + spinner.update(init_text) + if should_register: + reg_res = register() + if reg_res: + dongle_id, dongle_secret = reg_res + else: + raise Exception("server registration failed") else: - raise Exception("server registration failed") - else: - dongle_id = "c"*16 + dongle_id = "c"*16 - # set dongle id - cloudlog.info("dongle id is " + dongle_id) - os.environ['DONGLE_ID'] = dongle_id + # set dongle id + cloudlog.info("dongle id is " + dongle_id) + os.environ['DONGLE_ID'] = dongle_id - cloudlog.info("dirty is %d" % dirty) - if not dirty: - os.environ['CLEAN'] = '1' + cloudlog.info("dirty is %d" % dirty) + if not dirty: + os.environ['CLEAN'] = '1' - cloudlog.bind_global(dongle_id=dongle_id, version=version, dirty=dirty, is_eon=True) - crash.bind_user(id=dongle_id) - crash.bind_extra(version=version, dirty=dirty, is_eon=True) + cloudlog.bind_global(dongle_id=dongle_id, version=version, dirty=dirty, is_eon=True) + crash.bind_user(id=dongle_id) + crash.bind_extra(version=version, dirty=dirty, is_eon=True) + + os.umask(0) + try: + os.mkdir(ROOT, 0o777) + except OSError: + pass - os.umask(0) - try: - os.mkdir(ROOT, 0o777) - except OSError: - pass def system(cmd): try: @@ -495,17 +502,31 @@ def update_ssh(): raise RuntimeError def manager_update(): - update_ssh() - update_apks() + params = Params() + spinner_text = "chffrplus" if params.get("Passive")=="1" else "openpilot" + update_text = "updating {0}".format(spinner_text) + with Spinner() as spinner: + spinner.update(update_text) + update_ssh() + update_apks() def manager_prepare(): - # build cereal first - subprocess.check_call(["make", "-j4"], cwd=os.path.join(BASEDIR, "cereal")) - - # build all processes - os.chdir(os.path.dirname(os.path.abspath(__file__))) - for p in managed_processes: - prepare_managed_process(p) + params = Params() + spinner_text = "chffrplus" if params.get("Passive")=="1" else "openpilot" + loader_text = "loading {0}".format(spinner_text) + with Spinner() as spinner: + spinner.update(loader_text) + # build cereal first + subprocess.check_call(["make", "-j4"], cwd=os.path.join(BASEDIR, "cereal")) + + # build all processes + os.chdir(os.path.dirname(os.path.abspath(__file__))) + + process_cnt = len(managed_processes) + for n,p in enumerate(managed_processes): + loader_text = "loading {0}: {1}/{2} {3}".format(spinner_text, n+1, process_cnt, p) + spinner.update(loader_text) + prepare_managed_process(p) def uninstall(): cloudlog.warning("uninstalling") @@ -583,21 +604,9 @@ def main(): if params.get("Passive") is None: raise Exception("Passive must be set to continue") - # put something on screen while we set things up - if os.getenv("PREPAREONLY") is not None: - spinner_proc = None - else: - spinner_text = "chffrplus" if params.get("Passive")=="1" else "openpilot" - spinner_proc = subprocess.Popen(["./spinner", "loading %s"%spinner_text], - cwd=os.path.join(BASEDIR, "selfdrive", "ui", "spinner"), - close_fds=True) - try: - manager_update() - manager_init() - manager_prepare() - finally: - if spinner_proc: - spinner_proc.terminate() + manager_update() + manager_init() + manager_prepare() if os.getenv("PREPAREONLY") is not None: return diff --git a/selfdrive/ui/__init__.py b/selfdrive/ui/__init__.py new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/selfdrive/ui/spinner/__init__.py b/selfdrive/ui/spinner/__init__.py new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/selfdrive/ui/spinner/spinner b/selfdrive/ui/spinner/spinner index 65c198aabda3d2..50f2bce6e7bab7 100755 Binary files a/selfdrive/ui/spinner/spinner and b/selfdrive/ui/spinner/spinner differ diff --git a/selfdrive/ui/spinner/spinner.c b/selfdrive/ui/spinner/spinner.c index 3ec36e7403f3de..95780d2623f258 100644 --- a/selfdrive/ui/spinner/spinner.c +++ b/selfdrive/ui/spinner/spinner.c @@ -16,13 +16,14 @@ #include "common/framebuffer.h" -int main(int argc, char** argv) { +int main() { int err; - - const char* spintext = NULL; - if (argc >= 2) { - spintext = argv[1]; - } + fd_set readfds; + FD_ZERO(&readfds); + struct timeval timeout; + timeout.tv_sec = 0; + timeout.tv_usec = 0; + char spintext[50]; // spinner int fb_w, fb_h; @@ -49,6 +50,11 @@ int main(int argc, char** argv) { assert(spinner_comma_img >= 0); for (int cnt = 0; ; cnt++) { + FD_SET(STDIN_FILENO, &readfds); + if (select(1, &readfds, NULL, NULL, &timeout)) { + fgets(spintext, sizeof spintext, stdin); + spintext[strcspn(spintext, "\n")] = 0; + } glClearColor(0.1, 0.1, 0.1, 1.0); glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glEnable(GL_BLEND); @@ -85,11 +91,9 @@ int main(int argc, char** argv) { nvgFill(vg); // message - if (spintext) { - nvgTextAlign(vg, NVG_ALIGN_CENTER | NVG_ALIGN_TOP); - nvgFontSize(vg, 96.0f); - nvgText(vg, fb_w/2, (fb_h*2/3)+24, spintext, NULL); - } + nvgTextAlign(vg, NVG_ALIGN_CENTER | NVG_ALIGN_TOP); + nvgFontSize(vg, 96.0f); + nvgText(vg, fb_w/2, (fb_h*2/3)+24, spintext, NULL); nvgEndFrame(vg); eglSwapBuffers(display, surface); diff --git a/selfdrive/ui/spinner/spinner_manager.py b/selfdrive/ui/spinner/spinner_manager.py new file mode 100644 index 00000000000000..a16e09c12b0ebf --- /dev/null +++ b/selfdrive/ui/spinner/spinner_manager.py @@ -0,0 +1,18 @@ +import os +import subprocess +from common.basedir import BASEDIR + +class Spinner(object): + def __enter__(self): + self.spinner_proc = subprocess.Popen(["./spinner"], stdin=subprocess.PIPE, + cwd=os.path.join(BASEDIR, "selfdrive", "ui", "spinner"), + close_fds=True) + return self + + def update(self, spinner_text): + if os.getenv("PREPAREONLY") is None: + self.spinner_proc.stdin.write(spinner_text + "\n") + + def __exit__(self, type, value, traceback): + self.spinner_proc.stdin.close() + self.spinner_proc.terminate() \ No newline at end of file