Skip to content

Commit f79de5e

Browse files
committed
removed halt and added delayedReboot
Displays a error message before rebooting.
1 parent d44146a commit f79de5e

File tree

5 files changed

+84
-15
lines changed

5 files changed

+84
-15
lines changed

examples/companion_radio/main.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,16 @@ MyMesh the_mesh(radio_driver, fast_rng, rtc_clock, tables, store
101101

102102
/* END GLOBAL OBJECTS */
103103

104-
void halt() {
105-
delay(10000);
104+
void delayedReboot(DisplayDriver* disp, const char *msg, const unsigned long delayms) {
105+
#ifdef DISPLAY_CLASS
106+
char tmp[32];
107+
sprintf(tmp, "Rebooting in %3.1fs", delayms/1000.0);
108+
disp->startFrame();
109+
disp->drawTextCentered(disp->width() / 2, 24, msg);
110+
disp->drawTextCentered(disp->width() / 2, 32, tmp);
111+
disp->endFrame();
112+
#endif
113+
delay(delayms);
106114
board.reboot();
107115
}
108116

@@ -123,7 +131,13 @@ void setup() {
123131
}
124132
#endif
125133

126-
if (!radio_init()) { halt(); }
134+
if (!radio_init()) {
135+
#ifdef DISPLAY_CLASS
136+
delayedReboot(disp, "Radio Init Failed!", 5000);
137+
#else
138+
delayedReboot(NULL, NULL, 5000);
139+
#endif
140+
}
127141

128142
fast_rng.begin(radio_get_rng_seed());
129143

examples/simple_repeater/main.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,16 @@ SimpleMeshTables tables;
1313

1414
MyMesh the_mesh(board, radio_driver, *new ArduinoMillis(), fast_rng, rtc_clock, tables);
1515

16-
void halt() {
17-
delay(10000);
16+
void delayedReboot(DisplayDriver* disp, const char *msg, const unsigned long delayms) {
17+
#ifdef DISPLAY_CLASS
18+
char tmp[32];
19+
sprintf(tmp, "Rebooting in %3.1fs", delayms/1000.0);
20+
disp->startFrame();
21+
disp->drawTextCentered(disp->width() / 2, 24, msg);
22+
disp->drawTextCentered(disp->width() / 2, 32, tmp);
23+
disp->endFrame();
24+
#endif
25+
delay(delayms);
1826
board.reboot();
1927
}
2028

@@ -36,7 +44,11 @@ void setup() {
3644
#endif
3745

3846
if (!radio_init()) {
39-
halt();
47+
#ifdef DISPLAY_CLASS
48+
delayedReboot(disp, "Radio Init Failed!", 5000);
49+
#else
50+
delayedReboot(NULL, NULL, 5000);
51+
#endif
4052
}
4153

4254
fast_rng.begin(radio_get_rng_seed());

examples/simple_room_server/main.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,16 @@ StdRNG fast_rng;
1212
SimpleMeshTables tables;
1313
MyMesh the_mesh(board, radio_driver, *new ArduinoMillis(), fast_rng, rtc_clock, tables);
1414

15-
void halt() {
16-
delay(10000);
15+
void delayedReboot(DisplayDriver* disp, const char *msg, const unsigned long delayms) {
16+
#ifdef DISPLAY_CLASS
17+
char tmp[32];
18+
sprintf(tmp, "Rebooting in %3.1fs", delayms/1000.0);
19+
disp->startFrame();
20+
disp->drawTextCentered(disp->width() / 2, 24, msg);
21+
disp->drawTextCentered(disp->width() / 2, 32, tmp);
22+
disp->endFrame();
23+
#endif
24+
delay(delayms);
1725
board.reboot();
1826
}
1927

@@ -34,7 +42,14 @@ void setup() {
3442
}
3543
#endif
3644

37-
if (!radio_init()) { halt(); }
45+
46+
if (!radio_init()) {
47+
#ifdef DISPLAY_CLASS
48+
delayedReboot(disp, "Radio Init Failed!", 5000);
49+
#else
50+
delayedReboot(NULL, NULL, 5000);
51+
#endif
52+
}
3853

3954
fast_rng.begin(radio_get_rng_seed());
4055

examples/simple_secure_chat/main.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -550,8 +550,16 @@ StdRNG fast_rng;
550550
SimpleMeshTables tables;
551551
MyMesh the_mesh(radio_driver, fast_rng, rtc_clock, tables);
552552

553-
void halt() {
554-
delay(10000);
553+
void delayedReboot(DisplayDriver* disp, const char *msg, const unsigned long delayms) {
554+
#ifdef DISPLAY_CLASS
555+
char tmp[32];
556+
sprintf(tmp, "Rebooting in %3.1fs", delayms/1000.0);
557+
disp->startFrame();
558+
disp->drawTextCentered(disp->width() / 2, 24, msg);
559+
disp->drawTextCentered(disp->width() / 2, 32, tmp);
560+
disp->endFrame();
561+
#endif
562+
delay(delayms);
555563
board.reboot();
556564
}
557565

@@ -560,7 +568,13 @@ void setup() {
560568

561569
board.begin();
562570

563-
if (!radio_init()) { halt(); }
571+
if (!radio_init()) {
572+
#ifdef DISPLAY_CLASS
573+
delayedReboot(disp, "Radio Init Failed!", 5000);
574+
#else
575+
delayedReboot(NULL, NULL, 5000);
576+
#endif
577+
}
564578

565579
fast_rng.begin(radio_get_rng_seed());
566580

examples/simple_sensor/main.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,16 @@ SimpleMeshTables tables;
4646

4747
MyMesh the_mesh(board, radio_driver, *new ArduinoMillis(), fast_rng, rtc_clock, tables);
4848

49-
void halt() {
50-
delay(10000);
49+
void delayedReboot(DisplayDriver* disp, const char *msg, const unsigned long delayms) {
50+
#ifdef DISPLAY_CLASS
51+
char tmp[32];
52+
sprintf(tmp, "Rebooting in %3.1fs", delayms/1000.0);
53+
disp->startFrame();
54+
disp->drawTextCentered(disp->width() / 2, 24, msg);
55+
disp->drawTextCentered(disp->width() / 2, 32, tmp);
56+
disp->endFrame();
57+
#endif
58+
delay(delayms);
5159
board.reboot();
5260
}
5361

@@ -67,7 +75,13 @@ void setup() {
6775
}
6876
#endif
6977

70-
if (!radio_init()) { halt(); }
78+
if (!radio_init()) {
79+
#ifdef DISPLAY_CLASS
80+
delayedReboot(&display, "Radio Init Failed!", 5000);
81+
#else
82+
delayedReboot(NULL, NULL, 5000);
83+
#endif
84+
}
7185

7286
fast_rng.begin(radio_get_rng_seed());
7387

0 commit comments

Comments
 (0)