diff --git a/selfdrive/ui/android/ui.cc b/selfdrive/ui/android/ui.cc index 95b72719697ce4..d97c74a29898da 100644 --- a/selfdrive/ui/android/ui.cc +++ b/selfdrive/ui/android/ui.cc @@ -29,6 +29,18 @@ static void ui_set_brightness(UIState *s, int brightness) { } } +static bool handle_SA_touched(UIState *s, int touch_x, int touch_y) { + if (s->active_app == cereal::UiLayoutState::App::NONE) { // if onroad (not settings or home) + if ((s->awake && s->vision_connected && s->status != STATUS_OFFROAD) || s->ui_debug) { // if car started or debug mode + //if (handle_df_touch(s, touch_x, touch_y) || handle_ls_touch(s, touch_x, touch_y) || handle_ml_touch(s, touch_x, touch_y)) { + s->scene.uilayout_sidebarcollapsed = true; // collapse sidebar when tapping any SA button + return true; // only allow one button to be pressed at a time + //} + } + } + return false; +} + static void handle_display_state(UIState *s, bool user_input) { static int awake_timeout = 0; @@ -161,6 +173,7 @@ int main(int argc, char* argv[]) { UIState uistate = {}; UIState *s = &uistate; ui_init(s); + sa_init(s, true); s->sound = &sound; TouchState touch = {0}; @@ -192,10 +205,16 @@ int main(int argc, char* argv[]) { s->scene.dp_alert_type = 1; bool show_layer = true; + bool last_started = s->started; while (!do_exit) { if (!s->started) { usleep(50 * 1000); } + + if (s->started && !last_started) { + sa_init(s, false); // reset ml button and regrab params + } + last_started = s->started; double u1 = millis_since_boot(); ui_update(s); @@ -217,9 +236,11 @@ int main(int argc, char* argv[]) { int touch_x = -1, touch_y = -1; int touched = touch_poll(&touch, &touch_x, &touch_y, 0); if (touched == 1) { + if (s->ui_debug) { printf("touched x: %d, y: %d\n", touch_x, touch_y); } if (!handle_dp_btn_touch(s, touch_x, touch_y)) { handle_sidebar_touch(s, touch_x, touch_y); - handle_vision_touch(s, touch_x, touch_y); + if (!handle_SA_touched(s, touch_x, touch_y)) { // if SA button not touched + handle_vision_touch(s, touch_x, touch_y); } } diff --git a/selfdrive/ui/android/uiview.py b/selfdrive/ui/android/uiview.py new file mode 100644 index 00000000000000..0b6ba5ce5acf5e --- /dev/null +++ b/selfdrive/ui/android/uiview.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 +import os +import time +import signal +import subprocess +import cereal.messaging as messaging +from common.basedir import BASEDIR + +services = ['controlsState', 'thermal', 'radarState'] # the services needed to be spoofed to start ui offroad +procs = {'camerad': 'selfdrive/camerad/camerad', 'ui': 'selfdrive/ui/ui', + 'modeld': 'selfdrive/modeld/modeld', 'calibrationd': 'selfdrive/locationd/calibrationd.py'} +started_procs = [subprocess.Popen(os.path.join(BASEDIR, procs[p]), cwd=os.path.join(BASEDIR, os.path.dirname(procs[p]))) for p in procs] # start needed processes +pm = messaging.PubMaster(services) + +dat_cs, dat_thermal, dat_radar = [messaging.new_message(s) for s in services] +dat_cs.controlsState.rearViewCam = False # ui checks for these two messages +dat_thermal.thermal.started = True + +try: + while True: + pm.send('controlsState', dat_cs) + pm.send('thermal', dat_thermal) + pm.send('radarState', dat_radar) + time.sleep(1 / 100) # continually send, rate doesn't matter +except KeyboardInterrupt: + [p.send_signal(signal.SIGINT) for p in started_procs] diff --git a/selfdrive/ui/ui.hpp b/selfdrive/ui/ui.hpp index afeb64468f7268..5036609187caef 100644 --- a/selfdrive/ui/ui.hpp +++ b/selfdrive/ui/ui.hpp @@ -250,6 +250,7 @@ typedef struct UIState { bool ignition; bool is_metric; bool longitudinal_control; + bool ui_debug; uint64_t last_athena_ping; uint64_t started_frame; @@ -264,6 +265,7 @@ typedef struct UIState { } UIState; void ui_init(UIState *s); +void sa_init(UIState *s, bool full_init); void ui_update(UIState *s); int write_param_float(float param, const char* param_name, bool persistent_param = false);