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.

123 lines
2.9 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
  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(GPIOE, GPIO_PIN_4); }
  22. static inline bool clear_encoder_2_key_get_status() { return HAL_GPIO_ReadPin(GPIOE, GPIO_PIN_3); }
  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_clear_counter(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_clear_counter(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_2)
  85. {
  86. *udp_client_genlock_and_esync_active_flag_ret() = true;
  87. }
  88. }
  89. void user_main()
  90. {
  91. printf("==============ethernet_sound_acquisition_card=============\r\n");
  92. printf("version %d.%d", VERSION_MAIN_ID, VERSION_SUB_ID);
  93. encoder_all_start();
  94. udp_client_init();
  95. config_init();
  96. zkey_init(&s_key_module);
  97. port_uart_start_all_uart_receive();
  98. while (1)
  99. {
  100. udp_client_genlock_and_esync_active();
  101. udp_client_active();
  102. zkey_schedule();
  103. udp_client_recv();
  104. at_cmd_processer_try_process_data();
  105. encoder_light_schedule();
  106. port_do_debug_light_state();
  107. osDelay(1);
  108. }
  109. }