
----------------------------------------------------------------------------------------------------------
-- Flight Synthetiser Chombard adapted for Alize-BR1050 by RFN.
----------------------------------------------------------------------------------------------------------

----------------------------------- LOCATE AND/OR CREATE DATAREFS -----------------------------------
----ELEC----
Elec_bus_on = find_dataref("sim/cockpit2/electrical/bus_volts[0]")
DV_Roll = find_dataref("sim/cockpit2/autopilot/flight_director_roll_deg")
DV_Alt = find_dataref("sim/cockpit2/autopilot/flight_director_pitch_deg")
DV_Ils = find_dataref("sim/cockpit2/radios/indicators/hsi_vdef_dots_pilot")

synthe_select = create_dataref("custom/ALZ/synthe_select","number") --(0= horizon, 1= cap, 2= ILS from, 3= ILS to, 4= Appr)
synthe_alt = create_dataref("custom/ALZ/synthe_alt","number")

--------------------------------- DO THIS EACH FLIGHT START ---------------------------------
function flight_start()
    synthe_select = 0
    synthe_alt = 0
end
------------------------------- FUNCTIONS: COMMANDS CALLBACK -------------------------------

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


    ---SELECT MODE---
function cmd_synthe_sel_incr(phase, duration)
	if phase == 0 and synthe_alt == 0 then 
    synthe_select = synthe_select + 1
  end
  if synthe_select > 4 then synthe_select = 4
  end
end

function cmd_synthe_sel_decr(phase, duration)
	if phase == 0 and synthe_alt == 0 then 
    synthe_select = synthe_select - 1
  end
  if synthe_select < 0 then synthe_select = 0
  end
end

    ---ALTITUDE MODE---
function cmd_synthe_ALT_on(phase, duration)
	if phase == 0 and synthe_select == 0 then 
    synthe_alt = 1
    cmdalthold:start()
  end
end

function cmd_synthe_ALT_off(phase, duration)
	if phase == 0 and synthe_select == 0 then 
    synthe_alt = 0
    cmdalthold:stop()
    cmdapoff:start()
  end
end
    
     
------------------------------- LOCATE AND/OR CREATE COMMANDS -------------------------------

cmdalthold = find_command("sim/autopilot/altitude_hold")
cmdapoff = find_command("sim/autopilot/servos_off_any")
cmdsyntheselincr= create_command("custom/ALZ/cmd_synthe_sel_incr"," ",cmd_synthe_sel_incr)
cmdsyntheseldecr= create_command("custom/ALZ/cmd_synthe_sel_decr"," ",cmd_synthe_sel_decr)
cmdsyntheALTon= create_command("custom/ALZ/cmd_synthe_ALT_on"," ",cmd_synthe_ALT_on)
cmdsyntheALToff= create_command("custom/ALZ/cmd_synthe_ALT_off"," ",cmd_synthe_ALT_off)

