user_check.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #include "user_check.h"
  2. static user_check_work_s user_check_work = {
  3. .check_delay_count = 0,
  4. .check_stat = 2,
  5. .check_on_count = USER_CHECK_MAX_COUNT,
  6. .check_off_count = USER_CHECK_MAX_COUNT,
  7. .upload_func = NULL,
  8. };
  9. /*******************************************************************************
  10. * @函数名称 prvUser_check_out_gpio_init
  11. * @函数说明 GPIO输出初始化
  12. * @输入参数 无
  13. * @输出参数 无
  14. * @返回参数 无
  15. *******************************************************************************/
  16. static void prvUser_check_out_gpio_init(void)
  17. {
  18. GPIO_InitTypeDef GPIO_InitStructure = {0};
  19. GPIO_InitStructure.GPIO_Pin = USER_CHECK_SW_PIN;
  20. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  21. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_30MHz;
  22. GPIO_Init(USER_CHECK_SW_GPIO, &GPIO_InitStructure);
  23. USER_CHECK_SW_ON;
  24. }
  25. /*******************************************************************************
  26. * @函数名称 prvUser_check_in_gpio_init
  27. * @函数说明 GPIO输入初始化
  28. * @输入参数 无
  29. * @输出参数 无
  30. * @返回参数 无
  31. *******************************************************************************/
  32. static void prvUser_check_in_gpio_init(void)
  33. {
  34. GPIO_InitTypeDef GPIO_InitStructure = {0};
  35. GPIO_InitStructure.GPIO_Pin = USER_CHECK_IN_PIN;
  36. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  37. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_30MHz;
  38. GPIO_Init(USER_CHECK_IN_GPIO, &GPIO_InitStructure);
  39. }
  40. /*******************************************************************************
  41. * @函数名称 vUser_check_init
  42. * @函数说明 初始化
  43. * @输入参数 无
  44. * @输出参数 无
  45. * @返回参数 无
  46. *******************************************************************************/
  47. void vUser_check_init(void)
  48. {
  49. USER_CHECK_GPIO_RCC_ENABLE;
  50. prvUser_check_out_gpio_init();
  51. prvUser_check_in_gpio_init();
  52. }
  53. /*******************************************************************************
  54. * @函数名称 vUser_check_tick
  55. * @函数说明 任务计时器
  56. * @输入参数 无
  57. * @输出参数 无
  58. * @返回参数 无
  59. *******************************************************************************/
  60. void vUser_check_tick(void)
  61. {
  62. if(user_check_work.check_delay_count > 0)
  63. {
  64. user_check_work.check_delay_count--;
  65. }
  66. }
  67. /*******************************************************************************
  68. * @函数名称 vUser_check_in_pro
  69. * @函数说明 光敏状态检测
  70. * @输入参数 无
  71. * @输出参数 无
  72. * @返回参数 无
  73. *******************************************************************************/
  74. static void vUser_check_in_pro(void)
  75. {
  76. if(true == USER_CHECK_IN_IN)
  77. {
  78. user_check_work.check_off_count = USER_CHECK_MAX_COUNT;
  79. if(user_check_work.check_on_count == 0)
  80. {
  81. if(user_check_work.check_finish == false)
  82. {
  83. user_check_work.check_finish = true;
  84. if(user_check_work.check_stat != 1)
  85. {
  86. user_check_work.check_stat = 1;
  87. if(user_check_work.upload_func != NULL)
  88. {
  89. user_check_work.upload_func(false);
  90. }
  91. }
  92. }
  93. }
  94. else{
  95. user_check_work.check_finish = false;
  96. user_check_work.check_on_count--;
  97. }
  98. }
  99. else{
  100. user_check_work.check_on_count = USER_CHECK_MAX_COUNT;
  101. if(user_check_work.check_off_count == 0)
  102. {
  103. if(user_check_work.check_finish == false)
  104. {
  105. user_check_work.check_finish = true;
  106. if(user_check_work.check_stat != 0)
  107. {
  108. user_check_work.check_stat = 0;
  109. if(user_check_work.upload_func != NULL)
  110. {
  111. user_check_work.upload_func(true);
  112. }
  113. }
  114. }
  115. }
  116. else{
  117. user_check_work.check_finish = false;
  118. user_check_work.check_off_count--;
  119. }
  120. }
  121. }
  122. /*******************************************************************************
  123. * @函数名称 vUser_check_pro
  124. * @函数说明 任务
  125. * @输入参数 无
  126. * @输出参数 无
  127. * @返回参数 无
  128. *******************************************************************************/
  129. void vUser_check_pro(void)
  130. {
  131. if(user_check_work.check_delay_count == 0)
  132. {
  133. user_check_work.check_delay_count = USER_CHECK_INTERVAL;
  134. vUser_check_in_pro();
  135. }
  136. }
  137. /*******************************************************************************
  138. * @函数名称 vUser_check_set_upload_func
  139. * @函数说明 设置光敏状态上报回调函数
  140. * @输入参数 func:回调函数指针
  141. * @输出参数 无
  142. * @返回参数 无
  143. *******************************************************************************/
  144. void vUser_check_set_upload_func(user_check_upload_func func)
  145. {
  146. user_check_work.upload_func = func;
  147. }