fix: 修复蜂鸣器仅剩一个元素时,鸣响时长错误的问题
This commit is contained in:
@@ -25,7 +25,7 @@ void queue_add_element(int element)
|
|||||||
}
|
}
|
||||||
void queue_pop_element(void)
|
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) {
|
if (queue_long > 0) {
|
||||||
queue_long--;
|
queue_long--;
|
||||||
}
|
}
|
||||||
@@ -61,16 +61,19 @@ void by_buzzer_add(uint16_t tone)
|
|||||||
|
|
||||||
void by_buzzer_run(void)
|
void by_buzzer_run(void)
|
||||||
{
|
{
|
||||||
if (queue_long != 0) {
|
if (queue_long > 0) {
|
||||||
|
|
||||||
if (0 == time_out) {
|
if (0 == time_out) {
|
||||||
pwm_init(BUZZER_PIN, a[0], 5000);
|
pwm_init(BUZZER_PIN, a[0], 5000);
|
||||||
queue_pop_element();
|
queue_pop_element();
|
||||||
time_out = BUZZER_TIME;
|
time_out = BUZZER_TIME;
|
||||||
} else {
|
|
||||||
time_out--;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pwm_set_duty(BUZZER_PIN, 0);
|
if (0 == time_out)
|
||||||
|
pwm_set_duty(BUZZER_PIN, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (time_out) {
|
||||||
|
time_out--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user