Skip to content

Commit

Permalink
190 all durations of button press count as only 1 button press
Browse files Browse the repository at this point in the history
  • Loading branch information
Sabramz committed Aug 9, 2024
1 parent 0e4b614 commit dd21f7f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
5 changes: 1 addition & 4 deletions Core/Inc/cerberus_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@
/* Maximum AC braking current */
#define MAX_REGEN_CURRENT 20

// DEBUGGING: Start with a high debounce period, lower it if it is too slow
// NOTE: SteeringIOMonitor updates every 25 ms. Previous value of 25 ms doesn't
// give enough time to differentiate signal from noise.
#define STEERING_WHEEL_DEBOUNCE 70 /* ms */
#define STEERING_WHEEL_DEBOUNCE 10 /* ms */

/* Pin Assignments */
#define FAULT_MCU_Pin GPIO_PIN_3
Expand Down
2 changes: 2 additions & 0 deletions Core/Inc/steeringio.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ typedef struct {
ringbuffer_t *debounce_buffer;
bool raw_buttons[MAX_STEERING_BUTTONS];
bool debounced_buttons[MAX_STEERING_BUTTONS];
/* Array indicating that a button has already been pressed and not unpressed */
bool pressed_once[MAX_STEERING_BUTTONS];
} steeringio_t;

/* Creates a new Steering Wheel interface */
Expand Down
11 changes: 10 additions & 1 deletion Core/Src/steeringio.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ static void debounce_cb(void *arg)

steeringio_t *wheel = args->wheel;

if (wheel->raw_buttons[button]) {
if (wheel->raw_buttons[button] && !wheel->pressed_once[button]) {
wheel->pressed_once[button] = true;
switch (button) {
case STEERING_PADDLE_LEFT:
paddle_left_cb();
Expand Down Expand Up @@ -139,6 +140,9 @@ static void debounce_cb(void *arg)
default:
break;
}
} else if (!wheel->raw_buttons[button]) {
/* Button is no longer pressed, so it can be pressed again */
wheel->pressed_once[button] = false;
}
}

Expand Down Expand Up @@ -167,6 +171,11 @@ void steeringio_update(steeringio_t *wheel, uint8_t button_data)
debounce(wheel->raw_buttons[i],
wheel->debounce_timers[i],
STEERING_WHEEL_DEBOUNCE);
/* Debounce that the button has been unpressed */
else
debounce(!wheel->raw_buttons[i],
wheel->debounce_timers[i],
STEERING_WHEEL_DEBOUNCE);
}
osMutexRelease(wheel->button_mutex);
}

0 comments on commit dd21f7f

Please sign in to comment.