Jump to content
The simFlight Network Forums

Recommended Posts

Posted

Hi,

 

I'd like to write a watchdog for the PMDG NGX center fuel tank pumps that turns them off once the "low press" annunciation comes on. The pump check shall start when a certain button on a controller is pressed.

 

I do know all the required offsets and controls I need in order to achieve this and have the function start at a controller's button press, but I am unsure as to how this might be realized best in LUA code.

 

I was thinking about a simple loop that checks for the respective condition every 10 seconds or so, basically:

 

function start_pump_check()

  while (condition not met) do

     -- get data

      if (data meets condition) then

         -- turn pumps off

         break

       end

       ipc.sleep(10000)

  end

end

 

However, I wonder if there is any better alternative or any best practice on how to handle such things.

Any hints?

 

Thank you

 

bpcw001

Posted

I'd like to write a watchdog for the PMDG NGX center fuel tank pumps that turns them off once the "low press" annunciation comes on. The pump check shall start when a certain button on a controller is pressed.

 

I do know all the required offsets and controls I need in order to achieve this and have the function start at a controller's button press, but I am unsure as to how this might be realized best in LUA code.

 

I was thinking about a simple loop that checks for the respective condition every 10 seconds or so, basically:

 

What is actually calling your "start_pump_check" function?

 

Much better and more efficient than a loop, you should use event.offset for the offset(s) you are monitoring, and have that call the function. It provides the offset address and current value as parameters, so the code becomes very lean.

 

For intermittent events for which where is no specific event function, you would use event.timer (with, for instance, 10000 for 10 seconds) to cal a function at intervals. But that wouldn't apply for this case if you are monitoring offsets.

 

Pete

Posted

Hallo Pete,

 

thanks for your reply. The start_pump_check () function is called as follows:

 

In file NGX.lua

 

if ipcPARAM == 13 then

   start_pump_check ()

end

 

NGX lua with param 13 is assigned to a controller button press.

 

Seems like event.offset() is the way to go.

I knew that there had to be a better way :smile:

 

Based on how the event.offset() works (being active when the plugin loads, thus executing the event handlers right away if events are fired), I'd have to add some logic to only do something when I actually want the watchdog to run, since I don't want to have it start automatically on plugin loading, but only on controller button press.

 

Thanks

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
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.