Add support for Q4XP

This commit is contained in:
2023-06-06 19:11:40 +02:00
parent f1f7404f29
commit 6049225698

View File

@@ -31,6 +31,7 @@ local aircraft_data = {
["SR22"] = {["min_as"] = 64, ["max_as"] = 205, ["has_mach"] = false, ["has_csc"] = false},
["DR40"] = {["min_as"] = 49, ["max_as"] = 146, ["has_mach"] = false, ["has_csc"] = false},
["E55P"] = {["min_as"] = 89, ["max_as"] = 320, ["has_mach"] = true, ["max_mach"] = 0.78, ["has_csc"] = true},
["DH8D"] = {["min_as"] = 95, ["max_as"] = 290, ["has_mach"] = false, ["has_csc"] = false},
}
dataref("ac_icao", "sim/aircraft/view/acf_ICAO")
@@ -127,6 +128,10 @@ else
dataref("status_vnav", "sim/cockpit2/autopilot/vnav_status")
dataref("status_altmode", "sim/cockpit2/autopilot/altitude_mode")
dataref("status_machmode", "sim/cockpit2/autopilot/airspeed_is_mach")
if ac_icao == "DH8D" then
dataref("q4xp_status_altmode", "FJS/Q4XP/FMA/pitch_act")
dataref("q4xp_ap_pitch", "sim/cockpit2/autopilot/sync_hold_pitch_deg", "writable")
end
send_app_report(device, math.floor(ap_hdg + 0.5), build_leds(), math.floor(ap_alt + 0.5), -2, -2, status_machmode == 1)
local prev_status_altmode = 0
local prev_status_machmode = status_machmode
@@ -178,9 +183,24 @@ else
ap_alt = app_report[2]
end
-- vertical speed
if status_altmode == 4 and prev_status_altmode ~= 4 then
local enter_mode_vs = false
local exit_mode_vs = false
if ac_icao == "DH8D" then
if q4xp_status_altmode == 3 and prev_status_altmode ~= 3 then
enter_mode_vs = true
elseif q4xp_status_altmode ~= 3 and prev_status_altmode == 3 then
exit_mode_vs = true
end
else
if status_altmode == 4 and prev_status_altmode ~= 4 then
enter_mode_vs = true
elseif status_altmode ~= 4 and prev_status_altmode == 4 then
exit_mode_vs = true
end
end
if enter_mode_vs then
send_vs = math.floor(cur_vvi + 0.5)
elseif status_altmode ~= 4 and prev_status_altmode == 4 then
elseif exit_mode_vs then
send_vs = -2
elseif app_report_good and app_report[3] ~= 0xffff then
if bit.band(app_report[3], 0x8000) ~= 0 then
@@ -190,7 +210,29 @@ else
end
end
-- airspeed
if status_altmode == 5 and prev_status_altmode ~= 5 then
local enter_mode_flc = false
local exit_mode_flc = false
local mode_flc = false
if ac_icao == "DH8D" then
if q4xp_status_altmode == 2 and prev_status_altmode ~= 2 then
enter_mode_flc = true
elseif q4xp_status_altmode ~= 2 and prev_status_altmode == 2 then
exit_mode_flc = true
end
if q4xp_status_altmode == 2 then
mode_flc = true
end
else
if status_altmode == 5 and prev_status_altmode ~= 5 then
enter_mode_flc = true
elseif status_altmode ~= 5 and prev_status_altmode == 5 then
exit_mode_flc = true
end
if status_altmode == 5 then
mode_flc = true
end
end
if enter_mode_flc then
if status_machmode == 1 then
send_as = math.floor(cur_mach * 1000 + 0.5)
else
@@ -200,9 +242,9 @@ else
send_as = math.floor(cur_ias + 0.5)
end
end
elseif status_altmode ~= 5 and prev_status_altmode == 5 then
elseif exit_mode_flc then
send_as = -2
elseif status_altmode == 5 and status_machmode ~= prev_status_machmode then
elseif mode_flc and status_machmode ~= prev_status_machmode then
if status_machmode == 1 then
send_as = math.floor(ap_as_kt_mach*1000 + 0.5)
else
@@ -215,8 +257,33 @@ else
ap_as_kt_mach = app_report[4]
end
end
--pitch
local enter_mode_pitch = false
local exit_mode_pitch = false
if ac_icao == "DH8D" then
if q4xp_status_altmode == 1 and prev_status_altmode ~= 1 then
enter_mode_pitch = true
elseif q4xp_status_altmode ~= 1 and prev_status_altmode == 1 then
exit_mode_pitch = true
end
if enter_mode_pitch then
send_vs = math.floor(q4xp_ap_pitch + 0.5)*100
elseif exit_mode_pitch then
send_vs = -2
elseif app_report_good and app_report[3] ~= 0xffff then
if bit.band(app_report[3], 0x8000) ~= 0 then
q4xp_ap_pitch = (-bit.band(bit.bnot(app_report[3]), 0x7fff) - 1)/100
else
q4xp_ap_pitch = app_report[3]/100
end
end
end
send_app_report(device, send_hdg, build_leds(), send_alt, send_vs, send_as, status_machmode == 1)
prev_status_altmode = status_altmode
if ac_icao == "DH8D" then
prev_status_altmode = q4xp_status_altmode
else
prev_status_altmode = status_altmode
end
prev_status_machmode = status_machmode
end