@@ -6,9 +6,6 @@ const int HYUNDAI_MAX_RATE_DOWN = 7;
6
6
const int HYUNDAI_DRIVER_TORQUE_ALLOWANCE = 50 ;
7
7
const int HYUNDAI_DRIVER_TORQUE_FACTOR = 2 ;
8
8
9
- int hyundai_brake_prev = 0 ;
10
- int hyundai_gas_prev = 0 ;
11
- int hyundai_speed = 0 ;
12
9
int hyundai_camera_detected = 0 ;
13
10
int hyundai_giraffe_switch_2 = 0 ; // is giraffe switch 2 high?
14
11
int hyundai_rt_torque_last = 0 ;
@@ -67,11 +64,6 @@ static int hyundai_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
67
64
return 0 ;
68
65
}
69
66
70
- // disallow actuator commands if gas or brake (with vehicle moving) are pressed
71
- // and the the latching controls_allowed flag is True
72
- int pedal_pressed = hyundai_gas_prev || (hyundai_brake_prev && hyundai_speed );
73
- int current_controls_allowed = controls_allowed && !pedal_pressed ;
74
-
75
67
uint32_t addr ;
76
68
if (to_send -> RIR & 4 ) {
77
69
// Extended
@@ -87,7 +79,7 @@ static int hyundai_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
87
79
uint32_t ts = TIM2 -> CNT ;
88
80
int violation = 0 ;
89
81
90
- if (current_controls_allowed ) {
82
+ if (controls_allowed ) {
91
83
92
84
// *** global torque limit check ***
93
85
violation |= max_limit_check (desired_torque , HYUNDAI_MAX_STEER , - HYUNDAI_MAX_STEER );
@@ -112,12 +104,12 @@ static int hyundai_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
112
104
}
113
105
114
106
// no torque if controls is not allowed
115
- if (!current_controls_allowed && (desired_torque != 0 )) {
107
+ if (!controls_allowed && (desired_torque != 0 )) {
116
108
violation = 1 ;
117
109
}
118
110
119
111
// reset to 0 if either controls is not allowed or there's a violation
120
- if (violation || !current_controls_allowed ) {
112
+ if (violation || !controls_allowed ) {
121
113
hyundai_desired_torque_last = 0 ;
122
114
hyundai_rt_torque_last = 0 ;
123
115
hyundai_ts_last = ts ;
@@ -128,6 +120,13 @@ static int hyundai_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
128
120
}
129
121
}
130
122
123
+ // FORCE CANCEL: safety check only relevant when spamming the cancel button.
124
+ // ensuring that only the cancel button press is sent (VAL 4) when controls are off.
125
+ // This avoids unintended engagements while still allowing resume spam
126
+ if (((to_send -> RIR >>21 ) == 1265 ) && !controls_allowed && ((to_send -> RDTR >> 4 ) & 0xFF ) == 0 ) {
127
+ if ((to_send -> RDLR & 0x7 ) != 4 ) return 0 ;
128
+ }
129
+
131
130
// 1 allows the message through
132
131
return true;
133
132
}
0 commit comments