only set heartbeat lost when in a car safety mode
@@ -142,6 +142,12 @@ void set_safety_mode(uint16_t mode, int16_t param) {
can_init_all();
}
+bool is_car_safety_mode(uint16_t mode) {
+ return (mode != SAFETY_SILENT) &&
+ (mode != SAFETY_NOOUTPUT) &&
+ (mode != SAFETY_ELM327);
+}
+
// ***************************** USB port *****************************
int get_health_pkt(void *dat) {
@@ -467,9 +473,7 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired)
// **** 0xdf: set unsafe mode
case 0xdf:
// you can only set this if you are in a non car safety mode
- if ((current_safety_mode == SAFETY_SILENT) ||
- (current_safety_mode == SAFETY_NOOUTPUT) ||
- (current_safety_mode == SAFETY_ELM327)) {
+ if (!is_car_safety_mode(current_safety_mode)) {
unsafe_mode = setup->b.wValue.w;
}
break;
@@ -695,6 +699,11 @@ void tick_handler(void) {
siren_countdown = 5U;
}
+ // set flag to indicate the heartbeat was lost
+ if (is_car_safety_mode(current_safety_mode)) {
+ heartbeat_lost = true;
+ }
+
if (current_safety_mode != SAFETY_SILENT) {
set_safety_mode(SAFETY_SILENT, 0U);
}
@@ -702,9 +711,6 @@ void tick_handler(void) {
set_power_save_state(POWER_SAVE_STATUS_ENABLED);
}
- // set flag to indicate the heartbeat was lost
- heartbeat_lost = true;
-
// Also disable IR when the heartbeat goes missing
current_board->set_ir_power(0U);
@@ -728,7 +734,7 @@ void tick_handler(void) {
// set ignition_can to false after 2s of no CAN seen
if (ignition_can_cnt > 2U) {
ignition_can = false;
- };
+ }
// on to the next one
uptime_cnt += 1U;
