Jump to content
The simFlight Network Forums

Recommended Posts

Posted

Hi,

is it possible to add "delays" between a number of actions inside a macro, allocated to keyboard commands?

I only found "/delay" as an option for Axis Assignments.

Posted

is it possible to add "delays" between a number of actions inside a macro, allocated to keyboard commands?

No. But you could do this (and all sorts of other things) using Lua plug-ins. Quite easily.

What would be the application?

Regards

Pete

Posted

Hi Peter,

thanks for quick response. I have created a macro for a row of PMDG-EFIS-Actions (VOR1,2 on/off, Baro, FPV, Traffic/Stations Display a.s.o.) approx 9 actions in sequence for one keyboard command. Working fine but very fast :D. A delay (approx 200 - 500 ms) after each action would be great and more "realistic" but it's not essential. I will check out the LUA-Plugin.

Posted
Hi Peter,

thanks for quick response. I have created a macro for a row of PMDG-EFIS-Actions (VOR1,2 on/off, Baro, FPV, Traffic/Stations Display a.s.o.) approx 9 actions in sequence for one keyboard command. Working fine but very fast :D. A delay (approx 200 - 500 ms) after each action would be great and more "realistic" but it's not essential. I will check out the LUA-Plugin.

You could certainly do that very easily in Lua.

You'd send the actions using ipc.control or ipc.keypress depending on whether they are FS/FSUIPC controls or keypresses, and use ipc.sleep(500) between each one to delay half a second. If those operations are macros themselves, you'd need to send the macro name, instead of using ipc.control or ipc.keypress using

ipc.writeString(0x0D70,"macro name")

where the macro name is the same "filename:macroname" string you see in the FSUIPC dropdown when assigning keys or buttons to macros.

I think I ought to add another ipc function to Lua, to execute Macros without folks needing to know about offsets like 0x0D70. I may also add one for pressing "virtual buttons".

Regards

Pete

Posted

I think I ought to add another ipc function to Lua, to execute Macros without folks needing to know about offsets like 0x0D70. I may also add one for pressing "virtual buttons".

Okay. Versions 3.905 and 4.505 of FSUIPC are now available in the Updates Announcement, and contain these extra Lua facilities:

  • ipc.macro

which executes any named macro (or Lua program or control)
  • ipc.btnPress
    ipc.btnRelease
    ipc.btnToggle

which operate on a specific virtual button (0-287).

More details are given in the changes list in the Announcement.

Regards

Pete

Posted

something went wrong with my first steps with "Lua". I have no experiences in programming, i'm a solid user only.

Lua for windows 5.1.4 is installed, here my short script

local function efistest()
 	ipc.keypress(K72, 4) -- BARO
	ipc.sleep(500)
	ipc.keypress(K70, 4) -- FPV
	ipc.sleep(500)
	ipc.keypress(K86, 4) -- TFC
	ipc.sleep(500)
	ipc.keypress(K83, 4) -- STA
	ipc.sleep(500)
	ipc.keypress(K112, 1) -- FD1
	ipc.sleep(500)
	ipc.keypress(K113, 1) -- FD2
	ipc.sleep(500)
	ipc.keypress(K38, 2) -- VOR1
	ipc.sleep(500)
	ipc.keypress(K39, 2) -- VOR2
	ipc.sleep(500)
	ipc.keypress(K66, 8) -- QNH LOC
end

The file is named TEST.lua and stored within the modules folder. Assigning any key has no effect.

the fsuipc.ini part

[LuaFiles]

1=EFIS747off

2=EFIS747on

3=ipcDebug

4=landing

5=TEST

1 & 2 are similar 5

The test.log for debugging:

********* LUA: "TEST" Log [from FSUIPC version 3.905] *********
  3675579 System time = 10:46:01, FS2004 time = 10:31:13 (09:31Z)
  3675672 LUA: 0
  3675672 LUA: ...rosoft Games\Flight Simulator 9\MODULES\ipcDebug.lua
  3675797 LUA: return
  3675797 LUA: 

  3675813 LUA: 0
  3675907 LUA: ...rosoft Games\Flight Simulator 9\MODULES\ipcDebug.lua
  3675922 LUA: call
  3675922 LUA: 

  3676032 LUA: ...rosoft Games\Flight Simulator 9\MODULES\ipcDebug.lua:38
  3676032 LUA: beginning "G:\Programme\Microsoft Games\Flight Simulator 9\MODULES\TEST.lua"
  3676032 LUA: ...\Microsoft Games\Flight Simulator 9\MODULES\TEST.lua:19
  3676032 LUA: ended "G:\Programme\Microsoft Games\Flight Simulator 9\MODULES\TEST.lua"
  3676032 System time = 10:46:02, FS2004 time = 10:31:14 (09:31Z)
********* LUA execution terminated: Log Closed *********

Posted
Lua for windows 5.1.4 is installed

Erwhat do you mean? You don't need to install anything other than FSUIPC -- it has a built-in Lua interpreter. Why are you referring to this 5.1.4 -- are you planning to program Lua into one of your own applications?

If you are thinking of using the Lua plug-ins facilities in FSUIPC, you need nothing extra but a text editor to create the little Lua files. The only reason I provide a link to the Lua site is to show you where to get Lua language documentation from - or you can order the books from any bookshop or Amazon.

Did you not even bother to look at the examples i supply and try them, in order to get the hang of it? Do I waste my time on these things? :-(

local function efistest()
...

If you put the lines into a local function, you need to add code to actually CALL that function.

There is no need for the trrivial task you are trying to do. Delete the function line and the "end" at the end. You just want the statements in between!

If you'd bothered to look at some of the simple examples supplied, you would have seen howe much easier it is thn you seem to be making it. It is NOT "programming" for simple tihngs, just a list of things you are asking FSUIPC to do!

Regards

Pete

Posted

Ok, it's as simple as that. :D I think i misunderstood something in other Threads and /or reading the samples.

Thanks for wasting your time for my senseless request. :oops: My experiences with FSUIPC are pretty good since many years.

Simple and user-friendly. What a silly idea that you have changed your engagement.

Posted
Ok, it's as simple as that. :D I think i misunderstood something in other Threads and /or reading the samples.

Okay, can you tell me how you arrived at the misconceptions and I'll try to improve the documentation. The two threads started today about the Lua facilities are actually the very first feedback I've received since adding them six months or more ago.

If possible I'd like to try to make things clearer, but I'm rather at a loss to understand how you arrived at where you were.

Thanks for wasting your time for my senseless request.

No questions are senseless -- and the only stupid questions are those which go unasked, so what exactly do you mean?

I've been asking for feedback, it has been a long time coming though. And really but i do need folks to actually read what I provide first, else it isn't really feedback on what i provide, is it?.

My experiences with FSUIPC are pretty good since many years.

Simple and user-friendly. What a silly idea that you have changed your engagement.

Sorry, I don't understand this part at all? Can you explain please?

Regards

Pete

Posted
I think i misunderstood something in other Threads and /or reading the samples

here is a part of your landing.lua

local function endlanding()

-- reset landing part

event.cancel("calcagl")

event.cancel("calcvs")

-- enable restoration when GS low enough

event.offset(0x02b6, "UW", "calcgs") -- aircraft GS

end

and this thread (but i'm not sure) http://forums.simflight.com/viewtopic.php?f=54&t=75343

My experiences with FSUIPC are pretty good since many years.

Simple and user-friendly. What a silly idea that you have changed your engagement.

Should mean that i'm using FSUIPC for a very long time, no problems at all, easy to use. For a moment i thought: "FSUIPC is now going to be tricky" :lol: but since a few hours (your today's reply) i understand the mode of operation of the LUA plug-in. :idea:

Posted
I think i misunderstood something in other Threads and /or reading the samples

here is a part of your landing.lua

Yes, that is a specific example of using Events. That is, I think, the only one with such an example -- and rather the most complex one to look at to start with. There are much simpler ones. The use of Events to drive actions needs local functions defining, because the Event needs to know what function to call.

In your case all you are trying to do is make a sequence of actions when your Lua program is run -- and it is run when you press the button which is assigned, in the Buttons assignments, to make it run. You have no need to go into complex arrangements with events and functions.

and this thread (but i'm not sure) http://forums.simflight.com/viewtopic.php?f=54&t=75343

No, there is no use of Events or local functions there. There's an example of a simple loop, that is all.

Should mean that i'm using FSUIPC for a very long time, no problems at all, easy to use. For a moment i thought: "FSUIPC is now going to be tricky" :lol: but since a few hours (your today's reply) i understand the mode of operation of the LUA plug-in. :idea:

Ah, okay. I hope you make good progress with it, now, then.

Regards

Pete

Posted

First of all, thanks Pete for the LUA-Feature and your Assistance,

i have made some sequences yesterday (ipc.keypress, ipc.macro and ipc.control in one file mixed up), working pretty good. Added more than one of the "ipc.display" facility as a testing purpose, nice to see what FSUIPC is currently doing 8) . Also helpful to show "Finished XY" or "OK" after a longer file extending over several seconds due to multiple "ipc.sleep" usage.

My next lesson is to optimize macros, mouse.macros, key presses a.s.o. for a lot of AddOns ....

Posted
i have made some sequences yesterday (ipc.keypress, ipc.macro and ipc.control in one file mixed up), working pretty good. Added more than one of the "ipc.display" facility as a testing purpose, nice to see what FSUIPC is currently doing 8) . Also helpful to show "Finished XY" or "OK" after a longer file extending over several seconds due to multiple "ipc.sleep" usage.

Sounds like you are doing okay! Happy flying! ;-)

Pete

Posted

Good Morning,

another Question: is there a limitation of Lua-File numbers?

I have stored 128 (!) files but within the FSUIPC.ini (3.906) only 127 [LuaFiles] are indicated. Added # 129, no effect.

For the moment it's not necessary for me to store such a great many of files. Due to testing and experimentation the number of files runaway. :D I need to declutter , approx. up to 50 are currently not in use.

Posted

another Question: is there a limitation of Lua-File numbers?

Yes. 127.

I have stored 128 (!) files but within the FSUIPC.ini (3.906) only 127 [LuaFiles] are indicated. Added # 129, no effect.

Phew!

For the moment it's not necessary for me to store such a great many of files. Due to testing and experimentation the number of files runaway. :D I need to declutter , approx. up to 50 are currently not in use.

Are these all for different things? I'm amazed that anyone is finding so much use for this facility. Perhaps you would describe your uses to me some day, please? I'd be most interested. I've not had any feedback till recently, and now this!:-)

I'm afraid the limit is fixed at 127. I never thought that would be an effective limit -- seems I'll need to document it.

The reason is the way Button and Key assignments are encoded into a single 32-bit word. What with macros (also limited to 127) and all the Offset handling controls, conditionals and so on, I only had 7 bits left to encode the Lua number -- this was by pinching half the range originally assigned for Macros.

In turn, of course, this is a result of software growing up bit by bit, adding new facilities, never conceived earlier on, to an existing design. If i started again I'd do it differently! ;-)

Regards

Pete

Posted

Hi Peter,

thanks for explanation, here are some additional infos:

I always fly online on VATSIM with superior aircraft (PMDG, LDS, LSH Maddog ...) without the assistance of a "First Officer" (wife and kids favour other things :) )flying the Plane, talking to ATC, checking charts and weather, feeding the the FMC ...and this simultaneously , could be stressful sometimes. Therefore i dislike additional actions with the mouse during a flight.

Since a few years I use a Logitech G15 Keyboard beside my Saitek X45 Joystick. The Keyboard is featured with 56 additonal keys, programmable (macros, shortcuts) and stored as "XY-profile" for each plane. The "FSUIPC Mouse Macro" opened additional options for me, and LUA too.

an example: starting the engines during pushback; BCN on, Ignition on, start switch on, wait for 10 - 15 seconds to spool up, fuel lever on, wait for a few seconds - start switch off. With LUA it's now possible to assign this engine-sequence (or all engines step by step) to one key.

Another one: Approaching H/P for Take-Off; Taxi-Light off, RWY-Turnoff Light off, Landing Lights on, Strobe Lights on, Transponder Mode "C", Barometric check to confirm local QNH.

With one "Key press" i am able to delegate the upcoming job to my "Virtual F/O" named "FSUIPC", i relax and do my job, i fly the plane :D

LUA offers now the same feature as my programmable keyboard: adding a delay between "actions". Unfortunately all the programmable G15-keys are still in use for each plane. LUA is actually a welcome extension for me. 10 - 20 files for 7 different planes adds up to 70 - 140 LUA-Files :D

Posted

Thanks for that. Very interesting.

10 - 20 files for 7 different planes adds up to 70 - 140 LUA-Files :D

But you might be better off combining some of them. For example:

1. You could also use the event facilities to put all of the little button-activated sequences in one pre-loaded Lua file. Each would be a "function" declared inside that Lua file, and a sequence of "event.button" calls would tell FSUIPC which one to execute on each of those buttons. This actually would be very efficient because the Lua file would be loaded and compiled just once, and be sitting in its own thread just waiting for the calls. The disadvantage would be that you couldn't have more than one of those sequences operating at the same time, as they share the one thread.

Preloading is done using "ipcInit.lua" or "ipcReady.lua" depending on when you want them loaded. Those can load other Lua files using the ipc.macro function.

2. Surely there's a lot of commonality between the various planes? Those which are similar or the same could be using the same Lua files.

3. You could have single Lua files per action despite plane differences by testing the plane name -- the name string can be read, and significant substrings (like 767, 747, whatever) checked within them using the extensive and powerful Lua string library.

Just some ideas to get over the 127 limit and to make things a little more controllable, tidier, efficient?

Please keep me informed on progress. Maybe I could use some of your best results as examples for later updates of the package?

Regards

Pete

Posted

Good Morning,

meanwhile i have started a check for communality and for the possibility of (realistic) combinations. I think the result will be a maximum of 7 or 8 files for each aircraft and at most 10 common files. Definitely a total under 80 ! (with the same convenience as before).

This was - for the moment - the best solution for me. Time saving due to no global rework was needed. Copy & paste and changing some assignments, that's all.

3. You could have single Lua files per action despite plane differences by testing the plane name -- the name string can be read, and significant substrings (like 767, 747, whatever) checked within them using the extensive and powerful Lua string library.

Sounds good, that means it is possible to create one file for for more than one aircraft. Could you post an example with the next two files please? (Some EFIS actions for the 747 and the 737), Thanks in advance!

747_EFIS_OFF

ipc.macro("747_EFIS: VOR1_OFF")

ipc.sleep(500)

ipc.macro("747_EFIS: BARO_OFF")

ipc.sleep(500)

ipc.macro("747_EFIS: FPV_OFF")

ipc.sleep(500)

ipc.macro("747_EFIS: TFC_OFF")

ipc.sleep(500)

ipc.macro("747_EFIS: STA_OFF")

ipc.sleep(500)

ipc.macro("747_EFIS: FD1_OFF")

ipc.sleep(500)

ipc.macro("747_EFIS: FD2_OFF")

ipc.sleep(500)

ipc.macro("747_EFIS: VOR_21_OFF")

ipc.sleep(500)

ipc.macro("747_EFIS: VOR_22_OFF")

ipc.sleep(500)

ipc.macro("747_EFIS: VOR_12_OFF")

ipc.sleep(500)

ipc.display("EFIS -- RESET\nfor termination", 5)

and for the 737

ipc.macro("PMDG737: EFIS_9")

ipc.sleep(500)

ipc.macro("PMDG737: EFIS_10")

ipc.sleep(500)

ipc.macro("PMDG737: EFIS_11")

ipc.sleep(500)

ipc.macro("PMDG737: EFIS_12")

ipc.sleep(500)

ipc.macro("PMDG737: EFIS_13")

ipc.sleep(500)

ipc.macro("PMDG737: EFIS_14")

ipc.sleep(500)

ipc.macro("PMDG737: EFIS_15")

ipc.sleep(500)

ipc.macro("PMDG737: EFIS_16")

ipc.sleep(500)

ipc.macro("PMDG737: EFIS_17")

ipc.sleep(500)

ipc.macro("PMDG737: EFIS_18")

ipc.sleep(500)

ipc.macro("PMDG737: EFIS_19")

ipc.sleep(500)

ipc.macro("PMDG737: EFIS_20")

ipc.sleep(500)

ipc.display("EFIS -- RESET\nfor termination", 5)

I use "ShortAircraftNames" and "Profiles", e.g. PMDG 747 and PMDG NG

Posted

Sounds good, that means it is possible to create one file for for more than one aircraft. Could you post an example with the next two files please? (Some EFIS actions for the 747 and the 737)

Well, I can't do that off the top of my head like that. I'll try when I have half-an-hour or so to spare. Can you post details to petedowson@btconnect.com, please? Then it'll go in my "pending" list -- nothing here does.

Pete

Posted
Thanks Peter, there's no hurry, i will drop a message ...

I've done one which should work, for those two aircraft, and I've done it in a way you should be able to add to it quite flexibly.

There will be as many ways of doing this as there are programmers, but i am a beginner in Lua, so this is as good as I can do it in a short space of time:

aircraft = { "747", "737", 0 } -- needs to match somewhere in the aircraft title
macrofiles = { "747 EFIS", "PMDG737", 0 } -- the macro filenames for those aircraft

-- Lists of macros for each aircraft, followed by 0 then the control to use then the message to use
Actions747 = { "BARO_ON", "FPV_ON", "TFC_ON", "STA_ON",
							 "FD1_ON", "FD2_ON", "VOR1_ON", "VOR1_ON",
							 0, 65584, "EFIS  --  SET\nQNH  --  LOC SET" }
Actions737 = { "EFIS_1", "EFIS_2", "EFIS_3", "EFIS_4",
								"EFIS_5", "EFIS_6", "EFIS_7", "EFIS_8",
								0, 65584, "EFIS  --  SET\nQNH  --  LOC SET" }

-- table of those actions for indexing the same way as the aircraft and macrofile names
IndexToActions = { Actions747, Actions737 }

-- read aircraft title
Name = ipc.readSTR(0x3D00, 256)
ipc.log("Name = " .. Name)

-- identify aircraft by substring from "aircraft" list above
i = 1
j = 0
while aircraft[i] ~= 0 do
   if string.find(Name, aircraft[i], 1, true) ~= nil then
      j = i
      break
   end
   i = i + 1
end 

if j > 0 then
   -- found it!
   ipc.log("found it at " .. j)

   -- use action list
   actions = IndexToActions[j]
   i = 1

   -- first all the macros
   while actions[i] ~= 0 do
   		ipc.log("Action" .. i .. "= " .. macrofiles[j] .. ": " .. actions[i])
      ipc.macro(macrofiles[j] .. ": " .. actions[i])
      ipc.sleep(500)
      i = i + 1
   end

   -- now the control
   i = i + 1
   ipc.log("Sending control " .. actions[i])
   ipc.control(actions[i])
   ipc.sleep(500)

   -- and lastly the message
   i = i + 1
   ipc.display(actions[i], 5)
end

The parts you'd need to add to for other aircraft are:

Aircraft list

aircraft = { "747", "737", 0 } 

Identifying the aircraft by substring in its title. You may want these to be more specific -- they'll catch the default 737 and 747 too.

Just make sure there's a 0 at the end of the list, so stop the loop.

Macro file names used

macrofiles = { "747 EFIS", "PMDG737", 0 }

A one-for-one relationship to the aircraft list. If you need more than one macro file for an aircraft list you'll need to do it differently. i just separated the file nmae from the macro name to save space and typing! ;-)

Action lists

Add a list of the actions for the aircraft, naming it what you like, and adding the name to the correct place in:

IndexToActions = { Actions747, Actions737 }

Note that I've adopted a format with a list of any number of Macros, ended by 0, then the control you want to send (if it is always the same, take it out of there and use it explicitly instead at the end of the code), and the message you want displayed (same consideration).

You'll see "ipc.log" calls in there -- that is for testing, so i could see that it worked okay, even though i don't have the aircraft nor your macros. Take them out when you've done, as you like.

Regards

Pete

Posted

Good Morning at the first spring day (currently here in Austria: - 1° C and moderate snowfall :evil: )

Your file is working perfect :!: I have added another Aircraft (LDS763) and the result is pretty good.

Just a few questions again and then i will keep quiet for a while :)

1. for skipping the Macros or Controls (e.g there are no macros only controls or vice versa) i have set the according value to "0"

Example: Actions737 = { "0", 0, 65584, "QNH -- LOC SET" }, it works. The FSUIPC.log says:

Action1= PMDG737: 0

Sending control 65584

or

Action1= PMDG737: EFIS_1

Sending control 0

then the display comes up as expected. (I have no macro named "0" and i am sure there is no single-digit control ;) )

To ignore the "display" i have removed the string.

2. Are some adjustments required to process more than on control or display step by step too?

Thanks a lot!

Posted

1. for skipping the Macros or Controls (e.g there are no macros only controls or vice versa) i have set the according value to "0"

Example: Actions737 = { "0", 0, 65584, "QNH -- LOC SET" }, it works. The FSUIPC.log says:

But not good. Since the number 0 ends the list of Macros, all you needed to do for that example is:

 Actions737 = {0, 65584, "QNH  --  LOC SET" }

Then you won't get a spurious macro sent.

For no control, you should simply have

 Actions737 = { "MACRO NAME", .... , 0, 0, "QNH  --  LOC SET" }

and test for ~= 0 for sending the control. i.e.

   -- now the control
   i = i + 1
   if actions[i] ~= 0 then 
      ipc.log("Sending control " .. actions[i])
      ipc.control(actions[i])
      ipc.sleep(500)
   end

Better, if you want to allow a list of controls, do it like the macros:

   -- now the controls
   i = i + 1
   while actions[i] ~= 0 do
      ipc.log("Sending control " .. actions[i])
      ipc.control(actions[i])
      ipc.sleep(500)
      i = i + 1
   end

That will cope with zero or more controls.

2. Are some adjustments required to process more than on control or display step by step too?

Ahanswered! ;-)

To ignore the "display" i have removed the string.

Ouchdoesn't an error get reported? If the string is optional you should alter the code like this:

   -- and lastly the message
   i = i + 1
   if actions[i] ~= nil then
      ipc.display(actions[i], 5)
   end

You should be able to figure out your own code enhancements from these simple examples.

Regards

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.