|
@@ -0,0 +1,103 @@
|
|
|
+/**
|
|
|
+ * @file bikegearsensor.c
|
|
|
+ * @author Zhou xiong(zhouxiong9@midea.com)
|
|
|
+ * @brief Gear Sensor of ebike
|
|
|
+ * @version 0.1
|
|
|
+ * @date 2023-02-03
|
|
|
+ *
|
|
|
+ * @copyright Copyright (c) 2021
|
|
|
+ *
|
|
|
+ */
|
|
|
+
|
|
|
+/************************************************************************
|
|
|
+ Beginning of File, do not put anything above here except notes
|
|
|
+ Compiler Directives:
|
|
|
+*************************************************************************/
|
|
|
+#include "api.h"
|
|
|
+#include "board_config.h"
|
|
|
+#include "bikegearsensor.h"
|
|
|
+
|
|
|
+/******************************
|
|
|
+ *
|
|
|
+ * Parameter
|
|
|
+ *
|
|
|
+ ******************************/
|
|
|
+BIKE_GEARSENSOR_OUT bikegearsensor_stBikeGearsensorOut = GEARSENSOR_OUT_DEFAULT;
|
|
|
+
|
|
|
+/***************************************************************
|
|
|
+ Function: bikegearsensor_voBikeGearsensorInit;
|
|
|
+ Description: bike light control initialization
|
|
|
+ Call by: functions in main loop;
|
|
|
+ Input Variables: N/A
|
|
|
+ Output/Return Variables: N/A
|
|
|
+ Subroutine Call: N/A;
|
|
|
+ Reference: N/A
|
|
|
+****************************************************************/
|
|
|
+void bikegearsensor_voBikeGearsensorInit(void)
|
|
|
+{
|
|
|
+ bikegearsensor_stBikeGearsensorOut.uwDetectTimeCnt = 0;
|
|
|
+ bikegearsensor_stBikeGearsensorOut.uwGearSensorCnt = 0;
|
|
|
+ bikegearsensor_stBikeGearsensorOut.blGearSensorOnFlg = FALSE;
|
|
|
+}
|
|
|
+/***************************************************************
|
|
|
+ Function: bikegearsensor_voBikeGearsensorDetect;
|
|
|
+ Description: bike light control initialization
|
|
|
+ Call by: functions in main loop;
|
|
|
+ Input Variables: N/A
|
|
|
+ Output/Return Variables: N/A
|
|
|
+ Subroutine Call: N/A;
|
|
|
+ Reference: N/A
|
|
|
+****************************************************************/
|
|
|
+void bikegearsensor_voBikeGearsensorDetect(void)
|
|
|
+{
|
|
|
+ if (bikegearsensor_stBikeGearsensorOut.blGearSensorOnFlg == FALSE && (iGpio_Read(HW_GPIO_UARTTX_PIN) == 0))
|
|
|
+ {
|
|
|
+ bikegearsensor_stBikeGearsensorOut.uwGearSensorCnt++;
|
|
|
+ if (bikegearsensor_stBikeGearsensorOut.uwGearSensorCnt > 10)
|
|
|
+ {
|
|
|
+ bikegearsensor_stBikeGearsensorOut.blGearSensorOnFlg = TRUE;
|
|
|
+ bikegearsensor_stBikeGearsensorOut.uwGearSensorCnt = 0;
|
|
|
+ bikegearsensor_stBikeGearsensorOut.uwDetectTimeCnt = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (bikegearsensor_stBikeGearsensorOut.blGearSensorOnFlg == TRUE && (iGpio_Read(HW_GPIO_UARTTX_PIN) != 0))
|
|
|
+ {
|
|
|
+ bikegearsensor_stBikeGearsensorOut.uwGearSensorCnt++;
|
|
|
+ if (bikegearsensor_stBikeGearsensorOut.uwGearSensorCnt++ > 10)
|
|
|
+ {
|
|
|
+ bikegearsensor_stBikeGearsensorOut.blGearSensorOnFlg = FALSE;
|
|
|
+ bikegearsensor_stBikeGearsensorOut.uwGearSensorCnt = 0;
|
|
|
+ bikegearsensor_stBikeGearsensorOut.uwDetectTimeCnt = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(bikegearsensor_stBikeGearsensorOut.uwGearSensorCnt !=0 )
|
|
|
+ {
|
|
|
+ bikegearsensor_stBikeGearsensorOut.uwDetectTimeCnt++;
|
|
|
+ if(bikegearsensor_stBikeGearsensorOut.uwDetectTimeCnt == 50)
|
|
|
+ {
|
|
|
+ bikegearsensor_stBikeGearsensorOut.uwGearSensorCnt = 0;
|
|
|
+ bikegearsensor_stBikeGearsensorOut.uwDetectTimeCnt = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+/***************************************************************
|
|
|
+ Function: bikegearsensor_blBikeGetState;
|
|
|
+ Description: get bike gearsensor state
|
|
|
+ Call by: functions in main loop;
|
|
|
+ Input Variables: N/A
|
|
|
+ Output/Return Variables: N/A
|
|
|
+ Subroutine Call: N/A;
|
|
|
+ Reference: N/A
|
|
|
+****************************************************************/
|
|
|
+BOOL bikegearsensor_blBikeGetState(void)
|
|
|
+{
|
|
|
+ return bikegearsensor_stBikeGearsensorOut.blGearSensorOnFlg;
|
|
|
+}
|
|
|
+
|
|
|
+/*************************************************************************
|
|
|
+ End of this File (EOF)!
|
|
|
+ Do not put anything after this part!
|
|
|
+*************************************************************************/
|