123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- #include "light_driver.h"
- void LightDriver_Init(void)
- {
- GPIO_InitTypeDef GPIO_InitStruct;
- /* GPIO Ports Clock Enable */
- __HAL_RCC_GPIOA_CLK_ENABLE();
- __HAL_RCC_GPIOB_CLK_ENABLE();
-
- /*Configure GPIO pin Output Level */
- 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);
-
- /*Configure GPIO pins : PBPin PBPin */
- GPIO_InitStruct.Pin = LIGHT_F_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- HAL_GPIO_Init(LIGHT_F_GPIO_Port, &GPIO_InitStruct);
-
- /*Configure GPIO pins : PAPin PAPin */
- GPIO_InitStruct.Pin = LIGHT_B_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- HAL_GPIO_Init(LIGHT_B_GPIO_Port, &GPIO_InitStruct);
- }
- void LightDriver_Process(TrueOrFalse_Flag_Struct_t IsBreakFlag, MC_LightSwitch_Struct_t LightSwitchCode)
- {
- if(HAL_GetTick() < 3000)
- {
- return;
- }
-
- //前灯
- if(LightSwitchCode == MC_LightSwitch_ON)
- {
- HAL_GPIO_WritePin(LIGHT_F_GPIO_Port, LIGHT_F_Pin, GPIO_PIN_SET);
- }
- else if(LightSwitchCode == MC_LightSwitch_OFF)
- {
- HAL_GPIO_WritePin(LIGHT_F_GPIO_Port, LIGHT_F_Pin, GPIO_PIN_RESET);
- }
-
- //尾灯
- static uint16_t FlashTimeCnt = 0;
- if(strncmp("FLASH", (char*)UserString2, 5) == 0)//利用UserString2作为尾灯刹车时显示状态
- {
- if(IsBreakFlag == TRUE)//刹车时,快闪
- {
- if(FlashTimeCnt < 600)
- {
- HAL_GPIO_WritePin(LIGHT_B_GPIO_Port, LIGHT_B_Pin, GPIO_PIN_SET);
- }
- else if(FlashTimeCnt < 1200)
- {
- 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;
- }
- }
- else
- {
- 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 < 138)
- {
- HAL_GPIO_WritePin(LIGHT_B_GPIO_Port, LIGHT_B_Pin, GPIO_PIN_SET);
- }
- else if(FlashTimeCnt < 200)
- {
- 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;
- }
- }
- }
- }
|