pref: 优化长短按判断
This commit is contained in:
@@ -4,12 +4,15 @@
|
|||||||
#include "stdio.h"
|
#include "stdio.h"
|
||||||
#include "ch32v30x.h"
|
#include "ch32v30x.h"
|
||||||
|
|
||||||
typedef enum rotate_button_event{
|
#define LONG_PRESS_THRESHOLD_MS (300ULL)
|
||||||
|
#define LONG_PRESS_THRESHOLD_TICK (LONG_PRESS_THRESHOLD_MS * 18000ULL)
|
||||||
|
|
||||||
|
typedef enum rotate_button_event {
|
||||||
rotate_button_press_short = 1,
|
rotate_button_press_short = 1,
|
||||||
rotate_button_press_long = 2,
|
rotate_button_press_long = 2,
|
||||||
rotate_button_forward = 3,
|
rotate_button_forward = 3,
|
||||||
rotate_button_backward = 4,
|
rotate_button_backward = 4,
|
||||||
}rotate_button_event;
|
} rotate_button_event;
|
||||||
|
|
||||||
extern uint8_t rotate_button;
|
extern uint8_t rotate_button;
|
||||||
|
|
||||||
|
|||||||
24
app/isr.c
24
app/isr.c
@@ -219,24 +219,18 @@ void EXTI15_10_IRQHandler(void)
|
|||||||
}
|
}
|
||||||
if (SET == EXTI_GetITStatus(EXTI_Line11)) {
|
if (SET == EXTI_GetITStatus(EXTI_Line11)) {
|
||||||
static uint64_t time_via = 0;
|
static uint64_t time_via = 0;
|
||||||
|
system_delay_ms(10);
|
||||||
if (RESET == gpio_get_level(E11)) {
|
if (RESET == gpio_get_level(E11)) {
|
||||||
system_delay_us(200);
|
time_via = system_get_tick();
|
||||||
if (RESET == gpio_get_level(E11)) {
|
|
||||||
time_via = system_get_tick();
|
|
||||||
}
|
|
||||||
EXTI_ClearITPendingBit(EXTI_Line11);
|
EXTI_ClearITPendingBit(EXTI_Line11);
|
||||||
} else {
|
} else if (SET == gpio_get_level(E11)) {
|
||||||
system_delay_us(200);
|
time_via = system_get_tick() - time_via;
|
||||||
if (SET == gpio_get_level(E11)) {
|
if (time_via > LONG_PRESS_THRESHOLD_TICK) {
|
||||||
time_via = system_get_tick() - time_via;
|
rotate_button = rotate_button_press_long;
|
||||||
if (time_via > LONG_PRESS_THRESHOLD_TICK) {
|
} else {
|
||||||
rotate_button = rotate_button_press_long;
|
rotate_button = rotate_button_press_short;
|
||||||
} else {
|
|
||||||
rotate_button = rotate_button_press_short;
|
|
||||||
}
|
|
||||||
time_via = 0;
|
|
||||||
}
|
}
|
||||||
|
time_via = 0;
|
||||||
EXTI_ClearITPendingBit(EXTI_Line11);
|
EXTI_ClearITPendingBit(EXTI_Line11);
|
||||||
}
|
}
|
||||||
if (SET == EXTI_GetITStatus(EXTI_Line12)) {
|
if (SET == EXTI_GetITStatus(EXTI_Line12)) {
|
||||||
|
|||||||
@@ -39,9 +39,6 @@
|
|||||||
#include "zf_common_clock.h"
|
#include "zf_common_clock.h"
|
||||||
#include "zf_common_typedef.h"
|
#include "zf_common_typedef.h"
|
||||||
|
|
||||||
#define LONG_PRESS_THRESHOLD_MS (300ULL)
|
|
||||||
#define LONG_PRESS_THRESHOLD_TICK (LONG_PRESS_THRESHOLD_MS * 18000ULL)
|
|
||||||
|
|
||||||
void system_delay_ms(uint32 time);
|
void system_delay_ms(uint32 time);
|
||||||
void system_delay_us(uint32 time);
|
void system_delay_us(uint32 time);
|
||||||
uint64_t system_get_tick(void);
|
uint64_t system_get_tick(void);
|
||||||
|
|||||||
Reference in New Issue
Block a user