Jump to content
Sign in to follow this  
Damlimey

Monitoring Vs Reacting?

Recommended Posts

Hi all,

My question is this; is a LINDA actions file purely reacting to a change in a switch condition when it happens or, is LINDA monitoring the actions file repeatedly looking for a change in status?

I ask this because as I am building up my code for various switches and knobs on my panels, all is going well but where I am looking for LINDA to react to a change in a variable (say, 0x1264, TOTAL FUEL QUANTITY) it seems only to react to a change in that variable (i.e. quantity less than 30 gallons) if the code is embedded in a switch function.

What I am looking for is a way of placing the code that monitors the status of the variable constantly so LINDA detects the change in real time and not just on the prompt of a switch.

Is there a place where this sort of code can be placed so that LINDA checks it regularly or, is there something other than a 'function' call that I could use?

Otherwise, totally happy camper!

Thanks in advance,

G

Share this post


Link to post
Share on other sites

LINDA primarily waits for button presses and releases before calling the assigned functions. LINDA is also timer driven to monitor and display certain parameters for the likes of the MCP panels. A few of basic offsets are monitored and reacted to using event.offset().

There is a user timer that allows you to place repetitive code in user.lua to carry out he operation you describe. Alternatively, you can set up a event.offset(0x1264, "TotalFuel"). As far as resolution of the parameters are concerned you need to look up the FSUIPC Offset PDF in /modules/fsuipc documents.


Andrew Gransden

Scotland, UK

LINDA Support/Developer - VATSIM and BAVirtual - Airbus Flyer

i7 1TB SSD GTX980 - FSX/P3D - Aerosoft Airbus A318/A319/A320/A321 - FS2Crew

Share this post


Link to post
Share on other sites

Okay, so would a piece of code looking like this, placed in the user.lua file do the trick?

event.offset()

if ipc.readUD(0x1264)<=30
then
fuelwb=sound.playloop("Warning_Fuel_Tone")

end

Or is that me being too simplistic?

btw, the ipc.read offset does the job under a switch function but like I said, only once when the switch is activated.

Thanks,

G

Share this post


Link to post
Share on other sites

It can be that simply. However, you need to separate the event.offset and the code call. There are examples in the common.lua and various aircraft action.lua files.

I would however recommend that you user the built in user timer LibUserTime1Hz to repetitively call you fuel warning tone function in the aircraft's user.lua file. Setting up the event.offset requires some deep modification of the main LINDA LUA code (not recommended) or creating your initialisation code and calling it once when you first load the aircraft. 

 


Andrew Gransden

Scotland, UK

LINDA Support/Developer - VATSIM and BAVirtual - Airbus Flyer

i7 1TB SSD GTX980 - FSX/P3D - Aerosoft Airbus A318/A319/A320/A321 - FS2Crew

Share this post


Link to post
Share on other sites

I apologise for how clumsy this must look and it doesn't work but am I close? (In the .user file)...

function Init ()
LibUserTime1Hz=chkf
function checkfuel()
chkf=ipc.readUD(0x1264)
if chkf<=30
then
fuelwa=sound.play("Warning_Fuel")
fuelwb=sound.playloop("Warning_Fuel_Tone")
sound.adjust(fuelwa,-25)
sound.adjust(fuelwb,-25)
end
end
end

Share this post


Link to post
Share on other sites

You cannot define your own init() as this will prevent LINDA initialising correctly. I would leave this out.

You need to define LibUserTimer1Hz in your user.lua file as:

function LibUserTimer1Hz()

checkfuel()

end

Then use your checkfuel function without all the ends.

I cannot code for you. From past experience try it and see.

Edited by ScotFlieger

Andrew Gransden

Scotland, UK

LINDA Support/Developer - VATSIM and BAVirtual - Airbus Flyer

i7 1TB SSD GTX980 - FSX/P3D - Aerosoft Airbus A318/A319/A320/A321 - FS2Crew

Share this post


Link to post
Share on other sites

Thanks ScotFlieger, I'll pursue this and no, I won't benefit from having someone code for me but a little coaching, like this, goes a long way.

Thanks again,

G

Share this post


Link to post
Share on other sites

This was how I did it, using FSUIPC4 to autoload the lua file:

function fuelcheckAll ()

fuelcheck1 ()
fuelcheck2 ()
fuelcheck3 ()
fuelcheck4 ()

end

function fuelcheck1 (TankEng1)

i = ipc.readLvar("L:TankEng1")
n = ipc.readLvar("L:Eng1FuelCutOffSwitch")

if (0 < i and i <= 35) and (n==1)
then
alarm_enable ()
else
end
end
event.Lvar("L:TankEng1", 60000, "fuelcheck1")

function fuelcheck2 (TankEng2)

i = ipc.readLvar("L:TankEng2")
n = ipc.readLvar("L:Eng2FuelCutOffSwitch")

if (0 < i and i <= 35) and (n==1)
then
alarm_enable ()
else
end
end
event.Lvar("L:TankEng2", 60000, "fuelcheck2")

function fuelcheck3 (TankEng3)

i = ipc.readLvar("L:TankEng3")
n = ipc.readLvar("L:Eng3FuelCutOffSwitch")

if (0 < i and i <= 35) and (n==1)
then
alarm_enable ()
else
end
end
event.Lvar("L:TankEng3", 60000, "fuelcheck3")

function fuelcheck4 (TankEng4)

i = ipc.readLvar("L:TankEng4")
n = ipc.readLvar("L:Eng4FuelCutOffSwitch")

if (0 < i and i <= 35) and (n==1)
then
alarm_enable ()
else
end
end
event.Lvar("L:TankEng4", 60000, "fuelcheck4")

function alarm_enable ()

n=ipc.readLvar("L:GearHornSwitch")

if n==1 then
alarmf=sound.play("STALLHRN")
sound.adjust(alarmf, 100)
else
end
end

Share this post


Link to post
Share on other sites

Hi Masterius,

Thanks for this. I sort of boiled it down to suit my ship, which has only one tank and engine and tried to compensate for your Lvars with those that you will see herein.

LINDA doesn't like the event.Lvar line claiming that the Lvar is a nil value.

This is how I ended up, it's apprent that I'm missing something somewhere else but obviously, I don't know what it is:

function fuelcheckAll ()
fuelcheck ()
end

function fuelcheck ()
i = ipc.readLvar("L:FUEL TOTAL QUANTITY")
n = ipc.readLvar("L:FUEL VALVE ENG1")
if(0 < i and i <=30)
then
alarm_enable ()
else
end
end
event.Lvar("L:FUEL TOTAL QUANTITY", 1000, "fuelcheck")

function alarm_enable ()
if n==1 then
fuelwb=sound.play("Warning_Fuel_Tone")
sound.adjust(fuelwb, -100)
else
end
end

My previous approach was this:

function LibUserTime10Hz ()
checkfuel ()
end
function checkfuel ()
if ipc.readUD(0x1264) <=30 then
fuelwb=sound.playloop("Warning_Fuel_Tone")
sound.adjust(fuelwb,-100)
end
end

That didn't work either but I do know that the ipc.readUD... line works if I place the function under a switch such as the master battery. I think my understanding of 'event' calls is very primitive.

Thank you for your help so far,

G

Share this post


Link to post
Share on other sites
6 hours ago, Damlimey said:

function alarm_enable ()
if n==1 then
fuelwb=sound.play("Warning_Fuel_Tone")

Not sure if this is the only error, but you haven't set the "n" variable in the alarm_enable function. You really don't need that variable unless you want to use an aircraft switch to enable/disable the alarm. I used the gear horn as that wasn't actually used in the A2A B-17. Not sure if you have any handy spare switches.

Also, you probably need to autoload/run the function/script during sim initialization. I did so using FSUIPC4, but I'm sure there is a way of doing so with LINDA. I'm just not sure how to do that.

 

 

 

Edited by Masterius

Share this post


Link to post
Share on other sites

Hi all,

Success! Of sorts... I have taken on board guidence from ScottFlieger and example code from Masterius and came up with this, which works albeit on a basic level:

function LibUserTimer1Hz()
ipc.sleep(5000)
fuelcheck ()
end

function fuelcheck ()
i = ipc.readUD(0x1264)
if (i <=30)
then
fuelwb=sound.play("Warning_Fuel_Tone")
sound.adjust(fuelwb, -100)
--alarm_enable ()
else
end
end
event.offset(0x1264, "UD", "fuelcheck")

I will build on this and I am grateful to you both for your time.

Many thanks,

G

Edited by Damlimey

Share this post


Link to post
Share on other sites
On 10/6/2019 at 4:51 AM, Damlimey said:

I will build on this and I am grateful to you both for your time.

Many thanks,

You're very welcome! Hope you continue having fun with both LINDA and flight sims!

 

~Al

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...