Jump to content
The simFlight Network Forums

LUA Script goflight-project magenta


Recommended Posts

Hi i need some help...

im just in the beginning to learn this...

my problem is to light the leds on my GFRP48 Unit when programming in FSUIPC to project magenta software...

i could with help from here make it work with FSX original Ap and make a led light with this script!!

function set_ap(offset, value)

if value ~= 0 then

gfd.SetLight(GFRP48, 0, 7)

else

gfd.ClearLight(GFRP48, 0, 7)

end

end

event.offset(0x07BC, "UD", "set_ap")

but how should i do when i want to use project magenta MCP software... i read that the offset is 04F0 but i cant get it to work... and how can i know the function name like Set_ap in this case?

thoes anyone knows how to write script for project magenta MCP and make my GFRP48 light?

Regards:Tommy

Link to comment
Share on other sites

but how should i do when i want to use project magenta MCP software... i read that the offset is 04F0 but i cant get it to work.

Did you read the details for PM offset 04F0? To start with it says it is 2 bytes. 2 x 8 = 16 bits, or in other words a "WORD", so the type is 'UW'.

Second, the A/P indication in 04F0 are separate bits, one for each of up to 3 autopilots (for Boeing) or 2 (Airbus). So you need to say which you want to "light the LED" for.

You would need to test just those bits, so you'd need to use the logic library to AND the bits out for testing. For example, the test for any set of the three Boeing A/P bits would be:

if logic.And(value, 0x2003) ~= 0 then

The value 0x2003 is simply the bits 13 (0x2000), 1 (0x0002) and 0 (0x0001) mixed together. You could just test each separately if you wanted.

If you don't understand binary bits, and hexadecimal representation, please see my FAQ subforum., the thread "About bits ...."

and how can i know the function name like Set_ap in this case?

You "know" it because you choose the name yourself. It's just a name. Call it "MyLovelyLEDlights" if you like. Use something meaningful so you'll know next time what you did. Just use letters and number, starting with a letter. So you could call it X1243578 if you wanted, though that wouldn't be very helpful to understanding it.

thoes anyone knows how to write script for project magenta MCP and make my GFRP48 light?

Yes, you must do now! ;-) You have all of the elements, except maybe one more to note:

The function you name in the event.offset line is only called when the offset contents CHANGES. If it does not change nothing happens. That's the whole point of events -- an "event" is something happening, something changing. If you want to initialise the LED to some initially loaded value from the offset you need also to add to the plugin a line to call the function explicitly, like:

set_ap( 0x04F0, ipc.readUW(0x04F0))

All this line is doing is making your function operate according to the initial value read from the offset.

[Note here that this is such a common need that I am now seriously considering making the initial function call automatic. This should save a lot of this confusion].

Regards

Pete

Link to comment
Share on other sites

Hi Pete!!

thank you very much for answer!!

but if u have time.. can u explain some things?

i didnt catch this!!

You would need to test just those bits, so you'd need to use the logic library to AND the bits out for testing. For example, the test for any set of the three Boeing A/P bits would be:

if logic.And(value, 0x2003) ~= 0 then

The value 0x2003 is simple the bits 13 (0x2000), 1 (0x0002) and 0 (0x0001) mixed together. You could just test each separately if you wanted.

If you don't understand binary bits, and hexadecimal representation, please see my FAQ subforum., the thread "About bits ...."

why 0X0203?? i cant figure out how i can get bit 13? why cant i write 0x1101 i just dont understand this right now.. i read your faq but i still dont understand 0x0203 but i will

think of it all day!! :blink: :grin:

and another thing.. how can i get bit 0 as project magenta have for left ap on mcp??

regards:Tommy

Link to comment
Share on other sites

why 0X0203?

Sorry, it is bit 13, not bit 9, so it should be 0x2003 -- typo. I edited my original now to avoid confusion again. (It was late last night!)

i cant figure out how i can get bit 13? why cant i write 0x1101 i just dont understand this right now.. i read your faq but i still dont understand 0x0203 but i will

The BINARY number 1101 is decimal 13 or hexadecimal 0x000D. Your 0x1101 is 4096+256+1 = 4353 in decimal!

You've obviously confused BINARY (where you only get 1's and 0's) and hexadecimal, where you get 0 to 9 the A B C D E F representing 10-15 decimal!

Bit 13 is the 14th bit from the bottom end, the bit 0 meaning '1'. Look at 0x2003 in BINARY:

0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 1

This has bits 13, 1 and 0 set. Count them yourself, starting from 0 at the end. The first, or "top" bit is bit 15 -- it is a 16-bit value.

and another thing.. how can i get bit 0 as project magenta have for left ap on mcp??

Bit 0 is just 1 (0x0001). It is included in the value 0x2003 as you can see above.

Please read the FAQ again!

Bit 0 means "2 to the power 0" which = 1.

Bit 1 is "2 to the power 1" = 2 x 1 = 2

Bit 2 is "2 to the power 2" which is "2 squared" which is 2 x 2 x 1 = 4

etc.

It's all about multiplying by 2. Computers are that simple. They aren't really as clever as you, who I assume uses decimal. Binary ias simple, in only contains 1's and 0's, not 10 different digits like decimal.

Hexadecimal is just a convention we use to shorten numbers like

0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 1

to 2 0 0 3, by representing each group of 4 bits by one digit, 0-9 then A-F (16 digits because 4 bits holds decimal 0-15. 2 to the power 4 = 2 x 2 x 2 x 2 x 1 = 16).

Sorry if my typo was the source of your confusion.

Regards

Pete

Link to comment
Share on other sites

Hi..

okioki... i am a little confused but i start to understand now...

i made an examle from what u have written to me now but it doesent really work as it should... i know i write something wrong but here is what i write

function set_apRight(offset, value)

if logic.And(value, 0x2003) ~= 0 then

gfd.SetLight(GFRP48, 0, 5)

else

gfd.ClearLight(GFRP48, 0, 5)

end

end

set_apRight( 0x04F0, ipc.readUW(0x04F0))

i get a led to light but on buttom 4 instead of 5 as i write...

and is it correct that i can write just 0x2000 to get bit 13 (you just took 2003 because 3 is for the other AP.. left and center?) is that correct?

can u write an example if you got time and not to tired of me.. let say i want to have L AP (PM) and let say buttom 5 led? on GFRP48

cause after that maybye i can figure out how to do the rest..

anyway.. thanks for taking time...

Regards:Tommy

Link to comment
Share on other sites

i made an examle from what u have written to me now but it doesent really work as it should... i know i write something wrong but here is what i write

function set_apRight(offset, value)

if logic.And(value, 0x2003) ~= 0 then

gfd.SetLight(GFRP48, 0, 5)

else

gfd.ClearLight(GFRP48, 0, 5)

end

end

set_apRight( 0x04F0, ipc.readUW(0x04F0))

You've called it "apRight" but you are testing for all three Autopilots (0x2003). Is that what you want?

i get a led to light but on buttom 4 instead of 5 as i write...

Sorry, I don't know off-hand how the RP48 LEDs are numbered. When I had some GF stuff connected I had to find button and LED numbers by trial and error. You'll probably have to do the same.

and is it correct that i can write just 0x2000 to get bit 13 (you just took 2003 because 3 is for the other AP.. left and center?) is that correct?

Yes. But if you want 3 LEDs from the same offset you would be best treating them all in the same function, so:

function set_apAll(offset, value)
   -- Right
   if logic.And(value, 0x2000) ~= 0 then
  	gfd.SetLight(GFRP48, 0, 5)
  else
 	gfd.ClearLight(GFRP48, 0, 5)
  end

   -- Centre
   if logic.And(value, 0x0002) ~= 0 then
  	gfd.SetLight(GFRP48, 0, 6)
  else
 	gfd.ClearLight(GFRP48, 0, 6)
  end

   -- Left
   if logic.And(value, 0x0001) ~= 0 then
  	gfd.SetLight(GFRP48, 0, 7)
  else
 	gfd.ClearLight(GFRP48, 0, 7)
  end

 end

set_apAll( 0x04F0, ipc.readUW(0x04F0))

for setting lights 5,6, and 7

can u write an example if you got time and not to tired of me.. let say i want to have L AP (PM) and let say buttom 5 led? on GFRP48

cause after that maybye i can figure out how to do the rest..

Sorry, you'll need to find out the LED numbers yourself. You can't do any harm, and you can edit and save the Lua file whilst FS is running. You just need to re-run it afterwards (assign a button or keypress in FSUIPC to "Lua " followed by the name of the Lua file (e.g. Lua ipcready). It'll be in the drop-down assignment list).

Regards

Pete

Link to comment
Share on other sites

Wohoow it seems to working better now.. i dont know why...

but still dont know if im doing everything correct.. but i took everyone one by one instead like 2000,0400 etc....

and another question.. i made a script for GFT8 switches because i want the Autothrottle on that... i could program so the light goes on and A/T goes on but i cant take A/T to off because i need that for the LUA script?

any solution?

thank you again.. you really a genius..

Regards:Tommy

Edited by Tarzan737
Link to comment
Share on other sites

and another question.. i made a script for GFT8 switches because i want the Autothrottle on that... i could program so the light goes on and A/T goes on but i cant take A/T to off because i need that for the LUA script?

Sorry, I can't make sense of that question. Can you explain any better please?

Pete

Link to comment
Share on other sites

hmm i can try..

i have the goflight module GFT8 (Toggle switches (on)off

i want to put the swich so Autothrottle goes on.. (no problem in fsuipc) but i need to make one line in fsuipc for Autothrottle ON and the other to OFF

but then i have no place to add the lua script for the light?

hope you understand... if not i can try to put a screenshot or something...

//Tommy

Link to comment
Share on other sites

i want to put the swich so Autothrottle goes on.. (no problem in fsuipc) but i need to make one line in fsuipc for Autothrottle ON and the other to OFF

but then i have no place to add the lua script for the light?

Er ... sorry, that does not make sense. What is the difference in operating the A/T light from the offset to what we've been discussing for the autopilot? I really thought once oyu'd learned to do one LED from an offset you would be able to transfer this to any? If I have to show you how to do every single light and offset I suggest you give up now, because I will not do that. you have to be prepared to learn and try things out, not expect me to do it all for you!

hope you understand... if not i can try to put a screenshot or something...

Do NOT post screenshots please. Just tell me why you cannot adapt everything you should have learned by now to another offset and light? Just add the code to your current file.

Pete

Link to comment
Share on other sites

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.