Increased delay for CC

In Cruise Control (CC), the button can bounce. The beep delay is increased from 100ms to 200ms to prevent button bouncing and continuous activation/deactivation of CC.
This commit is contained in:
EmanuelFeru 2020-10-13 10:38:43 +02:00
parent 66857b5680
commit 8369e4d47d
2 changed files with 14 additions and 8 deletions

View File

@ -63,7 +63,7 @@ void UART_DisableRxErrors(UART_HandleTypeDef *huart);
// General Functions
void poweronMelody(void);
void shortBeep(uint8_t freq);
void shortBeepMany(uint8_t cnt);
void shortBeepMany(uint8_t cnt, int8_t dir);
void longBeep(uint8_t freq);
void calcAvgSpeed(void);
void adcCalibLim(void);

View File

@ -388,9 +388,15 @@ void shortBeep(uint8_t freq) {
buzzerFreq = 0;
}
void shortBeepMany(uint8_t cnt) {
for(uint8_t i = 0; i < cnt; i++) {
shortBeep(i + 5);
void shortBeepMany(uint8_t cnt, int8_t dir) {
if (dir >= 0) { // increasing tone
for(uint8_t i = cnt; i > 0; i--) {
shortBeep(i + 2);
}
} else { // decreasing tone
for(uint8_t i = 0; i < cnt; i++) {
shortBeep(i + 2);
}
}
}
@ -868,11 +874,11 @@ void readCommand(void) {
rtP_Right.n_cruiseMotTgt = rtY_Right.n_mot;
rtP_Left.b_cruiseCtrlEna = 1;
rtP_Right.b_cruiseCtrlEna = 1;
shortBeep(2);
shortBeepMany(2, 1); // 200 ms beep delay. Acts as a debounce also.
} else if (button1 && rtP_Left.b_cruiseCtrlEna) { // Cruise control deactivated
rtP_Left.b_cruiseCtrlEna = 0;
rtP_Right.b_cruiseCtrlEna = 0;
shortBeep(6);
shortBeepMany(2, -1);
}
#endif
}
@ -1224,7 +1230,7 @@ void sideboardSensors(uint8_t sensors) {
rtP_Right.z_ctrlTypSel = COM_CTRL;
break;
}
shortBeepMany(sensor1_index + 1);
shortBeepMany(sensor1_index + 1, 1);
}
// Field Weakening: use Sensor2 as push button
@ -1243,7 +1249,7 @@ void sideboardSensors(uint8_t sensors) {
Input_Lim_Init();
break;
}
shortBeepMany(sensor2_index + 1);
shortBeepMany(sensor2_index + 1, 1);
}
#endif
}