'##############
'Wiper Script
'##############

'Controls Wiper

'(c) 20.03.2009 Marcel Kuhnt

'Script Version: 1.0
'Omsi release: 1.0

'Needs:
'- rain
'- dirt

'Revision History:
'- Marcel Kuhnt		20.03.2009	Last Change		
'- Marcel Kuhnt		13.06.2009	Added Switch-Vars	
'- Marcel Kuhnt		13.06.2009	Added Wiper/Washer Function
'- Marcel Kuhnt		21.06.2009	Added AI-Activation
'- Rüdiger Hülsmann	14.05.2010	Added wiperpos_2xspeed for sinusdial movement during half a period

'--------------------------------------------------------------

{macro:wiper_R_init}
	0 (S.L.wiperrun_R)
{end}

{macro:wiper_R_frame}


	(L.L.elec_busbar_main) (L.L.cp_wischer_einaus_sw_R) &&
	{if}	
		(L.L.wiperrunning_R) 1 =
		{if}
			(L.L.wiperrun_R) (L.S.Timegap) (L.L.wiper_speed_R) * + (S.L.wiperrun_R)
		{endif}
	
		(L.L.wiperrun_R) 2 pi * >
		{if}
			(L.L.wiper_einaus_sw_R) (L.L.wiper_wascher_sw_R) || (S.L.wiperrunning_R)
			0 (S.L.wiperrun_R) (S.L.wiperrunning_R)
		{endif}
	
	
		(L.L.wiperrunning_R) ! (L.L.wiper_einaus_sw_R) (L.L.wiper_wascher_sw_R) || &&
		{if}
			1 (S.L.wiperrunning_R)
			(T.L.wiper_start)
			(L.L.Rain_Window_Wiped_Wetness_R) 0 =
			{if}
				(T.L.wiper_start_dry)
			{endif}
		{endif}

		(L.L.wiper_wascher_sw_R)
		{if}
			(L.L.wiper_wash_R) !
			{if}
				(T.L.wiper_wash_start)
			{endif}
			1 (S.L.wiper_wash_R)
			(L.L.wiper_wash_texpos_R) 3 (L.S.Timegap) * - (S.L.wiper_wash_texpos_R)
		{else}
			0 (S.L.wiper_wash_R)
		{endif}

'		Wischer Intervall
		(L.L.wiper_intervall_sw_R) (L.L.wiper_intervall_on_R) ! && (L.L.wiper_intervall_time_R) (C.L.wiper_intervall) > ||
		{if}
		(L.L.wiperrunning_R) !
		{if}
			(T.L.wiper_start)
			(L.L.Rain_Window_Wiped_Wetness_R) 0 =
			{if}
				(T.L.wiper_start_dry)
			{endif}
		{endif}
		1 (S.L.wiper_intervall_on_R) (S.L.wiperrunning_R)
		(L.S.GetTime) (S.L.wiper_intervall_starttime_R)


	{endif}

	{else}
		0 (S.L.wiperrunning_R)
	{endif}


	(L.L.wiperrun_R) 1.5 pi * + sin 1 + 2 / (S.L.wiperpos_R) (S.L.Rain_Wiper_Pos_R) (S.L.Dirt_Wiper_Pos_R) 

	(L.L.wiperrun_R) 2 * 1.5 pi * + sin 1 + 2 / (S.L.wiperpos_2xspeed_R)

'	Wischer schnell

	(L.L.wiper_schnell_sw_R) (L.L.wiper_einaus_sw_R) &&
	{if}
		4.5 (S.L.wiper_speed_R)
	{else}
		3.5 (S.L.wiper_speed_R)
	{endif}




	
	(L.L.wiper_intervall_sw_R) !
	{if}
		0 (S.L.wiper_intervall_on_R)
	{endif}

	(L.L.wiper_intervall_on_R)
	{if}
		(L.S.getTime) (L.L.wiper_intervall_starttime_R) - (S.L.wiper_intervall_time_R)
	{else}
		0 (S.L.wiper_intervall_time_R)
	{endif}







'Wiper function (wetness remove):	

	(L.L.Rain_Window_Wiped_Wetness_R)	
'   Calc Diff.:
	(L.L.Rain_Wiper_Pos_R) (L.L.Rain_wiper_Pos_Prev_R) - abs
'   Multiply with wiper effectivity
	(C.L.rain_wiper_eff) *
'   Subtract and set
	 -
	0 max
	(S.L.Rain_Window_Wiped_Wetness_R)

	(L.L.Rain_Wiper_Pos_R) (S.L.Rain_Wiper_Pos_Prev_R)


'Wiper function (dirt remove):	

	(L.L.Rain_Window_Wiped_Wetness_R) (L.L.wiper_wascher_sw_R) (L.L.wiperrunning_R) && ||
	{if}
	
		(L.L.Dirt_Wiped_R)	
'  	Calc Diff.:
		(L.L.Dirt_Wiper_Pos_R) (L.L.Dirt_wiper_Pos_Prev_R) - abs
'   	Multiply with wiper effectivity
		(C.L.Dirt_wiper_eff) *
'  	Subtract and set
		 -
		0 max
		(S.L.Dirt_Wiped_R)
	
		(L.L.Dirt_Wiper_Pos_R) (S.L.Dirt_Wiper_Pos_Prev_R)
	{endif}


'Washer wetness

	(L.L.wiper_wash_R)
	{if}
		(L.S.Timegap) 0.5 * s0

		(L.L.Rain_Window_Front_Wetness_R) l0
		+ 1 min 0 max
		(S.L.Rain_Window_Front_Wetness_R)
	
		(L.S.Timegap) s0

		(L.L.Rain_Window_Wiped_Wetness_R) l0
		+ 1 min 0 max
		(S.L.Rain_Window_Wiped_Wetness_R)
	{endif}
	
{end}
