You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
#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 uint16_t encoder_get_temp;
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_clear_counter(CAMERA_ENCODER); } else if (strcmp(key->name, CHEAR_ENCODER_2_KEY_NAME) == 0) { encoder_switch_clear_counter(DRIVEN_ENCODER_GEAR); } }
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_8) { *udp_client_genlock_and_esync_active_flag_ret() = true; } }
int32_t compute_uint16_t_minus_the_numbers(uint16_t now, uint16_t last) { int32_t diff1 = now - last; int32_t diff2 = UINT16_MAX - abs(diff1); int32_t diffreal = 0;
if (now > last) { diff2 = -diff2; }
diffreal = abs(diff1) < abs(diff2) ? diff1 : diff2;
return diffreal; }
void netif_link_up_user_func(void) { encoder_light_switch_set_color(CAMERA_ENCODER, ENCODER_LIGHT_COLOR_GREEN); encoder_light_switch_set_color(DRIVEN_ENCODER_GEAR, ENCODER_LIGHT_COLOR_GREEN); }
void netif_link_down_user_func(void) { encoder_light_switch_set_color(CAMERA_ENCODER, ENCODER_LIGHT_COLOR_RED); encoder_light_switch_set_color(DRIVEN_ENCODER_GEAR, ENCODER_LIGHT_COLOR_RED); }
static void encoder_get_and_calculation(void) { encoder_get_temp = __HAL_TIM_GET_COUNTER(encoder_get_camera_encoder_structer()->tim_handler); if (encoder_get_camera_encoder_structer()->last_count != encoder_get_temp) { encoder_get_camera_encoder_structer()->count += compute_uint16_t_minus_the_numbers(encoder_get_temp, encoder_get_camera_encoder_structer()->last_count); encoder_get_camera_encoder_structer()->last_count = encoder_get_temp; }
encoder_get_temp = __HAL_TIM_GET_COUNTER(encoder_get_driven_encoder_gear_structer()->tim_handler); if (encoder_get_driven_encoder_gear_structer()->last_count != encoder_get_temp) { encoder_get_driven_encoder_gear_structer()->count += compute_uint16_t_minus_the_numbers(encoder_get_temp, encoder_get_driven_encoder_gear_structer()->last_count); encoder_get_driven_encoder_gear_structer()->last_count = encoder_get_temp; } }
/* 重写了该函数,需要添加编码器采集部分的逻辑 */ void HAL_IncTick(void) { uwTick += uwTickFreq; encoder_get_and_calculation(); }
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(); 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); } }
|