Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

Commit

Permalink
uidebug
Browse files Browse the repository at this point in the history
  • Loading branch information
rav4kumar committed Dec 12, 2020
1 parent aa7a328 commit fbaf01f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
23 changes: 22 additions & 1 deletion selfdrive/ui/android/ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
}

Expand Down
26 changes: 26 additions & 0 deletions selfdrive/ui/android/uiview.py
Original file line number Diff line number Diff line change
@@ -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]
2 changes: 2 additions & 0 deletions selfdrive/ui/ui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down

0 comments on commit fbaf01f

Please sign in to comment.