ToLiSS_Auto_Wipers.lua

--[[
	ToLiSS Auto Wipers
	v1.0.4 FrankLFRS 2024
	
	Sets the wipers for you
		
	For ToLiSS Airbuses
--]]


-- Options

TOLISS_AUTO_LEFT_WIPER = true
TOLISS_AUTO_RIGHT_WIPER = false


-- DataRef

DataRef("ToLiSS_Left_Wiper_Switch", "AirbusFBW/LeftWiperSwitch", "writable") -- 0 = off, 1 = slow, 2 = fast
DataRef("ToLiSS_Right_Wiper_Switch", "AirbusFBW/RightWiperSwitch", "writable") -- 0 = off, 1 = slow, 2 = fast
DataRef("SIM_Precipitation_On_Aircraft", "sim/weather/aircraft/precipitation_on_aircraft_ratio") -- 0.0 = 0% to 1.0 = 100% rain
DataRef("SIM_Aircraft_On_Ground", "sim/flightmodel2/gear/on_ground") -- 0 = no, 1 = on ground
DataRef("SIM_Aircraft_Ground_Speed", "sim/cockpit2/gauges/indicators/ground_speed_kt") -- ground speed


-- Sets wipers

function ToLiSS_Auto_Wipers_Do_Sometimes()
	Wipers_Speed = 0
	if(SIM_Aircraft_On_Ground == 1 and SIM_Aircraft_Ground_Speed > 3) then
		if(SIM_Precipitation_On_Aircraft > 0.92) then
			Wipers_Speed = 2
		elseif(SIM_Precipitation_On_Aircraft > 0.30) then
			Wipers_Speed = 1
		end
	end
	if(TOLISS_AUTO_LEFT_WIPER and Wipers_Speed ~= ToLiSS_Left_Wiper_Switch) then
		ToLiSS_Left_Wiper_Switch = Wipers_Speed
	end
	if(TOLISS_AUTO_RIGHT_WIPER and Wipers_Speed ~= ToLiSS_Right_Wiper_Switch) then
		ToLiSS_Right_Wiper_Switch = Wipers_Speed
	end
end


-- Beginning of the periodic checking

do_sometimes("ToLiSS_Auto_Wipers_Do_Sometimes()")