
----------------------------------------------------------------------------------------------------------
-- External lights management for Alize-BR1050 by RFN.
----------------------------------------------------------------------------------------------------------

----------------------------------- LOCATE AND/OR CREATE DATAREFS -----------------------------------
Elec_bus_on = find_dataref("sim/cockpit2/electrical/bus_volts[array]")
Strobe_lts = find_dataref("sim/cockpit2/switches/strobe_lights_on")
Beacon_lts = find_dataref("sim/cockpit2/switches/beacon_on")
beacon_strobe_SW = create_dataref("custom/ALZ/beacon_strobe_SW","number")

Sup_inf_lts= find_dataref("sim/flightmodel2/lights/generic_lights_brightness_ratio[0]")
white_lts_SW = create_dataref("custom/ALZ/white_lts_SW","number")
SUP_lts = find_dataref("sim/cockpit2/switches/generic_lights_switch[0]")
INF_lts = find_dataref("sim/cockpit2/switches/generic_lights_switch[1]")

Form_lts_SW = create_dataref("custom/ALZ/form_lts_SW","number")
Form_lts = find_dataref("sim/cockpit2/switches/generic_lights_switch[2]")

--------------------------------- DO THIS EACH FLIGHT START ---------------------------------
function flight_start()
      beacon_strobe_SW = 0
      Strobe_lts = 0
      Beacon_lts = 0
      white_lts_SW = 1
end
------------------------------- FUNCTIONS: COMMANDS CALLBACK -------------------------------
function after_physics()
            ---BEACON AND STROBES---
      if beacon_strobe_SW == 1 and Elec_bus_on > 15 then
          Strobe_lts = 1 Beacon_lts = 1 
      elseif beacon_strobe_SW == 0 or Elec_bus_on < 15 then 
          Strobe_lts = 0 Beacon_lts = 0
      end 
                 
end
-----------------------RUNTIME------------------

    ---BEACON AND STROBES---
function cmd_beacon_strobe_on(phase, duration)
	if phase == 0 then 
    beacon_strobe_SW = 1
	end
end

function cmd_beacon_strobe_off(phase, duration)
	if phase == 0 then 
    beacon_strobe_SW = 0
      Strobe_lts = 0 Beacon_lts = 0 
	end
end

    ---TOP AND BOTTOM WHITE LIGHTS---
function cmd_white_lts_on(phase, duration)
	if phase == 0 and white_lts_SW > 0 then 
    white_lts_SW = white_lts_SW - 1
    SUP_lts = 1
	end
	if phase == 2 then white_lts_SW = 1 SUP_lts = 0 end
end

function cmd_white_lts_off(phase, duration)
	if phase == 0 and white_lts_SW < 2 then 
    white_lts_SW = white_lts_SW + 1
    INF_lts = 1
	end
	if phase == 2 then white_lts_SW = 1 INF_lts = 0 end
end

    ---FORMATION LIGHTS---
function cmd_form_on(phase, duration)
	if phase == 0 then
    Form_lts_SW = 1
    Form_lts = 1
	end
end

function cmd_form_off(phase, duration)
	if phase == 0 then 
    Form_lts_SW = 0
    Form_lts = 0 
	end
end

    


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

cmdbeaconstrobeon = create_command("custom/ALZ/cmd_beacon_strobe_on","",cmd_beacon_strobe_on)
cmdbeaconstrobeoff = create_command("custom/ALZ/cmd_beacon_strobe_off","",cmd_beacon_strobe_off)

cmdwhiteltson = create_command("custom/ALZ/cmd_white_lts_on","",cmd_white_lts_on)
cmdwhiteltsoff = create_command("custom/ALZ/cmd_white_lts_off","",cmd_white_lts_off)

cmdformon = create_command("custom/ALZ/cmd_form_lts_on","",cmd_form_on)
cmdformoff = create_command("custom/ALZ/cmd_form_lts_off","",cmd_form_off)
