bikegearsensor.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /**
  2. * @file bikegearsensor.c
  3. * @author Zhou xiong(zhouxiong9@midea.com)
  4. * @brief Gear Sensor of ebike
  5. * @version 0.1
  6. * @date 2023-02-03
  7. *
  8. * @copyright Copyright (c) 2021
  9. *
  10. */
  11. /************************************************************************
  12. Beginning of File, do not put anything above here except notes
  13. Compiler Directives:
  14. *************************************************************************/
  15. #include "api.h"
  16. #include "board_config.h"
  17. #include "bikegearsensor.h"
  18. #include "user.h"
  19. /******************************
  20. *
  21. * Parameter
  22. *
  23. ******************************/
  24. BIKE_GEARSENSOR_OUT bikegearsensor_stBikeGearsensorOut = GEARSENSOR_OUT_DEFAULT;
  25. /***************************************************************
  26. Function: bikegearsensor_voBikeGearsensorInit;
  27. Description: bike light control initialization
  28. Call by: functions in main loop;
  29. Input Variables: N/A
  30. Output/Return Variables: N/A
  31. Subroutine Call: N/A;
  32. Reference: N/A
  33. ****************************************************************/
  34. void bikegearsensor_voBikeGearsensorInit(void)
  35. {
  36. bikegearsensor_stBikeGearsensorOut.uwDetectTimeCnt = 0;
  37. bikegearsensor_stBikeGearsensorOut.uwGearSensorCnt = 0;
  38. bikegearsensor_stBikeGearsensorOut.blGearSensorOnFlg = FALSE;
  39. }
  40. /***************************************************************
  41. Function: bikegearsensor_voBikeGearsensorDetect;
  42. Description: bike light control initialization
  43. Call by: functions in main loop;
  44. Input Variables: N/A
  45. Output/Return Variables: N/A
  46. Subroutine Call: N/A;
  47. Reference: N/A
  48. ****************************************************************/
  49. void bikegearsensor_voBikeGearsensorDetect(void)
  50. {
  51. if (bikegearsensor_stBikeGearsensorOut.blGearSensorOnFlg == FALSE && (iGpio_Read(HW_GPIO_UARTTX_PIN) == 0))
  52. {
  53. bikegearsensor_stBikeGearsensorOut.uwGearSensorCnt++;
  54. if (bikegearsensor_stBikeGearsensorOut.uwGearSensorCnt > 10)
  55. {
  56. bikegearsensor_stBikeGearsensorOut.blGearSensorOnFlg = TRUE;
  57. bikegearsensor_stBikeGearsensorOut.uwGearSensorCnt = 0;
  58. bikegearsensor_stBikeGearsensorOut.uwDetectTimeCnt = 0;
  59. }
  60. }
  61. if (bikegearsensor_stBikeGearsensorOut.blGearSensorOnFlg == TRUE && (iGpio_Read(HW_GPIO_UARTTX_PIN) != 0))
  62. {
  63. bikegearsensor_stBikeGearsensorOut.uwGearSensorCnt++;
  64. if (bikegearsensor_stBikeGearsensorOut.uwGearSensorCnt++ > 10)
  65. {
  66. bikegearsensor_stBikeGearsensorOut.blGearSensorOnFlg = FALSE;
  67. bikegearsensor_stBikeGearsensorOut.uwGearSensorCnt = 0;
  68. bikegearsensor_stBikeGearsensorOut.uwDetectTimeCnt = 0;
  69. }
  70. }
  71. if(bikegearsensor_stBikeGearsensorOut.uwGearSensorCnt !=0 )
  72. {
  73. bikegearsensor_stBikeGearsensorOut.uwDetectTimeCnt++;
  74. if(bikegearsensor_stBikeGearsensorOut.uwDetectTimeCnt == 50)
  75. {
  76. bikegearsensor_stBikeGearsensorOut.uwGearSensorCnt = 0;
  77. bikegearsensor_stBikeGearsensorOut.uwDetectTimeCnt = 0;
  78. }
  79. }
  80. #if (GEARSENSOR_ENABLE == 0)
  81. bikegearsensor_stBikeGearsensorOut.blGearSensorOnFlg = FALSE;
  82. #endif
  83. }
  84. /***************************************************************
  85. Function: bikegearsensor_blBikeGetState;
  86. Description: get bike gearsensor state
  87. Call by: functions in main loop;
  88. Input Variables: N/A
  89. Output/Return Variables: N/A
  90. Subroutine Call: N/A;
  91. Reference: N/A
  92. ****************************************************************/
  93. BOOL bikegearsensor_blBikeGetState(void)
  94. {
  95. return bikegearsensor_stBikeGearsensorOut.blGearSensorOnFlg;
  96. }
  97. /*************************************************************************
  98. End of this File (EOF)!
  99. Do not put anything after this part!
  100. *************************************************************************/