From 0a1608ccfaea282748f68c4b7210375ac71316e4 Mon Sep 17 00:00:00 2001 From: bmy <2583236812@qq.com> Date: Tue, 16 Apr 2024 11:14:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=9C=82=E9=B8=A3?= =?UTF-8?q?=E5=99=A8=E4=BB=85=E5=89=A9=E4=B8=80=E4=B8=AA=E5=85=83=E7=B4=A0?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E9=B8=A3=E5=93=8D=E6=97=B6=E9=95=BF=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/by_buzzer.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/by_buzzer.c b/app/by_buzzer.c index 1626379..5b94c62 100644 --- a/app/by_buzzer.c +++ b/app/by_buzzer.c @@ -25,7 +25,7 @@ void queue_add_element(int element) } void queue_pop_element(void) { - memmove(a, &a[1], (queue_long - 1) * sizeof(a[0])); + memmove(a, &a[1], (queue_long - 1) * sizeof(a[0])); // FIXME 强迫症震怒,仅移动,未清除原位置上的值 if (queue_long > 0) { queue_long--; } @@ -61,16 +61,19 @@ void by_buzzer_add(uint16_t tone) void by_buzzer_run(void) { - if (queue_long != 0) { + if (queue_long > 0) { if (0 == time_out) { pwm_init(BUZZER_PIN, a[0], 5000); queue_pop_element(); time_out = BUZZER_TIME; - } else { - time_out--; } } else { - pwm_set_duty(BUZZER_PIN, 0); + if (0 == time_out) + pwm_set_duty(BUZZER_PIN, 0); + } + + if (time_out) { + time_out--; } } \ No newline at end of file