usafgadget Posted October 19, 2010 Report Posted October 19, 2010 I've trolled the forum for some time now and can't quite seem to find or recognize the answer I'm looking for. My issue is getting the GoFlight modules to fully function; that is the LEDs working with the appropriate switch (GF-T8). My research suggests LUA over GFKeys but I'm not a programmer and I'm a bit overwhelmed at the documentation. I can program the toggle switch through FSUIPC to generate the keystroke for the parking brake, and separately I made a simple lua script to light up an LED but I can't seem to understand how I can combine these two steps into one. I am also not proficient at writing or interpreting code for LUA so I guess I'm asking for someone to through me a little bone showing me the code in LUA to accomplish this. I hope once I can get past that part I can better understand the mechanics enough to figure out other actions. Thanks in advance for your help.
Pete Dowson Posted October 19, 2010 Report Posted October 19, 2010 My issue is getting the GoFlight modules to fully function; that is the LEDs working with the appropriate switch (GF-T8). My research suggests LUA over GFKeys but I'm not a programmer and I'm a bit overwhelmed at the documentation. Sorry, I don't know "GFKeys". But the documentation for the GFD library in the Lua plug-in facility is only just over two pages long, and the commands to light LEDs or extinguish them only amounts to gfd.setLight and gfd.ClearLight, so there really isn't very much to get your head around, surely? I can program the toggle switch through FSUIPC to generate the keystroke for the parking brake Why program a button to send a keystroke when there's a perfectly good parking brake command you can assign? It is always much more efficient to send the commands. All that sending a keystroke does is make FS look up the keystroke assignment and send the control itself, which you could have done directly. It is well worth reviewing the FS controls available to you -- a list of them is installed in the FSUIPC Documents folder, inside the FS Modules folder, for this very purpose. And FSUIPC adds many more, as listed in the Advanced User's guide. ... and separately I made a simple lua script to light up an LED but I can't seem to understand how I can combine these two steps into one. There are two ways to do that. One, possibly the easiest, is simply to call the Lua script as well as send the command or keystroke. You can either do that on the button release (part of the Buttons assignment dialogue) -- so pressing it operates the brake and releasing it changes the LED, or you could edit the FSUIPC INI file to make the double action on the press only. The Lua scripts are all listed in the drop down for control assignments. If you've only ever bothered to look at assigning keystrokes you'd have missed them all. The second and superior way of doing it is to get the LED switching driven by the status of the parking brake rather than you simply operating the switch. Then it reflects the setting on flight reloads or when the brake is operated by mouse or true keystroke. This is done by looking up the FSUIPC offset for the parking brake (for that you need the FSUIPC SDK, in which there's a document listing all of the offsets), and having your LED switching code in a Lua function called by an event.offset command. Such a Lua program would be named "ipcReady.lua" so it got loaded automatically as soon as FS is ready to fly. Have a think about this and a read of the bits I referred you to, again, and come back when you want more. I can do a little example of the last method for you, but show me what you've done yourself first. Regards Pete
usafgadget Posted October 20, 2010 Author Report Posted October 20, 2010 Sorry, I don't know "GFKeys". But the documentation for the GFD library in the Lua plug-in facility is only just over two pages long, and the commands to light LEDs or extinguish them only amounts to gfd.setLight and gfd.ClearLight, so there really isn't very much to get your head around, surely? True that isn't difficult and I figured that out already and wasn't my original point. Why program a button to send a keystroke when there's a perfectly good parking brake command you can assign? It is always much more efficient to send the commands. All that sending a keystroke does is make FS look up the keystroke assignment and send the control itself, which you could have done directly. It is well worth reviewing the FS controls available to you -- a list of them is installed in the FSUIPC Documents folder, inside the FS Modules folder, for this very purpose. And FSUIPC adds many more, as listed in the Advanced User's guide. Again, I am aware of available commands, keystrokes and the like. However my familiarity with FSUIPC is simply not on your level and understanding its nuances isn't going to happen overnight. The Lua scripts are all listed in the drop down for control assignments. If you've only ever bothered to look at assigning keystrokes you'd have missed them all. Ok, now you're being just a bit condescending. I clicked on every imaginable drop down list, tab and button and know what's in front of me. It's putting it to use that I'm having a hard time with. As I've already stated, I am not a programmer and can't digest the example lua files you provided to have them make sense. The second and superior way of doing it is to get the LED switching driven by the status of the parking brake rather than you simply operating the switch. Then it reflects the setting on flight reloads or when the brake is operated by mouse or true keystroke.This is done by looking up the FSUIPC offset for the parking brake (for that you need the FSUIPC SDK, in which there's a document listing all of the offsets), and having your LED switching code in a Lua function called by an event.offset command. Such a Lua program would be named "ipcReady.lua" so it got loaded automatically as soon as FS is ready to fly. Have a think about this and a read of the bits I referred you to, again, and come back when you want more. I can do a little example of the last method for you, but show me what you've done yourself first. I found the appropriate offset (or have I?) as 0BC8. I see that I have to define the function ahead of time (If I read the lua library file correct it's supposed to be function-name(offset, value). The value listed for set is 32768. The event.offset line lists offset (0BC8), type (SW for signed 16 bit word (from offset list showing S16) and the function name (set_brake). Finally the set light command for the GF RP-48) function set_brake(0BC8, 32768) event.offset(0BC8, SW, set_brake) gfd.SetLight (GFRP48, 0, 6) Obviously this does not work and I'm unable to proceed further without help. A correctly written set on instructions for my original task would go a long way in bettering my understanding of the program and it's uses. I look forward to your response. v/r Chris
Pete Dowson Posted October 20, 2010 Report Posted October 20, 2010 I found the appropriate offset (or have I?) as 0BC8. I see that I have to define the function ahead of time (If I read the lua library file correct it's supposed to be function-name(offset, value). The value listed for set is 32768. The event.offset line lists offset (0BC8), type (SW for signed 16 bit word (from offset list showing S16) and the function name (set_brake). Finally the set light command for the GF RP-48) You have the gist of it correct, but you aren't following the syntax correctly. And the offset 0BC8 is correct but the value is 32767 not 32768 -- when doing any sort of "programming" you need to be precise and therefore read carefully. function set_brake(0BC8, 32768) event.offset(0BC8, SW, set_brake) gfd.SetLight (GFRP48, 0, 6) To start with a function is a routine which contains code. In this case the function is set to be CALLED by the event, so the event cannot be inside the function. The end of the code in a function is indicated by "end". Secondly, the contents of the ( ) of the function definition are variables which are given values when the function is called. You do not define them except to give them a name, exactly as shown in the document. Thirdly, all strings (non-numeric strings of characters other than names) must be enclosed in "", otherwise they look like names. Hexadecimal numbers, like the offset 0BC8 need a prefix 0x to tell the system it's hexadecimal. Putting this together with your snippet would look like this: function set_brake(offset, value) if value == 32767 then gfd.SetLight(GFRP48, 0, 6) end end event.offset(0x0BC8, "SW", "set_brake") Of course this is only going to turn the LED on. You need to turn it off in the case that offset 0BC8 is not 32767, so the full code would be: function set_brake(offset, value) if value == 32767 then gfd.SetLight(GFRP48, 0, 6) else gfd.ClearLight(GFRP48, 0, 6) end end event.offset(0x0BC8, "SW", "set_brake") If that works to your satisfaction you can simply add other functions and events to the same Lua to drive the other LEDs. BTW it is worth perusing the example Lua programs provided in the FSUIPC package (alongside the documents -- see the plugins Zip). Even if you are not going to use any of those, it would have shown you some of the things I've mentioned and corrected some of your code quite readily. It is still worth doing so even if you are happy with the above. If you are at all interested in reading more about Lua itself then please follow the links to the Lua website, where there's lots of help and a reference guide. Regards Pete
usafgadget Posted October 20, 2010 Author Report Posted October 20, 2010 Pete, Thanks for your help. I now have a working example to go forward from. Perhaps this small script would be useful in your lua examples .zip . Try to see it from my perspective. Without programming knowledge it's like trying to reverse engineer a jet fighter into a paper airplane. v/r, Chris
Pete Dowson Posted October 20, 2010 Report Posted October 20, 2010 Perhaps this small script would be useful in your lua examples .zip . Most of the examples were actually contributions by users. There are a lot more in the "User Contributions" sub-forum. I'd prefer to keep it that way. There are an infinite possible applications and variations I could possibly provide examples for, and I am never going to be lucky enough to find the few to please enough folks. User contributions are much better and will reflect general user needs better that I could do -- I am most certainly not a "typical user"! To that end, when you have a fully working example I would be grateful if you will add a couple of notes to it to explain what it does and post it in said sub-Forum. You can add comments to the Lua code to make it self-documenting. Comments are lines starting with -- (two minus characters), as in: -- This is an example of a widget squeezer invented by Joe Soap, 20th October 2010. Thanks, Pete
kurby Posted December 13, 2010 Report Posted December 13, 2010 Of course this is only going to turn the LED on. You need to turn it off in the case that offset 0BC8 is not 32767, so the full code would be: function set_brake(offset, value) if value == 32767 then gfd.SetLight(GFRP48, 0, 6) else gfd.ClearLight(GFRP48, 0, 6) end end event.offset(0x0BC8, "SW", "set_brake") If that works to your satisfaction you can simply add other functions and events to the same Lua to drive the other LEDs. BTW it is worth perusing the example Lua programs provided in the FSUIPC package (alongside the documents -- see the plugins Zip). Even if you are not going to use any of those, it would have shown you some of the things I've mentioned and corrected some of your code quite readily. It is still worth doing so even if you are happy with the above. If you are at all interested in reading more about Lua itself then please follow the links to the Lua website, where there's lots of help and a reference guide. Regards Pete Hello Pete, Sorry to be crashing this topic but i wonder if you could help me, i started with the second example script you posted here to see if i could control the leds on my own GF RP48 and it works, but now i wanted to use it not to control the autobrake, but to control the autopilot toggle button and light the corresponding led acording to the status of the autopilot, could you give me an example of how to do this? I think if i have a example for AP or FD or any of those buttons i can take it from there and do the rest of my erj autopilot buttons. Thanks.
Pete Dowson Posted December 14, 2010 Report Posted December 14, 2010 i started with the second example script you posted here to see if i could control the leds on my own GF RP48 and it works, but now i wanted to use it not to control the autobrake, but to control the autopilot toggle button and light the corresponding led acording to the status of the autopilot ... You control the autopilot by assigning a switch or button to the appropriate control. You only need the Lua code to drive the LED indication. The example you are looking to base it on does not control anything in FS, it only operates the LED. ... could you give me an example of how to do this? It's virtually identical to the example you quoted already. you only have to add identical lines but changing the offset to the autopilot master offset (0x07BC) and some values and names to match. i.e. whereas for the brake you have: function set_brake(offset, value) if value == 32767 then gfd.SetLight(GFRP48, 0, 6) else gfd.ClearLight(GFRP48, 0, 6) end end event.offset(0x0BC8, "SW", "set_brake") Note the bits in RED. Those we shall change in the lines we add . function set_ap(offset, value) if value ~= 0 then gfd.SetLight(GFRP48, 0, 5) else gfd.ClearLight(GFRP48, 0, 5) end end event.offset(0x07BC, "UD", "set_ap") So, the name of the function is changed, because it is a different function. The test (value == 32767) has changed because the A/P is on if the offset is non-zero (~= 0), off otherwise, the offset is 07BC not 0BC8, and the type is "UD" because it's an unsigned Dword (4 bytes) not a Signed Word (2 bytes) -- though really that doesn't matter much because only one byte is ever used. It's just that it is best to stick to the correct type and length because in some cases it certainly would matter. I've changed the LED to number 5, but of course you need to select that yourself. If it's on a second RP48 you'd change the unit number (the 0 before it) too. I assume you've equipped yourself with the offsets list from the FSUIPC SDK, and of course the FSUIPC Lua library reference? You need both. Regards Pete
kurby Posted December 14, 2010 Report Posted December 14, 2010 You control the autopilot by assigning a switch or button to the appropriate control. You only need the Lua code to drive the LED indication. The example you are looking to base it on does not control anything in FS, it only operates the LED. It's virtually identical to the example you quoted already. you only have to add identical lines but changing the offset to the autopilot master offset (0x07BC) and some values and names to match. i.e. whereas for the brake you have: function set_brake(offset, value) if value == 32767 then gfd.SetLight(GFRP48, 0, 6) else gfd.ClearLight(GFRP48, 0, 6) end end event.offset(0x0BC8, "SW", "set_brake") Note the bits in RED. Those we shall change in the lines we add . function set_ap(offset, value) if value ~= 0 then gfd.SetLight(GFRP48, 0, 5) else gfd.ClearLight(GFRP48, 0, 5) end end event.offset(0x07BC, "UD", "set_ap") So, the name of the function is changed, because it is a different function. The test (value == 32767) has changed because the A/P is on if the offset is non-zero (~= 0), off otherwise, the offset is 07BC not 0BC8, and the type is "UD" because it's an unsigned Dword (4 bytes) not a Signed Word (2 bytes) -- though really that doesn't matter much because only one byte is ever used. It's just that it is best to stick to the correct type and length because in some cases it certainly would matter. I've changed the LED to number 5, but of course you need to select that yourself. If it's on a second RP48 you'd change the unit number (the 0 before it) too. I assume you've equipped yourself with the offsets list from the FSUIPC SDK, and of course the FSUIPC Lua library reference? You need both. Regards Pete Thank you very much for your help Pete, the part of the led number and unit number i had figured out by the example, leds are number 0 - 7. I have both those docs you mention no worries. I will give this a go, once again thank you Pete. Best regards.
kurby Posted December 14, 2010 Report Posted December 14, 2010 function set_brake(offset, value) if value == 32767 then gfd.SetLight(GFRP48, 0, 6) else gfd.ClearLight(GFRP48, 0, 6) end end event.offset(0x0BC8, "SW", "set_brake") Note the bits in RED. Those we shall change in the lines we add . function set_ap(offset, value) if value ~= 0 then gfd.SetLight(GFRP48, 0, 5) else gfd.ClearLight(GFRP48, 0, 5) end end event.offset(0x07BC, "UD", "set_ap") Hello Pete, I'm sorry to return to this subject, but i copied the function you created to a RP48.lua file in the modules folder and in fsuipc i assigned one of the pushbuttons to run the lua file on key pressed and unfortunatly nothing happens, i have checked the code and it is exactly as here. I can't figure out if something is wrong, if i only write "gfd.SetLight(GFRP48, 0, 7)" in the lua file when i press the push button the led lights up. Am i doing something wrong? Thanks Again.
kurby Posted December 14, 2010 Report Posted December 14, 2010 Hello Pete, I'm sorry to return to this subject, but i copied the function you created to a RP48.lua file in the modules folder and in fsuipc i assigned one of the pushbuttons to run the lua file on key pressed and unfortunatly nothing happens, i have checked the code and it is exactly as here. I can't figure out if something is wrong, if i only write "gfd.SetLight(GFRP48, 0, 7)" in the lua file when i press the push button the led lights up. Am i doing something wrong? Thanks Again. I have figured my mistake out, what i need is "event.button(joynum, button, “function-name”)" and not a offset driven event. The problem now is that i can't send the offset to the function :blink: .
Pete Dowson Posted December 15, 2010 Report Posted December 15, 2010 I'm sorry to return to this subject, but i copied the function you created to a RP48.lua file in the modules folder and in fsuipc i assigned one of the pushbuttons to run the lua file on key pressed and unfortunatly nothing happens, i have checked the code and it is exactly as here. The Lua program is an EVENT driven one. You simply get it loaded once and it runs forever, monitoring the chosen offsets as declared in the event.offset functions you use. You should definitely NOT call is "RP48.lua" and run it via a button. You CAN call it "RP48.lua" and run it from a Lua called "ipcReady.lua" which runs automatically when FS is ready to fly. Or you can simply rename your RP48.lua to ipcReady.lua. I can't figure out if something is wrong, if i only write "gfd.SetLight(GFRP48, 0, 7)" in the lua file when i press the push button the led lights up. Am i doing something wrong? The function is only called when the offsets you declare events for CHANGE. If they do not change nothing happens. That's the whole point of events -- an "event" is something happening, something changing. If you want to initialise the LEDs to some initially loaded values from the offsets you need also to add to the plugin lines to call the function explicitly, like: set_brake( 0x0BC8, ipc.readSW(0x0BC8)) set_ap( 0x07BC, ipc.readUD(0x07BC)) All these lines are doing is making your functions operate according to the initial values read from those offsets. [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]. Your subsequent message: I have figured my mistake out, what i need is "event.button(joynum, button, “function-name”)" and not a offset driven event. Why bother when you can execute the Lua by assigning it to that button? I don't see the point of making it event driven if you are using the button in any case. The problem now is that i can't send the offset to the function Of course you can. Please see the ipc library functions "read.." and "write.." for accessing all sorts of offsets in plug-ins -- and see the red examples above. You seem to want to make this much more complicated than it need be. If you only want lights changing when you press buttons then you can do it by, as you say: if i only write "gfd.SetLight(GFRP48, 0, 7)" in the lua file when i press the push button the led lights up. However, if you do that then the LEDs won't necessarily relfect the state when, for example, you start FS or load a new flight, or use the mouse to change the A/P instead of a button ... etc. Really you are best leaving the Lua function to reflect the FS state, no matter how it changes. Regards Pete
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