From 65298ce5b85231188100babecf8ed0dbc97c6ace Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hr=C3=A1zk=C3=BD?= Date: Sun, 22 Sep 2024 15:50:20 +0200 Subject: [PATCH] Fix crash on Duty Solid beep --- src/haptic_feedback.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/haptic_feedback.c b/src/haptic_feedback.c index 6335ead..79f6faf 100644 --- a/src/haptic_feedback.c +++ b/src/haptic_feedback.c @@ -106,12 +106,16 @@ void haptic_feedback_update( bool should_be_playing = false; if (hf->type_playing != HAPTIC_FEEDBACK_NONE) { uint8_t beats = get_beats(hf->type_playing); - float period = tone_length * beats; - float time = fmodf(current_time - hf->start_time, period); - uint8_t beat = floorf(time / tone_length); - uint8_t off_beat = beats > 2 ? beats - 2 : 0; - - should_be_playing = beats == 0 || (beat % 2 == 0 && (off_beat == 0 || beat != off_beat)); + if (beats == 0) { + should_be_playing = true; + } else { + float period = tone_length * beats; + float time = fmodf(current_time - hf->start_time, period); + uint8_t beat = floorf(time / tone_length); + uint8_t off_beat = beats > 2 ? beats - 2 : 0; + + should_be_playing = beat % 2 == 0 && (off_beat == 0 || beat != off_beat); + } } if (hf->is_playing && !should_be_playing) {