-- ============================================================================ -- X-Plane Glass Cockpit — G1000 UI-state publisher (FlyWithLua companion) -- ============================================================================ -- The web G1000 mirrors the in-sim G1000's display state. Most of it already -- flows over the Web API (attitude, radios, AP, CDI source, baro, ...). The few -- bits that are G1000-internal (MFD page, map range, PFD inset) aren't standard -- datarefs, so this script reads them and re-publishes them under our own -- namespace, which the bridge then streams to every tablet: -- -- glasscockpit/ui/mfd_page Int 0 = MAP, 1 = FPL, 2 = NRST -- glasscockpit/ui/map_range_nm Float active map range in NM -- glasscockpit/ui/inset Int PFD inset map on/off (0/1) -- -- INSTALL: copy to /Resources/plugins/FlyWithLua/Scripts/ (alongside -- fms-sync.lua). The web app follows these when present and falls back to its -- own local control when they're absent — so it never breaks without the plugin. -- ============================================================================ -- our published values (the create_dataref callbacks read these) ------------ local ui_mfd_page = -1 -- -1 = "unknown" -> web keeps local control local ui_map_range_nm = -1 local ui_inset = -1 create_dataref("glasscockpit/ui/mfd_page", "Int", function() return ui_mfd_page end) create_dataref("glasscockpit/ui/map_range_nm", "Float", function() return ui_map_range_nm end) create_dataref("glasscockpit/ui/inset", "Int", function() return ui_inset end) -- safe optional dataref readers (nil if the dataref doesn't exist) ---------- local function geti(name) local h = XPLMFindDataRef(name); if h then return XPLMGetDatai(h) end end local function getf(name) local h = XPLMFindDataRef(name); if h then return XPLMGetDataf(h) end end -- ============================================================================ -- TODO (confirm in YOUR sim): the exact G1000 source datarefs differ per -- aircraft. Run the probe below once, read the X-Plane Log.txt, and plug the -- right names in here. Until then these stay -1 and the web app uses its own -- local page/range/inset (no harm). -- ============================================================================ local function read_g1000_state() -- MAP RANGE — many G1000s expose an NM range or an enum index. Try a couple -- of common candidates; map_range may be an enum needing a lookup table. local rng = getf("sim/cockpit2/EFIS/map_range") -- <-- verify name if rng then ui_map_range_nm = rng end -- PFD INSET on/off — G1000-internal, name varies: -- local ins = geti("sim/cockpit2/EFIS/inset_map_on") -- <-- verify name -- if ins then ui_inset = ins end -- MFD PAGE group — G1000-internal, name varies: -- local pg = geti("sim/cockpit2/EFIS/mfd_page") -- <-- verify name -- if pg then ui_mfd_page = pg end end do_often("read_g1000_state()") -- ---- one-shot probe: log every dataref whose name contains a keyword ------- -- Bind to a key/macro, fire once, then read Log.txt to discover the real names. function gc_probe_g1000() local hits = {} for _, kw in ipairs({ "EFIS", "g1000", "GPS/g1000", "map_range", "inset", "mfd" }) do logMsg("[glass-cockpit] probe keyword: " .. kw .. " (search Log.txt / DataRefEditor)") end logMsg("[glass-cockpit] tip: use the DataRefEditor or DataRefTool plugin and filter for 'EFIS' / 'g1000' to find map-range / inset / page datarefs, then edit ui-sync.lua") end add_macro("Glass Cockpit: probe G1000 datarefs", "gc_probe_g1000()") logMsg("[glass-cockpit] UI-state publisher active (mfd_page / map_range_nm / inset)")