That ‘Code’ section in the LS4 model XML (I wrote it) is doing TWO things:
(1) it does a real-time calculation in the model XML to UPDATE a variable called L:B21_TE_MS which contains the Total Energy (m/s) reading for the current update cycle. This TE value is smoothed over approximately 1 second and capped at +/- 10 meters per second, both of which are necessary in the sim to act as a gust filter and also smooth out digital hiccups in the data coming from MSFS. But that L:B21_TE_MS reading is designed to be as responsive as necessary and generally useful in any gauge (there is a lot of stuff in the LS4/AS33 instruments that uses the TE value).
(2) The code section then READS a completely separate variable L:B21_BASIC_VARIO_NEEDLE which is being produced in the HTML/JS code 0…100 to animate the instrument needle, so that animation effectively throws away the L:B21_TE_MS value after it produces it.
Of course the HTML/JS gauge code for the vario is READING the L:B21_TE_MS variable, deciding what to do with it, and generating the 0…100 value in the L:B21_BASIC_VARIO_NEEDLE which the model XML is using to move the needle.
This technique means
(a) a total energy reading is being produced for the plane so all the gauge code can use it, and for various technical reasons this calculation HAS to be in the model XML as the html/js code doesn’t have the same millisecond-accurate real-time connection to the sim.
(b) Any gauge can read the L:B21_TE_MS value, and calculate some adjustment from it before it creates its animation value, e.g. in the LS4 the data going into the Netto gauge is slowed down slightly so the responsiveness is slower than the Computer Vario (and also it is calculating the amount to subtract for the glider polar before animating the needle). The Computer Vario can be given its own response rate, and also sending the TE data to the html/js code and then sending the animation data back to the gauge allows the needle to be easily flipped between the TE and the Speed to Fly reading.
In another aircraft, for the simplest code possible, the L:B21_TE_MS value (-10…+10) could be used to directly animate the gauge needle (e.g. for 0…100 just multiply by 5 and add 50.).
The code above is completely open source and works for any glider (luckily, the formula for TE doesn’t include the weight of the glider or any other unique parameter) so it’s a cut-and-paste freely available to use.
B21.