Jump to content
The simFlight Network Forums

Recommended Posts

Posted

let's try something like this:


function incdecHDG ( pDiff ) -- increment or decrement HDG by pDiff
local lHDG = ipc.readLvar( "L:AB_AP_HDG_Select" ) + pDiff
if lHDG > 359 then
lHDG = lHDG - 360
end if
if lHDG < 0 then
lHDG = lHDG + 360
end if
ipc.writeLvar( "L:AB_AP_HDG_Select", lHDG )
end
function incHDG ( joynum, button, downup )
incdecHDG ( 1 )
end
function decHDG ( joynum, button, downup )
incdecHDG ( -1 )
end
function incHDGFast ( joynum, button, downup )
incdecHDG ( 10 )
end
function decHDGFast ( joynum, button, downup )
incdecHDG ( -10 )
end

-- register the buttons of your joystick triggering the functions
-- replace joynum by the actual used number, also replace button by the actual button number
event.button(joynum, button1, 1, "incHDG")
event.button(joynum, button2, 1, "decHDG")
event.button(joynum, button3, 1, "incHDGFast")
event.button(joynum, button4, 1, "decHDGFast")
[/CODE]

Unfortunately this one doesn't work neither:

Here's my current lua:

[CODE]
-- toggle FD button
function toggleFD (joynum, button, downup)
ipc.writeLvar( "L:AB_MPL_FD", 1 - ipc.readLvar("L:AB_MPL_FD") )
ipc.writeLvar( "L:SmallOverheadPushButtons", 1 )
end
-- toggle ATHR button
function toggleILS (joynum, button, downup)
ipc.writeLvar( "L:AB_MPL_ILS", 1 - ipc.readLvar("L:AB_MPL_ILS") )
ipc.writeLvar( "L:SmallOverheadPushButtons", 1 )
end
-- HDG mode selection managed
function selectHDGmode (joynum, button, downup)
ipc.writeLvar( "L:AB_AP_HDGmode", 1 )
ipc.writeLvar( "L:SmallOverheadPushButtons", 1 )
end
-- HDG Knob
function incdecHDG ( pDiff ) -- increment or decrement HDG by pDiff
local lHDG = ipc.readLvar( "L:AB_AP_HDG_Select" ) + pDiff
if lHDG > 359 then
lHDG = lHDG - 360
end if
if lHDG < 0 then
lHDG = lHDG + 360
end if
ipc.writeLvar( "L:AB_AP_HDG_Select", lHDG )
end
function incHDG ( joynum, button, downup )
incdecHDG ( 1 )
end
function decHDG ( joynum, button, downup )
incdecHDG ( -1 )
end
function incHDGFast ( joynum, button, downup )
incdecHDG ( 10 )
end
function decHDGFast ( joynum, button, downup )
incdecHDG ( -10 )
end

event.button(175, 0, 1, "toggleFD")
event.button(175, 1, 1, "toggleILS")
event.button(149, 1, 1, "selectHDGmode")
event.button(149, 18, 1, "incHDG")
event.button(149, 17, 1, "decHDG")
event.button(149, 19, 1, "incHDGFast")
event.button(149, 16, 1, "decHDGFast")
[/CODE]

None of the functions work when I add the HDG knob turning part.

Thanks,

Dirk.

Posted

Hi,

Maybe some typo. Check the FSUIPC.log file for errors. It was late yesterday. I have no chance to test it. But must be a small correction.

Rgds

Reinhard

Posted

Hi,

I found it: Replace the "end if" statements by a simple "end".

That should fix it.

Rgds

Reinhard

Ooops, in which one of the two luas? :D

Thanks,

Dirk.

Posted

Haha! This code now increases VS by 100 or FPA by 0.1 each time I press the assigned button, depending on which state the VS/FPA button is in (not in the code yet, I do it manually). I think I can start building up on it.


-- VS/FPA Toggle code
function incFPAorVS ( joynum, button, downup )
if ipc.readLvar("L:AB_AP_HDGTRK") == 1 then -- 1 = TRK/FPA

local lFPA = ipc.readLvar( "L:AB_AP_FPA_Select2" ) + 0.1
if lFPA > 9.9 then
lFPA = 9.9
end
ipc.writeLvar( "L:AB_AP_FPA_Select2", lFPA )

else -- 0 = HDG/SPD so set VS

local lVS = ipc.readLvar( "L:AB_AP_VS_Select2" ) + 1
if lVS > 60 then
lVS = 60
end
ipc.writeLvar( "L:AB_AP_VS_Select2", lVS )

end

end


event.button(175, 4, 1, "incFPAorVS")[/CODE]

Will check the HDG inc/dec code without "end if" now.

Thanks!

Dirk.

Posted

The HDG knob turning code works perfect without "end if". You made my day, Reinhard, thank you very much.

I'm working on the VS/FPA knob and button script now, there are some parts missing yet.

Dirk.

Posted

I'll post soon my LUA for AXE, that basically can be used with any HID device, all interested please praise Reinhard (and Pete of course).

Question tor Reinhard:

I posted about this issue with AB_AP_VSlevel on aerosoft/axe/sdk forum. I'm not sure though I was right claiming it was an error or an omission of the current AXE SDK:

"AP_AP_VSlevel" actually resets FPA but not V/S to "0". It does not affect V/S

Please revise or explain how it should be handled.

You can easily check this out with this lua:

Quote

if ipcPARAM == 52 then

LVarSet = "L:AB_AP_VSlevel"

LVarGet = ipc.readLvar(LVarSet)

ipc.writeLvar(LVarSet, 1)

end

Try to change VS and use the above function, you'll see that nothing happens. Then switch HDGVS to TRKFPA, change FPA to some +/- and run the above again -> you'll see FPA will reset to +0.0.

I haven't found "AP_AP_FPAlevel" in SDK, so the above may well be a wrongly assigned function, with VS reset logic missing at all.

PS: I've just noticed in HDGVS mode the knob actually moves when you push VS knob with "L:AB_AP_VSlevel", but doesn't reset. In TRKFPA it also moves and resets FPA.

See, AB_AP_VSlevel resets only TRK/FPA to "0", when FCU is in TRK/FPA mode. It does nothing for HDG/VS mode though. I currently use this code:


-- VS/FPA level code
function levelVSlevel (joynum, button, downup)
ipc.writeLvar( "L:AB_AP_VSlevel", 1 - ipc.readLvar("L:AB_AP_VSlevel") )
ipc.writeLvar( "L:SmallOverheadPushButtons", 1 )
end

event.button(175, 5, 1, "levelVSlevel")[/CODE]

Is it possible to add some switching script to reset VS to 0 as well "outside" of AXE code?

Thanks,

Dirk.

Posted

Is it possible to add some switching script to reset VS to 0 as well "outside" of AXE code?

Thanks,

Dirk.

Yes, it is! With the tip from Joshua Che. on aerosoft boards (ipc.writeLvar( "L:AB_AP_VS_Select2", 0 ) I produced my own little script (or should I call it "hack"?) :


-- VS/FPA Level code
function levFPAorVS ( joynum, button, downup )
if ipc.readLvar("L:AB_AP_HDGTRK") == 1 then

ipc.writeLvar( "L:AB_AP_FPA_Select2", 0 )

else

ipc.writeLvar( "L:AB_AP_VS_Select2", 0 )

end

end

event.button(175, 5, 1, "levFPAorVS")
[/CODE]

See, Reinhard, your kind help and scripts do magic on me already, I feel like I can script something too, lol.

Thank you very much again,

Dirk.

Posted

I can't figure out why most of the script works ok, except for MACH Minus and MACH Minus Fast. The positivie part works both in SPD and MACH modes just fine:


-- SPD/MACH switch button
function switchSPDMACH (joynum, button, downup)
ipc.writeLvar( "L:AB_AP_SPDMACH", 1 - ipc.readLvar("L:AB_AP_SPDMACH") )
ipc.writeLvar( "L:SmallOverheadPushButtons", 1 )
end

-- SPD/MACH Inc
function incSPDorMACH ( joynum, button, downup )
if ipc.readLvar("L:AB_AP_SPDMACH") == 1 then

local lMACH = ipc.readLvar( "L:AB_AP_Mach_Select" ) + 0.01
if lMACH > 1.0 then
lMACH = 1.0
end
ipc.writeLvar( "L:AB_AP_Mach_Select", lMACH )

else

local lSPD = ipc.readLvar( "L:AB_AP_SPEED_Select" ) + 1
if lSPD > 340 then
lSPD = 340
end
ipc.writeLvar( "L:AB_AP_SPEED_Select", lSPD )

end

end

-- SPD/MACH IncFast
function incFastSPDorMACH ( joynum, button, downup )
if ipc.readLvar("L:AB_AP_SPDMACH") == 1 then

local lMACH = ipc.readLvar( "L:AB_AP_Mach_Select" ) + 0.1
if lMACH > 1.0 then
lMACH = 1.0
end
ipc.writeLvar( "L:AB_AP_Mach_Select", lMACH )

else

local lSPD = ipc.readLvar( "L:AB_AP_SPEED_Select" ) + 10
if lSPD > 340 then
lSPD = 340
end
ipc.writeLvar( "L:AB_AP_SPEED_Select", lSPD )

end

end

-- SPD/MACH Dec
function decSPDorMACH ( joynum, button, downup )
if ipc.readLvar("L:AB_AP_SMPDMACH") == 1 then

local lMACH = ipc.readLvar( "L:AB_AP_Mach_Select" ) - 0.01
if lMACH < 0 then
lMACH = 0
end
ipc.writeLvar( "L:AB_AP_Mach_Select", lMACH )

else

local lSPD = ipc.readLvar( "L:AB_AP_SPEED_Select" ) - 1
if lSPD < 0 then
lSPD = 0
end
ipc.writeLvar( "L:AB_AP_SPEED_Select", lSPD )

end

end

-- SPD/MACH DecFast
function decFastSPDorMACH ( joynum, button, downup )
if ipc.readLvar("L:AB_AP_SMPDMACH") == 1 then

local lMACH = ipc.readLvar( "L:AB_AP_Mach_Select" ) - 0.1
if lMACH < 0 then
lMACH = 0
end
ipc.writeLvar( "L:AB_AP_Mach_Select", lMACH )

else

local lSPD = ipc.readLvar( "L:AB_AP_SPEED_Select" ) - 10
if lSPD < 0 then
lSPD = 0
end
ipc.writeLvar( "L:AB_AP_SPEED_Select", lSPD )

end

end

event.button(149, 3, 1, "switchSPDMACH")
event.button(149, 22, 1, "incSPDorMACH")
event.button(149, 23, 1, "incFastSPDorMACH")
event.button(149, 21, 1, "decSPDorMACH")
event.button(149, 20, 1, "decFastSPDorMACH")[/CODE]

Any idea?

Much thanks,

Dirk.

Posted

Reinhard,

As I wrote I'm using your examples of scripts as templates for some other functions and controls in AXE. But as I think I already understand a little more in those scrips now, than when I started in this thread, I realize that some of them may not be very approriate for what I'm trying to achieve, due to different reasons, even when they seemingly function ok.

For example, you suggested these scripts for toggling FD and ATHR:

-- toggle FD button

function toggleFD (joynum, button, downup)

ipc.writeLvar( "L:AB_MPL_FD", 1 - ipc.readLvar("L:AB_MPL_FD") )

ipc.writeLvar( "L:SmallOverheadPushButtons", 1 )

end

-- toggle ATHR button

function toggleATHR (joynum, button, downup)

ipc.writeLvar( "L:AB_AP_ATHR", 1 - ipc.readLvar("L:AB_AP_ATHR") )

ipc.writeLvar( "L:SmallOverheadPushButtons", 1 )

end

-- register the buttons of your joystick triggering the functions

-- replace joyletter by the actual used letter/number, also replace buttonX by the actual value

event.button("joyletter", button1, 1, "toggleFD")

event.button("joyletter", button2, 1, "toggleATHR")

These examples are good for templates of toggling buttons that function On/Off. But they may be not so good for mode switching buttons like how I tried to adopt them for in SPD/MACH and VS/FPA switching:


-- VS/FPA switch button
function switchHDGTRK (joynum, button, downup)
ipc.writeLvar( "L:AB_AP_HDGTRK", 1 - ipc.readLvar("L:AB_AP_HDGTRK") )
ipc.writeLvar( "L:SmallOverheadPushButtons", 1 )
end

-- SPD/MACH switch button
function switchSPDMACH (joynum, button, downup)
ipc.writeLvar( "L:AB_AP_SPDMACH", 1 - ipc.readLvar("L:AB_AP_SPDMACH") )
ipc.writeLvar( "L:SmallOverheadPushButtons", 1 )
end[/CODE]

From AXE LVars list:

HDGTRK can be:

1 = TRK/FPA, 0 = HDG/SPD

SPDMACH can be:

1 = MACH, 0 = SPD

So, is there a different way to skin this cat, by explicitly using 1 and 0 switches in the scripts above?

Thanks,

Dirk.

PS: I mean, what if they were not 1 / 0, but rather 1 / -1? Would have the main script body above been valid yet?

Posted

Hi,

I added an alternative template for the FD using explicit values. Replace the variables and values acording to your need. But as these are basic programming tasks, I would suggest to read the LUA reference manual and especially try to understand the includes samples with the LUA package.

Rgds

Reinhard


-- toggle FD button
function toggleFD (joynum, button, downup)

local lFD = ipc.readLvar("L:AB_MPL_FD")

if lFD == 0 then
lFD = 1
else
lFD = 0
end

ipc.writeLvar( "L:AB_MPL_FD", lFD )
ipc.writeLvar( "L:SmallOverheadPushButtons", 1 )

end
[/CODE]

Posted

Hi,

I added an alternative template for the FD using explicit values. Replace the variables and values acording to your need. But as these are basic programming tasks, I would suggest to read the LUA reference manual and especially try to understand the includes samples with the LUA package.

Rgds

Reinhard


-- toggle FD button
function toggleFD (joynum, button, downup)

local lFD = ipc.readLvar("L:AB_MPL_FD")

if lFD == 0 then
lFD = 1
else
lFD = 0
end

ipc.writeLvar( "L:AB_MPL_FD", lFD )
ipc.writeLvar( "L:SmallOverheadPushButtons", 1 )

end
[/CODE]

Yes! Thank you very much, Reinhard, I've got to modify my lua as this version looks more logical to me)

Dirk.

PS: I wonder what this string meant in a verbal description (after ipc.wrtieLvar, the " - " part):

[color=#000000]ipc[/color][color=#666600].[/color][color=#000000]writeLvar[/color][color=#666600]([/color][color=#000000] [/color][color=#008800]"L:AB_AP_HDGTRK"[/color][color=#666600],[/color][color=#000000] [/color][color=#006666]1[/color][color=#000000] [/color][color=#666600]-[/color][color=#000000] ipc[/color][color=#666600].[/color][color=#000000]readLvar[/color][color=#666600]([/color][color=#008800]"L:AB_AP_HDGTRK"[/color][color=#666600])[/color][color=#000000] [/color][color=#666600])[/color]

[color=#666600]PPS: I'm like an addict on your scripts already, bAd feeling, strong craving. :)[/color]

  • 1 year later...
Posted

Now that I'm using AutoAssignLetters=Yes under [JoyNames] in FSUIPC4.ini I can' figure out how to name my "B" joystick in the lua scripts.

 

It used to be, for example, "0" as in: 

envent.button(0, 5, 1, "toggleFD")

 

Now it is "B" in FSUIPC GUI (also due to some additional usb input devices)

 

I tried "B" and "2" in the script in place of "0", but that does not work. Any idea?

 

Much thanks,

Dirk.

Posted

Now that I'm using AutoAssignLetters=Yes under [JoyNames] in FSUIPC4.ini I can' figure out how to name my "B" joystick in the lua scripts.

 

It used to be, for example, "0" as in: 

envent.button(0, 5, 1, "toggleFD")

 

Now it is "B" in FSUIPC GUI (also due to some additional usb input devices)

 

I tried "B" and "2" in the script in place of "0", but that does not work. Any idea?

 

Much thanks,

Dirk.

 

>>> If you use joystick lettering, you can put the letter here instead but it must be "" quotes, as a string.<<< The IPC Library.

 

Dirk.

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.