X_ATC_Chatter_Auto_Controller.lua

--[[
	X-ATC Chatter Auto Controller
	v1.2 FrankLFRS 2024
	
	The assistant checks a few parameters to set next logical controller
	
	For ToLiSS A32x Series
--]]


-- ToLiSS only

if PLANE_ICAO == "A319" or PLANE_ICAO == "A321" or PLANE_ICAO == "A20N" or PLANE_ICAO == "A346" then


-- Flight steps

local Step_Clearance = 0
local Step_Departure_Ground = 1
local Step_Departure_Tower = 2
local Step_Departure = 3
local Step_Control = 4
local Step_Approach = 5
local Step_Destination_Tower = 6
local Step_Destination_Ground = 7
local Step_End = 8


-- Init first flight step

local Step_Index = Step_Clearance


-- Datarefs

DataRef("XATC_Chat_Is_Engine_Running", "sim/flightmodel/engine/ENGN_running") -- Engine on and using fuel (only reliable in 740 and later)
DataRef("XATC_Chat_SpoilerArmed", "ckpt/speedbrakeUp/anim") -- 0 = no, 1 = armed
DataRef("XATC_Chat_Gear_Deploy_Ratio", "sim/aircraft/parts/acf_gear_deploy") -- Landing gear deployment, 0.0->1.0
DataRef("XATC_Chat_Altitude_ft", "sim/cockpit2/gauges/indicators/altitude_ft_pilot") -- Indicated height, MSL, in feet, primary system, based on pilots barometric pressure input
DataRef("XATC_Chat_APPR_On", "AirbusFBW/APPRilluminated") -- 0 = off, 1 = on
DataRef("XATC_Chat_APU_Switch", "sim/cockpit/engine/APU_switch") -- APU starter switch 0 = off, 1 = on, 2 = start


-- Next Controller

local function Set_Next_Controller()
	command_once("SRS/X-ATC-Chatter/Select_Next_Logical_Controller")
	Step_Index = (Step_Index+1)%Step_End
end


-- Auto Next Controller (every 10s)

function XATC_Chat_Do_Sometimes()
	if(Step_Index == Step_Clearance and XATC_Chat_Is_Engine_Running == 1) then
		Set_Next_Controller()
	elseif(Step_Index == Step_Departure_Ground and XATC_Chat_SpoilerArmed == 1) then
		Set_Next_Controller()
	elseif(Step_Index == Step_Departure_Tower and XATC_Chat_Gear_Deploy_Ratio < 0.9) then
		Set_Next_Controller()
	elseif(Step_Index == Step_Departure and XATC_Chat_Altitude_ft > 17200) then
		Set_Next_Controller()
	elseif(Step_Index == Step_Control and XATC_Chat_Altitude_ft < 16800) then
		Set_Next_Controller()
	elseif(Step_Index == Step_Approach and XATC_Chat_APPR_On == 1) then
		Set_Next_Controller()
	elseif(Step_Index == Step_Destination_Tower and XATC_Chat_APU_Switch > 0) then
		Set_Next_Controller()
	end
end


-- Beginning of the periodic checking

do_sometimes("XATC_Chat_Do_Sometimes()")


end -- ToLiSS only