diff --git a/Aircraft/Instruments-3d/glider/vario/ilec-sc7/ilec-sc7.nas b/Aircraft/Instruments-3d/glider/vario/ilec-sc7/ilec-sc7.nas
index 6570e01ae..1c71b14f3 100644
--- a/Aircraft/Instruments-3d/glider/vario/ilec-sc7/ilec-sc7.nas
+++ b/Aircraft/Instruments-3d/glider/vario/ilec-sc7/ilec-sc7.nas
@@ -1,102 +1,73 @@
+io.include("Aircraft/Generic/soaring-instrumentation-sdk.nas");
- var debug_enabled = 0;
-
- ## helpers
- #
- var FT2M=0.30480;
- var KT2MPS=1852/3600;
- var square=func(x) return x*x;
- var get_delta=func (current,previous) {return (current-previous);}
- var state = {new:func {return{parents:[state]};},altitude_m:0,airspeed_mps:0,timestamp:0,te_read:0};
- var samples = []; setsize(samples, 30);
- var te_needle =0;
+# Initialize exported properties
+setprop("/instrumentation/ilec-sc7/volume", 0.8);
+setprop("/instrumentation/ilec-sc7/audio", 2);
+setprop("/instrumentation/ilec-sc7/mode", 1);
+setprop("/instrumentation/ilec-sc7/sensitivity", 3);
+setprop("/instrumentation/ilec-sc7/lcd-digits-abs", 0);
+setprop("/instrumentation/ilec-sc7/lcd-digits-sgn", 0);
+setprop("/instrumentation/ilec-sc7/te-reading-mps", 0);
+setprop("/instrumentation/variometer/te-reading-mps", 0);
- setprop("/instrumentation/ilec-sc7/te-reading-mps",0);
- setprop("/instrumentation/ilec-sc7/volume",0.8);
- setprop("/instrumentation/ilec-sc7/audio",2);
- setprop("/instrumentation/ilec-sc7/mode",1);
- setprop("/instrumentation/ilec-sc7/sensitivity",1);
- setprop("/instrumentation/ilec-sc7/filter",0.05);
+# Helper function for updating lcd display
+var update_lcd_props = func(value) {
+ setprop("/instrumentation/ilec-sc7/lcd-digits-abs", math.abs(value));
+ setprop("/instrumentation/ilec-sc7/lcd-digits-sgn", (value < 0) ? 0 : 1);
+};
- var update_state = func {
- var s = state.new();
- s.altitude_m=getprop("/position/altitude-ft")*FT2M;
- s.airspeed_mps=getprop("/velocities/airspeed-kt")*KT2MPS;
- s.timestamp=systime();
- return s;
- }
+# Instrument setup:
- var push30 = func {
- var i = 0;
- while ( i < 30 ) {
- samples[i]=0;
- i += 1;
- };
- }
+# One TE probe feeds two vario needles and a 25s averager.
+# LCD digits are controlled by the.. um.. lcd_controller
+# that switches between battery level, temperature and averager
+# depending on mode switch posiion.
- ##
- # debug info
- var s_dump = func(s) {
- print(s.timestamp," ", s.altitude_m, " ", s.airspeed_mps);
- }
+# Why a second needle? A digital vario is usually installed together
+# with a mechanical one, so now we are at it, why not provide a bonus
+# TE reading for it and avoid loading an extra script?
- var averager = func {
- var sum = 0 ;
- var i = 0;
- while ( i < 29 ) {
- samples[i] = samples[i+1]; # shift everything to the "left"
- i += 1;
- };
- samples[29] = te_needle; # and set last sample to current
- i = 0;
- while ( i < 30 ) {
- sum = sum + samples[i];
- i += 1;
- };
- var average30 = sum / 30;
- setprop("/instrumentation/ilec-sc7/average",math.abs(average30));
- setprop("/instrumentation/ilec-sc7/average-sign",math.sgn(average30));
- if (debug_enabled) print (" average ",average30);
- settimer(averager, 1); # update rate
- }
-
+var probe = TotalEnergyProbe.new();
- var tvario = {
- new: func {return {parents:[tvario]};},
- state:{previous:,current:},
- init: func {state.previous=state.new(); state.current=state.new();},
- update:func {
- if (debug_enabled) print("\nUpdating TEV:");
- state.current = update_state();
- if (debug_enabled) {
- s_dump(state.current);
- s_dump(state.previous);
- }
- var delta_t = get_delta(state.current.timestamp, state.previous.timestamp);
- # TE reading = (h2-h1)/t + (v2^2 - v1^2) / 19.62*t
- if (debug_enabled) print("delta_t:",delta_t);
- var uncompensated = get_delta(state.current.altitude_m,state.previous.altitude_m) / delta_t;
- if (debug_enabled) print(" uncompensated:",uncompensated);
- var adjustment = get_delta(square(state.current.airspeed_mps),square(state.previous.airspeed_mps)) / (19.62 * delta_t);
- if (debug_enabled) print(" adjustment:",adjustment,"\n");
- var te_reading = uncompensated + adjustment;
- if (debug_enabled) print (" te_reading:",te_reading);
-
- te_needle = getprop("/instrumentation/ilec-sc7/te-reading-mps");
- var filter = 0.01 + 0.02 * getprop("/instrumentation/ilec-sc7/sensitivity");
- setprop("/instrumentation/ilec-sc7/filter",filter);
+var sc7_needle = Dampener.new(
+ input: probe,
+ dampening: 3,
+ on_update: update_prop("/instrumentation/ilec-sc7/te-reading-mps"));
- te_needle = te_needle * (1-filter) + filter * te_reading;
- setprop("/instrumentation/ilec-sc7/te-reading-mps",te_needle);
- setprop("/instrumentation/ilec-sc7/te-reading-neg",-te_needle);
- state.previous = state.current; # save current state for next call
- settimer(func me.update(), 1/20); # update rate
- }
- };
+var extra_needle = Dampener.new(
+ input: probe,
+ dampening: 2.7,
+ on_update: update_prop("/instrumentation/variometer/te-reading-mps"));
- var tv = tvario.new();
- tv.init();
- tv.update();
- push30();
- averager();
-
+var averager = Averager.new(
+ input: probe,
+ buffer_size: 25);
+
+var battery_level = { output: 9.9 };
+
+var temperature = PropertyReader.new(
+ property: "environment/temperature-degc",
+ scale: 0.1);
+
+var lcd_controller = InputSwitcher.new(
+ inputs: [battery_level, averager, temperature],
+ active_input: 1,
+ on_update: update_lcd_props);
+
+# Subscribe property listeners for instrument switches
+setlistener("instrumentation/ilec-sc7/mode",
+ func(n) { lcd_controller.select_input(n.getValue()) }, 0, 0);
+
+setlistener("instrumentation/ilec-sc7/sensitivity",
+ func(n) { sc7_needle.dampening = n.getValue() }, 0, 0);
+
+# Wrap everything together into an instrument
+var fast_instruments = Instrument.new(
+ update_period: 0,
+ components: [probe, sc7_needle, extra_needle],
+ enable: 1);
+
+var slow_instruments = Instrument.new(
+ update_period: 1,
+ components: [averager, temperature, lcd_controller],
+ enable: 1);
diff --git a/Aircraft/Instruments-3d/glider/vario/ilec-sc7/ilec-sc7.xml b/Aircraft/Instruments-3d/glider/vario/ilec-sc7/ilec-sc7.xml
index 912534b23..135656d9a 100644
--- a/Aircraft/Instruments-3d/glider/vario/ilec-sc7/ilec-sc7.xml
+++ b/Aircraft/Instruments-3d/glider/vario/ilec-sc7/ilec-sc7.xml
@@ -11,7 +11,7 @@
decimals-digit
units-digit
sign-digit
- dot-digit
+ dot-digit
0.028
0.014
@@ -19,14 +19,14 @@
systems/electrical/outputs/instrument-lights
-
+
rotate
Needle
/instrumentation/ilec-sc7/te-reading-mps
-
+
-5-119.713
0.0 0.0
5119.7135
@@ -42,9 +42,9 @@
0
-
+
-
+
rotate
mc-cready
@@ -61,7 +61,7 @@
0
-
+
pick
mc-cready
@@ -80,7 +80,7 @@
-
+
pick
mc-cready
@@ -99,9 +99,9 @@
-
+
-
+
rotate
vol-knob
@@ -118,7 +118,7 @@
0
-
+
pick
vol-knob
@@ -137,7 +137,7 @@
-
+
pick
vol-knob
@@ -156,9 +156,9 @@
-
+
-
+
rotate
audio-switch
@@ -179,191 +179,191 @@
0
-
+
pick
incr-audio
-
+
property-adjust
instrumentation/ilec-sc7/audio
1
0
2
- false
-
+ false
+
-
-
+
+
pick
decr-audio
-
+
property-adjust
instrumentation/ilec-sc7/audio
-1
0
2
- false
-
+ false
+
-
-
-
-
-
- rotate
- mode-switch
- instrumentation/ilec-sc7/mode
-
- 0-30
- 1.00
- 2.030
-
-
- 0.001
- 0.025
- -0.013
-
-
- 0
- -1
- 0
-
-
-
-
- pick
- incr-mode
-
-
-
- property-adjust
- instrumentation/ilec-sc7/mode
- 1
- 0
- 2
- false
-
-
-
-
-
- pick
- decr-mode
-
-
-
- property-adjust
- instrumentation/ilec-sc7/mode
- -1
- 0
- 2
- false
-
-
-
-
-
-
-
- rotate
- sens-switch
- instrumentation/ilec-sc7/sensitivity
-
- 0-30
- 1.030
-
-
- 0.001
- 0.003
- -0.031
-
-
- 0
- -1
- 0
-
-
-
-
- pick
- incr-sens
-
-
-
- property-adjust
- instrumentation/ilec-sc7/sensitivity
- 1
- 0
- 1
- false
-
-
-
-
-
- pick
- decr-sens
-
-
-
- property-adjust
- instrumentation/ilec-sc7/sensitivity
- -1
- 0
- 1
- false
-
-
-
-
-
-
-
- textranslate
- decimals-digit
- instrumentation/ilec-sc7/average
- 1
- 0.1
- 0.005
-
- 1
- 0
- 0
-
-
- textranslate
- units-digit
- instrumentation/ilec-sc7/average
- 0.1
- 1
- 0.005
-
- 1
- 0
- 0
-
-
-
-
- textranslate
- sign-digit
- instrumentation/ilec-sc7/average-sign
- 0.1
- 1
- 0.005
-
- 1
- 0
- 0
-
-
+
+
+
+ rotate
+ mode-switch
+ instrumentation/ilec-sc7/mode
+
+ 0-30
+ 1.00
+ 2.030
+
+
+ 0.001
+ 0.025
+ -0.013
+
+
+ 0
+ -1
+ 0
+
+
+
+
+ pick
+ incr-mode
+
+
+
+ property-adjust
+ instrumentation/ilec-sc7/mode
+ 1
+ 0
+ 2
+ false
+
+
+
+
+
+ pick
+ decr-mode
+
+
+
+ property-adjust
+ instrumentation/ilec-sc7/mode
+ -1
+ 0
+ 2
+ false
+
+
+
+
+
+
+
+ rotate
+ sens-switch
+ instrumentation/ilec-sc7/sensitivity
+
+ 130
+ 3-30
+
+
+ 0.001
+ 0.003
+ -0.031
+
+
+ 0
+ -1
+ 0
+
+
+
+
+ pick
+ decr-sens
+
+
+
+ property-adjust
+ instrumentation/ilec-sc7/sensitivity
+ 3
+ 1
+ 3
+ false
+
+
+
+
+
+ pick
+ incr-sens
+
+
+
+ property-adjust
+ instrumentation/ilec-sc7/sensitivity
+ -3
+ 1
+ 3
+ false
+
+
+
+
+
+
+
+ textranslate
+ decimals-digit
+ instrumentation/ilec-sc7/lcd-digits-abs
+ 1
+ 0.1
+ 0.005
+
+ 1
+ 0
+ 0
+
+
+
+
+ textranslate
+ units-digit
+ instrumentation/ilec-sc7/lcd-digits-abs
+ 0.1
+ 1
+ 0.005
+
+ 1
+ 0
+ 0
+
+
+
+
+ textranslate
+ sign-digit
+ instrumentation/ilec-sc7/lcd-digits-sgn
+ 0.1
+ 1
+ 0.005
+
+ 1
+ 0
+ 0
+
+