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.h"
  17. #include "board_config.h"
  18. /******************************
  19. *
  20. * Parameter
  21. *
  22. ******************************/
  23. static BIKEBRAKE_OUT bikebrake_stBikeBrakeOut = BIKEBRAKE_OUT_DEFAULT;
  24. /***************************************************************
  25. Function: bikebrake_voBikeBrakeInit;
  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 bikebrake_voBikeBrakeInit(void)
  34. {
  35. bikebrake_stBikeBrakeOut.uwDetectTimeCnt = 0;
  36. bikebrake_stBikeBrakeOut.uwBikeBrakeCnt = 0;
  37. bikebrake_stBikeBrakeOut.blBikeBrakeOnFlg = FALSE;
  38. }
  39. /***************************************************************
  40. Function: bikelight_voBikeLightInit;
  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 bikebrake_voBikeBrakeDetect(void)
  49. {
  50. if (bikebrake_stBikeBrakeOut.blBikeBrakeOnFlg == FALSE && (iGpio_Read(HW_GPIO_BREAK_PIN) == 0))
  51. {
  52. bikebrake_stBikeBrakeOut.uwBikeBrakeCnt++;
  53. if (bikebrake_stBikeBrakeOut.uwBikeBrakeCnt > 10)
  54. {
  55. bikebrake_stBikeBrakeOut.blBikeBrakeOnFlg = TRUE;
  56. bikebrake_stBikeBrakeOut.uwBikeBrakeCnt = 0;
  57. bikebrake_stBikeBrakeOut.uwDetectTimeCnt = 0;
  58. }
  59. }
  60. if (bikebrake_stBikeBrakeOut.blBikeBrakeOnFlg == TRUE && (iGpio_Read(HW_GPIO_BREAK_PIN) != 0))
  61. {
  62. bikebrake_stBikeBrakeOut.uwBikeBrakeCnt++;
  63. if (bikebrake_stBikeBrakeOut.uwBikeBrakeCnt > 10)
  64. {
  65. bikebrake_stBikeBrakeOut.blBikeBrakeOnFlg = FALSE;
  66. bikebrake_stBikeBrakeOut.uwBikeBrakeCnt = 0;
  67. bikebrake_stBikeBrakeOut.uwDetectTimeCnt = 0;
  68. }
  69. }
  70. if(bikebrake_stBikeBrakeOut.uwBikeBrakeCnt !=0 )
  71. {
  72. bikebrake_stBikeBrakeOut.uwDetectTimeCnt ++;
  73. if(bikebrake_stBikeBrakeOut.uwDetectTimeCnt == 50)
  74. {
  75. bikebrake_stBikeBrakeOut.uwDetectTimeCnt = 0;
  76. bikebrake_stBikeBrakeOut.uwBikeBrakeCnt = 0;
  77. }
  78. }
  79. }
  80. BOOL BikeBrake_blGetstate(void)
  81. {
  82. return bikebrake_stBikeBrakeOut.blBikeBrakeOnFlg;
  83. }
  84. /*************************************************************************
  85. End of this File (EOF)!
  86. Do not put anything after this part!
  87. *************************************************************************/