Skip to content

Commit

Permalink
Add a button to reset to origin if manager fails to start (commaai#183)
Browse files Browse the repository at this point in the history
This will fix occurrences like commaai#182
TextWindow updates:
- Git Reset button
- Made buttons transparent so you can see code behind them
  - Also moved the buttons further down so you can see more of the error
- Decreased font size
  • Loading branch information
sshane authored and jamcar23 committed Sep 1, 2020
1 parent f09c711 commit 541c57a
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 26 deletions.
7 changes: 5 additions & 2 deletions common/text_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ def close(self):

def wait_for_exit(self):
while True:
if self.get_status() == 1:
return
status = self.get_status()
if status == 1:
return 'exit'
elif status == 0: # git pull/reset button
return 'reset'
time.sleep(0.1)

def __del__(self):
Expand Down
20 changes: 17 additions & 3 deletions selfdrive/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,10 +596,24 @@ def main():
# Show last 3 lines of traceback
error = traceback.format_exc(3)

error = "Manager failed to start\n \n" + error
error = "Manager failed to start. Press Reset to pull and reset to origin!\n \n" + error
with TextWindow(error) as t:
t.wait_for_exit()

exit_status = t.wait_for_exit()
if exit_status == 'reset':
for _ in range(2):
try:
subprocess.check_output(["git", "pull"], cwd=BASEDIR)
subprocess.check_output(["git", "reset", "--hard", "@{u}"], cwd=BASEDIR)
print('git reset successful!')
break
except subprocess.CalledProcessError as e:
# print(e.output)
if _ != 1:
print('git reset failed, trying again')
time.sleep(5) # wait 5 seconds and try again

time.sleep(1)
subprocess.check_output(["am", "start", "-a", "android.intent.action.REBOOT"])
raise

# manual exit because we are forked
Expand Down
Binary file modified selfdrive/ui/text/text
Binary file not shown.
75 changes: 54 additions & 21 deletions selfdrive/ui/text/text.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,40 @@
extern const unsigned char _binary_opensans_regular_ttf_start[];
extern const unsigned char _binary_opensans_regular_ttf_end[];

void draw_exit_button(NVGcontext *vg, int b_x, int b_y, int b_w, int b_h) {
nvgBeginPath(vg);
nvgFillColor(vg, nvgRGBA(8, 8, 8, 178));
nvgRoundedRect(vg, b_x, b_y, b_w, b_h, 20);
nvgFill(vg);

nvgFillColor(vg, nvgRGBA(255, 255, 255, 255));
nvgTextAlign(vg, NVG_ALIGN_CENTER | NVG_ALIGN_MIDDLE);
nvgText(vg, b_x+b_w/2, b_y+b_h/2, "Exit", NULL);

nvgBeginPath(vg);
nvgStrokeColor(vg, nvgRGBA(255, 255, 255, 50));
nvgStrokeWidth(vg, 5);
nvgRoundedRect(vg, b_x, b_y, b_w, b_h, 20);
nvgStroke(vg);
}

void draw_git_button(NVGcontext *vg, int b_x, int b_y, int b_w, int b_h) {
nvgBeginPath(vg);
nvgFillColor(vg, nvgRGBA(8, 8, 8, 178));
nvgRoundedRect(vg, b_x, b_y, b_w, b_h, 20);
nvgFill(vg);

nvgFillColor(vg, nvgRGBA(255, 255, 255, 255));
nvgTextAlign(vg, NVG_ALIGN_CENTER | NVG_ALIGN_MIDDLE);
nvgText(vg, b_x+b_w/2, b_y+b_h/2, "Git Reset", NULL);

nvgBeginPath(vg);
nvgStrokeColor(vg, nvgRGBA(255, 255, 255, 50));
nvgStrokeWidth(vg, 5);
nvgRoundedRect(vg, b_x, b_y, b_w, b_h, 20);
nvgStroke(vg);
}

int main(int argc, char** argv) {
int err;

Expand Down Expand Up @@ -60,7 +94,7 @@ assert(font >= 0);

// Text
nvgFillColor(vg, COLOR_WHITE);
nvgFontSize(vg, 75.0f);
nvgFontSize(vg, 65.0f);

if (argc >= 2) {
float x = 150;
Expand All @@ -82,26 +116,21 @@ assert(font >= 0);
}
}

// Button
int b_x = 1500;
int b_y = 800;
int b_w = 300;
int b_h = 150;
// Exit Button
int exit_b_x = 1550;
int exit_b_y = 850;
int exit_b_w = 300;
int exit_b_h = 150;

nvgBeginPath(vg);
nvgFillColor(vg, nvgRGBA(8, 8, 8, 255));
nvgRoundedRect(vg, b_x, b_y, b_w, b_h, 20);
nvgFill(vg);
// Git Pull Button
int git_b_x = exit_b_x - exit_b_w - 50; // 50 px padding
int git_b_y = exit_b_y;
int git_b_w = 300;
int git_b_h = 150;

nvgFillColor(vg, nvgRGBA(255, 255, 255, 255));
nvgTextAlign(vg, NVG_ALIGN_CENTER | NVG_ALIGN_MIDDLE);
nvgText(vg, b_x+b_w/2, b_y+b_h/2, "Exit", NULL);
draw_exit_button(vg, exit_b_x, exit_b_y, exit_b_w, exit_b_h);
draw_git_button(vg, git_b_x, git_b_y, git_b_w, git_b_h);

nvgBeginPath(vg);
nvgStrokeColor(vg, nvgRGBA(255, 255, 255, 50));
nvgStrokeWidth(vg, 5);
nvgRoundedRect(vg, b_x, b_y, b_w, b_h, 20);
nvgStroke(vg);

// Draw to screen
nvgEndFrame(vg);
Expand All @@ -117,12 +146,16 @@ assert(font >= 0);
int touch_x = -1, touch_y = -1;
int res = touch_poll(&touch, &touch_x, &touch_y, 0);
if (res){

if (touch_x > b_x && touch_x < b_x + b_w){
if (touch_y > b_y && touch_y < b_y + b_h){
if (touch_x > exit_b_x && touch_x < exit_b_x + exit_b_w){
if (touch_y > exit_b_y && touch_y < exit_b_y + exit_b_h){
return 1;
}
}
if (touch_x > git_b_x && touch_x < git_b_x + git_b_w){
if (touch_y > git_b_y && touch_y < git_b_y + git_b_h){
return 0; // touched reset button
}
}
}

usleep(1000000 / 60);
Expand Down

0 comments on commit 541c57a

Please sign in to comment.