11dofile (LockOn_Options .script_path .. " CMFD/CMFD_NAV_ID_defs.lua" )
2+ dofile (LockOn_Options .script_path .. " Systems/ufcp_api.lua" )
23
34
45local CMFD_NAV_FYT_VALID = get_param_handle (" CMFD_NAV_FYT_VALID" )
@@ -22,6 +23,9 @@ local CMFD_NAV_FYT_OAP_MINS = get_param_handle("CMFD_NAV_FYT_OAP_MINS")
2223local CMFD_NAV_FYT_OAP_SECS = get_param_handle (" CMFD_NAV_FYT_OAP_SECS" )
2324local CMFD_NAV_FYT_OAP_AZIMUTH = get_param_handle (" CMFD_NAV_FYT_OAP_AZIMUTH" )
2425local CMFD_NAV_FYT_OAP_ELEVATION = get_param_handle (" CMFD_NAV_FYT_OAP_ELEVATION" )
26+ local CMFD_NAV_FYT_OAP_STT = get_param_handle (" CMFD_NAV_FYT_OAP_STT" )
27+ local CMFD_NAV_FYT_OAP_TTD = get_param_handle (" CMFD_NAV_FYT_OAP_TTD" )
28+ local CMFD_NAV_FYT_OAP_DT = get_param_handle (" CMFD_NAV_FYT_OAP_DT" )
2529local CMFD_NAV_ROUT_TEXT = get_param_handle (" CMFD_NAV_ROUT_TEXT" )
2630local CMFD_NAV_ROUT_TEXT1 = get_param_handle (" CMFD_NAV_ROUT_TEXT1" )
2731local CMFD_NAV_ROUT_TEXT2 = get_param_handle (" CMFD_NAV_ROUT_TEXT2" )
@@ -33,6 +37,7 @@ local CMFD_NAV_MARK_TEXT = get_param_handle("CMFD_NAV_MARK_TEXT")
3337
3438local nav_format = CMFD_NAV_FORMAT_IDS .AC
3539local nav_fyt = 1
40+ local nav_fyt_last = - 1
3641local route
3742local nav_fyt_list = {}
3843
@@ -81,6 +86,33 @@ local function get_heading(x1, y1, x2, y2)
8186 hdg = hdg % 360
8287 return hdg
8388end
89+ local function cmfd_nav_sel_next_wpt ()
90+ local nav_fyt_next = (nav_fyt + 1 ) % 100
91+ local limit = 0
92+ while nav_fyt_list [nav_fyt_next + 1 ]== nil do
93+ nav_fyt_next = (nav_fyt_next + 1 ) % 100
94+ limit = limit + 1
95+ if limit > 100 then
96+ nav_fyt_next = 0
97+ break
98+ end
99+ end
100+ return nav_fyt_next
101+ end
102+
103+ local function cmfd_nav_sel_prev_wpt ()
104+ local nav_fyt_prev = (nav_fyt - 1 ) % 100
105+ local limit = 0
106+ while nav_fyt_list [nav_fyt_prev + 1 ]== nil do
107+ nav_fyt_prev = (nav_fyt_prev - 1 ) % 100
108+ limit = limit + 1
109+ if limit > 100 then
110+ nav_fyt_prev = 0
111+ break
112+ end
113+ end
114+ return nav_fyt_prev
115+ end
84116
85117local function update_wpt_list (wpt_list )
86118 if wpt_list == nil then return wpt_list end
124156
125157local wpt_index = get_valid_wpt_list ()
126158
159+ local distance_last = - 1
160+
127161function update_nav ()
128162 count = count + 1
129163 CMFD_NAV_FORMAT :set (nav_format )
@@ -198,6 +232,12 @@ function update_nav()
198232 z = z - nav_fyt_list [nav_fyt + 1 ].lon_m
199233 local distance = math.sqrt (x * x + z * z ) * 0.000539957
200234 local elev = y * 3.28084
235+ if distance < 2 and distance > distance_last and nav_fyt_last == nav_fyt and UFCP_NAV_MODE :get () == UFCP_NAV_MODE_IDS .AUTO then
236+ local nav_fyt_next = cmfd_nav_sel_next_wpt ()
237+ if nav_fyt_next > nav_fyt and nav_fyt_next < 79 then nav_fyt = nav_fyt_next end
238+ end
239+ distance_last = distance
240+ nav_fyt_last = nav_fyt
201241
202242 local hdg
203243 if x ~= 0 then
@@ -232,6 +272,18 @@ function update_nav()
232272 time_mins = 99
233273 time_secs = 59
234274 end
275+
276+ local speed_to_target = 0
277+ local tot = nav_fyt_list [nav_fyt + 1 ].time or 0
278+ local diff_tot = tot - get_absolute_model_time ()
279+
280+ if diff_tot > 0 then
281+ speed_to_target = distance / diff_tot * 3600
282+ if speed_to_target > 999 then speed_to_target = 999 end
283+ else
284+ speed_to_target = - 1
285+ end
286+ local dt = diff_tot - time
235287
236288 local plane_hdg = math.deg (- sensor_data .getHeading ())
237289 if plane_hdg < 0 then plane_hdg = 360 + plane_hdg end
@@ -256,6 +308,9 @@ function update_nav()
256308
257309 CMFD_NAV_FYT_OAP_MINS :set (time_mins )
258310 CMFD_NAV_FYT_OAP_SECS :set (time_secs )
311+ CMFD_NAV_FYT_OAP_STT :set (speed_to_target )
312+ CMFD_NAV_FYT_OAP_TTD :set (time )
313+ CMFD_NAV_FYT_OAP_DT :set (dt )
259314
260315 if nav_fyt_list [nav_fyt + 1 ].lat >= 0 then CMFD_NAV_FYT_LAT_HEMIS :set (" N" ) else CMFD_NAV_FYT_LAT_HEMIS :set (" S" ) end
261316 CMFD_NAV_FYT_LAT_DEG :set (math.floor (math.abs (nav_fyt_list [nav_fyt + 1 ].lat )))
410465dev :listen_command (device_commands .NAV_INC_FYT )
411466dev :listen_command (device_commands .NAV_DEC_FYT )
412467
413- local function cmfd_nav_sel_next_wpt ()
414- nav_fyt = (nav_fyt + 1 ) % 100
415- local limit = 0
416- while nav_fyt_list [nav_fyt + 1 ]== nil do
417- nav_fyt = (nav_fyt + 1 ) % 100
418- limit = limit + 1
419- if limit > 100 then
420- nav_fyt = 0
421- break
422- end
423- end
424- end
425-
426- local function cmfd_nav_sel_prev_wpt ()
427- nav_fyt = (nav_fyt - 1 ) % 100
428- local limit = 0
429- while nav_fyt_list [nav_fyt + 1 ]== nil do
430- nav_fyt = (nav_fyt - 1 ) % 100
431- limit = limit + 1
432- if limit > 100 then
433- nav_fyt = 0
434- break
435- end
436- end
437- end
438468
439469function SetCommandNav (command ,value , CMFD )
440470 if value == 1 then
@@ -451,15 +481,15 @@ function SetCommandNav(command,value, CMFD)
451481 elseif command == device_commands .CMFD1OSS7 or command == device_commands .CMFD2OSS7 then
452482 nav_format = CMFD_NAV_FORMAT_IDS .AC
453483 elseif (command == device_commands .CMFD1OSS27 or command == device_commands .CMFD2OSS27 ) and nav_format == CMFD_NAV_FORMAT_IDS .FYT then
454- cmfd_nav_sel_next_wpt ()
484+ nav_fyt = cmfd_nav_sel_next_wpt ()
455485 elseif (command == device_commands .CMFD1OSS26 or command == device_commands .CMFD2OSS26 ) and nav_format == CMFD_NAV_FORMAT_IDS .FYT then
456- cmfd_nav_sel_prev_wpt ()
486+ nav_fyt = cmfd_nav_sel_prev_wpt ()
457487 elseif command == device_commands .CMFD1OSS28 or command == device_commands .CMFD2OSS28 then
458488 nav_format = CMFD_NAV_FORMAT_IDS .AFLD
459489 elseif command == device_commands .NAV_INC_FYT and value == 1 then
460- cmfd_nav_sel_next_wpt ()
490+ nav_fyt = cmfd_nav_sel_next_wpt ()
461491 elseif command == device_commands .NAV_DEC_FYT and value == 1 then
462- cmfd_nav_sel_prev_wpt ()
492+ nav_fyt = cmfd_nav_sel_prev_wpt ()
463493 end
464494 end
465495end
0 commit comments