Merge pull request #695 from surfdado/shutdown

COMM_SHUTDOWN command for shutdown/restart
This commit is contained in:
Benjamin Vedder 2024-01-11 08:39:44 +01:00 committed by GitHub
commit 25b424c717
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 1 deletions

View File

@ -1621,6 +1621,26 @@ void commands_process_packet(unsigned char *data, unsigned int len,
conf_custom_process_cmd(data - 1, len + 1, reply_func);
} break;
case COMM_SHUTDOWN: {
int ind = 0;
int force = data[ind++];
if ((fabsf(mc_interface_get_rpm()) > 100) && (force != 1)) {
// Don't allow shutdown/restart while riding, unless force == 1
break;
}
int is_restart = data[ind++];
if (is_restart == 1) {
// same as terminal rebootwdt command
chSysLock();
for (;;) {__NOP();}
}
else {
do_shutdown(false);
}
} break;
// Blocking commands. Only one of them runs at any given time, in their
// own thread. If other blocking commands come before the previous one has
// finished, they are discarded.

View File

@ -1094,6 +1094,13 @@ typedef enum {
COMM_LOG_DATA_F64 = 151,
COMM_LISP_RMSG = 152,
//Placeholders for pinlock commands
//COMM_PINLOCK1 = 153,
//COMM_PINLOCK2 = 154,
//COMM_PINLOCK3 = 155,
COMM_SHUTDOWN = 156,
} COMM_PACKET_ID;
// CAN commands

View File

@ -72,7 +72,7 @@ void shutdown_hold(bool hold) {
m_shutdown_hold = hold;
}
static bool do_shutdown(bool resample) {
bool do_shutdown(bool resample) {
conf_general_store_backup_data();
#ifdef USE_LISPBM
lispif_process_shutdown();
@ -223,6 +223,11 @@ void shutdown_hold(bool hold) {
(void)hold;
}
bool do_shutdown(bool resample) {
(void)resample;
return false;
}
static THD_FUNCTION(shutdown_thread, arg) {
(void)arg;

View File

@ -47,5 +47,6 @@ bool shutdown_button_pressed(void);
float shutdown_get_inactivity_time(void);
void shutdown_set_sampling_disabled(bool disabled);
void shutdown_hold(bool hold);
bool do_shutdown(bool resample);
#endif /* SHUTDOWN_H_ */