Skip to content

Commit e2d0851

Browse files
sshanejamcar23
authored and
jamcar23
committedSep 3, 2020
Add a button to reset to origin if manager fails to start (commaai#183)
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
1 parent c91ac2d commit e2d0851

File tree

4 files changed

+62
-28
lines changed

4 files changed

+62
-28
lines changed
 

‎common/text_window.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@ def close(self):
3232

3333
def wait_for_exit(self):
3434
while True:
35-
if self.get_status() == 1:
36-
return
35+
status = self.get_status()
36+
if status == 1:
37+
return 'exit'
38+
elif status == 0: # git pull/reset button
39+
return 'reset'
3740
time.sleep(0.1)
3841

3942
def __del__(self):

‎selfdrive/manager.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -596,20 +596,18 @@ def main():
596596
# Show last 3 lines of traceback
597597
error = traceback.format_exc(3)
598598

599-
error = "Manager failed to start\n \n" + error
599+
error = "Manager failed to start. Press Reset to pull and reset to origin!\n \n" + error
600600
with TextWindow(error) as t:
601601
exit_status = t.wait_for_exit()
602602
if exit_status == 'reset':
603603
for _ in range(2):
604604
try:
605-
subprocess.check_output(["git", "fetch"], cwd=BASEDIR)
606-
subprocess.check_output(["git", "checkout", "r2++"], cwd=BASEDIR)
605+
subprocess.check_output(["git", "pull"], cwd=BASEDIR)
607606
subprocess.check_output(["git", "reset", "--hard", "@{u}"], cwd=BASEDIR)
608-
subprocess.check_output(["git", "checkout", "r2+"], cwd=BASEDIR)
609607
print('git reset successful!')
610608
break
611609
except subprocess.CalledProcessError as e:
612-
print(e.output)
610+
# print(e.output)
613611
if _ != 1:
614612
print('git reset failed, trying again')
615613
time.sleep(5) # wait 5 seconds and try again

‎selfdrive/ui/text/text

-16 KB
Binary file not shown.

‎selfdrive/ui/text/text.c

+54-21
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,40 @@
2424
extern const unsigned char _binary_opensans_regular_ttf_start[];
2525
extern const unsigned char _binary_opensans_regular_ttf_end[];
2626

27+
void draw_exit_button(NVGcontext *vg, int b_x, int b_y, int b_w, int b_h) {
28+
nvgBeginPath(vg);
29+
nvgFillColor(vg, nvgRGBA(8, 8, 8, 178));
30+
nvgRoundedRect(vg, b_x, b_y, b_w, b_h, 20);
31+
nvgFill(vg);
32+
33+
nvgFillColor(vg, nvgRGBA(255, 255, 255, 255));
34+
nvgTextAlign(vg, NVG_ALIGN_CENTER | NVG_ALIGN_MIDDLE);
35+
nvgText(vg, b_x+b_w/2, b_y+b_h/2, "Exit", NULL);
36+
37+
nvgBeginPath(vg);
38+
nvgStrokeColor(vg, nvgRGBA(255, 255, 255, 50));
39+
nvgStrokeWidth(vg, 5);
40+
nvgRoundedRect(vg, b_x, b_y, b_w, b_h, 20);
41+
nvgStroke(vg);
42+
}
43+
44+
void draw_git_button(NVGcontext *vg, int b_x, int b_y, int b_w, int b_h) {
45+
nvgBeginPath(vg);
46+
nvgFillColor(vg, nvgRGBA(8, 8, 8, 178));
47+
nvgRoundedRect(vg, b_x, b_y, b_w, b_h, 20);
48+
nvgFill(vg);
49+
50+
nvgFillColor(vg, nvgRGBA(255, 255, 255, 255));
51+
nvgTextAlign(vg, NVG_ALIGN_CENTER | NVG_ALIGN_MIDDLE);
52+
nvgText(vg, b_x+b_w/2, b_y+b_h/2, "Git Reset", NULL);
53+
54+
nvgBeginPath(vg);
55+
nvgStrokeColor(vg, nvgRGBA(255, 255, 255, 50));
56+
nvgStrokeWidth(vg, 5);
57+
nvgRoundedRect(vg, b_x, b_y, b_w, b_h, 20);
58+
nvgStroke(vg);
59+
}
60+
2761
int main(int argc, char** argv) {
2862
int err;
2963

@@ -60,7 +94,7 @@ assert(font >= 0);
6094

6195
// Text
6296
nvgFillColor(vg, COLOR_WHITE);
63-
nvgFontSize(vg, 75.0f);
97+
nvgFontSize(vg, 65.0f);
6498

6599
if (argc >= 2) {
66100
float x = 150;
@@ -82,26 +116,21 @@ assert(font >= 0);
82116
}
83117
}
84118

85-
// Button
86-
int b_x = 1500;
87-
int b_y = 800;
88-
int b_w = 300;
89-
int b_h = 150;
119+
// Exit Button
120+
int exit_b_x = 1550;
121+
int exit_b_y = 850;
122+
int exit_b_w = 300;
123+
int exit_b_h = 150;
90124

91-
nvgBeginPath(vg);
92-
nvgFillColor(vg, nvgRGBA(8, 8, 8, 255));
93-
nvgRoundedRect(vg, b_x, b_y, b_w, b_h, 20);
94-
nvgFill(vg);
125+
// Git Pull Button
126+
int git_b_x = exit_b_x - exit_b_w - 50; // 50 px padding
127+
int git_b_y = exit_b_y;
128+
int git_b_w = 300;
129+
int git_b_h = 150;
95130

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

100-
nvgBeginPath(vg);
101-
nvgStrokeColor(vg, nvgRGBA(255, 255, 255, 50));
102-
nvgStrokeWidth(vg, 5);
103-
nvgRoundedRect(vg, b_x, b_y, b_w, b_h, 20);
104-
nvgStroke(vg);
105134

106135
// Draw to screen
107136
nvgEndFrame(vg);
@@ -117,12 +146,16 @@ assert(font >= 0);
117146
int touch_x = -1, touch_y = -1;
118147
int res = touch_poll(&touch, &touch_x, &touch_y, 0);
119148
if (res){
120-
121-
if (touch_x > b_x && touch_x < b_x + b_w){
122-
if (touch_y > b_y && touch_y < b_y + b_h){
149+
if (touch_x > exit_b_x && touch_x < exit_b_x + exit_b_w){
150+
if (touch_y > exit_b_y && touch_y < exit_b_y + exit_b_h){
123151
return 1;
124152
}
125153
}
154+
if (touch_x > git_b_x && touch_x < git_b_x + git_b_w){
155+
if (touch_y > git_b_y && touch_y < git_b_y + git_b_h){
156+
return 0; // touched reset button
157+
}
158+
}
126159
}
127160

128161
usleep(1000000 / 60);

0 commit comments

Comments
 (0)