Jump to content

Recommended Posts

Hello Al.

Your e-mail has arrived, thanks for that. I flew over it only briefly and come later to respond to it more precisely and to answer.

Now I understand the background to Notepad ++. It will display color coded code, similar to opening an XML file with Internet Explorer. I never thought of that, I'll keep that in mind. Thank you for your hint. Again something learned!

I had looked at the documentation for FSUIPC and LUA scripts several times, but I have never really learned all the descriptions. The descriptions were more confusing than helping them. Without your help, I would never have understood the code. Now the logic gradually opens up to me. But there I have to continue to learn to achieve a good "LUA script level" :smile:

In the beginning I will make the scripts as neat as possible and as simple as possible. There will be stored only those functions, which are otherwise not reached via the normal button assignment. In the beginning it should not be too complex, otherwise it will be too confusing for a beginner like me too fast.

Edited by Christian Bahr

For a sophisticated flight simulation
www.bahrometrix.de

Share this post


Link to post
Share on other sites

Hello,
I am reading this topic high interested: I am searching for help to readout LVars and write into Offsets (Aerosoft Airbus Pro). The offset must switch a LED "on" and "off".
For example: I have an LVar "AB_OVH_APU_MASTER_LIGHT_ON" and want to write the state of it into offset "0x66C0".
Could someone give me LUA Script example?
Every help is more than welcome!
Best regards/Guenter

 

Share this post


Link to post
Share on other sites
11 hours ago, gunterat said:

For example: I have an LVar "AB_OVH_APU_MASTER_LIGHT_ON" and want to write the state of it into offset "0x66C0".

apu_master_light = ipc.readLvar("L: AB_OVH_APU_MASTER_LIGHT_ON")  -- get state of the Lvar

ipc.writeXX( 0x66C0, apu_master_light)   -- write the Lvar state to location 0x66C0

where the XX is one of the following depending on the data format of the read Lvar, and thus the format of apu_master_light:

UB unsigned 8-bit byte
UW unsigned 16-bit word
UD unsigned 32-bit dword
SB signed 8-bit byte
SW signed 16-bit word
SD signed 32-bit dword
DD signed 64-bit value
DBL 64-bit double floating point
FLT 32-bit single floating point

In the case above, if the variable state is either 1 or 0 (for On and Off) you should be able to use the UB data format:

ipc.writeUB( 0x66C0, apu_master_light)

In the modules folder you should have FSUIPC documentation including the FSUIPC Lua library which will defines functions like ipc.readLvar(), ipc.writeXX(), etc. The documentation also includes examples of Lua scripts.

  Al

Edited by ark

Share this post


Link to post
Share on other sites

Hi Al,

thank you very much, I think I understand, at least I hope so.

Now I have my work for the holidays :).

Best regards

Guenter

Share this post


Link to post
Share on other sites

Hello Al, wonderful - it works perfect!!

Here you can see the content of my script and I have 2 questions:

- is there something in that code what can be optimized resp. simplified?

- is it possible to write more than one function into one script and how?

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

first = true
while true do
  if first then
    first = false
    initialValue = ipc.readLvar("L:AB_OVH_APU_MASTER_LIGHT_ON")
    ipc.writeUB(0x66C0, initialValue)
  else
    currentValue = ipc.readUB(0x66C0)
    ipc.writeLvar("L:AB_OVH_APU_MASTER_LIGHT_ON", currentValue)
  end
end

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

Regards

Guenter

Share this post


Link to post
Share on other sites
50 minutes ago, gunterat said:

- is there something in that code what can be optimized resp. simplified?

It's not that clear to me what you are trying to do, but it looks like this:

Offset = Lvar
loop forever
    Lvar = Offset
end

This doesn't seem to make sense to me as it just repeatedly copies back the value from the offset. But if that's what you intend, the only suggestion I'd make is to insert a pause, otherwise this will freewheel and consume a lot of resources unnecessarily:

Offset = Lvar
loop forever
    Lvar = Offset
    ipc.sleep(100)
end

I'd also probably be a bit more terse in the actual code:

ipc.writeUB(0x66C0, ipc.readLvar("L:AB_OVH_APU_MASTER_LIGHT_ON"))
while true do
    ipc.writeLvar("L:AB_OVH_APU_MASTER_LIGHT_ON", ipc.readUB(0x66C0))
    ips.sleep(100)
end

As for your last question, I think you can supply a numeric parameter to a Lua script and so switch between multiple functions by checking the parameter. But it's messy. If you're going to do much Lua programming I'd suggest you look at LINDA, which sits on top of FSUIPC and gives you a much nicer way in.


MarkH

gGzCVFp.jpg
Core i7-7700K / 32Gb DDR4 / Gigabyte GTX1070 / 1080p x 3 x weird / Win7 64 Pro

Share this post


Link to post
Share on other sites

I am a beginner in LUA and I tried some codes and they did not work. Finally I combined them to the above-noted one, it works but I was clear, it's a little bit "confused". Now I will include the adjustments you told me above!

Yes, I know LINDA but as I think it supports "only" Inputs and no Outputs. Anyway, I thank you very much for helping,

Merry Christmas!

Guenter

 

Share this post


Link to post
Share on other sites
3 hours ago, gunterat said:

I thank you very much for helping,

P.S. There's a typo in my code - ips.sleep(100) should be ipc.sleep(100) :huh:


MarkH

gGzCVFp.jpg
Core i7-7700K / 32Gb DDR4 / Gigabyte GTX1070 / 1080p x 3 x weird / Win7 64 Pro

Share this post


Link to post
Share on other sites
11 hours ago, gunterat said:

- is it possible to write more than one function into one script and how?

Yes, you can define functions as shown below, then assign parameter values to the script to call each function. For the example below, under the FSUIPC Key Presses tab, you could  assign the A key to activate funcName1 by putting a 1 in the parameter field for Lua ExampleScript (which will appear in the drop down list under Control sent when keys pressed), then assign the B key to activate funcName2 by putting a 2 in the parameter field for Lua ExampleScript, and finally assign the C key to activate funcName 3 by putting a 3 in the parameter field for Lua ExampleScript. If you want to assign buttons instead of keys, you would do the same thing but under the FSUIPC Buttons+Switches tab. The values you put in the parameter field become the ipcPARAM values in the script (ipcPARAM is a reserved FSUIPC variable name). Note that when assigning keys or buttons you have to be careful not to assign them to LuaKill ExampleScript, or LuaSet ExampleScript, etc. The point being the script name ExampleScript will appear in the FSUIPC dropdown list in a number of places so you need to be careful when assigning keys or buttons.

BTW, if you use the free editor Notepad++ and identify the language as Lua, Notepad++ will color code reserved words, etc.

Al

ExampleScript.Lua

function funcName1()
   code lines
return

function funcName2()
   code lines
return

function funcName3()
   code lines
return

--*************** Main Program********************
if ipcPARAM == 1 then
   funcName1()
  elseif ipcPARAM == 2 then
   funcName2()
  elseif ipcPARAM == 3 then
   funcName3
end
return

 

Edited by ark
  • Upvote 1

Share this post


Link to post
Share on other sites
2 hours ago, ark said:

BTW, if you use the free editor Notepad++ and identify the language as Lua, Notepad++ will color code reserved words, etc.

 

I can confirm that, Notepad++ saves lives 🙂


For a sophisticated flight simulation
www.bahrometrix.de

Share this post


Link to post
Share on other sites
23 hours ago, MarkDH said:

ipc.writeUB(0x66C0, ipc.readLvar("L:AB_OVH_APU_MASTER_LIGHT_ON"))

while true do    

ipc.writeLvar("L:AB_OVH_APU_MASTER_LIGHT_ON",

ipc.readUB(0x66C0)) ipc.sleep(100)

end

Problem: the state of the LVAr is written to the Offset only once, namely with starting. At this time the (Hardware) LED's are "on" or "off" according to the state in the "Aircraft".

But it does not update, the Offset shows always the same state (1 - if the state was 1 at beginning). As soon as the Illumination of the pushbutton goes "off", the state in the Offset would have to go to "0". But it does' nt. (and conversely too)

Share this post


Link to post
Share on other sites
51 minutes ago, gunterat said:

Problem: the state of the LVAr is written to the Offset only once, namely with starting. At this time the (Hardware) LED's are "on" or "off" according to the state in the "Aircraft".

But it does not update, the Offset shows always the same state (1 - if the state was 1 at beginning). As soon as the Illumination of the pushbutton goes "off", the state in the Offset would have to go to "0". But it does' nt. (and conversely too)

Well that's just your own code reflected back at you. Can you say exactly what you are trying to do?


MarkH

gGzCVFp.jpg
Core i7-7700K / 32Gb DDR4 / Gigabyte GTX1070 / 1080p x 3 x weird / Win7 64 Pro

Share this post


Link to post
Share on other sites
59 minutes ago, MarkDH said:

Can you say exactly what you are trying to do? 

I will try: it is about the Flightsim "Prepar3D_V4 - 64 Bit" , "Aerosoft Airbus Pro" and the freewaretool "Mobiflight" as link between hard- and software. The Aerosoft Airbus is working with LVars, but Mobiflight works only with offsets (at least for outputs - Led's in my particular case). My hardware, e.g. pushbuttons, is connected via "Arduino 2560 Boards", controlled by "Mobiflight".

Now I have to read out the state of the LVar and write this into an offset ("0" or "1"). "Mobiflight" is monitoring the state of the offsets permanently and switches the Leds "on" and "off" as soon as the State in the Offset changes from "1" to "0" or conversely.

So I think I need a script that is:

1. monitoring the state of the Lvar (resp. recognizing changes)

2 and writing to the Offset as soon the state changes

and both permanently !

Once more, the code above works, but it misses the "monitoring function".

Sorry for my simple description, I hope it is understandable.

Best regards

Guenter

Share this post


Link to post
Share on other sites
19 minutes ago, gunterat said:

So I think I need a script that is:

1. monitoring the state of the Lvar (resp. recognizing changes)

2 and writing to the Offset as soon the state changes

and both permanently !

Well then surely this ought to work:

while true do
    ipc.writeUB(0x66C0, ipc.readLvar("L:AB_OVH_APU_MASTER_LIGHT_ON"))
    ipc.sleep(100)
end

I am assuming you set this to auto-run. Personally I would prefer not to rely on perpetually looping programs monitoring statuses in this way, as you are likely to have lots of them. Are you actually using hardware switches too? If so, it would be more satisfactory to trigger your LED update when the switch is manipulated.


MarkH

gGzCVFp.jpg
Core i7-7700K / 32Gb DDR4 / Gigabyte GTX1070 / 1080p x 3 x weird / Win7 64 Pro

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...