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
Japmaco
Posts: 48
Im trying to get this triple use of buttons with lua to work with my e37 encoder with pushbtn connected to my 2560 mega board. But the code is asking for a joy number, and when i open the console in fsx its no joy when running via mobiflight. So is there some way to still use this lua script when running e37 encoders via mobifligt?

The goal here was to minimize the number of physical btns in my rig, if i can get 3 functions on one btn that would be awesome. So single press, double press and long press (0.5sec)

Example
-- Example of making a single button give three separate uses:
-- To keep things relatively simple, here we deal with one
-- specific button (defined as joystick 1, button 0 below).
-- But you could generalise this and have multple buttons,
-- each with multiple actions

-- The multiple use is obtained by a simple method:
-- A short press and release (like a mouse click)
-- A double short press and release (like a double click)
-- A press held for longer (over half second)

-- Just for a visible example which can be applied easily,
-- here a single button is used to select left view, right
-- and forward view, using FS controls. You could just as
-- easily send keypresses or sequences of either.

-- Single short press = left view (VIEW LEFT = 65680)
-- Two short presses = right view (VIEW RIGHT = 65676)
-- A longer press = frward view (VIEW FRWARD = 65674)

joy = 1
btn = 0
interval = 500 -- 1/2 second press, gap, press limits
2016-12-28 23:06
Avatar
pizman82
From: ETSI, Germany
Posts: 5128
Supporter
There is a way to "simulate" a joystick button by Mobiflight but it´s not direct in the system at the moment..... I talked to sebastion some days ago about this function. Maby he support this in a futured version.
I do not test it myself but you can look to Offset 3340 or 2910. Both systems allowed to let Mobiflight say " If Switch x is pushed then simulate a Joystick button push in FSUIPC"
In youre situation you just set youre Lua script to these button.

But i´m not sure if Mobiflight here is the right plattform cause the transfer to FSUIPC takes a little time..... the Double Click may not sent in right intervall everytime.
I would use a Joystick Controller for this special use and config it directly by FSUPC or Lua. ( But i do not think this is verry profitable)

Finaly i can maby give you some different input....
What do you think about a 4 way or 8 way HAT Switch from a joystick or from electro discount for self mounting.....
With a Hat Switch you got 4 (8) different Momentary switch options and you can set all by mobiflight directly ( Or in FSUIPC if you use a gamecontroller)

Maby i´m wrong but i just think about if it´s usefull to let one button controll 3 things.... Every real cockpit workes with "One Button for 1 Action logic" to minimize Issues while handling. When you got 20 of these Buttons you realy have to think about what button is now with what clicking logic for what function..... 60 Buttons looks harder like 20 buttons but you still know Button A = Function A Button B is functon B and so on.... Decide yourself what is better for you......

Good Luck
Good Luck !
2016-12-29 00:35
Avatar
Japmaco
Posts: 48
I have been playing around with Lua tonite and its really cool.

The only thing that bothers me now is when i wanna have a long press function on my nav1 to activate the IDENT or RADIO_VOR1_IDENT_TOGGLE sequencs 65842... When realasing that long press he swaps freq.. I have set up the single press to swap freq, so i guess when i release the long press, he Thinks i wanna swap freq. So now i have removed the single press and im just using the long press for IDENT and double press for swap. That works. But it bugs me that the single press doesnt work
2016-12-29 02:13
Avatar
DocMoebiuz
Moderator
From: NW of KPWK, United States
Posts: 1477
Has anyone looked at this:
iconCode:
event.offset(offset, "type", "function-name")


Whenever the offset changes the function will be called - I think this is an excellent way to do whatever you want, when MobiFlight sets a Custom Offset at 0x66C0 ff.

Create a file named mobiflight.lua inside the FSX/Modules folder and add the following content:

iconCode:
ipc.log("\n\n")
ipc.log("MobiFlight: Start")
ipc.setowndisplay("MobiFlight Lua", 0, 60, 6,  1)

function mfFunction(offset, value)
  ipc.display("MobiFlight " .. value)
end

event.offset(0x66C0, "UB", "mfFunction")

Make sure it is started by adding a line in the ipcReady.lua script:
iconCode:
ipc.runlua('mobiflight')


Now configure your input (e.g. switch) to write a value to that offset. It works great after few tests.
[Last edited by DocMoebiuz, 2017-01-03 00:04]
Have a great day!
Sebastian

MobiFlight - Simply build your own home cockpit for your favorite flight sim - MSFS2020, FSX, Prepar3D (FSUIPC), X-Plane (XPUIPC)
2017-01-02 23:48
Avatar
pizman82
From: ETSI, Germany
Posts: 5128
Supporter
iconJapmaco:


When realasing that long press he swaps freq.. I have set up the single press to swap freq, so i guess when i release the long press, he Thinks i wanna swap freq.



I do not understand the complete code..... My Lua Skills are already poor after only some weeks of trying......

I try this by the example code of Pete Dawson and got the same problem like you.... The Release of the "Long Push" will start a new loop in the function... So this release looks like a single press for the programm and it starts this event.
So the original Exmaple file is maby "bugged" too.

Hope somebody with better Lua Experience ( Sebastian ;) ) can check this code.... I think theres only a little issue with "cancel event" but i´m not understanding at the moment.


iconCode:
-- Example of making a single button give three separate uses:
	-- To keep things relatively simple, here we deal with one
	-- specific button (defined as joystick 1, button 0 below).
	-- But you could generalise this and have multple buttons,
	-- each with multiple actions
	
	-- The multiple use is obtained by a simple method:
	  -- A short press and release (like a mouse click)
	  -- A double short press and release (like a double click)
	  -- A press held for longer (over half second)
	
	-- Just for a visible example which can be applied easily,
	-- here a single button is used to select left view, right
	-- and forward view, using FS controls. You could just as
	-- easily send keypresses or sequences of either.
		
	-- Single short press = left view (VIEW LEFT = 65680)
	-- Two short presses = right view (VIEW RIGHT = 65676)
	-- A longer press = frward view (VIEW FRWARD = 65674)

joy = 1
btn = 0
interval = 500 -- 1/2 second press, gap, press limits

-- Function to time the button being pressed or left released
-- Allow only up to "interval" till decide no change
local function timebutton(test)
  while true do
		time2 = ipc.elapsedtime()
		if (time2 - time1) > interval then
			return false
		end
	 	if ipc.testbutton(joy, btn) == test then
			time1 = time2
			return true
		end
	 	ipc.sleep(20)
	end
end

function buttonpress(j, b, du)
	-- Cancel event so we don't get called again for double press
	event.cancel("buttonpress")
	
	-- Note time button was pressed
	time1 = ipc.elapsedtime()

	if timebutton(false) then
		-- First press / release counts: see if there's another
		if timebutton(true) then
			-- got another press in time, look for release
			if timebutton(false) then
				-- this was a double press, send VIEW RIGHT
				ipc.control(65676)
			end
  	else	
			-- This was a single press, send VIEW LEFT
			ipc.control(65680)
		end
	else
		-- This was a longer press, send VIEW FORWARD
		ipc.control(65674)
	end
	-- Restore cancelled event
	event.button(joy, btn, 1, "buttonpress")
end

-- Enable event on button being pressed (only)
event.button(joy, btn, 1, "buttonpress")
Good Luck !
2017-01-03 01:05
Avatar
pizman82
From: ETSI, Germany
Posts: 5128
Supporter
Hello Guys.... Hello Japmaco.

I´m a bit busy this time but i do not forget this problem.....
So i start a request personaly to Pete Dawson about that.

Good News....
This promblem is not regulary and the function should normaly work like you want !

Bad News....
Until now he cant tell me a solution for this.... But i sent him my logging Data and maby next days i can tell you more.

By the Way..... Pete is a realy nice Guy. Responding verry fast.... Perfect support (Like Sabastian in Mobiflight :thumbup: )

I will report when we can solve this !
Good Luck !
2017-01-08 01:33
Avatar
pizman82
From: ETSI, Germany
Posts: 5128
Supporter
And it´s solved !
With great support of Pete Dawson the probleme is gone.....

The TripleUse.Lua that shared with FSUIPC in Example folder is a old version ( Maby its buggy or have worked with earlyer Versions but not till now)
So Pete gives me a New Code for testing and it workes great !
iconCode:

joy = 20
btn = 5
interval = 500 -- 1/2 second press, gap, press limits
ignorepress = false

local function timebutton(test)
  ignorepress = true
  while true do
		time2 = ipc.elapsedtime()
		if (time2 - time1) > interval then
		  ignorepress = false
			return false
		end
	 	if ipc.testbutton(joy, btn) == test then
			time1 = time2
			return true
		end
	 	ipc.sleep(20)
	end
end

function buttonpress(j, b, du)
  if ignorepress then
     ignorepress = false
     return
  end
  
	-- ipc.log("buttonpress called " .. j .. " " .. b .. " " .. du)
	time1 = ipc.elapsedtime()
	time2 = 0

	if timebutton(false) then
		-- First press / release counts: see if there's another
		if timebutton(true) then
			-- got another press in time, look for release
			if timebutton(false) then
				-- this was a double press, CS6
				ipc.keypress(54,11)
			end
  	else	
			-- This was a single press, send CS7
			ipc.keypress(55,11)
      ignorepress = false
		end
	else
	 		-- This was a single long press, send CS2
			ipc.keypress(50,11)
  end
end

event.button(joy, btn, 1, "buttonpress")


Attention : This is just a script that Pete uses at the moment in his System..... For our personal use we have to change the Keypresses (he used) into the commands we like.
Additional we need to change the JOY and BTN to set our specific Joystick-Button.


Good Luck !
Good Luck !
2017-01-09 00:31
Avatar
DocMoebiuz
Moderator
From: NW of KPWK, United States
Posts: 1477
Hi guys, I am glad you did it.

So bottomline - is there anything that we should add to MobiFlight to make all this easier or does that solution works for you and other users...?
Have a great day!
Sebastian

MobiFlight - Simply build your own home cockpit for your favorite flight sim - MSFS2020, FSX, Prepar3D (FSUIPC), X-Plane (XPUIPC)
2017-01-09 07:16
Avatar
pizman82
From: ETSI, Germany
Posts: 5128
Supporter
Hi Sebastian.

:-) For me theres no problem.....
I build a B737 and this not need unreal switches (Like this). I just do this research to solve the Problem for Japmaco. No personal use for this stuff.

But basicly.....

Lots of the LUA things can be done in FSUIPC or Linda..... But there we need a Joystickcontroller or we need to use a tricky way like you suscribe above (Custom Offset as a bypass to bring our Buttonpush from Mobiflight to FSUIPC)

The Question is : Should we use for those things simply a LeoBodnar or a Gamecontroller
OR
Should Mobiflight give us a better Interface to controll Lua Stuff like this ( Not difficult Customoffset)

As you talked in our Email i think "Simulated Joystickbuttons" AND "RunLua" both via Offsets and Mobiflight Configentrys will be the "Bridge" between our "lovely" Mobiflight and the "mighty" FSUIPC .
Good Luck !
2017-01-09 23:52
Avatar
DocMoebiuz
Moderator
From: NW of KPWK, United States
Posts: 1477
I tried the offsets to run a Lua Script without success. Everything was prepared but I was not able to run a lua script e.g. by Name.

I understand the documentation like this:
send "LuaRun:MyLuaScript" to Offset 0x0D70

Should actually run the MyLuaScript.lua plugin which should be in the plugins folder.
I am actually not sure if my String gets written into the Offset at all. When I monitor the offset via LINDA I can´t see anything happening.
Have a great day!
Sebastian

MobiFlight - Simply build your own home cockpit for your favorite flight sim - MSFS2020, FSX, Prepar3D (FSUIPC), X-Plane (XPUIPC)
2017-01-11 04:44
Avatar
pizman82
From: ETSI, Germany
Posts: 5128
Supporter
iconDocMoebiuz:

I tried the offsets to run a Lua Script without success. Everything was prepared but I was not able to run a lua script e.g. by Name.

I understand the documentation like this:
send "LuaRun:MyLuaScript" to Offset 0x0D70



Today i´m free of work.... Looking forward to do some testlines from my "ToDo List" I will try this.

But in first look youre control is wrong.....
At this point we start a lua script from Outside..... Not inside from another script.

If i´m right then the command should be "Lua:MyLuaScript"
(The contorl "LuaRun" is not listed in FSUIPC Offset Status)

Additional question..... If you like to start a script by another script the control should be "ipc.runLua" Is maby the syntax you use (LuaRun.... Lua in front of run) from youre c# experience ??

Ok... I try if i find time today and will report.

EDIT: Can Report that offset 3340 (Virtual Joystickbutton) is working great !
But the 0D70 Lua System i can NOT get to work.... But i think the Problem is in Mobiflight String Logic maby.
Not shure if this Board is a good place to debatte this Problem. Send me a mail if you want so we can talk german :-)
[Last edited by pizman82, 2017-01-11 12:49]
Good Luck !
2017-01-11 07:52
icon