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. /******************************
  19. *
  20. * Parameter
  21. *
  22. ******************************/
  23. BIKE_GEARSENSOR_OUT bikegearsensor_stBikeGearsensorOut = GEARSENSOR_OUT_DEFAULT;
  24. /***************************************************************
  25. Function: bikegearsensor_voBikeGearsensorInit;
  26. Description: bike light control initialization
  27. Call by: functions in main loop;
  28. Input Variables: N/A
  29. Output/Return Variables: N/A
  30. Subroutine Call: N/A;
  31. Reference: N/A
  32. ****************************************************************/
  33. void bikegearsensor_voBikeGearsensorInit(void)
  34. {
  35. bikegearsensor_stBikeGearsensorOut.uwDetectTimeCnt = 0;
  36. bikegearsensor_stBikeGearsensorOut.uwGearSensorCnt = 0;
  37. bikegearsensor_stBikeGearsensorOut.blGearSensorOnFlg = FALSE;
  38. }
  39. /***************************************************************
  40. Function: bikegearsensor_voBikeGearsensorDetect;
  41. Description: bike light control initialization
  42. Call by: functions in main loop;
  43. Input Variables: N/A
  44. Output/Return Variables: N/A
  45. Subroutine Call: N/A;
  46. Reference: N/A
  47. ****************************************************************/
  48. void bikegearsensor_voBikeGearsensorDetect(void)
  49. {
  50. if (bikegearsensor_stBikeGearsensorOut.blGearSensorOnFlg == FALSE && (iGpio_Read(HW_GPIO_UARTTX_PIN) == 0))
  51. {
  52. bikegearsensor_stBikeGearsensorOut.uwGearSensorCnt++;
  53. if (bikegearsensor_stBikeGearsensorOut.uwGearSensorCnt > 10)
  54. {
  55. bikegearsensor_stBikeGearsensorOut.blGearSensorOnFlg = TRUE;
  56. bikegearsensor_stBikeGearsensorOut.uwGearSensorCnt = 0;
  57. bikegearsensor_stBikeGearsensorOut.uwDetectTimeCnt = 0;
  58. }
  59. }
  60. if (bikegearsensor_stBikeGearsensorOut.blGearSensorOnFlg == TRUE && (iGpio_Read(HW_GPIO_UARTTX_PIN) != 0))
  61. {
  62. bikegearsensor_stBikeGearsensorOut.uwGearSensorCnt++;
  63. if (bikegearsensor_stBikeGearsensorOut.uwGearSensorCnt++ > 10)
  64. {
  65. bikegearsensor_stBikeGearsensorOut.blGearSensorOnFlg = FALSE;
  66. bikegearsensor_stBikeGearsensorOut.uwGearSensorCnt = 0;
  67. bikegearsensor_stBikeGearsensorOut.uwDetectTimeCnt = 0;
  68. }
  69. }
  70. if(bikegearsensor_stBikeGearsensorOut.uwGearSensorCnt !=0 )
  71. {
  72. bikegearsensor_stBikeGearsensorOut.uwDetectTimeCnt++;
  73. if(bikegearsensor_stBikeGearsensorOut.uwDetectTimeCnt == 50)
  74. {
  75. bikegearsensor_stBikeGearsensorOut.uwGearSensorCnt = 0;
  76. bikegearsensor_stBikeGearsensorOut.uwDetectTimeCnt = 0;
  77. }
  78. }
  79. #if (GEARSENSOR_ENABLE == 0)
  80. bikegearsensor_stBikeGearsensorOut.blGearSensorOnFlg = FALSE;
  81. #endif
  82. }
  83. /***************************************************************
  84. Function: bikegearsensor_blBikeGetState;
  85. Description: get bike gearsensor state
  86. Call by: functions in main loop;
  87. Input Variables: N/A
  88. Output/Return Variables: N/A
  89. Subroutine Call: N/A;
  90. Reference: N/A
  91. ****************************************************************/
  92. BOOL bikegearsensor_blBikeGetState(void)
  93. {
  94. return bikegearsensor_stBikeGearsensorOut.blGearSensorOnFlg;
  95. }
  96. /*************************************************************************
  97. End of this File (EOF)!
  98. Do not put anything after this part!
  99. *************************************************************************/