Add support for different speed limits on different airplanes

This commit is contained in:
2023-04-03 19:10:17 +02:00
parent 6b4104c955
commit de10af9a5f
3 changed files with 121 additions and 63 deletions

View File

@@ -27,12 +27,24 @@ local led_flc = 0x0400
local led_spd = 0x0800
local led_n1 = 0x1000
local aircraft_data = {
["SR22"] = {["min_as"] = 64, ["max_as"] = 205},
["DR40"] = {["min_as"] = 49, ["max_as"] = 146},
["E55P"] = {["min_as"] = 89, ["max_as"] = 320},
}
dataref("ac_icao", "sim/aircraft/view/acf_ICAO")
print("Aircraft is " .. ac_icao)
local cur_aircraft = aircraft_data[ac_icao]
print("Min AS " .. cur_aircraft.min_as .. ", Max AS " .. cur_aircraft.max_as)
function table.clone(org)
return {table.unpack(org)}
end
function send_app_report(device, hdg, leds, alt, vs, as)
hid_write(device, 2, bit.band(hdg, 0xff), bit.arshift(hdg, 8), bit.band(leds, 0xff), bit.arshift(leds, 8),
hid_write(device, 2, 0, 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))
end
@@ -74,6 +86,8 @@ if device == nil then
print("No device!")
else
hid_set_nonblocking(device, 1)
hid_write(device, 2, 1, bit.band(cur_aircraft.min_as, 0xff), bit.arshift(cur_aircraft.min_as, 8),
bit.band(cur_aircraft.max_as, 0xff), bit.arshift(cur_aircraft.max_as, 8), 0, 0, 0, 0, 0, 0)
dataref("ap_hdg", "sim/cockpit2/autopilot/heading_dial_deg_mag_pilot", "writable")
dataref("mag_hdg", "sim/cockpit2/gauges/indicators/heading_AHARS_deg_mag_copilot")
@@ -106,12 +120,12 @@ else
repeat
local tmp_cnt
local tmp = {}
tmp_cnt, tmp[0], tmp[1], tmp[2], tmp[3], tmp[4], tmp[5], tmp[6], tmp[7], tmp[8], tmp[9], tmp[10] = hid_read(device, 11)
if tmp_cnt >= 11 and tmp[0] == 2 then
app_report = {bit.bor(tmp[1], bit.lshift(tmp[2], 8)),
bit.bor(tmp[5], bit.lshift(tmp[6], 8)),
bit.bor(tmp[7], bit.lshift(tmp[8], 8)),
bit.bor(tmp[9], bit.lshift(tmp[10], 8))}
tmp_cnt, tmp[0], tmp[1], tmp[2], tmp[3], tmp[4], tmp[5], tmp[6], tmp[7], tmp[8], tmp[9], tmp[10], tmp[11] = hid_read(device, 12)
if tmp_cnt >= 11 and tmp[0] == 2 and tmp[1] == 0 then
app_report = {bit.bor(tmp[2], bit.lshift(tmp[3], 8)),
bit.bor(tmp[6], bit.lshift(tmp[7], 8)),
bit.bor(tmp[8], bit.lshift(tmp[9], 8)),
bit.bor(tmp[10], bit.lshift(tmp[11], 8))}
app_report_good = true
end
loops = loops - 1
@@ -147,8 +161,8 @@ else
end
-- airspeed
if status_altmode == 5 and prev_status_altmode ~= 5 then
if cur_ias < 64 then
send_as = 64
if cur_ias < cur_aircraft.min_as then
send_as = cur_aircraft.min_as
else
send_as = math.floor(cur_ias + 0.5)
end