EmileBax Posted December 19, 2015 Report Posted December 19, 2015 I want to use keyboard commands to operate the CDU of the PMDG 777 via a Lua plug-in. Via FSUIPC, each key command executes the LuaValue control for this plug-in but with a different parameter. The parameter values range from 0 to 68. The Lua plug-in called by the LuaValue control contains a function like this (with thanks to Günter Steiner for the source) : function PMDG777CDU() local CDUStartVar if ipc.readUB("66C4") == 0 then CDUStartVar = 328 else CDUStartVar = 401 end ipc.control(PMDGBaseVariable + CDUStartVar + ipcPARAM, 1)end The function is called by :event.param("PMDG777CDU") But when I press a CDU key command, nothing happens. When using ipcDebug, I notice in the log that the event is not triggered. So what am I doing wrong ? I do not like asking for help as I prefer to figure things out for myself, but at times I'm stuck and this is one of them. Any help would be much appreciated, thanks. Regards, Emile Bax Auckland New Zealand.
Pete Dowson Posted December 19, 2015 Report Posted December 19, 2015 But when I press a CDU key command, nothing happens. When using ipcDebug, I notice in the log that the event is not triggered. So what am I doing wrong ? The ipcDebug facility has long been superseded by the "Trace/Debug" option in the Logging options tab. I doubt the facility to detect Events is built into ipcDebug. Please try using the built in trace/debug option which is far superior. Then let me see the log (or suitable extract) and your FSUIPC4.INI file, please. BTW, I assume "PMDGBaseVariable" is defined somewhere earlier in the Lua code? Pete
EmileBax Posted December 19, 2015 Author Report Posted December 19, 2015 The ipcDebug facility has long been superseded by the "Trace/Debug" option in the Logging options tab. I doubt the facility to detect Events is built into ipcDebug. Please try using the built in trace/debug option which is far superior. Then let me see the log (or suitable extract) and your FSUIPC4.INI file, please. BTW, I assume "PMDGBaseVariable" is defined somewhere earlier in the Lua code? Pete Hi Pete, Thanks ever so much for your quick response. But would you believe that I have found the problem ?! I had overlooked that (as stated in the FSUIPC Lua Library document, so no excuse :oops:) the event.param facility will call the function only when it detects an externally generated change in the ipcPARAM variable for the plug-in. And the way I tested it yesterday, did not effect a change in ipcPARAM (it kept it at 0 as that was the value I initially used for the test key) so nothing happened ! I changed the values that my keys throw at the plug-in, which fixed that issue. The only problem left, was the situation where two consecutive identical key presses would be required, e.g. when entering the code for my home airport NZAA in the Route page. The first A would work but not the second, unless I entered a different letter (e.g. NZAB), then pressed CLR to get rid of the B and then entered the second A. Too cumbersome, but I found a way around it. For each key command I added another LuaValue FS Control when the key is released, with a value that represents a dummy change in ipcPARAM but has no effect in the function. This works like a charm :). It may be worth compiling the plug-in so that it loads just that little bit faster because it is now loaded twice for each key press, but that's for another day. Sorry to have bothered you unnecessarily - it's getting close to Christmas and I do need a decent holiday :roll: Wishing you & yours a Merry Christmas and all the best for the coming year. Cheers, Emile.
Pete Dowson Posted December 20, 2015 Report Posted December 20, 2015 I had overlooked that (as stated in the FSUIPC Lua Library document, so no excuse :oops:) the event.param facility will call the function only when it detects an externally generated change in the ipcPARAM variable for the plug-in. Yes, in other words externally to the actual plug-in. If you change ipcPARAM inside the same plug-in, it doesn't generate another event for that plug-in. However, assigning "luavalue" is an external source of change for the parameter, so should work fine. And the way I tested it yesterday, did not effect a change in ipcPARAM (it kept it at 0 as that was the value I initially used for the test key) so nothing happened ! Er ... you mean you were only setting it the once, in the same plug-in? The only problem left, was the situation where two consecutive identical key presses would be required, e.g. when entering the code for my home airport NZAA in the Route page. The first A would work but not the second, unless I entered a different letter (e.g. NZAB), then pressed CLR to get rid of the B and then entered the second A. Too cumbersome, but I found a way around it. For each key command I added another LuaValue FS Control when the key isreleased, with a value that represents a dummy change in ipcPARAM but has no effect in the function. This works like a charm :). Yes, that's one way. But possibly easier altogether, if you only need up to 256 values, would be to use LuaToggle with flag numbers 0-256 and event.flag to provide the number -- instead of ipcPARAM. Since a toggle is ALWAYS a change, you need not assign anything to the release. It may be worth compiling the plug-in so that it loads just that little bit faster because it is now loaded twice for each key press, but that's for another day. There's no point in compiling it as it is only loaded the once (I assume you are loading it via the [AUTO] facility in the INI file, or possibly from ipcREADY.lua?). Any event-based Lua plug-in stays resident once loaded unless it terminates itself or uses event.cancel to remove all outstanding event detection. Pete
EmileBax Posted December 20, 2015 Author Report Posted December 20, 2015 Er ... you mean you were only setting it the once, in the same plug-in? EB: Sorry, I didn't make that clear. The key I used for testing sent an ipcPARAM value of 0 to the plug-in. I interpreted the failure to work as being caused by ipcPARAM having a value of 0 as initialised, so no change being detected.. Yes, that's one way. But possibly easier altogether, if you only need up to 256 values, would be to use LuaToggle with flag numbers 0-256 and event.flag to provide the number -- instead of ipcPARAM. Since a toggle is ALWAYS a change, you need not assign anything to the release. EB: Thanks for that suggestion, I will put that in place. There's no point in compiling it as it is only loaded the once (I assume you are loading it via the [AUTO] facility in the INI file, or possibly from ipcREADY.lua?). Any event-based Lua plug-in stays resident once loaded unless it terminates itself or uses event.cancel to remove all outstanding event detection. EB: Ah thanks. Yes it is loaded from the [AUTO] section in the profile INI for the aircraft. Cheers, Emile.
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