local dev = GetSelf()

local update_time_step = 0.01

make_default_activity(update_time_step)

local sensor_data = get_base_data()

function post_initialize()

end


function update()
	--So, to start off, we are looking at things once per second.
	local ias = sensor_data.getIndicatedAirSpeed()
	local tas = sensor_data.getTrueAirSpeed()
	local mach = sensor_data.getMachNumber()
	local currentsweep = get_aircraft_draw_argument_value(7)
	local targetsweep = -1.0
	local sweeprate = 1/15 --percentage total sweep per second
	local sweepstep = sweeprate/100
	if mach > 0.8 and currentsweep < 1.0 then
	targetsweep = 1.0
	elseif tas < 110.0 and currentsweep > 0.0 then
	targetsweep = 0.0
	elseif tas > 120 and currentsweep < 0.22 then
	targetsweep = 0.222
	elseif mach < .78 and currentsweep > .222  then
	targetsweep = 0.222
	end
	--if we get through all that and targetsweep still equals -1, then the sweeep is still where we need to be, so we don't mess with it, otherwise

	if targetsweep >= 0.0 then
		if math.abs(targetsweep-currentsweep) < sweepstep then
			set_aircraft_draw_argument_value(7,targetsweep)
		elseif targetsweep > currentsweep then
			set_aircraft_draw_argument_value(7,currentsweep+sweepstep)
		elseif targetsweep < currentsweep then
			set_aircraft_draw_argument_value(7,currentsweep-sweepstep)
			end
	end
end

-- For now, there is no manual command of the sweeping, to keep things simple. But it can be done.
function SetCommand(command,value)
--	seconds = abs(command-value)*.0667
	
 
end

--need_to_be_closed = true
