MobiFlight Community Support

Welcome to the forum for MobiFlight! Feel free to reach out to the community in case you have questions, issues or just want to share great ideas or details about your latest home cockpit project.

You like MobiFlight? Donate via PayPal and support the MobiFlight development. Thanks! 

icon
Avatar
SteveBurney
Posts: 9
I've installed Bob Kellogg's G5 in the panel of my A2A 182. It's a great XML gauge, but it's coded to use the mouse to manipulate the settings. The real G5 has a rotary encoder with a push button to interact with the instrument, but Mr. Kellogg has his gauge programmed to use the mouse wheel button to simulate the button press and the left and right mouse buttons to simulate turning the knob either left or right. Here is a piece of his code:

(M:Event) 'LeftSingle' scmp 0 == if{ (>K:HEADING_BUG_DEC) }
(M:Event) 'RightSingle' scmp 0 == if{ (>K:HEADING_BUG_INC) }

It seems like it should be easy to use a rotary encoder and replace the " (M:Event) 'LeftSingle' " with something like 'knob twist left', but the solution escapes me. Any suggestions on how to 'read' the movement of the knob and button and communicate the movement to the gauge?
2021-06-30 03:51
Avatar
pizman82
Moderator
From: ETSI, Germany
Posts: 4989
Supporter
Do you try out if a FSUIPC Macro work ?
Good Luck !
2021-07-05 15:06
Avatar
SteveBurney
Posts: 9
Yeah, it ended up only taking 6 lines of script, it just took me a really long time to figure out what the 6 lines were. In case anyone else is using this instrument, here's what I had to do to make it work with a rotary encoder.

--Create 3 macros. The first line of the macro is the x,y coordinates of where the button is on the screen. You'll have to experiment to find the values for your sim. The final digit on the first line is telling the sim to use FS window relative coordinates. The digit on the 2nd line tells the sim which mouse button is being pressed. 0 for left, 1 for middle, and 2 for right. Make sure the 3 macros are saved in your MODULES folder.
Macro 1, save as 'G5right.lua': mouse.move(-1965, 403, 1)
mouse.click(2)

Macro 2, save as 'G5left.lua': mouse.move(-1965, 403, 1)
mouse.click(0)

Macro 3, save as 'G5button.lua': mouse.move(-1965, 403, 1)
mouse.click(1)

--Set up 1 input on Mobiflight for the button part of the encoder, and 1 input for the rotary part of the encoder. (You know how to do that and assign the pins from the Arduino, right?)
--On the button input settings, set the 'on press' action type to 'lua macro', the macro name as 'lua g5button', and the value as '0'.
--On the encoder input settings, set the 'on left' action type to 'lua macro', the macro name as 'lua g5left', and the value as '0'. Set the 'on right' action type to 'lua macro', the macro name as 'lua g5right', and the value as '0'.

The G5 gauge the Mr. Kellog wrote (and made available for free) is a really great addition to a GA sim. Being able to use Mobiflight and a rotary encoder makes it even better.
2021-07-12 02:53
icon