bikebrake.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 "syspar.h"
  16. #include "typedefine.h"
  17. #include "mathtool.h"
  18. #include "bikebrake.h"
  19. #include "hwsetup.h"
  20. /******************************
  21. *
  22. * Parameter
  23. *
  24. ******************************/
  25. static BIKEBRAKE_OUT bikebrake_stBikeBrakeOut = BIKEBRAKE_OUT_DEFAULT;
  26. /***************************************************************
  27. Function: bikebrake_voBikeBrakeInit;
  28. Description: bike light control initialization
  29. Call by: functions in main loop;
  30. Input Variables: N/A
  31. Output/Return Variables: N/A
  32. Subroutine Call: N/A;
  33. Reference: N/A
  34. ****************************************************************/
  35. void bikebrake_voBikeBrakeInit(void)
  36. {
  37. bikebrake_stBikeBrakeOut.uwDetectTimeCnt = 0;
  38. bikebrake_stBikeBrakeOut.uwBikeBrakeCnt = 0;
  39. bikebrake_stBikeBrakeOut.blBikeBrakeOnFlg = FALSE;
  40. }
  41. /***************************************************************
  42. Function: bikelight_voBikeLightInit;
  43. Description: bike light control initialization
  44. Call by: functions in main loop;
  45. Input Variables: N/A
  46. Output/Return Variables: N/A
  47. Subroutine Call: N/A;
  48. Reference: N/A
  49. ****************************************************************/
  50. void bikebrake_voBikeBrakeDetect(void)
  51. {
  52. if (bikebrake_stBikeBrakeOut.blBikeBrakeOnFlg == FALSE && (IO_BIKEBRAKE_STATE == 0))
  53. {
  54. bikebrake_stBikeBrakeOut.uwBikeBrakeCnt++;
  55. if (bikebrake_stBikeBrakeOut.uwBikeBrakeCnt > 10)
  56. {
  57. bikebrake_stBikeBrakeOut.blBikeBrakeOnFlg = TRUE;
  58. bikebrake_stBikeBrakeOut.uwBikeBrakeCnt = 0;
  59. bikebrake_stBikeBrakeOut.uwDetectTimeCnt = 0;
  60. }
  61. }
  62. if (bikebrake_stBikeBrakeOut.blBikeBrakeOnFlg == TRUE && (IO_BIKEBRAKE_STATE != 0))
  63. {
  64. bikebrake_stBikeBrakeOut.uwBikeBrakeCnt++;
  65. if (bikebrake_stBikeBrakeOut.uwBikeBrakeCnt > 10)
  66. {
  67. bikebrake_stBikeBrakeOut.blBikeBrakeOnFlg = FALSE;
  68. bikebrake_stBikeBrakeOut.uwBikeBrakeCnt = 0;
  69. bikebrake_stBikeBrakeOut.uwDetectTimeCnt = 0;
  70. }
  71. }
  72. if(bikebrake_stBikeBrakeOut.uwBikeBrakeCnt !=0 )
  73. {
  74. bikebrake_stBikeBrakeOut.uwDetectTimeCnt ++;
  75. if(bikebrake_stBikeBrakeOut.uwDetectTimeCnt == 50)
  76. {
  77. bikebrake_stBikeBrakeOut.uwDetectTimeCnt = 0;
  78. bikebrake_stBikeBrakeOut.uwBikeBrakeCnt = 0;
  79. }
  80. }
  81. }
  82. BOOL BikeBrake_blGetstate(void)
  83. {
  84. return bikebrake_stBikeBrakeOut.blBikeBrakeOnFlg;
  85. }
  86. /*************************************************************************
  87. End of this File (EOF)!
  88. Do not put anything after this part!
  89. *************************************************************************/