bikebrake.c 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**
  2. * @file Bikebrake.c
  3. * @author Wang, Zhiyu(wangzy49@midea.com)
  4. * @brief throttle of ebike
  5. * @version 0.1
  6. * @date 2021-10-08
  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 "bikebrake.h"
  16. #include "api_rt.h"
  17. /******************************
  18. *
  19. * Parameter
  20. *
  21. ******************************/
  22. static BIKEBRAKE_OUT bikebrake_stBikeBrakeOut = BIKEBRAKE_OUT_DEFAULT;
  23. /***************************************************************
  24. Function: bikebrake_voBikeBrakeInit;
  25. Description: bike light control initialization
  26. Call by: functions in main loop;
  27. Input Variables: N/A
  28. Output/Return Variables: N/A
  29. Subroutine Call: N/A;
  30. Reference: N/A
  31. ****************************************************************/
  32. void bikebrake_voBikeBrakeInit(void)
  33. {
  34. bikebrake_stBikeBrakeOut.uwDetectTimeCnt = 0;
  35. bikebrake_stBikeBrakeOut.uwBikeBrakeCnt = 0;
  36. bikebrake_stBikeBrakeOut.blBikeBrakeOnFlg = FALSE;
  37. }
  38. /***************************************************************
  39. Function: bikelight_voBikeLightInit;
  40. Description: bike light control initialization
  41. Call by: functions in main loop;
  42. Input Variables: N/A
  43. Output/Return Variables: N/A
  44. Subroutine Call: N/A;
  45. Reference: N/A
  46. ****************************************************************/
  47. void bikebrake_voBikeBrakeDetect(void)
  48. {
  49. if (bikebrake_stBikeBrakeOut.blBikeBrakeOnFlg == FALSE && (iGpio_Read(HW_GPIO_BREAK_PIN) == 0))
  50. {
  51. bikebrake_stBikeBrakeOut.uwBikeBrakeCnt++;
  52. if (bikebrake_stBikeBrakeOut.uwBikeBrakeCnt > 10)
  53. {
  54. bikebrake_stBikeBrakeOut.blBikeBrakeOnFlg = TRUE;
  55. bikebrake_stBikeBrakeOut.uwBikeBrakeCnt = 0;
  56. bikebrake_stBikeBrakeOut.uwDetectTimeCnt = 0;
  57. }
  58. }
  59. if (bikebrake_stBikeBrakeOut.blBikeBrakeOnFlg == TRUE && (iGpio_Read(HW_GPIO_BREAK_PIN) != 0))
  60. {
  61. bikebrake_stBikeBrakeOut.uwBikeBrakeCnt++;
  62. if (bikebrake_stBikeBrakeOut.uwBikeBrakeCnt > 10)
  63. {
  64. bikebrake_stBikeBrakeOut.blBikeBrakeOnFlg = FALSE;
  65. bikebrake_stBikeBrakeOut.uwBikeBrakeCnt = 0;
  66. bikebrake_stBikeBrakeOut.uwDetectTimeCnt = 0;
  67. }
  68. }
  69. if(bikebrake_stBikeBrakeOut.uwBikeBrakeCnt !=0 )
  70. {
  71. bikebrake_stBikeBrakeOut.uwDetectTimeCnt ++;
  72. if(bikebrake_stBikeBrakeOut.uwDetectTimeCnt == 50)
  73. {
  74. bikebrake_stBikeBrakeOut.uwDetectTimeCnt = 0;
  75. bikebrake_stBikeBrakeOut.uwBikeBrakeCnt = 0;
  76. }
  77. }
  78. }
  79. BOOL BikeBrake_blGetstate(void)
  80. {
  81. return bikebrake_stBikeBrakeOut.blBikeBrakeOnFlg;
  82. }
  83. /*************************************************************************
  84. End of this File (EOF)!
  85. Do not put anything after this part!
  86. *************************************************************************/