Jump to content
The simFlight Network Forums

Recommended Posts

Posted

Hey guys, based on the TripleUse.lua i tried to get an more generic and easier to configure script.

This supports to easily assign lua functions to button presses but not only for the rising or falling edge of the signal but also for double-press (like doubleclick) or for long press.

It is based on Pete's TripleUse.lua but extended to be able to call the funtions that were already defined in other lua scripts like the ones coming with LINDA.

You can just refer to it and re-use all the additional stuff like writing something to VRInsight panel displays etc.

--[[
    1=BU0836A Interface
    2=MFG Crosswind V2
    3=FCU / Lights
    5=Joystick
    7=Controller (GAME FOR WINDOWS >)

    btnFunc is an multi-dimensional array (lua:table) containing data in the format

    { joy, button, singlePressFunctionName, doublePressFunctionName, longPressFunctionName }

    use function name "ignore" to mark an status as unused.
]]


btnFunc = {
    { 3, 7, "DeIce_PITOT_on", "ignore", "DeIce_PITOT_off"},
    { 5, 3, "APU_STARTER", "APU_EXTINGUISH_FIRE", "APU_OFF_SWITCH"}
}

In the 2nd line of the btnFunc "Table"/ array you can see, that the Joystick button three has the APU assigned that way:

  • single short press: APU start
  • double short presses: APU extinguisher fires
  • long press: APU is switched off.

Of course that list / array with buttons can be easily extended to all recognized "USB_Gamecontroller_Buttons".

I published the more generic TripleUse.lua and TripleUseAssignments.lua on Github.

See: https://github.com/joeherwig/msfs-fsuipc-lua-scripts

Probably someone might find that useful.
Thanks Pete for your support!

Joe

  • Like 1
  • 3 weeks later...
Posted

Joe,

I use HomeFries' T.A.R.G.E.T. profiles in DCS World and have grown very fond of having short, long and double presses for each key on my TM HOTAS, so I was really glad to see you post this.  It will be great to be able to do this in MSFS and P3D.     Thanks for sharing your hard work.   

However, despite all my efforts I haven't been able to make this work.   I hope you or someone can tell me what I am doing wrong.  I admit to being a total novice when it come to LUA code and it is probably something pretty simple, but after about four days of "bumping around in the dark" and trying everything I can think of, I am asking for help.

Using FSUIPC's logging functions, I receive the following error any time I run the TripleUse.lua plug-in.  "*** LUA Error: [string "DeIce_PITOT_off()"]:1: attempt to call global 'DeIce_PITOT_off' (a nil value)"   I am attaching the TripleUse.log file.

I am running this in P3D and FSUIPC v6, but I have verified the functions you are calling in your example are valid.  I can make the function work by programing buttons in FSUIPC for those functions in your TripleUseAssignment table.  I have posted the contents of the pertinent files below.

Any help would be greatly appreciated.

Alan

 

Below is my version of your TripleUse.Lua I am using

-----------------------------------------------------------

interval = 500 -- 1/2 second press, gap, press limits
ignorepress = false

btnFunc = {
{ 7, 1, "DeIce_PITOT_on", "ignore", "DeIce_PITOT_off"},
{ 7, 2, "G1000_MFD_SOFTKEY12", "ignore", "G1000_MFD_SOFTKEY11"},
{ 7, 3, "MasterCaution_reset", "ignore", "MasterWarning_reset"}
}


function ignore ()
end

local function timebutton(joy, btn, 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, i)
    if ignorepress then
        ignorepress = false
        return
    end
    time1 = ipc.elapsedtime()
    time2 = 0
    if timebutton(j, b, false) then
        -- First press / release counts: see if there's another
        if timebutton(j, b, true) then
            -- got another press in time, look for release
            if timebutton(j, b, false) then  -- this was a double press, CS6
                assert(loadstring(btnFunc[i][4].."()"))()
            end
          else  -- This was a single press, send CS7
            assert(loadstring(btnFunc[i][3].."()"))()
            ignorepress = false
        end
    else  -- This was a single long press, send CS2
        assert(loadstring(btnFunc[i][5].."()"))()
  end
end


for i = 1, #btnFunc do
    event.button(btnFunc[i][1], btnFunc[i][2], i, "buttonpress")
end69

--------------------------------------------------------------------

Here is my IpcReady.lua

------------------------------------------------------------------

ipc.runlua('TripleUse')

------------------------------------------------------------------

And the IpcReady.log

********* LUA: "ipcReady" Log [from FSUIPC version 6.0.12] *********
    47906 System time = 22/01/2021 17:41:01, Simulator time = 17:40:23 (03:40Z)
    47906 LUA: beginning "C:\Users\AlanH\Documents\Prepar3D v5 Add-ons\FSUIPC6\ipcReady.lua"
    47906 LUA: ...H\Documents\Prepar3D v5 Add-ons\FSUIPC6\ipcReady.lua:1
    47906 LUA: Global: ipcPARAM = 0
    48015 >>> Thread forced exit (ipc.exit or os.exit) <<<
    48015 System time = 22/01/2021 17:41:02, Simulator time = 17:40:23 (03:40Z)
********* LUA execution terminated: Log Closed *********

 

Below is my FSUIPC6.ini,

Quote

 

General]
UpdatedByVersion=6012
History=PWW9FJ4L0CKM8NOCM0SDJ
InitDelayDevicesToo=No
PMDG737offsets=Auto
PMDG747offsets=Auto
PMDG777offsets=Auto
Annotate=Yes
UseSystemTime=No
UseMidMouseBtn=Yes
MouseWheelMove=No
MouseWheelTrim=No
MouseWheelTrimSpeed=1
JoystickTimeout=20
RestoreSimcWindows=No
FixMachSpeedBug=No
AutoScanDevices=Yes
DisconnTrimForAP=No
ZeroElevForAPAlt=No
ThrottleSyncAll=No
WhiteMessages=No
ShowPMcontrols=No
SpoilerIncrement=512
MagicBattery=No
RudderSpikeRemoval=No
ElevatorSpikeRemoval=No
AileronSpikeRemoval=No
ReversedElevatorTrim=No
ClockSync=No
ClockSyncMins=5
ClearWeatherDynamics=No
TimeForSelect=4
LoadFlightMenu=No
LoadPlanMenu=No
PauseAfterCrash=No
BrakeReleaseThreshold=75
SaveDataWithFlights=No
ZapSound=firework
ZapAirRange=1.50
ZapGroundRange=0.25
ZapCylinderAltDiff=0
ShortAircraftNameOk=Substring
UseProfiles=Yes
EnableMouseLook=No
DelayedMouseLookZoom=No
WideLuaGlobals=Yes
AxesWrongRange=No
TCASid=Flight
TCASrange=40,3
AxisCalibration=No
DirectAxesToCalibs=No
ShowMultilineWindow=Yes
SuppressSingleline=No
SuppressMultilineFS=No
AxisIntercepts=No
DontResetAxes=No
ThreadAffinityMask=x0
LuaAffinityMask=x0
InitDelay=0
GetNearestAirports=Yes
LogOptionProtect=Yes
TimeForLuaClosing=2
WeatherReadFactor=2
WeatherRewriteSeconds=1
TrafficStallTime=1
InitialStallTime=10
NormalStallTime=1
LuaRerunDelay=66
ComReadLoopTime=20
Console=Yes
ConsoleWindowTopMost=No
InvokeFSUIPCOptionsKey=70,26
ConsoleWindow=156,156,1349,675
LogEvents=Yes
LogLua=Yes
DebugLua=Yes
LogButtonsKeys=Yes
FSVersionUsed="Lockheed Martin® Prepar3D® v5",5.1.12.26829
SimConnectUsed=5.1.0.0

[Traffic Limiter]
AirportPreference=50
PlannedAirportsPreference=50
GroundPreference=50
NearerPreference=50
TargetFrameRate=0
LoLimit=0
HiLimit=0

[JoyNames]
AutoAssignLetters=No
1=Throttle - HOTAS Warthog
1.GUID={646A1090-F58C-11E9-8002-444553540000}
3=RIGHT VPC Stick MT-50CM
3.GUID={A7F15CB0-9604-11EA-8004-444553540000}
4=MFG Crosswind V2
4.GUID={39EFC3D0-F589-11E9-8001-444553540000}
5=F16 MFD 1
5.GUID={C3895F50-F58B-11E9-8003-444553540000}
6=F16 MFD 3
6.GUID={C3895F50-F58B-11E9-8004-444553540000}
7=F16 MFD 2
7.GUID={C3895F50-F58B-11E9-8005-444553540000}
9=Nostromo n52 Speedpad2
9.GUID={5AF36D40-F58C-11E9-8007-444553540000}

[JoystickCalibration]
RudderBlendLowest=1

[Axes]
PollInterval=10
RangeRepeatRate=10

[Auto]
1=TripleUse

[LuaFiles]
1=TripleUse
2=ipcReady

[Buttons]
PollInterval=25
ButtonRepeat=20,10
1=P5,0,K70,14     -{Key press: ctl+tab+F}-


[AutoSave]
Interval=60
Files=10
SaveOnGround=No
AutoSaveEnabled=No

[GPSout]
GPSoutEnabled=No
Port=COM1
Speed=4800
Interval=2000
PosTo6Decimal=No
SimModeIndicator=No
Sentences=

[GPSout2]
GPSoutEnabled=No
Port=<none set>
Speed=4800
Interval=2000
PosTo6Decimal=No
SimModeIndicator=No
Sentences=

[WideServer]
WideFSenabled=Yes
AdvertiseService=1
Port=8002
Port2=9002

[Sounds]
Path=D:\Games\Prepar3D v5\Sound\
Device1=Primary Sound Driver
Device2=SAMSUNG (NVIDIA High Definition Audio)
Device3=Realtek HD Audio 2nd output (Realtek(R) Audio)
Device4=Speakers (Realtek(R) Audio)
Device5=55S403-3 (NVIDIA High Definition Audio)

[AutoSaveFilesV5]
Next=1

[Keys]
1=70,26,1930,0     -{ctl+tab+F: Press= }-

 

Below is the FSUIPC6.log for the run

********* FSUIPC6, Version 6.0.12 (12th January 2021) by Pete & John Dowson *********
Prepar3D.exe version = 5.1.12.26829
Running inside Prepar3D v5
Module base=7FFED5930000
Windows 10 Pro 64 Bit reported as Build 19041, Release ID: 2004 (OS 10.0)
Reading options from "C:\Users\AlanH\Documents\Prepar3D v5 Add-ons\FSUIPC6\FSUIPC6.ini"
Checking the Registrations now ...
User Name=
User Addr=
FSUIPC6 Key is provided
WideFS7 Key is provided
       62 System time = 22/01/2021 17:40:14
       62 FLT UNC path = "\\I9-9900K\E\UserFiles\AlanH\Documents\Prepar3D v5 Files\"
       62 Using DialogMode
       93 FS UNC path = "\\I9-9900K\D\Games\Prepar3D v5\"
      156 ---------------------- Joystick Device Scan -----------------------
      171 Product= RIGHT VPC Stick MT-50CM
      171    Manufacturer= ATMEL/VIRPIL/200325
      171    Vendor=044F, Product=0402 (Version 0.1)
      187    GUIDs returned for product: VID_044F&PID_0402:
      187       GUID= {A7F15CB0-9604-11EA-8004-444553540000}
      187       Details: Btns=19, POVs=(0, 0, 0, 0), Cal=x00000000, Max=R0,U0,V0,X16384,Y16384,Z0
      187 Product= F16 MFD 3
      187    Manufacturer= Thrustmaster
      187    Vendor=044F, Product=B353 (Version 1.0)
      187    GUIDs returned for product: VID_044F&PID_B353:
      187       GUID= {C3895F50-F58B-11E9-8004-444553540000}
      187       Details: Btns=28, POVs=(0, 0, 0, 0), Cal=x00000000, Max=R0,U0,V0,X0,Y0,Z0
      187 Product= F16 MFD 1
      187    Manufacturer= Thrustmaster
      187    Vendor=044F, Product=B351 (Version 1.0)
      187    GUIDs returned for product: VID_044F&PID_B351:
      187       GUID= {C3895F50-F58B-11E9-8003-444553540000}
      187       Details: Btns=28, POVs=(0, 0, 0, 0), Cal=x00000000, Max=R0,U0,V0,X0,Y0,Z0
      187 Product= F16 MFD 2
      187    Manufacturer= Thrustmaster
      187    Vendor=044F, Product=B352 (Version 1.0)
      187    GUIDs returned for product: VID_044F&PID_B352:
      187       GUID= {C3895F50-F58B-11E9-8005-444553540000}
      187       Details: Btns=28, POVs=(0, 0, 0, 0), Cal=x00000000, Max=R0,U0,V0,X0,Y0,Z0
      187 Product= MFG Crosswind V2
      187    Manufacturer= MFG
      187    Serial Number= MFG500002
      187    Vendor=16D0, Product=0A38 (Version 33.1)
      187    GUIDs returned for product: VID_16D0&PID_0A38:
      187       GUID= {39EFC3D0-F589-11E9-8001-444553540000}
      187       Details: Btns=2, POVs=(0, 0, 0, 0), Cal=x00000000, Max=R4096,U0,V0,X4096,Y4096,Z0
      187 Product=
      187    Vendor=050D, Product=0815 (Version 2.16)
      187    GUIDs returned for product: VID_050D&PID_0815:
      187       GUID= {5AF36D40-F58C-11E9-8007-444553540000}
      187       Details: Btns=24, POVs=(0, 0, 0, 0), Cal=x00000000, Max=R255,U255,V255,X255,Y255,Z255
      187 Product= Throttle - HOTAS Warthog
      187    Manufacturer= Thrustmaster
      187    Vendor=044F, Product=0404 (Version 1.0)
      187    GUIDs returned for product: VID_044F&PID_0404:
      187       GUID= {646A1090-F58C-11E9-8002-444553540000}
      187       Details: Btns=32, POVs=(0, 0, 0, 0), Cal=x00000000, Max=R16383,U1023,V0,X1023,Y1023,Z16383
      203 -------------------------------------------------------------------
      203 Device acquired for use:
      203    Joystick ID = 3 (Registry okay)
      203    3=RIGHT VPC Stick MT-50CM
      203    3.GUID={A7F15CB0-9604-11EA-8004-444553540000}
      203 Device acquired for use:
      203    Joystick ID = 6 (Registry okay)
      203    6=F16 MFD 3
      203    6.GUID={C3895F50-F58B-11E9-8004-444553540000}
      203 Device acquired for use:
      203    Joystick ID = 5 (Registry okay)
      203    5=F16 MFD 1
      203    5.GUID={C3895F50-F58B-11E9-8003-444553540000}
      203 Device acquired for use:
      203    Joystick ID = 7 (Registry okay)
      203    7=F16 MFD 2
      203    7.GUID={C3895F50-F58B-11E9-8005-444553540000}
      203 Device acquired for use:
      203    Joystick ID = 4 (Registry okay)
      203    4=MFG Crosswind V2
      203    4.GUID={39EFC3D0-F589-11E9-8001-444553540000}
      203 Device acquired for use:
      203    Joystick ID = 9 (Registry okay)
      203    9=Nostromo n52 Speedpad2
      203    9.GUID={5AF36D40-F58C-11E9-8007-444553540000}
      203 Device acquired for use:
      203    Joystick ID = 1 (Registry okay)
      203    1=Throttle - HOTAS Warthog
      203    1.GUID={646A1090-F58C-11E9-8002-444553540000}
      203 -------------------------------------------------------------------
      250 Controllers are set to OFF
      250 LogOptions=E0000000 00000001
      250 -------------------------------------------------------------------
      250 SimConnect_Open succeeded: waiting to check version okay
      250 Opened separate AI Traffic client okay
     2890 Running in "Lockheed Martin® Prepar3D® v5", Version: 5.1.12.26829 (SimConnect: 5.1.0.0)
     2890 Initialising SimConnect data requests now
     2890 FSUIPC Menu entry added
     2906 ... Using Prepar3D with Professional License
     2937 \\I9-9900K\E\UserFiles\AlanH\Documents\Prepar3D v5 Files\C172 Anniversary N265K - 2021-01-14 19-27-07.fxml
     2937 \\I9-9900K\D\Games\Prepar3D v5\SimObjects\Airplanes\Carenado C172II N\SingleEngineProp.air
    19156 ### The user object is 'C172 Anniversary'
    19156 ### Mode is NORMAL
    19859 ### Mode: PAUSE on
    40906 Loading Complete ...
    40921 ### Mode is NORMAL
    41656 User Aircraft ID 1 supplied, now being used
    41656 Aircraft loaded: running normally now ...
    41828 System time = 22/01/2021 17:40:55, Simulator time = 17:40:17 (03:40Z)
    41843 Aircraft="C172 Anniversary"
    47843 -------------------- Starting everything now ----------------------
    47843 Starting WideServer now ...
    49031 Advanced Weather Interface Enabled
    52000 KEYDOWN: VK=65, Waiting=0, Repeat=N, Shifts=0
    52000 .. Key not programmed -- passed on to FS
    52015 *** EVENT: Cntrl= 66153 (0x00010269), Param= 0 (0x00000000) NEXT_SUB_VIEW
    52171 KEYUP: VK=65, Waiting=0, Shifts=0
    52781 KEYDOWN: VK=65, Waiting=0, Repeat=N, Shifts=0
    52781 .. Key not programmed -- passed on to FS
    52781 *** EVENT: Cntrl= 66153 (0x00010269), Param= 0 (0x00000000) NEXT_SUB_VIEW
    52906 KEYUP: VK=65, Waiting=0, Shifts=0
    61968 KEYDOWN: VK=17, Waiting=0, Repeat=N, Shifts=2
    61968 .. Key not programmed -- passed on to FS
    62265 KEYDOWN: VK=69, Waiting=0, Repeat=N, Shifts=2
    62265 .. Key not programmed -- passed on to FS
    62265 *** EVENT: Cntrl= 66224 (0x000102b0), Param= 0 (0x00000000) ENGINE_AUTO_START
    62359 KEYUP: VK=69, Waiting=0, Shifts=2
    62593 KEYUP: VK=17, Waiting=0, Shifts=0
    88703 KEYDOWN: VK=80, Waiting=0, Repeat=N, Shifts=0
    88703 .. Key not programmed -- passed on to FS
    88703 *** EVENT: Cntrl= 65561 (0x00010019), Param= 0 (0x00000000) PAUSE_TOGGLE
    88703 ### Mode: PAUSE on
    88875 KEYUP: VK=80, Waiting=0, Shifts=0
    94375 *** EVENT: Cntrl= 65794 (0x00010102), Param= 0 (0x00000000) PAUSE_ON
 16990296 *** EVENT: Cntrl= 65732 (0x000100c4), Param= 0 (0x00000000) EXIT
 16990375 Sim stopped: average frame rate for last 16949 secs = 30.0 fps
 16990375    Max AI traffic was 0 aircraft
 16990375 -------------------------------------------------------------------
 16992765 === Closing session: waiting for DLLStop to be called ...
 16999093 === DLLStop called ...
 16999093 === Closing external processes we started ...
 17000093 === About to kill any Lua plug-ins still running ...
 17000234 Lua threads being terminated:
 17000234       2 = "C:\Users\AlanH\Documents\Prepar3D v5 Add-ons\FSUIPC6\TripleUse.lua"
 17000406 LUA: "C:\Users\AlanH\Documents\Prepar3D v5 Add-ons\FSUIPC6\TripleUse.lua": killed
 17000406 === Closing global Lua thread
 17001421 === About to kill my timers ...
 17001625 === Restoring window procs ...
 17001625 === Unloading libraries ...
 17001625 === stopping other threads ...
 17001625 === ... Button scanning ...
 17001718 === ... Axis scanning ...
 17001828 === Releasing joystick devices ...
 17001828 === Freeing macro memory
 17001828 === Removing any offset overrides
 17001828 === Closing all WideFS threads
 17003171 === Clearing any displays left
 17003171 === NOTE: not calling SimConnect_Close ...
 17003171 === AI slots deleted!
 17003187 === Freeing button memory ...
 17003187 === Deleting wxstationlist.bin file ...
 17003187 === Closing my Windows ...
 17003187 === Freeing FS libraries ...
 17004187 === Closing devices ...
 17004187 === Closing the Log ... Bye Bye! ...
 17004187 System time = 22/01/2021 22:23:38, Simulator time = 17:41:04 (03:41Z)
 17004187 *** FSUIPC log file being closed
Minimum frame rate was 29.6 fps, Maximum was 30.1 fps
Average frame rate for running time of 16949 secs = 30.0 fps
Maximum AI traffic for session was 0 aircraft
Memory managed: 7796 Allocs, 7795 Freed
********* FSUIPC Log file closed ***********

 

TripleUse.log

Posted

Sorry I just can't leave it alone......

Since the TripleUse.lua was written for FSUIPC7 and MSFS, I wanted to rule out that the error I am getting is because I'm trying to use TripleUse.lua with FSUIPC6 and P3DV5.1.  So I tried running the TripleUse.lua with FSUIPC7/MSFS and I receive the same error.  Below is a cut and paste of the FSUIPC7 log file.

   167625 LUA.1: beginning "D:\Programs\FSUIPC7\ipcReady.lua"
   321469 *** LUA Error: [string "DeIce_PITOT_off()"]:1: attempt to call global 'DeIce_PITOT_off' (a nil value)
   326437 *** LUA Error: D:\Programs\FSUIPC7\TripleUse.lua:45: attempt to index field '?' (a nil value)
   327766 *** LUA Error: [string "DeIce_PITOT_on()"]:1: attempt to call global 'DeIce_PITOT_on' (a nil value)
   328297 *** LUA Error: D:\Programs\FSUIPC7\TripleUse.lua:45: attempt to index field '?' (a nil value)

   369687 LUA.2: Waiting for an event in "D:\Programs\FSUIPC7\TripleUse.lua"
   376969 LUA.2: Button event: calling "buttonpress" in "D:\Programs\FSUIPC7\TripleUse.lua"
  
377906 *** LUA Error: [string "DeIce_PITOT_on()"]:1: attempt to call global 'DeIce_PITOT_on' (a nil value)
   377922 LUA.2: Waiting for an event in "D:\Programs\FSUIPC7\TripleUse.lua"
   518219 LUA.2: Button event: calling "buttonpress" in "D:\Programs\FSUIPC7\TripleUse.lua"
 
  518766 *** LUA Error: D:\Programs\FSUIPC7\TripleUse.lua:45: attempt to index field '?' (a nil value)
   518781 LUA.2: Waiting for an event in "D:\Programs\FSUIPC7\TripleUse.lua"

Attached is my version of the TripleUse.lua.

Now it looks like there are two errors: "

LUA Error: [string "DeIce_PITOT_on()"]:1: attempt to call global 'DeIce_PITOT_on' (a nil value)

LUA Error: D:\Programs\FSUIPC7\TripleUse.lua:45: attempt to index field '?' (a nil value)

btnFunc  is a table array defined as

btnFunc = {
{ 7, 1, "DeIce_PITOT_on", "ignore", "DeIce_PITOT_off"},
{ 7, 2, "G1000_MFD_SOFTKEY12", "ignore", "G1000_MFD_SOFTKEY11"},
{ 7, 3, "MasterCaution_reset", "ignore", "MasterWarning_reset"}
}

So looking at the code, the "assert(loadstring(btnFunc[i][3].."()"))()"  statements must be the means by which TripleUse tells FSUIPC to send the command contained in the string elements stored in the table array (i.e. btnFunc) to MSFS, but for some reason FSUIPC (or lua) doesn't like the fact the string is a global or it has a "nil value".  Can someone explain this error?

I must be missing something.....

I don't know about the second error, I didn't see it in the logs from the FSUIPC6/P3D runs.   I think it indicates TripleUse is trying to index a value outside of the array size.

TripleUse.lua

Posted
5 hours ago, FastBlueMooney said:

Sorry I just can't leave it alone......

Seems that the author of the original hasn't seen your pleas for help, and this being a Reference subforum, not a support forum, you might not get any other replies.

The author is cleverer than I with respect to Lua programming. I don't know much about "Assert", and I didn't even know you could have arrays of functions. However, looking at your Lua file I can't see any sign of the functions referred to in the Array:

btnFunc = {
{ 7, 1, "DeIce_PITOT_on", "ignore", "DeIce_PITOT_off"},
{ 7, 2, "G1000_MFD_SOFTKEY12", "ignore", "G1000_MFD_SOFTKEY11"},
{ 7, 3, "MasterCaution_reset", "ignore", "MasterWarning_reset"} 
}

That seems to list 7 distinct functions which are nowhere to be found!

Looking at the author's original files (and there are TWO ofthem), the shorter one included these lines:

dofile([[.\LINDA\system\common.lua]])
dofile([[.\LINDA\libs\lib-msfs.lua]])
dofile([[.\LINDA\libs\lib-fsxcontrols.lua]])
dofile([[.\TripleUseAssignments.lua]])

function ignore ()
end

Here I can see the "ignore" function, and I assume the others are within those LINDA files.

Evidently you have removed this stuff and hence have a result which includes none of the functions needs to make it work!

If you are not using LINDA then I guess you need to supply those functions yourself. Write them in your Lua.

Pete

 

Posted
On 1/7/2021 at 2:24 PM, joeherwig said:

It is based on Pete's TripleUse.lua but extended to be able to call the funtions that were already defined in other lua scripts like the ones coming with LINDA.

As the author says. this is calling other lua scripts and those functions are defined in Linda. Maybe the author should make it clear that those functions are used.
I'm not sure if you could extract those functions and use them without Linda, as they probably reference other Linda functions.

Maybe the author, @joeherwig, could either let you know if this script
   - only works with Linda installed, or
   - can be used by extracting a self-contained set of lua functions? If so, maybe this can also be added to github?

John

Posted (edited)

Thanks for the responses Pete and John.   I was assuming (wrongly apparently!) that by some magic in FSUIPC, that when TripleUse "asserted" the function names (which I thought were THE EXACT same names showing up in FSUIPC.ini when I simply program a button to those FS controls )  that the ASSERT command  somehow triggered FSUIPC to issue the command to FS.   I'm embarrassed by my lack of understanding.

I saw the OP's "dofile XXXXXXX" commands in his files, but thought those were related to LINDA.    I did try  installing LINDA, but the "lib-msfs.lua" and "lib-fsxcontrols.lua" files were missing and resulted in errors when I tried executing with his original files.   So I tried stripping them out, thinking they weren't necessary.  As you observed he didn't say anything about LINDA being REQUIRED to make TripleUse work.     So sounds like that is the missing link between the ASSERT (btnFunc....) command  and execution of a command is contained in those files.

Hopefully, Joe will comment on how to make this work.   I did open an issue on his GitHub.  It would be a really great way to gain extra utility from joystick buttons.

Alan

Edited by FastBlueMooney
Posted

Do you ever have one of those days (or weeks) where you are unable "to pour pee out of a boot even if the instructions were written on the heel!"🤬???

Thanks to Pete and John, I figured out the problem and have TripleUse working with MSFS/FSUIPC7.   As they suggested the missing element was indeed the lib-fsxcontrols.lua and  lib-msfs.lua found in the library for LINDA_4_0_3_41, which is for MSFS only.  The lib-fsxcontrols.lua contains a long list of calls to the default FSX control offsets like:

function _PITOT_HEAT_OFF (p)     ipc.control( 66073, p )  end
function _PITOT_HEAT_ON (p)     ipc.control( 66072, p )  end

The lib-msfs.lua appears to map some MSFS commands to their FSX equivalent :

function DeIce_PITOT_on ()
    _PITOT_HEAT_ON ()
end

function DeIce_PITOT_off ()
    _PITOT_HEAT_OFF ()
end

Looking back on this experience, I really was a bull wondering around in a FSUIPC china shop.   I was messing with areas in FSUIPC that I had never ventured before (i.e. lua code) and with a program (LINDA) I had heard about, but had no idea about its functions.

My first mistake was trying to use this TripleUse with P3Dv5/FSUIPC6.  The OP stated it was for MSFS/FSUIPC7.   When I tried loading LINDA for P3Dv5/FSUIP6, the lib-fsxcontrols.lua and lib-msfs.lua were not in that vesion of Linda\lib and running TripleUse resulted in the error I reported in my first post.

My second error was assuming that I didn't need LINDA, since TripleUse wasn't working  with LINDA installed in P3D/FSUIPC6.

My third error was next trying it with MSFS/FSUIPC7, without loading LINDA.   Not knowing LUA or having a deeper understanding about FSUIP, I assumed some magic was happening when the FSUIPC names for the controls were mentioned in the ASSET call.

After Pete's and John's comments, I spent time reading about LINDA and installed it for MSFS. Browsing through those lib-files, I realized they were the missing  connection between the ASSERT(btn_Func) command in TripleUse and executing the function in FS.

Although embarrassing to publicly post and reveal my ignorance on this forum,  I have learned a lot about FSUIPC, LUA functions and LINDA that I wouldn't have learned if I had done everything right and it had worked the first time. 

Pete or John:  Feel free to delete my posts from the user contributions or move them to the general comments if you feel that they have any value to anyone else trying to get TripleUse working on their systems.

Posted
On 1/24/2021 at 11:50 AM, John Dowson said:

Maybe the author, @joeherwig, could either let you know if this script
   - only works with Linda installed, or
   - can be used by extracting a self-contained set of lua functions? If so, maybe this can also be added to github?

John

Thanks for pointing towards that John.
Now it is:

--[[ 
	The following files are included using "dofile" to ensure that the functions you want to assign / call within the TripleUseAssignments.lua are available. 
	The Examples listed in here refer to teh new MSFS2020 where LINDA (https://www.avsim.com/forums/forum/427-linda-downloads/) is used.
	LINDA (Lua Integrated Non complex Device Assignments) brings LUA scripts that map FSUIPC Offsets and even more logic to nice and 
	self descriptive function names, which makes it much easier to assign them and even at a later point simply understand the assignments.
	In Case you want to get it running for other Simulators like P3D, FSX etc. you have to refer the related Function lists here.
	Of course TripleUse does not require to run LINDA to refer to those script files. You can also write and add your own.
	For me it was simply convenient to use the already made ones which saved me a lot of time.
]]--

-- Common functions needed, when you want to refer to the lib-msfs and lim-fsxcontrols functions.
dofile([[.\LINDA\system\common.lua]])
-- The function definitions as provided with LINDA. 
dofile([[.\LINDA\libs\lib-msfs.lua]])
dofile([[.\LINDA\libs\lib-fsxcontrols.lua]])
-- The assignments of functions to your game device buttons itself
dofile([[.\TripleUseAssignments.lua]])

-- Used to have a placeholder in case you do not want to assign something in the TripleUseAssignments.lua for some function. In that case just assign "ignore". As an "ignore" function did not exist in the above Function libs, i just added it here.
function ignore ()	
end

The rest of the document remained functional the same and does not contain additional comments.

Hope that helps.

  • Like 1
Posted

Joe,

Thanks for posting the additional explanation and for taking the initiative to generalize Pete's TripleUse.lua .  I figured out how to install LINDA and access the lib-fsxControls.lua provide in LINDA's library.   I have also learned a lot about LUA programming  and FSUIPC in trying to get this code to work on my system.  However; despite my efforts, I couldn't get any other entries in the TripleUseAssignment.lua to work except the very first entry.   All the other entries returned a "nil" error.

After studying your code, I think I may have found two potential problems (if I understand correctly, which maybe a bad assumptions on my part!) and hope you can review and confirm.

The first problem is in line 67 of TripleUse.Lua:
66   for i = 1, #btnFunc do
67     event.button(btnFunc[i][1], btnFunc[i][2],
i, "buttonpress")
68   end

Line 67 is assigning the a current value ("i") to the "downup" parameter of the event.button() call.  Where, in your code "i" can be any number from 1 to the number of joystick buttons (i.e. #btnFunc) contained in the TripleAssignment.Lua.  However according the page 24 of the FSUIPC Lua Library.pdf,  for the event.button(joynum, button, downup, "function-name"), the only defined  values for "downup"  are  "1", "2", or "3".  My understanding is that "downup"  is telling event.button() to trigger on a press, release or both.   So I'm not sure what happens for values when i > 3.   The "downup" parameter can also be omitted, and if so will look for a "press".    (Perhaps Pete or John will comment, if I am wrong.)
 

The second problem is the indexing used in the "assert(loadstring(btnFunc[i][i.e. 3,4, or 5].."()"))"  in lines #54, 57 and 61.   The value for "i" is being returned from the event.button() is via line #42:   function buttonpress(j, b, i).

My understanding from reading about event.button(), is that the value, being returned thorough  "i" ,  is the "downup" parameter and not an index to the joystick button in btnFunc() as loaded into the event.button() in line#67.    In my testing,  the only values i will ever be is "1" or "0".   This explains why only the first joystick/button entry in TripleUseAssignment worked.

Primarily as an opportunity to learn a bit of LUA coding,  debugging techniques and more about FSUIP, I have attempted to correct the above issues in TripleUse.lua.  In my testing with P3Dv5 and FSUIPC6, it now works for any number of joystick buttons. 

Briefly,   I replaced "i" in your line #67 with  "1".  I also added the following function to determine the index based on "j" and "b" into btnFunc() in order to call the desired FSX_control function.

function sendFSControl(j,b,typePress)
    for key, value in pairs(btnFunc) do
        if value[1] == j and value[2] == b then
        assert(_G[value[typePress]])()
        end    
    end
end  

{Apologies:  I tried including the files as ATTACHMENTS, but for some reason there the file limit of only 841 bytes!?}  So, I have pasted them into this message. }

 

Below is my revised version of your TripleUse.Lua and for your review, I have added comments explain what I changed.  

-------------------------------------------BEGIN TRIPLEUSE.LUA----------------------------------------------------

 

interval = 500 -- 1/2 second press, gap, press limits
ignorepress = false

dofile([[.\LINDA\system\common.lua]])
dofile([[.\LINDA\libs\lib-fsxcontrols.lua]])
dofile([[.\TripleUseAssignments.lua]])

function ignore ()
end

local function timebutton(joy, btn, 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
---------------------------------------------------------

-- New function added below and called by funtion buttonpress()
-- Determine index into buttonpress() based on Joy# (j)and Button# (b)
-- and then call the FSX or MSFS control defined in "btnFunc" table
-- "typePress" is either single, double or long as press
--  as determined in "function buttonpress"

--
--
function sendFSControl(j,b,typePress)
    for key, value in pairs(btnFunc) do
        if value[1] == j and value[2] == b then
        assert(_G[value[typePress]])()
        end    
    end
end    

---------------------------------------------------------
function buttonpress(j, b, i)
--

-- note: the "i" parameter returned is "downup" state of the button
-- it is not an index pointing to which button was pressed
-- see FSUIPC Lua Library Document page 24 for details

--
    if ignorepress then
        ignorepress = false
        return
    end
    time1 = ipc.elapsedtime()
    time2 = 0
    if timebutton(j, b, false) then
        -- First press / release counts: see if there's another
        if timebutton(j, b, true) then
            -- got another press in time, look for release
            if timebutton(j, b, false) then
                -- This was a double press, CS6
                
-- replace original line: "assert(loadstring(btnFunc[i][4].."()"))()"
                -- with this new line

                -----------------------------------------
                sendFSControl(j,b,4)
                -----------------------------------------
            end
        else  -- This was a single press, send CS7
          
   -- replace original line: "assert(loadstring(btnFunc[i][3].."()"))()"
              -- with the following new line

            ---------------------------------------------
            sendFSControl(j,b,3)
            ---------------------------------------------     
            ignorepress = false
        end
    else  -- This was a single long press, send CS2
         
-- replace original line: "assert(loadstring(btnFunc[i][5].."()"))()"
          -- with the following new new

        -------------------------------------------------  
        sendFSControl(j,b,5)
        -------------------------------------------------
    end
end

 

for i = 1, #btnFunc do
 
   -- replace original line "event.button(btnFunc[k][1], btnFunc[k][2], i, "buttonpress")"
    -- with the following new line
    -- the third parameter ("i") of event.button function is "downup" and can only be = 1,2,3 or ommitted.  
    -- it specifies whether to trigger on a press (=1 or omitted) , a release (=2) or either press or release (=3)
    -- so the new line set downup = 1 detect a button press
    -- see FSUIPC Lua Library document, page 24 for details

    -----------------------------------------------------
    event.button(btnFunc[i][1], btnFunc[i][2], 1, "buttonpress")
    -----------------------------------------------------
end

-----------------------------------------------END TRIPLEUSE.LUA----------------------------------------------------

For anyone else  wanting to gives this a try, below  are my TripleUseAssignments.lua and the Joystick section from my FSUIPC.ini   One thing I would note is that the name of the FSX functions contained in the LINDA lib-fsxControls.lua are different than what is used in FSUIPC in that they all begin with an underscore.

-------------------------------------- BEGIN TRIPLEUSEASSIGNMENTS.LUA----------------------------------------------------

btnFunc = {
{ 7, 0, "_XPNDR_1000_INC", "ignore", "_XPNDR_1000_DEC"},
{ 7, 1, "_XPNDR_100_INC", "ignore", "_XPNDR_100_DEC"},
{ 7, 2, "_XPNDR_10_INC", "ignore", "_XPNDR_10_DEC"},
{ 7, 3, "_XPNDR_1_INC", "ignore", "_XPNDR_1_DEC"},
{ 5, 1, "_FLAPS_INCR", "ignore", "_FLAPS_DECR"},
{ 5, 2, "_FLAPS_DOWN", "ignore", "_FLAPS_UP"}
}

-------------------------------------- END TRIPLEUSEASSIGNMENTS.LUA----------------------------------------------------

From my FSUIPC6.ini

[JoyNames]
AutoAssignLetters=No
T=Throttle - HOTAS Warthog
T.GUID={646A1090-F58C-11E9-8002-444553540000}
S=RIGHT VPC Stick MT-50CM
S.GUID={A7F15CB0-9604-11EA-8004-444553540000}
L=F16 MFD 1
L.GUID={C3895F50-F58B-11E9-8003-444553540000}
N=F16 MFD 3
N.GUID={C3895F50-F58B-11E9-8004-444553540000}
M=F16 MFD 2
M.GUID={C3895F50-F58B-11E9-8005-444553540000}
K=Nostromo n52 Speedpad2
K.GUID={5AF36D40-F58C-11E9-8007-444553540000}
X=MFG Crosswind V2
X.GUID={39EFC3D0-F589-11E9-8001-444553540000}
0=MFG Crosswind V2
0.GUID={39EFC3D0-F589-11E9-8001-444553540000}
1=Throttle - HOTAS Warthog
1.GUID={646A1090-F58C-11E9-8002-444553540000}
3=RIGHT VPC Stick MT-50CM
3.GUID={A7F15CB0-9604-11EA-8004-444553540000}
5=F16 MFD 1
5.GUID={C3895F50-F58B-11E9-8003-444553540000}
6=F16 MFD 3
6.GUID={C3895F50-F58B-11E9-8004-444553540000}
7=F16 MFD 2
7.GUID={C3895F50-F58B-11E9-8005-444553540000}
9=Nostromo n52 Speedpad2
9.GUID={5AF36D40-F58C-11E9-8007-444553540000}

What I have not yet figured out is how to make TripleUse.lua work with Joystick letters in lieu of Joystick numbers.   The event.button() appears to be capable of handling either. (i.e. event.button("joyletter", button,“function-name”).    So there are still some challenges and opportunities remaining in completely generalizing TripleUse.lua.

Alan

 

 

  • Like 1
Posted

Uhm... Sounds reasonable Alan. 

I introduced the index later and did not properly investigate into the event.Button params well... 

'll have to take a look at it. 

Thanks for your great analysis. 

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.