
---------------------------------------------------------------------
-- gear handle animation for F-8E Crusader adapted by Restauravia.
---------------------------------------------------------------------

----------------------------------- LOCATE OR CREATE DATAREFS -----------------------------------

gear_handle_down = find_dataref("sim/cockpit2/controls/gear_handle_down") -- 0 up, 1 down
landing_gear_handle = create_dataref("custom/F8E/landing_gear_handle","number",landing_gear_handle_func)

------------------------------- FUNCTIONS -------------------------------
function update_gear_handle()
	landing_gear_handle = landing_gear_handle + ((gear_handle_down - landing_gear_handle) * (3 * SIM_PERIOD))
end

------------------------------- FUNCTIONS FOR WRITABLE DATAREFS -------------------------------

function landing_gear_handle_func()
	if landing_gear_handle > 0 and landing_gear_handle < 0.5 then
		gear_handle_down = 0
	elseif landing_gear_handle > 0.5 and landing_gear_handle < 1 then
		gear_handle_down = 1
	end
end

--------------------------------- RUNTIME ---------------------------------

-- DO THIS EACH FLIGHT START
function flight_start()
	landing_gear_handle = gear_handle_down
end

-- REGULAR RUNTIME
function after_physics()
	-- KEEP THE CUSTOM LAND GEAR POSITION SYNC WITH THE ACTUAL XPLANE ONE
	if landing_gear_handle ~= gear_handle_down then update_gear_handle() end
end
