/*
 * Lamp.c
 *
 *  Created on: 2025. 10. 1.
 *      Author: MSI
 */

#include "Operation_Layer/Lamp/Lamp.h"
#include "Global_Variable.h"
#include "can.h"
#include "board.h"

void PWM_for_dirve_mode(void)
{
	switch(GV_VCU_Drive_Mode)
	{
		case 0:
			switch(GV_PWM_2)
			{
				case 0:
					Set_PWM_Duty(PWM_CH0, 0);
					Set_PWM_Duty(PWM_CH1, 100);	// 0.2초 주기로 점멸 변경
					GV_PWM_1 = 0;
					GV_PWM_2 = 1;
					break;
				default:
					Set_PWM_Duty(PWM_CH0, 0);
					Set_PWM_Duty(PWM_CH1, 0);
					GV_PWM_1 = 0;
					GV_PWM_2 = 0;
					break;
			}
			break;
		case 1:
			switch(GV_PWM_1)
			{
				case 0:
					Set_PWM_Duty(PWM_CH0, 100); // 0.2초 주기로 점멸 변경
					Set_PWM_Duty(PWM_CH1, 0);
					GV_PWM_1 = 1;
					GV_PWM_2 = 0;
					break;
				default:
					Set_PWM_Duty(PWM_CH0, 0);
					Set_PWM_Duty(PWM_CH1, 0);
					GV_PWM_1 = 0;
					GV_PWM_2 = 0;
					break;
			}
			break;
		default:
			Set_PWM_Duty(PWM_CH0, 0);
			Set_PWM_Duty(PWM_CH1, 0);
			GV_PWM_1 = 0;
			GV_PWM_2 = 0;
			break;
	}
}


void LampCheck(void)
{
	if(GV_IMU_AX_Val <= -0.7 || GV_RC_BrakeTorqueCommand >= 1.)	GV_Lamp_BRAKE_CMD = 1;
	else														GV_Lamp_BRAKE_CMD = 0;

	if(GV_VCU_GearSelStat == 1)	GV_Lamp_Reverse_CMD = 1;
	else						GV_Lamp_Reverse_CMD = 0;
}

void RCLampSet(void)
{
	LampCheck();

	GV_Lamp_DRL_CMD 		= GV_RC_Lamp_DRL_CMD;
	GV_Lamp_HBEAM_CMD 		= GV_RC_Lamp_HBEAM_CMD;
	GV_Lamp_Head_CMD 		= GV_RC_Lamp_Head_CMD;
	GV_Lamp_Position_CMD	= GV_RC_Lamp_Position_CMD;

	GV_Lamp_Hazard_CMD 		= GV_RC_Lamp_Hazard_CMD;
	GV_Lamp_LTRN_CMD 		= GV_RC_Lamp_LTRN_CMD;
	GV_Lamp_RTRN_CMD 		= GV_RC_Lamp_RTRN_CMD;
	GV_Wiper_CMD 			= GV_RC_Wiper_CMD;
}

void ACULampSet(void)
{
	LampCheck();

	GV_Lamp_DRL_CMD 		= GV_ACU_Lamp_DRL_CMD;
	GV_Lamp_HBEAM_CMD 		= GV_ACU_Lamp_HBEAM_CMD;
	GV_Lamp_Head_CMD 		= GV_ACU_Lamp_Head_CMD;
	GV_Lamp_Position_CMD	= GV_ACU_Lamp_Position_CMD;

	GV_Lamp_Hazard_CMD 		= GV_ACU_Lamp_Hazard_CMD;
	GV_Lamp_LTRN_CMD 		= GV_ACU_Lamp_LTRN_CMD;
	GV_Lamp_RTRN_CMD 		= GV_ACU_Lamp_RTRN_CMD;
	GV_Wiper_CMD 			= GV_ACU_Wiper_CMD;
}

void DefaultLampSet(void)
{
	GV_Lamp_BRAKE_CMD 		= 0;
	GV_Lamp_Hazard_CMD 		= 0;
	GV_Lamp_HBEAM_CMD 	  	= 0;
	GV_Lamp_Head_CMD 	  	= 0;
	GV_Lamp_LTRN_CMD 	  	= 0;
	GV_Lamp_Reverse_CMD   	= 0;
	GV_Lamp_RTRN_CMD 	  	= 0;
	GV_Lamp_Position_CMD	= 0;
	GV_Lamp_DRL_CMD 	  	= 1;
	GV_Wiper_CMD 		  	= 0;
}

void EmergencyLampSet(void)
{
	GV_Lamp_BRAKE_CMD		= 2;
	GV_Lamp_Hazard_CMD		= 2;
	GV_Lamp_HBEAM_CMD 	  	= 0;
	GV_Lamp_Head_CMD 	  	= 0;
	GV_Lamp_LTRN_CMD 	  	= 0;
	GV_Lamp_Reverse_CMD   	= 0;
	GV_Lamp_RTRN_CMD 	  	= 0;
	GV_Lamp_Position_CMD	= 0;
	GV_Lamp_DRL_CMD 	  	= 0;
	GV_Wiper_CMD 		  	= 0;
}
