zkv1000 / zkv1000.nas /
Sébastien MARQUE adds Map on MFD
5a54e73 7 years ago
1 contributor
157 lines | 7.688kb
# Nasal files to be loaded at start
# the order could be important as some files need other one to be loaded first
files_to_load = [
    'lib.nas',     # some useful functions, should stay first loaded
    'radios.nas',  # all about radios COMM, NAV, XPDR
    'knobs.nas',   # handles knobs
    'buttons.nas', # handles knobs and buttons
    'softkeys.nas',# handles softkeys and menus items
    'map.nas',     # moves the maps
    'display.nas',
    'core.nas',    # the scheduler and switch on button
];
#    'menu.nas',    # manages menu entries andd perform some simple actions
#    'afcs.nas',    # Automatic Flight Control System
#    'routes.nas',  # manages flightplans and routes
#    'display.nas', # display messages and popups
#    'infos.nas',   # get informations from environment
#    'alerts.nas',  # in flight tests
#    'mud.nas',     # displays simple embedded GUI (Multi-Use Display)

var zkv = cdi = radios = alerts = infos = cursors = afcs = eis = nil;

var init_props = func {
    zkv = props.globals.getNode('/instrumentation/zkv1000',1);
    zkv.getNode('emission',1).setDoubleValue(0.5);
    zkv.getNode('body-emission',1).setDoubleValue(0.0);
    zkv.getNode('body-texture',1).setValue('');
    zkv.getNode('display-brightness-norm',1).setValue(0.5);

    radios = zkv.getNode('radios', 1);
    radios.getNode('nav1-selected',1).setIntValue(0);
    radios.getNode('nav1-standby',1).setIntValue(0);
    radios.getNode('nav2-selected',1).setIntValue(0);
    radios.getNode('nav2-standby',1).setIntValue(0);
    radios.getNode('nav-tune',1).setIntValue(0);
    radios.getNode('nav-freq-mhz',1).alias('/instrumentation/nav/frequencies/standby-mhz');
    radios.getNode('comm1-selected',1).setIntValue(1);
    radios.getNode('comm2-selected',1).setIntValue(0);
    radios.getNode('comm-tune',1).setIntValue(0);
    radios.getNode('comm-freq-mhz',1).alias('/instrumentation/comm/frequencies/standby-mhz');
    radios.getNode('xpdr-mode',1).setValue('GND');
    radios.getNode('brg1-source',1).setValue('OFF');
    radios.getNode('brg2-source',1).setValue('OFF');

    cdi = zkv.getNode('cdi', 1);
    cdi.getNode('source', 1).setValue('OFF');
    cdi.getNode('no-flag', 1).setBoolValue(0);
    cdi.getNode('FROM-flag', 1).alias('no-flag');
    cdi.getNode('TO-flag', 1).alias('no-flag');
    cdi.getNode('course', 1);
    cdi.getNode('course-deflection', 1);
    cdi.getNode('radial', 1);
    cdi.getNode('in-range', 1);

    alerts = zkv.getNode('alerts',1);
    alerts.getNode('traffic-proximity',1).setIntValue(0);
    alerts.getNode('marker-beacon', 1).setIntValue(0);
    alerts.getNode('warning', 1).setBoolValue(0);
    alerts.getNode('alert', 1).setBoolValue(0);
    alerts.getNode('message', 1).setValue('');

    afcs = zkv.getNode('afcs',1);
    afcs.getNode('fd-bars-visible',1).setBoolValue(0);
    afcs.getNode('alt-bug-visible',1).setBoolValue(0);
    afcs.getNode('heading-bug-deg',1).setDoubleValue(getprop('/orientation/heading-magnetic-deg'));
    afcs.getNode('target-pitch-deg',1).setDoubleValue(0.0);
    afcs.getNode('selected-alt-ft',1).setIntValue(2000);
    afcs.getNode('selected-alt-ft-diff',1).setDoubleValue(0.0);
    afcs.getNode('selected-ias-kt-diff',1).setDoubleValue(0.0);
    afcs.getNode('vertical-speed-fpm',1).setDoubleValue(0.0);
    afcs.getNode('roll-armed', 1).setBoolValue(0);
    afcs.getNode('pitch-armed', 1).setBoolValue(0);
    afcs.getNode('roll-armed-mode-text',1).setValue('');
    afcs.getNode('roll-active-mode-text',1).setValue('');
    afcs.getNode('roll-armed-mode',1).setIntValue(0);
    afcs.getNode('roll-active-mode',1).setIntValue(0);
    afcs.getNode('roll-active-mode-blink',1).setBoolValue(0);
    afcs.getNode('pit-armed-mode-text',1).setValue('');
    afcs.getNode('pit-active-mode-text',1).setValue('');
    afcs.getNode('pit-armed-mode',1).setIntValue(0);
    afcs.getNode('pit-active-mode',1).setIntValue(0);
    afcs.getNode('pit-active-mode-blink',1).setBoolValue(0);
    afcs.getNode('route',1);

    eis = zkv.getNode('eis',1);
    eis.getNode('fuel-qty-at-start', 1).setValue(
        getprop('/consumables/fuel/tank/level-gal_us')
      + getprop('/consumables/fuel/tank/level-gal_us'));

    setprop('/sim/gui/dialogs/map-canvas/draw-APT', 1);
    setprop('/sim/gui/dialogs/map-canvas/draw-FIX', 1);
    setprop('/sim/gui/dialogs/map-canvas/draw-VOR', 1);
    setprop('/sim/gui/dialogs/map-canvas/draw-DME', 1);
    setprop('/sim/gui/dialogs/map-canvas/draw-NDB', 1);
    setprop('/sim/gui/dialogs/map-canvas/draw-TFC', 1);
    setprop('/sim/gui/dialogs/map-canvas/draw-data', 1);
    setprop('/sim/gui/dialogs/map-canvas/draw-FLT', 1);
    setprop('/sim/gui/dialogs/map-canvas/draw-WXR', 1);
    setprop('/sim/gui/dialogs/map-canvas/draw-TUT', 1);
    setprop('/sim/gui/dialogs/map-canvas/aircraft-heading-up', 0);
    mfd = zkv.getNode('mfd', 1);
    var tiles_server = getprop('/sim/online-tiles-server');
    var tiles_type = getprop('/sim/online-tiles-type');
    # see https://www.mediawiki.org/wiki/Maps
    mfd.getNode('online-tiles-server', 1).setValue(tiles_server != nil ? tiles_server : 'maps.mediawiki.org');
    mfd.getNode('online-tiles-type', 1).setValue(tiles_type != nil ? tiles_type : 'osm-intl');

    props.globals.getNode('/instrumentation/transponder/id-code',1).setIntValue(1200);
    props.globals.getNode('/instrumentation/transponder/serviceable',1).setBoolValue(1);
    props.globals.getNode('/autopilot/settings/heading-bug-deg', 1).alias('/instrumentation/zkv1000/afcs/heading-bug-deg');
    props.globals.getNode('/autopilot/settings/target-altitude-ft',1).setDoubleValue(0.0);
    props.globals.getNode('/autopilot/settings/target-speed-kt',1).setDoubleValue(0.0);
    props.globals.getNode('/autopilot/settings/vertical-speed-fpm',1).setDoubleValue(0.0);
    props.globals.getNode('/autopilot/internal/target-pitch-deg',1).setDoubleValue(0.0);
    props.globals.getNode('/autopilot/internal/flc-altitude-pitch-deg',1).setDoubleValue(0.0);
    props.globals.getNode('/autopilot/internal/flc-airspeed-pitch-deg',1).setDoubleValue(0.0);
    props.globals.getNode('/autopilot/internal/target-roll-deg',1).setDoubleValue(0.0);
    props.globals.getNode('/autopilot/locks/pitch',1).setValue('');
    props.globals.getNode('/autopilot/locks/roll',1).setValue('');
    props.globals.getNode('/autopilot/locks/passive-mode', 1).setIntValue(1);
}

var set_listeners = func {
#    setlistener('/instrumentation/nav[0]/radials/selected-deg', popup_course_info,  0, 0);
#    setlistener('/instrumentation/nav[1]/radials/selected-deg', popup_course_info,  0, 0);
#    setlistener('/instrumentation/zkv1000/afcs/heading-bug-deg',popup_hdg_info,     0, 0);
#    setlistener('/instrumentation/zkv1000/afcs/selected-alt-ft',popup_selected_alt, 0, 0);
#    setlistener('/instrumentation/zkv1000/radios/nav-tune',     setNavTune,         0, 0);
#    setlistener('/instrumentation/zkv1000/radios/comm-tune',    setCommTune,        0, 0);
}

var load_nasal = func {
    var zkv1000_dir = getprop('/sim/fg-aircraft') ~ '/Instruments-3d/zkv1000/Nasal/';
    for (var i = 0; i < size(files_to_load); i += 1)
        io.load_nasal(zkv1000_dir ~ files_to_load[i], 'zkv1000');
    files_to_load = nil;
}

var load_multikey = func {
    fgcommand('loadxml', props.Node.new({
        'filename': getprop('/sim/fg-aircraft') ~ '/Instruments-3d/zkv1000/Systems/multikey.xml',
        'targetnode': '/input/keyboard/'
    }));
    multikey.init();
}

var zkv1000_init = func {
    removelistener(init);
    load_multikey();
    load_nasal();
    init_props();
    set_listeners();
    print('zkv1000 loaded');
}

var init = setlistener('/sim/signals/fdm-initialized', zkv1000_init, 0, 0);