'##############
'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_init}
	0 (S.L.wiperrun)
{end}

{macro:wiper_frame}
(M.L.wiper_left_frame)
(M.L.wiper_right_frame)
'-------------------------------------------
'AI-Einfluss auf den Scheibenwischer:
'Nur wenn Motor an sein soll:
	(L.L.AI) (L.L.AI_Engine) 1 = &&
	{if}
'Wenn der Intervallwischer nicht ausreicht, dann Dauermodus:
		(C.L.wiper_intervall) (L.L.PrecipRate) * (C.L.rain_wiper_eff) >
		{if}
			0 (S.L.wiper_intervall_sw)
			1 (S.L.wiper_einaus_sw)
		{else}
'Sonst (falls es regnet) den Intervallmodus:
		(L.L.PrecipRate) 0 >
		{if}
			1 (S.L.wiper_intervall_sw)
			0 (S.L.wiper_einaus_sw)
		{else}
			0 (S.L.wiper_intervall_sw)
			0 (S.L.wiper_einaus_sw)
		{endif}
		{endif}
	{endif}

	(L.L.elec_busbar_main)
	{if}	
		(L.L.wiperrunning) 1 =
		{if}
			(L.L.wiperrun) (L.S.Timegap) (L.L.wiper_speed) * + (S.L.wiperrun)
		{endif}
	
		(L.L.wiperrun) 2 pi * >
		{if}
			(L.L.wiper_einaus_sw) (L.L.wiper_wascher_sw) || (S.L.wiperrunning)
			0 (S.L.wiperrun) (S.L.wiperrunning)
		{endif}
	
	
		(L.L.wiperrunning) ! (L.L.wiper_einaus_sw) (L.L.wiper_wascher_sw) || &&
		{if}
			1 (S.L.wiperrunning)
			(T.L.wiper_start)
			(L.L.Rain_Window_Wiped_Wetness) 0 =
			{if}
				(T.L.wiper_start_dry)
			{endif}
		{endif}

		(L.L.wiper_wascher_sw)
		{if}
			(L.L.wiper_wash) !
			{if}
				(T.L.wiper_wash_start)
			{endif}
			1 (S.L.wiper_wash)
			(L.L.wiper_wash_texpos) 3 (L.S.Timegap) * - (S.L.wiper_wash_texpos)
		{else}
			0 (S.L.wiper_wash)
		{endif}

'		Wischer Intervall
		(L.L.wiper_intervall_sw) (L.L.wiper_intervall_on) ! && (L.L.wiper_intervall_time) (C.L.wiper_intervall) > ||
		{if}
		(L.L.wiperrunning) !
		{if}
			(T.L.wiper_start)
			(L.L.Rain_Window_Wiped_Wetness) 0 =
			{if}
				(T.L.wiper_start_dry)
			{endif}
		{endif}
		1 (S.L.wiper_intervall_on) (S.L.wiperrunning)
		(L.S.GetTime) (S.L.wiper_intervall_starttime)


	{endif}

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


	(L.L.wiperrun) 1.5 pi * + sin 1 + 2 / (S.L.wiperpos) (S.L.Rain_Wiper_Pos) (S.L.Dirt_Wiper_Pos) 

	(L.L.wiperrun) 2 * 1.5 pi * + sin 1 + 2 / (S.L.wiperpos_2xspeed)

'	Wischer schnell

	(L.L.wiper_schnell_sw) (L.L.wiper_einaus_sw) &&
	{if}
		10.5 (S.L.wiper_speed)
	{else}
		1.7 (S.L.wiper_speed)
	{endif}




	
	(L.L.wiper_intervall_sw) !
	{if}
		0 (S.L.wiper_intervall_on)
	{endif}

	(L.L.wiper_intervall_on)
	{if}
		(L.S.getTime) (L.L.wiper_intervall_starttime) - (S.L.wiper_intervall_time)
	{else}
		0 (S.L.wiper_intervall_time)
	{endif}







'Wiper function (wetness remove):	

	(L.L.Rain_Window_Wiped_Wetness)	
'   Calc Diff.:
	(L.L.Rain_Wiper_Pos) (L.L.Rain_wiper_Pos_Prev) - abs
'   Multiply with wiper effectivity
	(C.L.rain_wiper_eff) *
'   Subtract and set
	 -
	0 max
	(S.L.Rain_Window_Wiped_Wetness)

	(L.L.Rain_Wiper_Pos) (S.L.Rain_Wiper_Pos_Prev)


'Wiper function (dirt remove):	

	(L.L.Rain_Window_Wiped_Wetness) (L.L.wiper_wascher_sw) (L.L.wiperrunning) && ||
	{if}
	
		(L.L.Dirt_Wiped)	
'  	Calc Diff.:
		(L.L.Dirt_Wiper_Pos) (L.L.Dirt_wiper_Pos_Prev) - abs
'   	Multiply with wiper effectivity
		(C.L.Dirt_wiper_eff) *
'  	Subtract and set
		 -
		0 max
		(S.L.Dirt_Wiped)
	
		(L.L.Dirt_Wiper_Pos) (S.L.Dirt_Wiper_Pos_Prev)
	{endif}


'Washer wetness

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

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

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

{macro:wiper_left_frame}
 (L.L.wiperpos) (F.L.wiperpos_left_pos) (S.L.wiperpos_left)
{end}

{macro:wiper_right_frame}
 (L.L.wiperpos) (F.L.wiperpos_right_pos) (S.L.wiperpos_right)
 
{end}