bikebrake.c 3.0 KB

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