Files
QDAC-firmware/app/by_buzzer.c

63 lines
1.1 KiB
C
Raw Normal View History

2024-01-08 22:08:43 +08:00
#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};
2024-01-08 22:08:43 +08:00
void queue_init(void)
{
memset(a, 0, sizeof(a));
}
void queue_add_element(int element)
{
if (queue_long < BUZZER_QUEUE_LENGTH) {
2024-01-08 22:08:43 +08:00
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) {
2024-01-16 20:03:21 +08:00
pwm_init(BUZZER_PIN, a[0], 5000);
2024-01-08 22:08:43 +08:00
queue_pop_element();
system_delay_ms(100);
2024-01-16 20:03:21 +08:00
pwm_set_duty(BUZZER_PIN, 0);
2024-01-08 22:08:43 +08:00
}
}
void by_buzzer_init(void)
{
queue_init();
2024-01-16 20:03:21 +08:00
pwm_init(BUZZER_PIN, 2000, 0);
by_buzzer_add(1250);
by_buzzer_add(1500);
by_buzzer_add(1750);
}
void by_buzzer_add(uint16_t tone)
{
queue_add_element(tone);
2024-01-08 22:08:43 +08:00
}
2024-02-10 16:19:51 +08:00
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);
}
}