|
@@ -25,16 +25,125 @@ void LightDriver_Init(void)
|
|
|
HAL_GPIO_Init(LIGHT_B_GPIO_Port, &GPIO_InitStruct);
|
|
|
}
|
|
|
|
|
|
-void LightDriver_Process(MC_LightSwitch_Struct_t LightSwitchCode)
|
|
|
-{
|
|
|
- if(LightSwitchCode == MC_LightSwitch_ON)
|
|
|
+void LightDriver_Process(MC_TailLight_Mode_Struct_t TailLight_Mode, TrueOrFalse_Flag_Struct_t IsBreakFlag, MC_LightSwitch_Struct_t LightSwitchCode)
|
|
|
+{
|
|
|
+ //控制前灯
|
|
|
+ if(LightSwitchCode == MC_LightSwitch_ON)
|
|
|
{
|
|
|
HAL_GPIO_WritePin(LIGHT_F_GPIO_Port, LIGHT_F_Pin, GPIO_PIN_SET);
|
|
|
- HAL_GPIO_WritePin(LIGHT_B_GPIO_Port, LIGHT_B_Pin, GPIO_PIN_SET);
|
|
|
}
|
|
|
else if(LightSwitchCode == MC_LightSwitch_OFF)
|
|
|
{
|
|
|
HAL_GPIO_WritePin(LIGHT_F_GPIO_Port, LIGHT_F_Pin, GPIO_PIN_RESET);
|
|
|
- HAL_GPIO_WritePin(LIGHT_B_GPIO_Port, LIGHT_B_Pin, GPIO_PIN_RESET);
|
|
|
+ }
|
|
|
+
|
|
|
+ //控制尾灯
|
|
|
+ static uint16_t FlashTimeCnt = 0;
|
|
|
+ uint16_t OnTime = 8;
|
|
|
+ uint16_t Period = 15;
|
|
|
+ switch(TailLight_Mode)
|
|
|
+ {
|
|
|
+ case MC_TAIL_LIGHT_MODE1://连接尾灯,开灯时低亮,刹车时高亮
|
|
|
+ {
|
|
|
+ if(IsBreakFlag == TRUE)//刹车时,高亮
|
|
|
+ {
|
|
|
+ HAL_GPIO_WritePin(LIGHT_B_GPIO_Port, LIGHT_B_Pin, GPIO_PIN_SET);
|
|
|
+ FlashTimeCnt = 0;
|
|
|
+ }
|
|
|
+ else//无刹车时,开灯低亮
|
|
|
+ {
|
|
|
+ if(LightSwitchCode == MC_LightSwitch_ON)
|
|
|
+ {
|
|
|
+ if(FlashTimeCnt < OnTime)
|
|
|
+ {
|
|
|
+ HAL_GPIO_WritePin(LIGHT_B_GPIO_Port, LIGHT_B_Pin, GPIO_PIN_SET);
|
|
|
+ }
|
|
|
+ else if(FlashTimeCnt < Period) //控制周期:15K / Period
|
|
|
+ {
|
|
|
+ HAL_GPIO_WritePin(LIGHT_B_GPIO_Port, LIGHT_B_Pin, GPIO_PIN_RESET);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ FlashTimeCnt = 0;
|
|
|
+ }
|
|
|
+ FlashTimeCnt++;
|
|
|
+ }
|
|
|
+ else if(LightSwitchCode == MC_LightSwitch_OFF)
|
|
|
+ {
|
|
|
+ HAL_GPIO_WritePin(LIGHT_B_GPIO_Port, LIGHT_B_Pin, GPIO_PIN_RESET);
|
|
|
+ FlashTimeCnt = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case MC_TAIL_LIGHT_MODE2: default://连接尾灯,开灯时高亮,刹车时闪烁
|
|
|
+ {
|
|
|
+ if(IsBreakFlag == TRUE)//刹车时,快闪
|
|
|
+ {
|
|
|
+ if(FlashTimeCnt < 600)
|
|
|
+ {
|
|
|
+ HAL_GPIO_WritePin(LIGHT_B_GPIO_Port, LIGHT_B_Pin, GPIO_PIN_SET);
|
|
|
+ }
|
|
|
+ else if(FlashTimeCnt < 1200) //闪烁频率:15K / 1200 = 12.5Hz
|
|
|
+ {
|
|
|
+ HAL_GPIO_WritePin(LIGHT_B_GPIO_Port, LIGHT_B_Pin, GPIO_PIN_RESET);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ FlashTimeCnt = 0;
|
|
|
+ }
|
|
|
+ FlashTimeCnt++;
|
|
|
+ }
|
|
|
+ else//无刹车时,开灯亮
|
|
|
+ {
|
|
|
+ if(LightSwitchCode == MC_LightSwitch_ON)
|
|
|
+ {
|
|
|
+ HAL_GPIO_WritePin(LIGHT_B_GPIO_Port, LIGHT_B_Pin, GPIO_PIN_SET);
|
|
|
+ }
|
|
|
+ else if(LightSwitchCode == MC_LightSwitch_OFF)
|
|
|
+ {
|
|
|
+ HAL_GPIO_WritePin(LIGHT_B_GPIO_Port, LIGHT_B_Pin, GPIO_PIN_RESET);
|
|
|
+ }
|
|
|
+ FlashTimeCnt = 0;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case MC_TAIL_LIGHT_MODE3://连接刹车灯,刹车高亮
|
|
|
+ {
|
|
|
+ if(IsBreakFlag == TRUE)//刹车时,高亮
|
|
|
+ {
|
|
|
+ HAL_GPIO_WritePin(LIGHT_B_GPIO_Port, LIGHT_B_Pin, GPIO_PIN_SET);
|
|
|
+ }
|
|
|
+ else//无刹车时,关闭
|
|
|
+ {
|
|
|
+ HAL_GPIO_WritePin(LIGHT_B_GPIO_Port, LIGHT_B_Pin, GPIO_PIN_RESET);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case MC_TAIL_LIGHT_MODE4://连接刹车灯,刹车闪烁
|
|
|
+ {
|
|
|
+ if(IsBreakFlag == TRUE)//刹车时,快闪
|
|
|
+ {
|
|
|
+ if(FlashTimeCnt < 600)
|
|
|
+ {
|
|
|
+ HAL_GPIO_WritePin(LIGHT_B_GPIO_Port, LIGHT_B_Pin, GPIO_PIN_SET);
|
|
|
+ }
|
|
|
+ else if(FlashTimeCnt < 1200) //闪烁频率:15K / 1200 = 12.5Hz
|
|
|
+ {
|
|
|
+ HAL_GPIO_WritePin(LIGHT_B_GPIO_Port, LIGHT_B_Pin, GPIO_PIN_RESET);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ FlashTimeCnt = 0;
|
|
|
+ }
|
|
|
+ FlashTimeCnt++;
|
|
|
+ }
|
|
|
+ else//无刹车时,关闭
|
|
|
+ {
|
|
|
+ HAL_GPIO_WritePin(LIGHT_B_GPIO_Port, LIGHT_B_Pin, GPIO_PIN_RESET);
|
|
|
+ FlashTimeCnt = 0;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
}
|