I'm trying to create a simple ammeter gauge for GA aircraft that will work in MSFS2020. I'm using Hannes Schulten's Bombardier Ammeter gauge from the online store as a template since it's the same style (center-zero) as the one in the C172 I fly. The gauge should operate like the one in this instructional video (https://www.youtube.com/watch?v=Eg5o7MKCeTs).
However, I'm running into a couple of issues.
1) The default gauge behavior is odd in that it only seems to produce values of -32, 32, or 28 depending on different combinations of master battery and alternator states. The gauge should produce a floating integer on the full continuum between -30 and 30, and not just 3 static, pre-determined values. My basic understanding is that the gauge should indicate the numerical result of the following equation: amps produced by the alternator - amps discharged by the battery (e.g., an alternator producing 30 amps - the battery discharging at 28 amps = 2 amps; a slight charge to the battery as in normal flight).
Questions:
A) Am I thinking about this totally wrong?
B) If not, how would the formula be coded?
2) I also have a hardware LED light on the panel that should light up whenever the ammeter indicates a discharge state of 5 or more amps (i.e., when the result of the equation is less than or equal to -5 amps). It's not really a "low volt" light in this case. It indicates when the aircraft's electrical supply is primarily being supplied by the battery (i.e., alternator failure).
Question:
A) How would this "If" statement be coded within the function?
Here's the code I'm running:
Code: Select all
img_add_fullscreen("background.png")
pointer = img_add("pointer.png", 48, 140, 400, 400)
rotate(pointer, 90)
rotate(pointer, 122)
rotate(pointer, 57)
function new_amp (pamp)
amp = pamp
amp = 122 - (65 * ((amp + 30)/60))
amp = var_cap(amp, 55, 110)
rotate(pointer, amp)
end
fs2020_variable_subscribe("ELECTRICAL GENALT BUS AMPS:1","Amperes", new_amp)
fs2020_variable_subscribe("ELECTRICAL BATTERY BUS AMPS", "Amperes", new_amp)
---------------------------------------------
-- Controls Add --
---------------------------------------------
hw_led_id = hw_led_add("Ammeter Light", 0.25)