lua: Fix pitch mode

This commit is contained in:
2023-06-22 22:14:29 +02:00
parent 818ac65352
commit a3d7b24d19

View File

@@ -48,11 +48,14 @@ function table.clone(org)
return {table.unpack(org)}
end
function send_app_report(device, hdg, leds, alt, vs, as, mach)
function send_app_report(device, hdg, leds, alt, vs, as, mach, pitch)
type_ = 0
if mach then
type_ = bit.bor(type_, 0x10)
end
if pitch then
type_ = bit.bor(type_, 0x20)
end
hid_write(device, 2, type_, bit.band(hdg, 0xff), bit.arshift(hdg, 8), bit.band(leds, 0xff), bit.arshift(leds, 8),
bit.band(alt, 0xff), bit.arshift(alt, 8), bit.band(vs, 0xff), bit.arshift(vs, 8),
bit.band(as, 0xff), bit.arshift(as, 8))
@@ -131,8 +134,10 @@ else
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")
send_app_report(device, math.floor(ap_hdg + 0.5), build_leds(), math.floor(ap_alt + 0.5), -2, -2, status_machmode == 1, q4xp_status_altmode == 1)
else
send_app_report(device, math.floor(ap_hdg + 0.5), build_leds(), math.floor(ap_alt + 0.5), -2, -2, status_machmode == 1, false)
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
local prev_ap_hdg = ap_hdg
@@ -219,7 +224,7 @@ else
if enter_mode_vs then
send_vs = math.floor(cur_vvi + 0.5)
elseif enter_mode_pitch then
send_vs = math.floor(q4xp_ap_pitch + 0.5)*100
send_vs = math.floor(q4xp_ap_pitch + 0.5)
elseif exit_mode_vs or exit_mode_pitch then
send_vs = -2
elseif app_report_good and app_report[3] ~= 0xffff then
@@ -231,9 +236,9 @@ else
end
elseif mode_pitch then
if bit.band(app_report[3], 0x8000) ~= 0 then
q4xp_ap_pitch = (-bit.band(bit.bnot(app_report[3]), 0x7fff) - 1)/100
q4xp_ap_pitch = (-bit.band(bit.bnot(app_report[3]), 0x7fff) - 1)
else
q4xp_ap_pitch = app_report[3]/100
q4xp_ap_pitch = app_report[3]
end
end
end
@@ -285,10 +290,11 @@ else
ap_as_kt_mach = app_report[4]
end
end
send_app_report(device, send_hdg, build_leds(), send_alt, send_vs, send_as, status_machmode == 1)
if ac_icao == "DH8D" then
send_app_report(device, send_hdg, build_leds(), send_alt, send_vs, send_as, status_machmode == 1, q4xp_status_altmode == 1)
prev_status_altmode = q4xp_status_altmode
else
send_app_report(device, send_hdg, build_leds(), send_alt, send_vs, send_as, status_machmode == 1, false)
prev_status_altmode = status_altmode
end
prev_status_machmode = status_machmode
@@ -297,7 +303,7 @@ else
do_every_frame("usb_app()")
function exit_handler()
send_app_report(device, -2, 0, -2, -2, -2, 0)
send_app_report(device, -2, 0, -2, -2, -2, 0, 0)
end
do_on_exit('exit_handler()')