#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 #define CHEAR_ENCODER_1_KEY_NAME "Clear_Encoder_1_Key" #define CHEAR_ENCODER_2_KEY_NAME "Clear_Encoder_2_Key" static uint16_t s_key_long_press_time_ms = 3000; static inline bool clear_encoder_1_key_get_status() { return HAL_GPIO_ReadPin(GPIOE, GPIO_PIN_4); } static inline bool clear_encoder_2_key_get_status() { return HAL_GPIO_ReadPin(GPIOE, GPIO_PIN_3); } static void onkey(zkey_t *key, zkey_state_t key_state); static zkey_t s_keys[] = { ZKEY_INIT(CHEAR_ENCODER_1_KEY_NAME, clear_encoder_1_key_get_status), // ZKEY_INIT(CHEAR_ENCODER_2_KEY_NAME, clear_encoder_2_key_get_status), // }; 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) { if (strcmp(key->name, CHEAR_ENCODER_1_KEY_NAME) == 0) { encoder_switch_encoder_clear_count_and_structer_count(CAMERA_ENCODER); printf("clear encoder 1 count\r\n"); } else if (strcmp(key->name, CHEAR_ENCODER_2_KEY_NAME) == 0) { encoder_switch_encoder_clear_count_and_structer_count(DRIVEN_ENCODER_GEAR); printf("clear encoder 2 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 HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { if (GPIO_Pin == GPIO_PIN_2) { *udp_client_genlock_and_esync_active_flag_ret() = true; } } 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_client_genlock_and_esync_active(); udp_client_active(); zkey_schedule(); udp_client_recv(); at_cmd_processer_try_process_data(); encoder_light_schedule(); port_do_debug_light_state(); osDelay(1); } }