From 8369e4d47dc9594615dd3e2c99550d25a029d944 Mon Sep 17 00:00:00 2001 From: EmanuelFeru Date: Tue, 13 Oct 2020 10:38:43 +0200 Subject: [PATCH] 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. --- Inc/util.h | 2 +- Src/util.c | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Inc/util.h b/Inc/util.h index 42f90b2..7e7c83d 100644 --- a/Inc/util.h +++ b/Inc/util.h @@ -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); diff --git a/Src/util.c b/Src/util.c index c0f3520..8ec88cd 100644 --- a/Src/util.c +++ b/Src/util.c @@ -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 }