Jump to content
The simFlight Network Forums

Recommended Posts

Posted

Dear Mr Dowson,

I have written this small Lua, and allthough it does work, I would like to know if I did it in the correct way.

It would not be the first time I get something working in a completely wrong or too complicated way.......

This is supposed to handle GoFlight Led's when Aircraft doors are opened or closed, APU is started or stopped, APU generator is activated or de-activated.

______________________________________________________________________________________________________________________

function Doors(off, val)

if logic.And(val, 1) ==1 then --Opening Doors (Offset 3367/ size1/ read only)

gfd.SetLight(GFP8, 1, 0) --Door Led on

else

gfd.ClearLight(GFP8, 1, 0)

end

end

function ApuStart(off, val)

if logic.And(val, 99) >=99 then -- When RPM is at 99% or more (Offset 0B54/ size4/ read only)

gfd.SetLight(GFT8, 0, 0) --Apu Led on

else

gfd.ClearLight(GFT8, 0, 0)

end

end

function ApuGen (off,val)

if logic.And(val,1) ==1 then --When Generator is activated (Offset 0B52/ size1/read only)

gfd.SetLight(GFT8, 0, 1) --Gen Led on

else

gfd.ClearLight(GFT8, 0, 1)

end

end

event.offset(0x3367, "UB", "Doors") --Doors Check

event.offset(0x0B54, "FLT", "ApuStart") --Apu Starter

event.offset(0x0B52, "UB", "ApuGen") --Apu Generator Active?

______________________________________________________________________________________________________________________

Thanks,

Jackson

Posted

if logic.And(val, 99) >=99 then -- When RPM is at 99% or more (Offset 0B54/ size4/ read only)

All okay except for that line. The "AND" function logically ANDs two binary values -- in your case one is 99 (0x63 or binary 0110 0011). If the value was 100 (say), or x64, binary 0110 0100 then ANDing it with 0110 0011 gives 0110 0000 which is actually LESS than 99!

AND gives a 1 where both values contain a 1, else a 0, see:

0 1 1 0 0 0 1 1 = 99

0 1 1 0 0 1 0 0 = 100

--------------------

0 1 1 0 0 0 0 0 = 96

You use logical functions to extract and testor toggle bits. But arithmetic values you just use values! i.e

if val >=99 then -- When RPM is at 99% or more (Offset 0B54/ size4/ read only)

Pete

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.