#include #include #include #include #include "lwip/opt.h" #include "lwip/sys.h" #include "lwip/api.h" #include "main.h" #include "zport.h" #include "zboard.h" #include "encoder.h" #include "udpclient.h" #include "zflash.h" #include "config.h" #include "zkey.h" #include "atcmd.h" #define KEY_SCAN_PERIOD 20 static uint16_t s_key_long_press_time_ms = 3000; static inline bool clear_key_get_status() { return HAL_GPIO_ReadPin(GPIOE, GPIO_PIN_4); } static void onkey(zkey_t *key, zkey_state_t key_state); static zkey_t s_keys[] = { ZKEY_INIT("Clear_Key", clear_key_get_status), // // ZKEY_INIT("Signal_INT1", port_get_gpio_int1), // // ZKEY_INIT("Signal_INT2", port_get_gpio_int2), // // ZKEY_INIT("Signal_INT3", port_get_gpio_int3), // }; static zkey_module_t s_key_module = ZMODULE_INIT(s_keys, onkey); static void zkey_schedule() { static uint32_t lastprocess_key_ticket; if (sys_haspassedms(lastprocess_key_ticket) >= KEY_SCAN_PERIOD) { zkey_do_loop_in_each_period(NULL); lastprocess_key_ticket = HAL_GetTick(); } } static void onkey(zkey_t *key, zkey_state_t key_state) { if (key_state == zks_rising_edge) { encoder_all_clear_counter(); printf("clear encoder count\r\n"); } if (key_state == zks_keep) { if (key->keep_state_count == s_key_long_press_time_ms / KEY_SCAN_PERIOD) { // 触发长按事件 key->hasProcessed = true; } } else if (key_state == zks_falling_edge) { /** * @brief 触发短按事件,如果长按事件已经触发,则丢弃该短按事件 */ if (!key->hasProcessed) { } } } /** * @brief 处理从串口接收到的数据 */ void port_mock_on_uart_rx(uart_t *uart) { // 处理指令串口接收到的数据 if (uart->uarthandler == &DEBUG_UART) { at_cmd_processer_push_data(uart->rxbuf); } } void user_main() { printf("==============ethernet_sound_acquisition_card=============\r\n"); printf("version %d.%d", VERSION_MAIN_ID, VERSION_SUB_ID); encoder_all_start(); udp_client_init(); config_init(); zkey_init(&s_key_module); port_uart_start_all_uart_receive(); while (1) { udp_cllient_genlock_and_esync_active(); udp_cllient_active(); zkey_schedule(); udp_client_recv(); at_cmd_processer_try_process_data(); port_do_debug_light_state(); osDelay(1); } }