Skip to content

L\L calculation for DMS precision=0 incorrectly rounds to 60 seconds #73

@aeronautes

Description

@aeronautes

This problem affects modules that use DMS precision=0, such as AV8 Harrier. A latlon entry with 60 seconds is invalid and will not be accepted by AV8 nav system.

Repro:

  1. slot into Harrier, or other DMS precision=0 module
  2. enable 'L/L'
  3. in F10 map go to a lat or lon location that has seconds > 59.5
  4. click 'L/L'
  5. Notice the reported lat/lon will have seconds = 60

Cause: Lua's string.format() will round to the nearest decimal whole number to accomodate precision spec. However in the case of sexagesimal systems it will not know to rollover 60 seconds to the next minute+1, seconds=0.

Fix:

diff --git a/Scripts/Hooks/scratchpad-hook.lua b/Scripts/Hooks/scratchpad-hook.lua
index 8c262e5..b63e53c 100644
--- a/Scripts/Hooks/scratchpad-hook.lua
+++ b/Scripts/Hooks/scratchpad-hook.lua
@@ -610,6 +610,14 @@ local function loadScratchpad()
             m = math.floor(m)
             local s = d * 3600 - g * 3600 - m * 60
             s = math.floor(s * 100) / 100
+            if precision == 0 and s >= 59.5 then
+                s = 0
+                m = m + 1
+                if m > 59 then
+                    m = 0
+                    g = g + 1
+                end
+            end
             return string.format('%s %0'..degreesWidth..'d°%.2d\'%0'..(precision+2)..'.'..precision..'f', h, g, m, s)

         elseif format == "DDM" then -- Degree Decimal Minutes

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions