Jump to content
The simFlight Network Forums

Recommended Posts

Posted

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?

Posted

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

Posted

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.

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.