|
|
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#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(KEY0_GPIO_Port, KEY0_Pin); } static inline bool clear_encoder_2_key_get_status() { return HAL_GPIO_ReadPin(KEY1_GPIO_Port, KEY1_Pin); }
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);
HAL_GPIO_WritePin(DIS_R1_GPIO_Port, DIS_R1_Pin, GPIO_PIN_RESET); HAL_GPIO_WritePin(DIS_G1_GPIO_Port, DIS_G1_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(DIS_B1_GPIO_Port, DIS_B1_Pin, GPIO_PIN_RESET); HAL_GPIO_WritePin(DIS_R2_GPIO_Port, DIS_R2_Pin, GPIO_PIN_RESET); HAL_GPIO_WritePin(DIS_G2_GPIO_Port, DIS_G2_Pin, GPIO_PIN_RESET); HAL_GPIO_WritePin(DIS_B2_GPIO_Port, DIS_B2_Pin, GPIO_PIN_SET);
encoder_all_start(); udp_client_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); } }
|