Jump to content
The simFlight Network Forums

Recommended Posts

Posted

Hello Pete, Hello Comunity

First sorry for my poor english and sorry if this question is already awnsered.... I found no Topic till now.

My experience for Lua Pragramming is still at beginning and i´m not understanding all of the  concept at the moment. So i can´t find the Error in the following situation....

 

I want to set 3 Functions to a Joystick Button for a testing Project.   So i found the "tripleUse.lua" Example.   My opinion was to try your Example Lua first to see how it work but i got a problem with it.....   First i locate the Joystickbutton i want to use and change the "joy = 0   and btn = 1 " Variable for my personal using.  This workes and i can controll the Example View Left/Right/Forward with my joystick.

Problem:

Singeclick workes fine.....    Doubleclick workes fine too.   But Long Press gets a issue....       It change view like you suscribe BUT when i release the Button (after view changed) then the view not stay (Like Short and double press). It swaps back to "Left View" like with a short press.

It Looks like the Release after "Long Press" is checked by your Luascript as a another new short press and result in a new Loop with a Ipc.control for the Left View. 

 

If possible please explane me if i made something wrong.  Or did i found maby a "Bug" in this file ??

Looking forward for some information about that.....

Thank You !

Posted
On 1/3/2017 at 1:15 AM, Pizman said:

Singeclick workes fine.....    Doubleclick workes fine too.   But Long Press gets a issue....       It change view like you suscribe BUT when i release the Button (after view changed) then the view not stay (Like Short and double press). It swaps back to "Left View" like with a short press.

It Looks like the Release after "Long Press" is checked by your Luascript as a another new short press and result in a new Loop with a Ipc.control for the Left View. 

No. That cannot be true because I use TripleUse all the time with no such problem.

This line in the Lua program explains why the release is ignored:

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

The "1" parameter means "press". To have an event of release as well it would need to be 3, not 1.

So, it sounds more likely related to the view control(s) you've assigned. Try using FSUIPC's logging to see what is going on.

Pete

 

Posted

Hello Pete, Hope you enjoy youre holliday.

Thanks for quick respond.....realy nice support !  

 

Sad to report i can´t solve the issue....

I try to change the "Events" to check if maby the viewchange are wrong and tha "flip bag" is normal with this event 65674 from the example file. BUT i got the same Problem with other Event´s.    For testing i use AP_ALT_VAR_INC 65892  for singlepress  and AP_ALT_VAR_DEC 65893 for doublepress. For Longpress i used AP_HDG_HOLD. 65725

The effect is the Same.... Single Press workes (Increase ALT)    Doublepress workes (decrease ALT) but Longpress become the same Issue.....  It Aktivate the HDG Hold function but when i relase the button then it Increase ALT one time like i do another singlepress.

FSUIPC Logging is a little confusing for me (Not sure witch logging is the right one) but it report that....

   156781 FS Control Sent: Ctrl=65892, Param=0     -----   This was the Single Press
   162444 FS Control Sent: Ctrl=65893, Param=0    -----    This is the Doublepress
   164394 FS Control Sent: Ctrl=65725, Param=0    -----   Longpress
   165252 FS Control Sent: Ctrl=65892, Param=0   ------   This come from self  maby a second after i release longpress.  ( same event like singlepress)

 

Additional Information.....   while i use the View Events (from exmple file) i can´t see that the longpress result in a repeat..... With the HDG Hold Event i see that the function is repeat as long i hold the button  (shown in FSUIPC LOGGING and opitcal in On/Off/On/Off of the HDG Hold Button..... is this right or a part of the problem ??

 

So Pete...  If you need report of another FSUIPC Logging please tell me "WHAT" logging i should use....  Or if you need a copy of the Lua File, just aks pls.  But i can tell you i just use the Example file i got with Fsuipc und had only change the Joy and Btn Variable to use my specific joystick .... and i chage the Event ID´s for the second testing like suscribe above..... Else it is 1:1 original.

Hope you find time to help.....     Thnak you and greetings from germany.

Posted
6 hours ago, Pizman said:

FSUIPC Logging is a little confusing for me (Not sure witch logging is the right one) but it report that....

   156781 FS Control Sent: Ctrl=65892, Param=0     -----   This was the Single Press
   162444 FS Control Sent: Ctrl=65893, Param=0    -----    This is the Doublepress
   164394 FS Control Sent: Ctrl=65725, Param=0    -----   Longpress
   165252 FS Control Sent: Ctrl=65892, Param=0   ------   This come from self  maby a second after i release longpress.  ( same event like singlepress)

That's just the results, which you stated in any case and I believed. You need to enable the Button logging, the input, not the output! It's the button I am suspicious about. It sounds like it is "bouncing" (technical term).

Pete

6 hours ago, Pizman said:

Additional Information.....   while i use the View Events (from exmple file) i can´t see that the longpress result in a repeat..... With the HDG Hold Event i see that the function is repeat as long i hold the button  (shown in FSUIPC LOGGING and opitcal in On/Off/On/Off of the HDG Hold Button..... is this right or a part of the problem ??

Repeating action buttons presses have to have the "Repeat" option selected in the assignment. You shouldn't use "repeat" with a Lua assignment! It will cause the Lua program to be loaded and killed repeatedly. There's a limit set by parameter as to how often FSUIPC allows this -- 66 mSecs is the default I think. If the Lua finishes in less time than that then it will repeat faster. If it takes longer then it will be killed some time after so it can be run again.

So, yes, that could be the problem. If you wnt the Lua to repeat whilst you keep the button pressed you'd neen to program that in the Lua, but you can't do that with the TripleUse one because it is the holding down which changes the action.

Pete

 

Posted (edited)

Hello again Pete.

Now i try lots of things but i can´t solve this. Hope you got another idea what i´am making wrong.

-First about logging...  I Try all Logging options in FSUIPC but not find what you said......   When i use "Button and Key Operations" then This Button NOT will be shown....  Looks like the logging only show buttons that assigned in FSUIPC "Button+Switches Tab".....    With another button on this stick  i set in FSUIPC for maby Gear Down.... There i got a logging like "Button pressed.... Button released"     But the specific button i used in this Luascript (not assigned in fsuipc) is not shown when pressed or released.... Only the "FSContorl Part" i quote you is logged at this time.

To check one thing....  Is it right i run the tripleuse.lua automaticly by a entry in ini file Auto section ???    I try to set the file to a button, too  in "Button and switches" but i think thats wrong....is this the Right way  ??

 

- Second  about the repeat....

Primary i hope you understand right....  I do NOT want the Button do a repeat.... and i do NOT set this somewhere.   Like i explane above i do not set the script in FSUIPC Button+Switch Tab... The script run per AUTO in Ini file.....  I don´t think i set somewhere "repeat"

To test if the button is ok i delete the tripleuse.lua and the ini entry and start FSX normaly..... then i set THIS Button for a normal function like AP_HDG_HOLD....   When i push it then Logging tells me "Press of this button" ....   When i Hold it theres NO repeat shown..... When i released it the Logging report release .... Nothing else.  I don´t think theres a bouncing on hardware part.

BUT:  Youre comment let me think about another thing.    It looks like the "repeat" let the Loop start again. So if i stop Longpress right in the moment before a new repeat comes again then it should work.... And Yes.... After 10-20 Trys i can see when i release the button in perfect moment then the "NewLoop" does not start.  But this isn´t the solution. It´s just some milliseconds to find this point.  To erly or to late and the Singlepush Event is run again.

 

So sumary i just can confirm.....

When the Luascript is active then a holding of the Button results in permanet Repeating the Event....And This Repeat result in 99% of trys in a additional Singleclick event sending after release the button. 

If you got another idea pls tell me.   Can you Confirm, that the Original File from LUA Examples workes OK (I Used it with --comments ....  Just Copy it to modules folder) ???

 

Thank you !

Edited by Pizman
Posted
9 hours ago, Pizman said:

I Try all Logging options in FSUIPC but not find what you said......   When i use "Button and Key Operations" then This Button NOT will be shown....  Looks like the logging only show buttons that assigned in FSUIPC "Button+Switches Tab"

Try assigning it to something innocuous, one which does nothing of interest or note -- just for logging. There are other logging options which will do it without assignment but they are more technical.

Also enable Event logging.

9 hours ago, Pizman said:

Is it right i run the tripleuse.lua automaticly by a entry in ini file Auto section ???    I try to set the file to a button, too  in "Button and switches" but i think thats wrong....is this the Right way  ??

It is designed to be loaded once and left to run, so don't assign to it.

I just checked the version of TripleUse I am actually using. There are some subtle differences I don't remember doing. Perhaps you can use this as a basis for what you want to do.  It sends KeyPresses, not Controls, but you can change those lines easily enough. It lacks most of the comments in the released version.

Let me know if it works better for you. If so then maybe I should rleases the updated version.

Here it is:

-- Alternative PTT interpretations:
		-- Single short press = CS7 (RC Ack)
		-- Two short presses within a time limit = CS 6 (ProATC contact etc)

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")

Let me know please

Pete

 

Posted

Hi Pete and Pizman,

I seem to have encountered the same issue, while using TripleUse.lua in my Level-D B767 MCP, as reported in this post:

in which I have stated:

On 7/1/2015 at 0:11 PM, ckovoor said:

One little wrinkle still to be ironed out is that while applying a long press (3), the script also seems to apply a short press (1), and toggles the associated bit.

I decided to live with the problem, at the time, and it has been a while since I have flown the LD-B767. But I will now be taking out the MCP and making a few tests with your new lua to see whether it solves the problem.

Thanks,

Chakko.

Posted
13 hours ago, Pete Dowson said:

I just checked the version of TripleUse I am actually using. There are some subtle differences I don't remember doing. Perhaps you can use this as a basis for what you want to do.  It sends KeyPresses, not Controls, but you can change those lines easily enough. It lacks most of the comments in the released version.

Let me know if it works better for you. If so then maybe I should rleases the updated version.

Let me know please

Pete

 

Dear Pete.

Wunderfull work! .     Thats it !

Youre quoted code workes great    No Repeats, No Bugs.

I´m sad i must say i dont understand completley what the little differences done. Just see you don´t use "cancel Event" and have a new Variable "ignorepress" now (Think this is to solve the reloop) .... But in some weeks and a lot of testing and learning about LUA  i will check this myself i hope.

So.... Great Support...   It was a pleasure to talk personally  to you ....  Thank you Sir !

Posted
17 minutes ago, Pizman said:

Youre quoted code workes great    No Repeats, No Bugs.

Oh, good. I'll use it in the releases in future, with the comments added back and probably with the controls again instead of my keypresses.

Thanks for letting me know.

Pete

 

Posted
On 1/8/2017 at 5:23 PM, Pete Dowson said:

Okay. Let me know how you get on, please.

Dear Pete,

After a couple of flights on the Level-D B767 with my hardware MCP running with the old and new lua's alternately, I can also confirm that the new version does not suffer from the same 'bug' (i.e. short press also acting with long press). I will therefore be using the newer version from now on. I look forward to seeing a commented version of this new lua.

Thanks and regards,

Chakko.

Posted
6 hours ago, ckovoor said:

I look forward to seeing a commented version of this new lua.

It'll be renamed "TripleUse2.lua" to make it obvious it is changed, and it will be iinstalled in the ZIP in the FSUIPC Documents folder by the next full release of FSUIPC, later this month. There's an interim release this week, but only the FSUIPC4.DLL itself.

Thanks,
Pete

 

 

  • 3 years later...
Posted (edited)

Hi Pete, hi John, hey guys,

I tried to make the tripleUse.lua for me a bit more flexible.
Most of the part i already succeeded.
But still one small thing is missing.

I'm trying to hand in a config, where i can set function calls for each of the three types (single-, double-, long-press)
So far all the events are registered and entered. I also get the right "function call". But obviously the functions are not found.

Probably you can give me a hint on that, how i'm able to access the MSFS / FS2020 functions which i can also assign via LINDA.

Thanks a lot and best regards,

            Joe

Code: FSUIPC7.log

********* FSUIPC7, Version 7.0.3 (23rd December 2020) by John Dowson *********
...
15312 -------------------- Starting everything now ----------------------
15375 LUA.1: beginning "H:\FSUIPC7\ipcReady.lua"
15516 LUA.2: beginning "H:\FSUIPC7\linda.lua"
15531 LUA.2: LINDA:: [START] *********************** STARTING LINDA ***********************
15547 LUA.2: [START] LINDA Ver = 4.0.3
15562 LUA.2: [START] FSUIPC Ver = 70030000
15578 LUA.2: [START] MSFS Ver = 110
15641 LUA.3: beginning "H:\FSUIPC7\TripleUse.lua"
15641 LUA.3: 3 7 1
15656 LUA.3: 3 8 2
15687 LUA.3: 3 9 3
15906 LUA.2: LINDA:: [START] Loading System Configuration files
...
19219 *** LUA Error: [string "Avionics_MASTER_on()"]:1: attempt to call global 'Avionics_MASTER_on' (a nil value)
22125 *** LUA Error: [string "Avionics_MASTER_off()"]:1: attempt to call global 'Avionics_MASTER_off' (a nil value)
24094 *** LUA Error: [string "Avionics_MASTER_on()"]:1: attempt to call global 'Avionics_MASTER_on' (a nil value)
25391 LUA.3: ...... ignoring buttonpress

It seems, that the function calls are not found.

Do you have any hints for me?

And congrats... It's phantastic, what is possible with FSUIPC! Worth every penny. 🙂

TripleUse.lua

Edited by joeherwig
Posted
9 hours ago, joeherwig said:

I'm trying to hand in a config, where i can set function calls for each of the three types (single-, double-, long-press)
So far all the events are registered and entered. I also get the right "function call". But obviously the functions are not found.

Probably you can give me a hint on that, how i'm able to access the MSFS / FS2020 functions which i can also assign via LINDA.

I don't know LINDA, sorry, But to "access functions in MSFS" you use the controls or events. From Lua that would be via the ipc.comtrol function. Please refer to the Lua library documentation. I don't understand why you want functions for them when they are just simple numbers as parameters in that function. See the Controls List for the numbers available.

Of course not all yet work in MSFS yet. MSFS is still a work-in-progress.

Pete

 

Posted

Hi Pete,

Thanks for the fast reply. Well... It's not LINDA specific but just a matter of organizing my LUA code.
Using the already available functions from the other lua file has a simple benefit:
It makes the code more readable and ways easier to understand and doesn't require fiddling around with cryptic numbers nor duplicating code lines.

Anyway... The work of mapping offsets and the corresponding values to functions was already done, so why should i do it again? Being "functional lazy" is not always bad.
And it also includes writing messages to the VRInsight display or able to play sounds directly, which is quite handy imho.

See some extract from the file LINDA\lib\lib-msfs.lua underneath the FSUIPC.exe path:

-- Default MSFS
-- Updated for LINDA 4.0.0
-- Aug 2020
-- V 1.20

--[[

v1.20
* changed Auto_MASTER implementation

--]]

-- ## Autopilot controls #####################################

-- ...

function Autopilot_HDG_BUG_align ()
	val = ipc.readDBL(0x2B00)
	ipc.writeUW("07cc", val/360*65536)
	DspHDG(val)
end

-- ...

-- ## Radios functions  #####################################

function isAvionicsOn ()
	return ipc.readUB(0x2E80) == 1
end

function Radios_DME_AUDIO_toggle ()
    if logic.And(ipc.readUB(0x3122), 2) ~= 2 then
        if _MCP1 () then
            DspShow("DME","AUD")
        else
            if RADIOS_MODE == 4 then -- DME display is open
                DspRadioIdent_on ()
            else
                DspShow("DME","AUD","DME","Ident On")
            end
        end
    	ipc.control(65839)
	else
        if _MCP1 () then
            DspShow("DME","off")
        else
            if RADIOS_MODE == 4 then -- DME display is open
                DspRadioIdent_off ()
            else
                DspShow("DME","aud","  DME","IdentOff")
            end
        end
    	ipc.control(65834)
	end
end

-- ...


So instead of again writing the same 24 additional lines for toggling the DME Audio on long-press just in another lua file, i'd like to include the function call in the above mentioned LUA table (array), and that's it.

But i'm simply not sure, how i can access the functions being defined in 
 

C:\FSUIPC7\LINDA\lib\lib-msfs.lua 

in my

C:\FSUIPC7\TripleUse.lua

that's all i wish to do. 🙂

Posted
44 minutes ago, joeherwig said:

The work of mapping offsets and the corresponding values to functions was already done, so why should i do it again?

So it seems I don't understand your original question: 

3 hours ago, Pete Dowson said:

Probably you can give me a hint on that, how i'm able to access the MSFS / FS2020 functions which i can also assign via LINDA.

So, the "functions" you mean there are evidently not controls to make things happen in MSFS. Reading further it seems you want to access functions in one Lua plug-in from another. But your first question definitely concealed that request I'm afraid!

I think you need to import the other Lua into yours.  That's something I've never done,, but I think you use "require". Best to refer to the Lua reference website, or the book if you have one. You are doing more advanced stuff than I in any case, using arrays or functions, so continue your research. Or you could ask on the LINDA forum. I'm pretty sure LINDA makes use of these mechanisms.

Pete

 

 

Posted
11 hours ago, joeherwig said:

Probably someone might find it usefull as well.

Okay, thanks.  I see you solved the function access using "dofile". That's another one I've never used.

Perhaps you could make a more permanent place for it in the User Contributions sub-forum, with an appropriate title -- including I think mentioning that it uses LINDA. Otherwise it will scroll off into the distance in this forum.

Pete

 

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.