Skip to content

Commit b27e690

Browse files
rtds adjustements
1 parent a174567 commit b27e690

3 files changed

Lines changed: 44 additions & 39 deletions

File tree

Core/Inc/u_rtds.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <stdbool.h>
55

66
/* Config: */
7-
#define RTDS_DURATION 5000 /* RTDS duration (in ticks). */
7+
#define RTDS_DURATION 1500 /* RTDS duration (in ticks). */
88

99
/* API */
1010
int rtds_init(void); // Initializes the RTDS timer.

Core/Src/u_rtds.c

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -95,26 +95,6 @@ int rtds_init(void) {
9595
return U_SUCCESS;
9696
}
9797

98-
/* Sounds the RTDS (Ready-to-drive sound). */
99-
int rtds_soundRTDS(void) {
100-
101-
/* Stop the reverse sound if active. */
102-
rtds_stopReverseSound();
103-
104-
/* Trigger the RTDS sound. */
105-
_set_rtds_pin();
106-
107-
/* Restart RTDS timer. */
108-
int status = timer_restart(&rtds_timer);
109-
if(status != U_SUCCESS) {
110-
PRINTLN_ERROR("Failed to restart RTDS timer (Status: %d).", status);
111-
queue_send(&faults, &(fault_t){RTDS_FAULT}, TX_NO_WAIT);
112-
return U_ERROR;
113-
}
114-
115-
return U_SUCCESS;
116-
}
117-
11898
/* Cancels the RTDS sound. The RTDS sound already stops automatically once it's over, but this function lets you cancel it prematurely. */
11999
int rtds_cancelRTDS(void) {
120100
/* Stop the RTDS sound. */
@@ -148,23 +128,6 @@ int rtds_startReverseSound(void) {
148128
return U_SUCCESS;
149129
}
150130

151-
/* Stops the reverse sound. */
152-
int rtds_stopReverseSound(void) {
153-
/* Turn off the RTDS sound */
154-
_clear_rtds_pin();
155-
156-
/* Deactivate the reverse sound timer */
157-
int status = timer_stop(&reverse_sound_timer);
158-
if(status != U_SUCCESS) {
159-
PRINTLN_ERROR("Failed to deactivate reverse sound timer (Status: %d).", status);
160-
queue_send(&faults, &(fault_t){RTDS_FAULT}, TX_NO_WAIT);
161-
return U_ERROR;
162-
}
163-
164-
PRINTLN_INFO("Stopped reverse sound.");
165-
return U_SUCCESS;
166-
}
167-
168131
/* Reads the status of the RTDS pin (true = RTDS pin is active, false = RTDS pin is not active). */
169132
/* Useful for debugging. */
170133
bool rtds_readRTDS(void) {
@@ -212,3 +175,41 @@ int rtds_isInSounding(bool* state) {
212175

213176
return U_SUCCESS;
214177
}
178+
179+
/* Stops the reverse sound. */
180+
int rtds_stopReverseSound(void) {
181+
182+
/* Turn off the RTDS sound */
183+
_clear_rtds_pin();
184+
185+
/* Deactivate the reverse sound timer */
186+
int status = timer_stop(&reverse_sound_timer);
187+
if(status != U_SUCCESS) {
188+
PRINTLN_ERROR("Failed to deactivate reverse sound timer (Status: %d).", status);
189+
queue_send(&faults, &(fault_t){RTDS_FAULT}, TX_NO_WAIT);
190+
return U_ERROR;
191+
}
192+
193+
PRINTLN_INFO("Stopped reverse sound.");
194+
return U_SUCCESS;
195+
}
196+
197+
/* Sounds the RTDS (Ready-to-drive sound). */
198+
int rtds_soundRTDS(void) {
199+
200+
/* Stop the reverse sound if active. */
201+
rtds_stopReverseSound();
202+
203+
/* Trigger the RTDS sound. */
204+
_set_rtds_pin();
205+
206+
/* Restart RTDS timer. */
207+
int status = timer_restart(&rtds_timer);
208+
if(status != U_SUCCESS) {
209+
PRINTLN_ERROR("Failed to restart RTDS timer (Status: %d).", status);
210+
queue_send(&faults, &(fault_t){RTDS_FAULT}, TX_NO_WAIT);
211+
return U_ERROR;
212+
}
213+
214+
return U_SUCCESS;
215+
}

Core/Src/u_statemachine.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,11 @@ static int transition_functional_state(func_state_t new_state)
111111

112112
/* Make sure wheels are not spinning before changing modes */
113113
bool brake_state;
114-
rtds_stopReverseSound();
114+
115+
/* If we're actively in the reverse state, stop the reverse sound before doing any state changes. */
116+
if(cerberus_state.functional == F_REVERSE) {
117+
rtds_stopReverseSound();
118+
}
115119

116120
/* Catching state transitions */
117121
switch (new_state) {

0 commit comments

Comments
 (0)