bpcw001 Posted March 22, 2016 Report Posted March 22, 2016 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
Pete Dowson Posted March 22, 2016 Report Posted March 22, 2016 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
bpcw001 Posted March 22, 2016 Author Report Posted March 22, 2016 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now