diff --git a/app/by_buzzer.c b/app/by_buzzer.c new file mode 100644 index 0000000..c29e383 --- /dev/null +++ b/app/by_buzzer.c @@ -0,0 +1,42 @@ +#include "by_buzzer.h" +#include "by_rt_button.h" + +#include "zf_common_headfile.h" +#include + +uint16_t queue_long = 0; +const uint32_t max_long = 40; +uint32_t a[40]; +void queue_init(void) +{ + memset(a, 0, sizeof(a)); +} + +void queue_add_element(int element) +{ + if (queue_long < max_long) { + 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(TIM8_PWM_MAP0_CH1_C6, a[0], 5000); + queue_pop_element(); + system_delay_ms(100); + pwm_set_duty(TIM8_PWM_MAP0_CH1_C6, 0); + } +} + +void by_buzzer_init(void) +{ + pwm_init(TIM8_PWM_MAP0_CH1_C6, 2000, 0); +} diff --git a/app/by_buzzer.h b/app/by_buzzer.h new file mode 100644 index 0000000..9bf9f9a --- /dev/null +++ b/app/by_buzzer.h @@ -0,0 +1,24 @@ +#ifndef _BY_BUZZER_H__ +#define _BY_BUZZER_H__ + +#include "by_rt_button.h" + +#include "stdio.h" +#include "ch32v30x.h" + +#define BY_PRESS_SHORT 2000 +#define BY_PRESS_LONG 2500 +#define BY_FORWARD 1500 +#define BY_BACKWARD 1800 + +extern void by_buzzer_init(void); +extern void queue_init(void); +extern void queue_add_element(int element); +extern void queue_pop_element(void); +extern void queue_pop_read(void); + +extern uint32_t a[40]; +extern uint16_t queue_long; +extern const uint32_t max_long; +extern uint8_t queue_flag; +#endif \ No newline at end of file diff --git a/app/isr.c b/app/isr.c index 41e16fa..9c47092 100644 --- a/app/isr.c +++ b/app/isr.c @@ -37,6 +37,8 @@ #include "by_rt_button.h" #include "by_imu.h" #include "jj_blueteeth.h" +#include "by_buzzer.h" + void NMI_Handler(void) __attribute__((interrupt())); void HardFault_Handler(void) __attribute__((interrupt())); @@ -200,9 +202,10 @@ void EXTI9_5_IRQHandler(void) if (SET == gpio_get_level(E10)) { rotate_button = rotate_button_backward; - + queue_add_element(BY_BACKWARD); } else { rotate_button = rotate_button_forward; + queue_add_element(BY_FORWARD); } EXTI_ClearITPendingBit(EXTI_Line9); } @@ -228,8 +231,11 @@ void EXTI15_10_IRQHandler(void) time_via = system_get_tick() - time_via; if (time_via > LONG_PRESS_THRESHOLD_TICK) { rotate_button = rotate_button_press_long; + queue_add_element(BY_PRESS_LONG); + } else { rotate_button = rotate_button_press_short; + queue_add_element(BY_PRESS_SHORT); } time_via = 0; EXTI_ClearITPendingBit(EXTI_Line11); diff --git a/app/main.c b/app/main.c index a9903fd..80dc0d3 100644 --- a/app/main.c +++ b/app/main.c @@ -28,7 +28,8 @@ #include "jj_blueteeth.h" #include "jj_param.h" #include "./page/page_ui_widget.h" -int falg_false = 0; +#include "by_buzzer.h" + int main(void) { @@ -41,6 +42,7 @@ int main(void) by_exit_init(); by_pwm_init(); jj_bt_init(); + by_buzzer_init(); // while (imu660ra_init()) // ; jj_param_eeprom_init(); @@ -50,6 +52,8 @@ int main(void) Page_Run(); jj_bt_run(); + queue_pop_read(); + if (mt9v03x_finish_flag) { // 该操作消耗大概 1970 个 tick,折合约 110us memcpy(mt9v03x_image_copy[0], mt9v03x_image[0], (sizeof(mt9v03x_image_copy) / sizeof(uint8_t))); diff --git a/app/page/page.c b/app/page/page.c index 740b228..794ddaa 100644 --- a/app/page/page.c +++ b/app/page/page.c @@ -89,7 +89,7 @@ uint8_t Page_GetStatus(void) */ void Page_Run(void) { - uint8_t temp_status = by_get_rb_status(); // 轮询旋钮状态 + uint8_t temp_status = by_get_rb_status(); // 轮询旋钮状态 if(temp_status){ pagelist[now_page].EventCallback(temp_status); }