
----------------------------------------------------------------------------------------------------------
-- Special controls and custom datarefs for F8E-Crusader by BERJU83.--emergency supply--
----------------------------------------------------------------------------------------------------------

----------------------------------- LOCATE AND/OR CREATE DATAREFS AND COMMANDS -----------------------------------

Elec_bus_on = find_dataref("sim/cockpit2/electrical/bus_volts[0]")
Batt_ONOFF = find_dataref("sim/cockpit2/electrical/battery_on[0]")
Gen_ONOFF = find_dataref("sim/cockpit2/electrical/generator_on[0]")
RAT_lever = find_dataref("sim/cockpit2/switches/ram_air_turbine_on")
Emer_SW = create_dataref("custom/F8E/Emer_SW","number")
Emer_light = create_dataref("custom/F8E/Emer_light","number")
Grounded = find_dataref("sim/flightmodel2/gear/on_ground[0]")
RAT_out = find_dataref("sim/cockpit2/switches/ram_air_turbine_on")


--------------------------------- VARIABLES ---------------------------------


------------------------------- FUNCTIONS: COMMANDS CALLBACK -------------------------------
function flight_start()
    RAT_lever = 0
    RAT_out = 0
end
-----------------------RUNTIME------------------


function after_physics()
  if Grounded == 1 then RAT_lever = 0 RAT_out = 0 end
  if Grounded == 0 and RAT_lever == 1 and Emer_SW == 1 and Elec_bus_on > 15 then Emer_light = 1 else Emer_light = 0 end
  
end
    
    
    ---EMERGENCY SW---
function cmd_EMER_SW_on(phase, duration)
	if phase == 0 then 
    Emer_SW = 1
  end
end

function cmd_EMER_SW_off(phase, duration)
	if phase == 0 then 
    Emer_SW = 0
  end
end


------------------------------- LOCATE AND/OR CREATE COMMANDS -------------------------------

---COMMANDS EMERGENCY SW---
cmdEMERSWon = create_command("custom/F8E/EMER_SW_on"," ",cmd_EMER_SW_on)
cmdEMERSWoff = create_command("custom/F8E/EMER_SW_off"," ",cmd_EMER_SW_off)