Skip to content

Commit

Permalink
Fix crash on Duty Solid beep
Browse files Browse the repository at this point in the history
  • Loading branch information
lukash committed Sep 22, 2024
1 parent d6b751f commit 65298ce
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/haptic_feedback.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 65298ce

Please sign in to comment.