I've been developing MVP for months. There are approximately 15 screens with hundreds of functions, but I got tangled up in this item. After trying over a month, I can't think of a script that can integrate local variables, data, and the _txt inside a canvas draw callback.
Way Point, Track, F to WP, T to WP, D to WP does not work. The screen shows all functional when works with txt_add
1st screeen with _txt canvas
2nd screen with txt_add
Could you give me some guidance?
Thank You
Code: Select all
--- TELA FUEL MANAGMENT ACESSADA PELO MENU SETUP
--- ENTRADA DE TEXTO FUEL MANAGEMENT -----------
txt_Fuel_L_cyan2 = "font:Oita W01 Cond Medium.ttf;size:32px; color:cyan; halign:right;valign:center;", 75, 80, 120, 50
txt_Fuel_R_cyan2 = "font:Oita W01 Cond Medium.ttf;size:32px; color:cyan; halign:right;valign:center;", 75, 103, 120, 50
txt_fuel_total_cyan2 = "font:Oita W01 Cond Medium.ttf;size:32px; color:cyan; halign:right;valign:center;", 75, 173, 120, 50
txt_Fuel_F_cyan2 = "font:Oita W01 Cond Medium.ttf;size:32px; color:cyan; halign:right;valign:center;", 75, 230, 120, 50
txt_fused_trip2 = "font:Oita W01 Cond Medium.ttf;size:32px; color:cyan; halign:right;", 75, 255, 120, 50
txt_Fuel_U_cyan2 = "font:Oita W01 Cond Medium.ttf;size:32px; color:cyan; halign:right;", 75, 281, 120, 50
txt_Fused_trip2 = "font:Oita W01 Cond Medium.ttf;size:32px; color:cyan; halign:right;", 75, 335, 120, 50
txt_Fuel_SF = "font:Oita W01 Cond Medium.ttf;size:32px; color:cyan; halign:right;", 75, 310, 120, 50
txt_Fuel_rem = "font:Oita W01 Cond Medium.ttf;size:32px; color:#ff0000; halign:right;", 75, 325, 120, 50
txt_hss2 = "font:Oita W01 Cond Medium.ttf;size:32px; color:red; halign:right;valign:center;", 38, 340, 120, 50
txt_mn2 = "font:Oita W01 Cond Medium.ttf;size:32px; color:red; halign:right;valign:center;", 75, 340, 120, 50
txt_dis_to_e2 = "font:Oita W01 Cond Medium.ttf;size:32px; color:#ff0000; halign:right;valign:center;", 75, 367, 120, 50
txt_altimeter2 = "font:Oita W01 Cond Medium.ttf;size:32px; color:cyan; halign:right;", 284, 228, 120, 50
txt_speed_knots2 = "font:Oita W01 Cond Medium.ttf;size:32px; color:cyan; halign:right;", 284, 173, 120, 50
txt_eficy2 = "font:Oita W01 Cond Medium.ttf;size:32px; color:cyan; halign:right;", 284, 197, 120, 50
--- ENTRADA DE TEXTO GPS DATA WAYPOINT CANVAS------------------------------------------------------
txt_bearingC = "font:Oita W01 Cond Medium.ttf;size:32px; color:cyan; halign:right;", 284, 150, 120, 50
txt_speed_knotsC = "font:Oita W01 Cond Medium.ttf;size:32px; color:cyan; halign:right;", 284, 173, 120, 50
txt_altimeterC = "font:Oita W01 Cond Medium.ttf;size:32px; color:cyan; halign:right;", 284, 228, 120, 50
txt_waypointC = "font:Oita W01 Cond Medium.ttf;size:38px; color:cytan; halign:right;", 250, 110, 120, 50
txt_ftowpC = "font:Oita W01 Cond Medium.ttf;size:32px; color:cyan; halign:right;", 284, 307, 120, 50
txt_ttowp_hsC = "font:Oita W01 Cond Medium.ttf;size:32px; color:cyan; halign:right;", 244, 337, 120, 50
txt_ttowp_mnC = "font:Oita W01 Cond Medium.ttf;size:32px; color:cyan; halign:right;", 284, 337, 120, 50
txt_dtowpC = "font:Oita W01 Cond Medium.ttf;size:32px; color:cyan; halign:right;", 284, 367, 120, 50
lat1=0
lon1=0
lat2= 0
lon2= 0
--- FUEL MANAGMENTCANVAS MENU -------------------------------------------------------------------------------------------------
fuelmanag_canvas = canvas_add(0,0,451,488)
function Fuelmcanvas_callback(fuelleft2,fuelright2,ftl2,
fuelflow2,fusd,fuelcv,frem,ff2, fw2, altimeter,spd2,eficy2)
---What this function is doing is creating a TABLE named <waypoints2C>
---Distance between two gps coordinates---
R = 6371e3
a1 = math.rad(lat1) -- φ1
a2 = math.rad(lat2) -- φ2
o1 = math.rad(lon1) -- λ1
o2 = math.rad(lon2) -- λ2
ax = math.rad(lat2-lat1) -- Δφ
ay = math.rad(lon2-lon1) -- Δλ
a = (math.sin(ax/2)*math.sin(ax/2)) + math.cos(a1) * math.cos(a2) * (math.sin(ay/2)*math.sin(ay/2))
c = 2 * math.atan(math.sqrt(a)/math.sqrt(1-a))
d = R * c
print("Distance in nm "..d/1852)
print("Distance in meters "..d)
print("Distance in Kilometers "..d/1000)
distwayp = 0
function new_xpl_data_callback(latitude, longitude)
lat1=latitude
lon1=longitude
print("Latitude: " .. lat1)
print("Longitude: " .. lon1)
nav_get_nearest("WAYPOINT",lat1, lon1, 1, data_callback)
data_callback()
end
---Bearing between two coordinates---
y = math.sin(o2-o1) * math.cos(a2);
x = math.cos(a1)*math.sin(a2) - math.sin(a1)*math.cos(a2)*math.cos(o2-o1)
brng = math.atan(y, x)
deg_brng=math.deg(brng)
--------------------------------xxx
function xpl_dataref_subscribe_trottle(...)
-- Local variables
local args = {...}
local user_callback = args[#args - 1]
local delta_ms = table.remove(args, #args)
local data = nil
-- Replace the user callback with our own
args[#args] = function (...)
data = {...}
end
-- Do the actual subscribe
xpl_dataref_subscribe(table.unpack(args))
-- Start a timer that will fire the callback on requested interval
timer_start(0, delta_ms, function()
if data ~= nil then
user_callback(table.unpack(data))
data = nil
end
xpl_dataref_subscribe_trottle("sim/flightmodel/position/latitude", "DOUBLE",
"sim/flightmodel/position/longitude", "DOUBLE",
"sim/cockpit2/engine/indicators/fuel_flow_kg_sec", "FLOAT[8]",new_xpl_data_callback, 1000)
end)
end
-------------------------------xxx
canvas_draw(fuelmanag_canvas, function()
_rect(0,0,451,488)
_fill_img("tela_fuelmanagment_short.png",0,0,451,488)
fuelleft2 = var_cap(fuelleft2, 0, 238)
fuelright2 = var_cap(fuelright2, 0, 238)
ftl2 = var_cap(ftl2, 0, 474)
fuelflow2 = var_cap(fuelflow2[1] * 5.75462262 / 6.81 * 3600, 0, 130)
fusd = var_cap(fusd, 0, 442)
fuelcv = var_cap(442-fuelcv, 0, 442)
ftrem = var_cap(frem, 0, 442)
_txt(string.format("%02.0f", fuelleft2),txt_Fuel_L_cyan2, 195, 96)
_txt(string.format("%02.0f", fuelright2), txt_Fuel_R_cyan2,195, 120 )
_txt(string.format("%02.0f", ftl2),txt_fuel_total_cyan2,195, 190 )
_txt(string.format("%02.0f", fuelflow2),txt_Fuel_F_cyan2, 195,245 )
_txt( string.format("%1.0f", fusd ), txt_Fused_trip2,195,254)
_txt(string.format("%01.0f", fuelcv),txt_Fuel_SF,195,282 )
_txt(string.format("%01.00f",frem),txt_Fuel_rem,195,310 )
_txt(string.format("%01.00f",spd2),txt_speed_knots2,400,173)
_txt(string.format("%1.01f", spd2/eficy2[1] / 1000),txt_eficy2,400,197)
_txt(string.format("%01.00f", altimeter),txt_altimeter2, 400,228)
--- FUEL TO WAYPOINT CANVAS MENU SETUP --- --- D to E CANVAS MENU SETUP
local t_seconds = fif(ff2[1] > 0, fw2 / ff2[1], 0)
_txt(string.format("%02.0f", math.floor(t_seconds / 3600)),txt_hss2, 155,355 )
_txt(string.format(": %02.0f", math.floor(t_seconds / 60)%60),txt_mn2,195, 355 )
local t_distance = fif(ff2[1] > 0, fw2 / ff2[1], 0)
_txt(string.format("%02.0f", math.floor(t_distance / 39)), txt_dis_to_e2,196, 383 )
local function data_callback(waypoints)
if waypoints ~= nil then
lat2= waypoints[1]["LATITUDE"]
lon2= waypoints[1]["LONGITUDE"]
print("Direction/Bearing "..deg_brng)
print(" name:" .. waypoints[1]["ICAO"] .. " lon:" .. waypoints[1]["LONGITUDE"] .. " lat:" .. waypoints[1]["LATITUDE"])
_txt(waypoints[1]["ICAO"],txt_waypointC, 380,110)
_txt(string.format("%.2f",d/1852),txt_dtowpC,402,367)
_txt(string.format("%.2f",deg_brng),txt_bearingC, 402,150)
--- COMBUSTIVEL NECESSÁRIO PARA ALCANÇAR O WAYPOINT
_txt(string.format("%.2f", d/1852 * 0.1705, data_callback),txt_ftowpC,402,307)
local ttw_seconds = 3600
--- TEMPO NECESSÁRIO PARA ALCANÇAR O WAYPOINT
_txt(string.format("%02.0f", d/1852 * math.floor( ttw_seconds / 530400, data_callback)),txt_ttowp_hsC, 365,337 )
_txt(string.format(": %02.0f", d/1852 * math.floor( ttw_seconds /3600)%120,data_callback),txt_ttowp_mnC, 402,337)
end
end
end)
end
xpl_dataref_subscribe( "sim/flightmodel/weight/m_fuel_total", "FLOAT",
"sim/cockpit2/engine/indicators/fuel_flow_kg_sec", "FLOAT[8]", function(fw3C,ff3hC)
end)
xpl_dataref_subscribe("sim/cockpit2/fuel/fuel_level_indicated_left", "FLOAT",
"sim/cockpit2/fuel/fuel_level_indicated_right", "FLOAT",
"sim/flightmodel/weight/m_fuel_total", "FLOAT",
"sim/cockpit2/engine/indicators/fuel_flow_kg_sec", "FLOAT[8]",
"sim/cockpit2/fuel/fuel_totalizer_sum_kg", "FLOAT",
"sim/flightmodel/weight/m_fuel_total", "FLOAT",
"sim/flightmodel/weight/m_fuel_total", "FLOAT",
"sim/cockpit2/engine/indicators/fuel_flow_kg_sec", "FLOAT[8]",
"sim/flightmodel/weight/m_fuel_total", "FLOAT",
"sim/cockpit2/gauges/indicators/altitude_ft_pilot", "FLOAT",
"sim/cockpit/radios/gps_dme_speed_kts", "FLOAT",
"sim/cockpit2/engine/indicators/fuel_flow_kg_sec", "FLOAT[8]",
Fuelmcanvas_callback)