diff --git a/comm/commands.c b/comm/commands.c index 56937cfe..55a660aa 100644 --- a/comm/commands.c +++ b/comm/commands.c @@ -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. diff --git a/datatypes.h b/datatypes.h index e18711b2..83e9a6c7 100644 --- a/datatypes.h +++ b/datatypes.h @@ -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 diff --git a/hwconf/shutdown.c b/hwconf/shutdown.c index 3bfaa2af..6b19fcae 100644 --- a/hwconf/shutdown.c +++ b/hwconf/shutdown.c @@ -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; diff --git a/hwconf/shutdown.h b/hwconf/shutdown.h index aa017758..6396afd5 100644 --- a/hwconf/shutdown.h +++ b/hwconf/shutdown.h @@ -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_ */