Battery Weirdness

Help creating logic scripts for Air Manager Instruments

Moderators: russ, Ralph

Post Reply
Message
Author
User avatar
skymed
Posts: 46
Joined: Thu Mar 26, 2020 6:29 pm
Location: East Coast, Canada.

Battery Weirdness

#1 Post by skymed »

Folks Hi, I'm learning the gauge programming and just running a couple tests to see what happens when I turn the power off. Seems to work fine when I rubn the gauge as long as the avionics battery and alternators (B58) are on ( bus voltage), but if I turn the alternators off and leave the battery on I get a constant stream of the print "power on". Then if I turn everything off and turn the alternator on, start the gauge then turn the battery on I get a constant stream of power on.

SHouldn't I just get a single power on or power off print instead of a constant stream?

Guidance appreciated.

- Functions --
function test_power (bus_volts,avionics)

if bus_volts[1]>12 and avionics == 1 then


print ("power on")

else

print ("power off")


end

end

xpl_dataref_subscribe( "sim/cockpit2/electrical/bus_volts", "FLOAT[6]", "sim/cockpit/electrical/avionics_on", "INT", test_power)

SimPassion
Posts: 5338
Joined: Thu Jul 27, 2017 12:22 am

Re: Battery Weirdness

#2 Post by SimPassion »

When a value is varying in real time like here the bus_volts, the subscribe statement trigger the defined function,
even if the avionics_on don't change, this because the subscribe is made with two datarefs at the same time in one statement
a way is to make two different subscribe ...

Gilles

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Battery Weirdness

#3 Post by Sling »

skymed,

If you only want it to do the prints once on the first change, you can do something like this.

Code: Select all



- Functions --
function test_power (bus_volts,avionics)

    power_state = bus_volts[1]>12 and avionics == 1
    If power_state_last == nil then power_state_last = not power_state end
    
    If power_state ~= power_state_last then

        If power_state then

            print ("power on")

        else

            print ("power off")

        end
    end

    power_state_last = power_state
end

xpl_dataref_subscribe("sim/cockpit2/electrical/bus_volts", "FLOAT[6]",
                                   "sim/cockpit/electrical/avionics_on", "INT", test_power)

User avatar
skymed
Posts: 46
Joined: Thu Mar 26, 2020 6:29 pm
Location: East Coast, Canada.

Re: Battery Weirdness

#4 Post by skymed »

Cheers Tony thanks

Post Reply