| 1 |
io.include("Aircraft/Generic/soaring-instrumentation-sdk.nas"); |
| 2 |
|
| 3 |
# Initialize exported properties |
| 4 |
setprop("/instrumentation/ilec-sc7/volume", 0.8); |
| 5 |
setprop("/instrumentation/ilec-sc7/audio", 2); |
| 6 |
setprop("/instrumentation/ilec-sc7/mode", 1); |
| 7 |
setprop("/instrumentation/ilec-sc7/sensitivity", 3); |
| 8 |
setprop("/instrumentation/ilec-sc7/lcd-digits-abs", 0); |
| 9 |
setprop("/instrumentation/ilec-sc7/lcd-digits-sgn", 0); |
| 10 |
setprop("/instrumentation/ilec-sc7/te-reading-mps", 0); |
| 11 |
setprop("/instrumentation/variometer/te-reading-mps", 0); |
| 12 |
setprop("/instrumentation/ilec-sc7/sound-pitch", 1); |
| 13 |
|
| 14 |
# Helper function for updating lcd display |
| 15 |
var update_lcd_props = func(value) { |
| 16 |
setprop("/instrumentation/ilec-sc7/lcd-digits-abs", math.abs(value)); |
| 17 |
setprop("/instrumentation/ilec-sc7/lcd-digits-sgn", (value < 0) ? 0 : 1); |
| 18 |
}; |
| 19 |
|
| 20 |
# Instrument setup: |
| 21 |
|
| 22 |
# One TE probe feeds two vario needles and a 25s averager. |
| 23 |
# LCD digits are controlled by the.. um.. lcd_controller |
| 24 |
# that switches between battery level, temperature and averager |
| 25 |
# depending on mode switch posiion. |
| 26 |
|
| 27 |
# Why a second needle? A digital vario is usually installed together |
| 28 |
# with a mechanical one, so now we are at it, why not provide a bonus |
| 29 |
# TE reading for it and avoid loading an extra script? |
| 30 |
|
| 31 |
var probe = TotalEnergyProbe.new(); |
| 32 |
|
| 33 |
var sc7_needle = Dampener.new( |
| 34 |
input: probe, |
| 35 |
dampening: 3, |
| 36 |
on_update: update_prop("/instrumentation/ilec-sc7/te-reading-mps")); |
| 37 |
|
| 38 |
var sc7_sound = SoundPitchController.new( |
| 39 |
input: sc7_needle, |
| 40 |
max_input: 5, |
| 41 |
on_update: update_prop("/instrumentation/ilec-sc7/sound-pitch")); |
| 42 |
|
| 43 |
var extra_needle = Dampener.new( |
| 44 |
input: probe, |
| 45 |
dampening: 2.7, |
| 46 |
on_update: update_prop("/instrumentation/variometer/te-reading-mps")); |
| 47 |
|
| 48 |
var averager = Averager.new( |
| 49 |
input: probe, |
| 50 |
buffer_size: 25); |
| 51 |
|
| 52 |
var battery_level = PropertyReader.new( |
| 53 |
property: "systems/electrical/volts", |
| 54 |
scale: 0.1); |
| 55 |
|
| 56 |
var temperature = PropertyReader.new( |
| 57 |
property: "environment/temperature-degc", |
| 58 |
scale: 0.1); |
| 59 |
|
| 60 |
var lcd_controller = InputSwitcher.new( |
| 61 |
inputs: [battery_level, averager, temperature], |
| 62 |
active_input: 1, |
| 63 |
on_update: update_lcd_props); |
| 64 |
|
| 65 |
# Subscribe property listeners for instrument switches |
| 66 |
setlistener("instrumentation/ilec-sc7/mode", |
| 67 |
func(n) { lcd_controller.select_input(n.getValue()) }, 0, 0); |
| 68 |
|
| 69 |
setlistener("instrumentation/ilec-sc7/sensitivity", |
| 70 |
func(n) { sc7_needle.dampening = n.getValue() }, 0, 0); |
| 71 |
|
| 72 |
# Wrap everything together into an instrument |
| 73 |
var fast_instruments = UpdateLoop.new( |
| 74 |
update_period: 0, |
| 75 |
components: [probe, sc7_needle, sc7_sound, extra_needle], |
| 76 |
enable: 1); |
| 77 |
|
| 78 |
var slow_instruments = UpdateLoop.new( |
| 79 |
update_period: 1, |
| 80 |
components: [battery_level, averager, temperature, lcd_controller], |
| 81 |
enable: 1); |