Jump to content
The simFlight Network Forums

Little LUA help. please


Recommended Posts

Hello Pete,

you know already about my programming (and logical) knowledge :oops:

I'm searching now for an code to assign a rotary knob.

As many (all?) airliners the PMDG MD11 has also some functions to show datas on the ND: MAP, PLAN, VOR, APPR, TCAS

I have now the VRInsight Combo with a rotary switch which I'd like to assign to all this functions (if possible)

The rotary knob does nothing more than give out a signal if you turn right and a signal if you turn left.

The MD11 ND mode functions are all commanded via the ROTOR_BRAKE parameter, e.g. MAP mode is ipc.control(66587, 71132), APPR is ipc.control(66587, 71135) and so on.

Could you please help me how I could make a kind of counter which switches through the ipc.control parameter up when rotating the knob to the right and down when rotating to the left?

Any kind of similar counters I have programmed till now have had some kind of value which I was able to read out (ipc.readLvar) and then I counted up from this variables... but with this I have no clue.

The problem is that I can of course always start a counter up from 1, but that means whenever the rotary knob will be used, the ND modes begins from start.

E.g. if you are currently in VOR and want to the next APPR, then the counter begins from 1 and you go from MAP, PLAN, VOR to APPR...

Do you think there is a solution?

Thank you very much,

Guenter

Link to comment
Share on other sites

Could you please help me how I could make a kind of counter which switches through the ipc.control parameter up when rotating the knob to the right and down when rotating to the left?

Two ways, up to you.

With just [buttons] entries, you can make a set of entries for each of the two effective buttons (clockwise and counterclockwise). In each of the two sets you have one unconditional entry which uses "Offset Byte Cyclic Increment" (clockwise) or "... Decrement" (counter-clockwise) to change a user-available offset (e.g x66C0 -- all of those from x66C0 to x66FF are available to users).

Then you have a conditional entry, for the same button, for each of the cyclic values that offset can take, one for each of the controls you wish to send.

Conditional entries based on offset values are the same as ordinary button entries but preceded by the condition, for example B66C0=1. Check the section in the Advanced User's document headed "ADDING OFFSET CONDITIONS".

If you want to see a few practical examples, download the GFdisplay package. althoguh it's for Go Flight buttons, there are several cases there of using iffsets and conditions in this way.

Alternatively, if you really want to use Lua, as your subject heading suggests, you'd need to trap both button press actions with an event.button(...) arrangement, using a local variable in the Lua program to keep track of what control should be sent. Then it's just a matter of a few if's and else's as you've done before.

The problem is that I can of course always start a counter up from 1, but that means whenever the rotary knob will be used, the ND modes begins from start.

E.g. if you are currently in VOR and want to the next APPR, then the counter begins from 1 and you go from MAP, PLAN, VOR to APPR...

But it will only start from the same place each time you restart FS. If you want to have a memory of the position outside of FS you will have to create an INI or CFG file to remember it in. you can do that using Lua io.open() and :read() and write() calls. You'd need to refer to the Lua reference website or programming book for that. There is an example of file reading and writing I added to the end of my Lua announcement -- it's a little Lua program I wrote for scaling the FSUIPC dialogues up by automatically reading and modifying the C/C++ resource file which defines them ("ScaleRC.lua").

Regards

Pete

Link to comment
Share on other sites

Many thanks!

I'm a big step closer....

Just one problem left:

I need the code for keystrokes not for buttons (unfortunately the MCP Combo couldn't give out joybuttons, just keystrokes)

heres my code (just for increment):

110=117,26,Cx510066C0,x00040001

111=B66C0=0 117,26,C66587,71132

112=B66C0=1 117,26,C66587,71133

113=B66C0=2 117,26,C66587,71134

114=B66C0=3 117,26,C66587,71135

115=B66C0=4 117,26,C66587,71136

I have tested it with buttons, adding a "P" and the button number and it was working very well.

But my "simple" transforming for keystrokes isn't working.

There must be obvisiously an error in my code...?

Secod question.

Is it right, that for decrement that code have to change to

Cx610066C0,x00040001 ?

thank you very much!

Link to comment
Share on other sites

110=117,26,Cx510066C0,x00040001

111=B66C0=0 117,26,C66587,71132

112=B66C0=1 117,26,C66587,71133

113=B66C0=2 117,26,C66587,71134

114=B66C0=3 117,26,C66587,71135

115=B66C0=4 117,26,C66587,71136

There's no 'C' for Control in the Keys parameters -- it is only needed in the Buttons parameter section to distinguish Keys from Controls, but you can't program a key to send a key. (I should probably have accepted the 'C' for consistency).

117,26 is Ctrl+Tab+F6. I assume that's what you programmed the device to send?

I have tested it with buttons, adding a "P" and the button number and it was working very well.

But my "simple" transforming for keystrokes isn't working.

There must be obvisiously an error in my code...?

Just the 'C' I think.

Is it right, that for decrement that code have to change to

Cx610066C0,x00040001 ?

Yes, that should work, but without the C..

Regards

Pete

Link to comment
Share on other sites

Thanks for the fast reply!!

And its working!

Here's the final coding for the MD11X ND Mode cycle

110=117,26,x510066C0,x00040001 ;ND Mode increase start
111=B66C0=0 117,26,66587,71132 
112=B66C0=1 117,26,66587,71133 
113=B66C0=2 117,26,66587,71134 
114=B66C0=3 117,26,66587,71135 
115=B66C0=4 117,26,66587,71136 ;ND Mode increase end
116=115,26,x610066C0,x00040001 ;ND Mode decrease start
117=B66C0=0 115,26,66587,71132 
118=B66C0=1 115,26,66587,71133 
119=B66C0=2 115,26,66587,71134 
120=B66C0=3 115,26,66587,71135 
121=B66C0=4 115,26,66587,71136 ;ND Mode decrease end

117,26 is Ctrl+Tab+F6. I assume that's what you programmed the device to send?

Yes, you're right.

I also use the MCP Combo and as stated in the other threads here it is just able to send keystrokes via a keymanager.

Joybuttons would be much better but what should we do...

The Combo is a very good hardware if you consider the price and what you get.

Of course GoFlight and all the high priced modules are better and far more realistic in design, but the MCP Combo works very well if you know how to tweak with FSUIPC ;-)

Thank you very much Pete and thank you for your outstanding fast service again!!!

p.s. I haven't forgot the "database", if you remember.

In the next weeks I consider how to make it in the best way: maybe I will write PDFs for each aircraft where the codes and some explanings will be written down.

Or I will make ZIPs with the MACRO and LUA Files... I will think about it

But anyway it would be important to collect the hole codings together that not any user must start from beginning...

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.