Files
QD4C-firmware/app/by_buzzer.c
2024-02-07 14:12:00 +08:00

66 lines
1.2 KiB
C

#include "by_buzzer.h"
#include <string.h>
#include "zf_common_headfile.h"
#define BUZZER_QUEUE_LENGTH 40
uint16_t queue_long = 0;
uint32_t a[40] = {0};
void queue_init(void)
{
memset(a, 0, sizeof(a));
}
void queue_add_element(int element)
{
if (queue_long < BUZZER_QUEUE_LENGTH) {
a[queue_long] = element;
queue_long += 1;
}
}
void queue_pop_element(void)
{
memmove(a, &a[1], queue_long * sizeof(a));
if (queue_long > 0) {
queue_long--;
}
}
void queue_pop_read(void)
{
while (queue_long != 0) {
pwm_init(BUZZER_PIN, a[0], 5000);
queue_pop_element();
system_delay_ms(100);
pwm_set_duty(BUZZER_PIN, 0);
}
}
void by_buzzer_init(void)
{
queue_init();
pwm_init(BUZZER_PIN, 2000, 0);
by_buzzer_add(1250);
by_buzzer_add(1500);
by_buzzer_add(1750);
by_buzzer_add(1500);
by_buzzer_add(1200);
by_buzzer_add(900);
}
void by_buzzer_add(uint16_t tone)
{
queue_add_element(tone);
}
void by_buzzer_run(void)
{
if (queue_long != 0) {
pwm_init(BUZZER_PIN, a[0], 5000);
queue_pop_element();
system_delay_ms(100);
pwm_set_duty(BUZZER_PIN, 0);
}
}