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.

140 lines
3.7 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. #include <stdbool.h>
  2. #include <stdint.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include "lwip/opt.h"
  6. #include "lwip/sys.h"
  7. #include "lwip/api.h"
  8. #include "main.h"
  9. #include "zport.h"
  10. #include "zboard.h"
  11. #include "encoder.h"
  12. #include "udpclient.h"
  13. #include "zflash.h"
  14. #include "config.h"
  15. #include "zkey.h"
  16. #include "atcmd.h"
  17. #define KEY_SCAN_PERIOD 20
  18. #define CHEAR_ENCODER_1_KEY_NAME "Clear_Encoder_1_Key"
  19. #define CHEAR_ENCODER_2_KEY_NAME "Clear_Encoder_2_Key"
  20. static uint16_t s_key_long_press_time_ms = 3000;
  21. static inline bool clear_encoder_1_key_get_status() { return HAL_GPIO_ReadPin(KEY0_GPIO_Port, KEY0_Pin); }
  22. static inline bool clear_encoder_2_key_get_status() { return HAL_GPIO_ReadPin(KEY1_GPIO_Port, KEY1_Pin); }
  23. static void onkey(zkey_t *key, zkey_state_t key_state);
  24. static zkey_t s_keys[] = {
  25. ZKEY_INIT(CHEAR_ENCODER_1_KEY_NAME, clear_encoder_1_key_get_status), //
  26. ZKEY_INIT(CHEAR_ENCODER_2_KEY_NAME, clear_encoder_2_key_get_status), //
  27. };
  28. static zkey_module_t s_key_module = ZMODULE_INIT(s_keys, onkey);
  29. static void zkey_schedule()
  30. {
  31. static uint32_t lastprocess_key_ticket;
  32. if (sys_haspassedms(lastprocess_key_ticket) >= KEY_SCAN_PERIOD)
  33. {
  34. zkey_do_loop_in_each_period(NULL);
  35. lastprocess_key_ticket = HAL_GetTick();
  36. }
  37. }
  38. static void onkey(zkey_t *key, zkey_state_t key_state)
  39. {
  40. if (key_state == zks_rising_edge)
  41. {
  42. if (strcmp(key->name, CHEAR_ENCODER_1_KEY_NAME) == 0)
  43. {
  44. encoder_switch_encoder_clear_count_and_structer_count(CAMERA_ENCODER);
  45. printf("clear encoder 1 count\r\n");
  46. }
  47. else if (strcmp(key->name, CHEAR_ENCODER_2_KEY_NAME) == 0)
  48. {
  49. encoder_switch_encoder_clear_count_and_structer_count(DRIVEN_ENCODER_GEAR);
  50. printf("clear encoder 2 count\r\n");
  51. }
  52. }
  53. if (key_state == zks_keep)
  54. {
  55. if (key->keep_state_count == s_key_long_press_time_ms / KEY_SCAN_PERIOD)
  56. {
  57. // 触发长按事件
  58. key->hasProcessed = true;
  59. }
  60. }
  61. else if (key_state == zks_falling_edge)
  62. {
  63. /**
  64. * @brief
  65. */
  66. if (!key->hasProcessed)
  67. {
  68. }
  69. }
  70. }
  71. /**
  72. * @brief
  73. */
  74. void port_mock_on_uart_rx(uart_t *uart)
  75. {
  76. // 处理指令串口接收到的数据
  77. if (uart->uarthandler == &DEBUG_UART)
  78. {
  79. at_cmd_processer_push_data(uart->rxbuf);
  80. }
  81. }
  82. void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
  83. {
  84. if (GPIO_Pin == GPIO_PIN_8)
  85. {
  86. *udp_client_genlock_and_esync_active_flag_ret() = true;
  87. }
  88. }
  89. void netif_link_up_user_func(void)
  90. {
  91. encoder_light_switch_set_color_and_brightness(CAMERA_ENCODER, ENCODER_LIGHT_COLOR_GREEN, encoder_light_max_brightness);
  92. encoder_light_switch_set_color_and_brightness(DRIVEN_ENCODER_GEAR, ENCODER_LIGHT_COLOR_GREEN, encoder_light_max_brightness);
  93. }
  94. void netif_link_down_user_func(void)
  95. {
  96. encoder_light_switch_set_color_and_brightness(CAMERA_ENCODER, ENCODER_LIGHT_COLOR_RED, encoder_light_max_brightness);
  97. encoder_light_switch_set_color_and_brightness(DRIVEN_ENCODER_GEAR, ENCODER_LIGHT_COLOR_RED, encoder_light_max_brightness);
  98. }
  99. /* 重写了该函数,需要添加编码器采集部分的逻辑 */
  100. void HAL_IncTick(void)
  101. {
  102. uwTick += uwTickFreq;
  103. }
  104. void user_main()
  105. {
  106. printf("==============ethernet_sound_acquisition_card=============\r\n");
  107. printf("version %d.%d", VERSION_MAIN_ID, VERSION_SUB_ID);
  108. encoder_all_start();
  109. udp_client_init();
  110. zkey_init(&s_key_module);
  111. port_uart_start_all_uart_receive();
  112. while (1)
  113. {
  114. udp_client_genlock_and_esync_active();
  115. udp_client_active();
  116. zkey_schedule();
  117. udp_client_recv();
  118. at_cmd_processer_try_process_data();
  119. encoder_light_schedule();
  120. port_do_debug_light_state();
  121. osDelay(1);
  122. }
  123. }