Dirk98 Posted March 29, 2013 Author Report Posted March 29, 2013 let's try something like this: function incdecHDG ( pDiff ) -- increment or decrement HDG by pDifflocal lHDG = ipc.readLvar( "L:AB_AP_HDG_Select" ) + pDiffif lHDG > 359 thenlHDG = lHDG - 360end ifif lHDG < 0 thenlHDG = lHDG + 360end ifipc.writeLvar( "L:AB_AP_HDG_Select", lHDG )endfunction incHDG ( joynum, button, downup )incdecHDG ( 1 )endfunction decHDG ( joynum, button, downup )incdecHDG ( -1 )endfunction incHDGFast ( joynum, button, downup )incdecHDG ( 10 )endfunction 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 numberevent.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 buttonfunction 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 buttonfunction 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 managedfunction selectHDGmode (joynum, button, downup)ipc.writeLvar( "L:AB_AP_HDGmode", 1 )ipc.writeLvar( "L:SmallOverheadPushButtons", 1 )end-- HDG Knobfunction incdecHDG ( pDiff ) -- increment or decrement HDG by pDifflocal lHDG = ipc.readLvar( "L:AB_AP_HDG_Select" ) + pDiffif lHDG > 359 then lHDG = lHDG - 360end ifif lHDG < 0 then lHDG = lHDG + 360end ifipc.writeLvar( "L:AB_AP_HDG_Select", lHDG )endfunction incHDG ( joynum, button, downup )incdecHDG ( 1 )endfunction decHDG ( joynum, button, downup )incdecHDG ( -1 )endfunction incHDGFast ( joynum, button, downup )incdecHDG ( 10 )endfunction decHDGFast ( joynum, button, downup )incdecHDG ( -10 )endevent.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.
aua668 Posted March 29, 2013 Report Posted March 29, 2013 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
aua668 Posted March 29, 2013 Report Posted March 29, 2013 Hi, I found it: Replace the "end if" statements by a simple "end". That should fix it. Rgds Reinhard
Dirk98 Posted March 29, 2013 Author Report Posted March 29, 2013 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.
Dirk98 Posted March 29, 2013 Author Report Posted March 29, 2013 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 codefunction incFPAorVS ( joynum, button, downup )if ipc.readLvar("L:AB_AP_HDGTRK") == 1 then -- 1 = TRK/FPAlocal lFPA = ipc.readLvar( "L:AB_AP_FPA_Select2" ) + 0.1if lFPA > 9.9 thenlFPA = 9.9endipc.writeLvar( "L:AB_AP_FPA_Select2", lFPA )else -- 0 = HDG/SPD so set VSlocal lVS = ipc.readLvar( "L:AB_AP_VS_Select2" ) + 1if lVS > 60 thenlVS = 60endipc.writeLvar( "L:AB_AP_VS_Select2", lVS )endendevent.button(175, 4, 1, "incFPAorVS")[/CODE]Will check the HDG inc/dec code without "end if" now.Thanks!Dirk.
Dirk98 Posted March 29, 2013 Author Report Posted March 29, 2013 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.
Dirk98 Posted March 29, 2013 Author Report Posted March 29, 2013 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/SPlease 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 codefunction levelVSlevel (joynum, button, downup)ipc.writeLvar( "L:AB_AP_VSlevel", 1 - ipc.readLvar("L:AB_AP_VSlevel") )ipc.writeLvar( "L:SmallOverheadPushButtons", 1 )endevent.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.
Dirk98 Posted March 31, 2013 Author Report Posted March 31, 2013 Just in case somebody needs current AXE LVars, the latest list is available here: http://forum.aerosoft.com/index.php?/topic/64255-airbus-x-extended-sdk-variables/ Cheers, Dirk.
Dirk98 Posted March 31, 2013 Author Report Posted March 31, 2013 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 codefunction levFPAorVS ( joynum, button, downup )if ipc.readLvar("L:AB_AP_HDGTRK") == 1 thenipc.writeLvar( "L:AB_AP_FPA_Select2", 0 )elseipc.writeLvar( "L:AB_AP_VS_Select2", 0 )endendevent.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.
Dirk98 Posted March 31, 2013 Author Report Posted March 31, 2013 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 buttonfunction 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 Incfunction incSPDorMACH ( joynum, button, downup )if ipc.readLvar("L:AB_AP_SPDMACH") == 1 thenlocal lMACH = ipc.readLvar( "L:AB_AP_Mach_Select" ) + 0.01if lMACH > 1.0 thenlMACH = 1.0endipc.writeLvar( "L:AB_AP_Mach_Select", lMACH )elselocal lSPD = ipc.readLvar( "L:AB_AP_SPEED_Select" ) + 1if lSPD > 340 thenlSPD = 340endipc.writeLvar( "L:AB_AP_SPEED_Select", lSPD )endend-- SPD/MACH IncFastfunction incFastSPDorMACH ( joynum, button, downup )if ipc.readLvar("L:AB_AP_SPDMACH") == 1 thenlocal lMACH = ipc.readLvar( "L:AB_AP_Mach_Select" ) + 0.1if lMACH > 1.0 thenlMACH = 1.0endipc.writeLvar( "L:AB_AP_Mach_Select", lMACH )elselocal lSPD = ipc.readLvar( "L:AB_AP_SPEED_Select" ) + 10if lSPD > 340 thenlSPD = 340endipc.writeLvar( "L:AB_AP_SPEED_Select", lSPD )endend-- SPD/MACH Decfunction decSPDorMACH ( joynum, button, downup )if ipc.readLvar("L:AB_AP_SMPDMACH") == 1 thenlocal lMACH = ipc.readLvar( "L:AB_AP_Mach_Select" ) - 0.01if lMACH < 0 thenlMACH = 0endipc.writeLvar( "L:AB_AP_Mach_Select", lMACH )elselocal lSPD = ipc.readLvar( "L:AB_AP_SPEED_Select" ) - 1if lSPD < 0 thenlSPD = 0endipc.writeLvar( "L:AB_AP_SPEED_Select", lSPD )endend-- SPD/MACH DecFastfunction decFastSPDorMACH ( joynum, button, downup )if ipc.readLvar("L:AB_AP_SMPDMACH") == 1 thenlocal lMACH = ipc.readLvar( "L:AB_AP_Mach_Select" ) - 0.1if lMACH < 0 thenlMACH = 0endipc.writeLvar( "L:AB_AP_Mach_Select", lMACH )elselocal lSPD = ipc.readLvar( "L:AB_AP_SPEED_Select" ) - 10if lSPD < 0 thenlSPD = 0endipc.writeLvar( "L:AB_AP_SPEED_Select", lSPD )endendevent.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.
Dirk98 Posted April 1, 2013 Author Report Posted April 1, 2013 Any idea how to add the sound of turning knobs? All button pull / pushes tick ok. Thanks, Dirk.
Dirk98 Posted April 3, 2013 Author Report Posted April 3, 2013 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 buttonfunction 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 buttonfunction 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/SPDSPDMACH can be:1 = MACH, 0 = SPDSo, 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?
aua668 Posted April 5, 2013 Report Posted April 5, 2013 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 buttonfunction 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]
Dirk98 Posted April 5, 2013 Author Report Posted April 5, 2013 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 buttonfunction toggleFD (joynum, button, downup)local lFD = ipc.readLvar("L:AB_MPL_FD")if lFD == 0 thenlFD = 1else lFD = 0endipc.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]
aua668 Posted April 5, 2013 Report Posted April 5, 2013 Hi, It' simple math: 1 - 0 = 1 1 - 1 = 0 So with every call you are flipping between the two values. Rgds Reinhard
Dirk98 Posted April 7, 2013 Author Report Posted April 7, 2013 Yes, I thought that was it. Thank you, Reinhard. Dirk.
Dirk98 Posted May 26, 2014 Author Report Posted May 26, 2014 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.
Dirk98 Posted May 26, 2014 Author Report Posted May 26, 2014 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now