20
20
#include <pbsys/program_stop.h>
21
21
#include <pbsys/bluetooth.h>
22
22
23
+ // Singleton with information about the currently (or soon) active program.
23
24
static pbsys_main_program_t program ;
24
25
26
+ /**
27
+ * Checks if a start request has been made for the main program.
28
+ *
29
+ * @param [in] program A pointer to the main program structure.
30
+ * @returns true if a start request has been made, false otherwise.
31
+ */
32
+ static bool pbsys_main_program_start_requested () {
33
+ return program .start_request_type != PBSYS_MAIN_PROGRAM_START_REQUEST_TYPE_NONE ;
34
+ }
35
+
36
+ /**
37
+ * Gets the type of start request for the main program.
38
+ *
39
+ * @param [in] program A pointer to the main program structure.
40
+ * @returns The type of start request.
41
+ */
42
+ pbsys_main_program_start_request_type_t pbsys_main_program_get_start_request_type (void ) {
43
+ return program .start_request_type ;
44
+ }
45
+
25
46
/**
26
47
* Requests to start the main user application program.
27
48
*
@@ -31,10 +52,10 @@ static pbsys_main_program_t program;
31
52
* ::PBIO_ERROR_NOT_SUPPORTED if the program is not available.
32
53
* Otherwise ::PBIO_SUCCESS.
33
54
*/
34
- pbio_error_t pbsys_main_program_request_start (pbio_pybricks_user_program_id_t id ) {
55
+ pbio_error_t pbsys_main_program_request_start (pbio_pybricks_user_program_id_t id , pbsys_main_program_start_request_type_t start_request_type ) {
35
56
36
57
// Can't start new program if already running or new requested.
37
- if (pbsys_status_test (PBIO_PYBRICKS_STATUS_USER_PROGRAM_RUNNING ) || program . start_requested ) {
58
+ if (pbsys_status_test (PBIO_PYBRICKS_STATUS_USER_PROGRAM_RUNNING ) || pbsys_main_program_start_requested () ) {
38
59
return PBIO_ERROR_BUSY ;
39
60
}
40
61
@@ -49,7 +70,7 @@ pbio_error_t pbsys_main_program_request_start(pbio_pybricks_user_program_id_t id
49
70
return err ;
50
71
}
51
72
52
- program .start_requested = true ;
73
+ program .start_request_type = start_request_type ;
53
74
54
75
return PBIO_SUCCESS ;
55
76
}
@@ -68,15 +89,15 @@ int main(int argc, char **argv) {
68
89
while (!pbsys_status_test (PBIO_PYBRICKS_STATUS_SHUTDOWN_REQUEST )) {
69
90
70
91
#if PBSYS_CONFIG_USER_PROGRAM_AUTO_START
71
- pbsys_main_program_request_start (PBIO_PYBRICKS_USER_PROGRAM_ID_REPL );
92
+ pbsys_main_program_request_start (PBIO_PYBRICKS_USER_PROGRAM_ID_REPL , PBSYS_MAIN_PROGRAM_START_REQUEST_TYPE_BOOT );
72
93
#endif
73
94
74
95
// REVISIT: this can be long waiting, so we could do a more efficient
75
96
// wait (i.e. __WFI() on embedded system)
76
97
while (pbio_do_one_event ()) {
77
98
}
78
99
79
- if (!program . start_requested ) {
100
+ if (!pbsys_main_program_start_requested () ) {
80
101
continue ;
81
102
}
82
103
@@ -98,7 +119,7 @@ int main(int argc, char **argv) {
98
119
pbsys_bluetooth_rx_set_callback (NULL );
99
120
pbsys_program_stop_set_buttons (PBIO_BUTTON_CENTER );
100
121
pbio_stop_all (true);
101
- program .start_requested = false ;
122
+ program .start_request_type = PBSYS_MAIN_PROGRAM_START_REQUEST_TYPE_NONE ;
102
123
}
103
124
104
125
// Stop system processes and save user data before we shutdown.
0 commit comments