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

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

Elec_bus_on = find_dataref("sim/cockpit2/electrical/bus_volts[0]")
Ailron_trim = find_dataref("sim/cockpit2/controls/aileron_trim")
Flap_hdl = find_dataref("sim/cockpit2/controls/flap_handle_deploy_ratio")
Eng_fire = find_dataref("sim/flightmodel2/engines/is_on_fire[0]")
Refuel_probe = find_dataref("sim/flightmodel2/misc/custom_slider_ratio[5]")
Rudder_trim = find_dataref("sim/flightmodel2/controls/rudder_trim")
Speed_brk = find_dataref("sim/flightmodel2/controls/speedbrake_ratio")
Slats_dn = find_dataref("sim/cockpit2/annunciators/slats")
Eng_ice = find_dataref("sim/cockpit2/ice/ice_inlet_heat_on_per_engine[0]")
Boost_ppe = find_dataref("sim/cockpit/warnings/annunciators/afterburners_on")
Mixt_rat = find_dataref("sim/cockpit2/engine/actuators/mixture_ratio[0]")
Eng_ppe = find_dataref("sim/operation/failures/rel_fuepmp0")
Fuel_dump = find_dataref("sim/cockpit2/switches/dump_fuel")
Fuel_low = find_dataref("sim/cockpit2/fuel/fuel_quantity[0]")
Hyd_press = find_dataref("sim/cockpit2/annunciators/hydraulic_pressure")
Oxy_qty = find_dataref("sim/cockpit2/oxygen/indicators/o2_bottle_rem_liter")
Roll_stab = find_dataref("sim/cockpit/autopilot/heading_roll_mode")
Yaw_stab = find_dataref("sim/cockpit2/annunciators/yaw_damper")
Grounded = find_dataref("sim/flightmodel2/gear/on_ground[0]")

lamp_test = create_dataref("custom/F8E/lamp_test","number")
Ann_ailr_neut = create_dataref("custom/F8E/Ann_ailr_neut","number")
Ann_BLC = create_dataref("custom/F8E/Ann_BLC","number")
Ann_eng_fire = create_dataref("custom/F8E/Ann_eng_fire","number")
Ann_probe_out = create_dataref("custom/F8E/Ann_probe_out","number")
Ann_rudder_neut = create_dataref("custom/F8E/Ann_rudder_neut","number")
Ann_spdbrk = create_dataref("custom/F8E/Ann_spdbrk","number")
Ann_wwh_droop = create_dataref("custom/F8E/Ann_wwh_droop","number")
Ann_LH_Eng_ice = create_dataref("custom/F8E/Ann_LH_Eng_ice","number")
Ann_Boost_Ppe = create_dataref("custom/F8E/Ann_Boost_Ppe","number")
Ann_Fuel_cutoff = create_dataref("custom/F8E/Ann_Fuel_cutoff","number")
Ann_Eng_Ppe = create_dataref("custom/F8E/Ann_Eng_Ppe","number")
Ann_Fuel_dump = create_dataref("custom/F8E/Ann_Fuel_dump","number")
Ann_Low_fuel = create_dataref("custom/F8E/Ann_Low_fuel","number")
Ann_Hyd_P = create_dataref("custom/F8E/Ann_Hyd_P","number")
Ann_Oxygen = create_dataref("custom/F8E/Ann_Oxygen","number")
Ann_Roll_stab = create_dataref("custom/F8E/Ann_Roll_stab","number")
Ann_Yaw_stab = create_dataref("custom/F8E/Ann_Yaw_stab","number")


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


------------------------------- FUNCTIONS: COMMANDS CALLBACK -------------------------------

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


function after_physics()

  --Aileron neutral--
    if Grounded == 1 then
        if (lamp_test == 1) or (math.abs(Ailron_trim) < 0.1) then Ann_ailr_neut = 1 else Ann_ailr_neut = 0 end
    elseif Grounded == 0 then
        if (lamp_test == 1) then Ann_ailr_neut = 1 else Ann_ailr_neut = 0 end
    end
    
      --Rudder neutral--
    if Grounded == 1 then
        if (lamp_test == 1) or (math.abs(Rudder_trim) < 0.1) then Ann_rudder_neut = 1 else Ann_rudder_neut = 0 end
    elseif Grounded == 0 then    
        if (lamp_test == 1) then Ann_rudder_neut = 1 else Ann_rudder_neut = 0 end 
    end 
     
  --BLC--
    if (lamp_test == 1) or (Flap_hdl == 1) then Ann_BLC = 1 else Ann_BLC = 0 end
    
  --Eng_fire--
    if (lamp_test == 1) or (Eng_fire == 1) then Ann_eng_fire = 1 else Ann_eng_fire = 0 end
 
  --Fuel probe--
    if (lamp_test == 1) or (Refuel_probe == 1) then Ann_probe_out = 1 else Ann_probe_out = 0 end
  
  --Speedbrake--
    if (lamp_test == 1) or (Speed_brk > 0.1) then Ann_spdbrk = 1 else Ann_spdbrk = 0 end       

  --Slats droop--
    if (lamp_test == 1) or (Slats_dn > 0) then Ann_wwh_droop = 1 else Ann_wwh_droop = 0 end
    
  --Engine ice LH--
    if (lamp_test == 1) or (Eng_ice == 1) then Ann_LH_Eng_ice = 1 else Ann_LH_Eng_ice = 0 end

  --Boost pump--
    if (lamp_test == 1) or (Boost_ppe == 1) then Ann_Boost_Ppe = 1 else Ann_Boost_Ppe = 0 end
    
  --Fuel cutoff--
    if (lamp_test == 1) or (Mixt_rat == 1) then Ann_Fuel_cutoff = 1 else Ann_Fuel_cutoff = 0 end  
    
   --Engine Eng pump--
    if (lamp_test == 1) or (Eng_ppe == 6) then Ann_Eng_Ppe = 1 else Ann_Eng_Ppe = 0 end  
    
   --Fuel dump--
    if (lamp_test == 1) or (Fuel_dump == 1) then Ann_Fuel_dump = 1 else Ann_Fuel_dump = 0 end
    
   --Engine low fuel--
    if (lamp_test == 1) or (Fuel_low < 180) then Ann_Low_fuel = 1 else Ann_Low_fuel = 0 end
    
   --Engine Hydraulic pressure--
    if (lamp_test == 1) or (Hyd_press == 1) then Ann_Hyd_P = 1 else Ann_Hyd_P = 0 end
    
   --Oxygen reserve--
    if (lamp_test == 1) or (Oxy_qty < 0.5) then Ann_Oxygen = 1 else Ann_Oxygen = 0 end
    
    --Roll stab--
    if (lamp_test == 1) or (Roll_stab >= 1) then Ann_Roll_stab = 1 else Ann_Roll_stab = 0 end
    
    --Yaw stab--
    if (lamp_test == 1) or (Yaw_stab == 1) then Ann_Yaw_stab = 1 else Ann_Yaw_stab = 0 end
                                
end

function cmd_lamp_test(phase, duration)
	if phase == 1 and Elec_bus_on > 15 then 
    lamp_test = 1 
   else
    lamp_test = 0 
  end
end 
------------------------------- LOCATE AND/OR CREATE COMMANDS -------------------------------

cmdlAmptest = create_command("custom/F8E/lamp_test_cmd","Lamp test",cmd_lamp_test)