DEN19 Posted May 21, 2015 Report Share Posted May 21, 2015 I am trying to set an annunciator for the oil pressure so that it lights up if the pressure is below a certain value, goes off if it is above, but does not come on at all if the battery is off. The code I have is : - w7 = wnd.open("Oil", WND_FIXED, -48,160,45,50) wnd.font(w7, WND_ARIAL, 10.0, WND_BOLD) --Font, Size, Properties function oil(off,val) if val > 5000.0 then wnd.backcol(w7, 0x400) --Set off wnd.textcol(w7, 0x000) wnd.clear(w7) wnd.text(w7, "\n\n\ Oil") else if ipc.readUD(0x281C) ~= 1 then -- battery is off wnd.backcol(w7, 0xfff) --Set off wnd.textcol(w7, 0x000) wnd.clear(w7) wnd.text(w7, "\n\n\ Oil") else wnd.backcol(w7, 0xF20) --Set on wnd.textcol(w7, 0x000) wnd.clear(w7) wnd.text(w7, "\n\n\ Oil") end end end event.offset(0x08BA, "UW", "oil") It seems to work OK sometimes but not others and I cannot see why. From C & D it lights up the correct colour, switch batt on- right colour, start engine - right colour, stop engine right colour, batt off right colour sometimes, batt back on right colour sometimes only. Note colours are only for test purpose, when working the fff colour will be changed to the correct one. I set it to white for the test only. I must have something wrong in the logic, but can't see what. Can anyone point it out to me please? Link to comment Share on other sites More sharing options...
Paul Henty Posted May 21, 2015 Report Share Posted May 21, 2015 The way you have it, the oil function only runs when the oil changes pressure changes. From your description you're getting inconstant results when turning the battery on and off. Unless the oil pressure happens to be changing at the same time the oil function will not run. You could try changing the oil function to read the oil pressure using a direct ipc.read call (rather than using the value passed in by the event handler). Then create another event to call this new oil function on the battery offset (281C). This way the annunciator will update immediately when the oil pressure or the battery state changes. Paul Link to comment Share on other sites More sharing options...
DEN19 Posted May 22, 2015 Author Report Share Posted May 22, 2015 Thank you Paul. I couldn't figure out why it was so unrepeatable, but your explanation makes it clear now! I will have another look at it later. Link to comment Share on other sites More sharing options...
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