Jump to content
Sign in to follow this  
Airtrain

Led Lights - How To Detect Change Automatically (Axe)

Recommended Posts

Hello Simmers,

 

I've recently started to use LINDA to do all my button assignments. That works great.

 

However, I have custom Panel, with Korry Syle switches with LEDs on an Arcaze USB board using the Arcaze FSUIPC connector and the offsets 0x66c0 to 0x66c4.

 

Here is the code I'm using

AA_WING_var = ipc.readLvar("L:AB_OVH_ANTIICE_WING")
if AA_WING_var == 1 then
AA_WING = 1
else
AA_WING = 0
end

AA_ENGR_var = ipc.readLvar("L:AB_OVH_ANTIICE_ENGR")
if AA_ENGR_var == 1 then
AA_ENGR = 1
else
AA_ENGR = 0
end

AA_ENGL_var = ipc.readLvar("L:AB_OVH_ANTIICE_ENGL")
if AA_ENGL_var == 1 then
AA_ENGL = 1
else
AA_ENGL = 0
end

APU_MASTER_var = ipc.readLvar("L:AB_OVH_APU_MASTER")
if APU_MASTER_var == 1 then
APU_MASTER = 1
else
APU_MASTER = 0
end

APU_START_LIGHT_AVAIL_var = ipc.readLvar("L:AB_OVH_APU_START_LIGHT_AVAIL")
if APU_START_LIGHT_AVAIL_var == 1 then
APU_START_LIGHT_AVAIL = 1
else
APU_START_LIGHT_AVAIL = 0
end

ipc.writeUB(0x66c2,AA_WING)
ipc.writeSB(0x66c3,AA_ENGR)
ipc.writeUB(0x66c4,AA_ENGR)
ipc.writeUB(0x66c1,APU_MASTER)
ipc.writeUB(0x66c0,APU_START_LIGHT_AVAIL)

IIRC, it has to be in the Linda/Aircraft/AXE folder and can be any *.lua file? I#ve called mine just axe.lua.

 

Whenever I press I button on my panel, the Sim acts accordingly, but the LEDs in the switches don't turn on.

 

However when I reload the LUA engine in Linda, it correctly detects the current button state and changes the LEDs accordingly. But when I press a button again (and the Sim acts correctly), the LED doesn't change. Only when I reload the LUA engine again.

 

I've read in a forum somewhere something about using while like this

a_var = 1
while a_var < 255 do

...my code from above here...

end

it could work. But when I do this, Linda and the LUA engine crash and I have to use the Task Manager to quit Linda and the LUA engine.

 

Any ideas how I could fix it and to it properly? Where is my mistake?

 

Many thanks in advance!

 

Pat


Regards,

Patrick Krolzik

Share this post


Link to post
Share on other sites

Pat

 

Like all realtime systems, LINDA must have control returned to it on a regularly basis (every few millisecs using timers) so that it can handle button presses and update displays. All code must be kept short. If you use a while loop, your code can take too long to execute and take control away from LINDA's interrupt handling. LINDA and LUA has probably not crashed it is just that you are keeping it working too hard.


Andrew Gransden

Scotland, UK

LINDA Support/Developer - VATSIM and BAVirtual - Airbus Flyer

i7 1TB SSD GTX980 - FSX/P3D - Aerosoft Airbus A318/A319/A320/A321 - FS2Crew

Share this post


Link to post
Share on other sites

Thanks fr your reply!

So it would make more sense to put every LED change detection in its own while loop? It also seems to me that this is actually an infinite loop... Is there a more elegant solution?


Regards,

Patrick Krolzik

Share this post


Link to post
Share on other sites

Patrick

 

I don't know what aircraft or other hardware you are using with FSX and LINDA but if you explore the LINDA folders you should find in /Linda/system several LUA files beginning with HANDLERS and in /LINDA/aircraft/{your aircraft} an ACTIONS.lua.  The former handles the device (e.g. VRinsight Combo) and the later the aircraft functions.  If you explore these with the LINDA editor you will find functions labelled TIMER.  You can put your short code to read or output the required function (i.e. light LED).  LINDA will then call these functions on a regular basis (say once a second).

 

You will need to experiment on some simple functions before trying anything major.  WARNING! Avoid altering any other LINDA LAU files and ALWAYS make a backup first.

 

Andrew


Andrew Gransden

Scotland, UK

LINDA Support/Developer - VATSIM and BAVirtual - Airbus Flyer

i7 1TB SSD GTX980 - FSX/P3D - Aerosoft Airbus A318/A319/A320/A321 - FS2Crew

Share this post


Link to post
Share on other sites

Hi Andrew,

 

I'm using it with the Airbus X Extended. My hardware is an Arcaze USB with an attached LED Driver 2 (custom panel). The Arcaze FSUIPC Connector tools is active, and in test mode, the LEDs are working

 

For testing purposes, I added thie following line directly in the Timer function of the actions.lua in the Airbus X Extended directory:

ipc.writeUB(0x66c2,1)

this should set the FSUIPC offset of 0x66c2 to the value 1. Which would result in the corresponding LED to indicate. Unfortunately, nothing happens. the ArcazeFC says that the FSUIPC offset 0x66c2 value is still 0. Something is afoul, and I don't know what.

 

Do I somehow need to call the Timer function?

Edited by Airtrain

Regards,

Patrick Krolzik

Share this post


Link to post
Share on other sites

Hi Patrick

 

I too am working with ABX with version 2.4 of the SDK (see downloads).  You will not need to call the timers as LINDA does this for you.  All you need to do is create your own function(s) with the code call you want and place it in lib_user.lau (in folder /libs).  You then place a call to that function in the Timer function in the handler-xxx.lua file (xxx is one of those available e.g. handlers-mpa.lau).

 

Andrew


Andrew Gransden

Scotland, UK

LINDA Support/Developer - VATSIM and BAVirtual - Airbus Flyer

i7 1TB SSD GTX980 - FSX/P3D - Aerosoft Airbus A318/A319/A320/A321 - FS2Crew

Share this post


Link to post
Share on other sites

i could only find the function VRI_TIMER in handlers-mcp.lua . But that doesn't seem to call my function. An I'm not using the MCP and have it disabled in Linda. Do I need to enable it? Or do I need to create a new function Timer () in that file?


Regards,

Patrick Krolzik

Share this post


Link to post
Share on other sites

Hi Patrick

 

You are in the right area. You should be able to insert a call to your function in VRI_TIMER (at the bottom).  Then put your function (as you listed in your first posting) in lib_user.lua.  Use some test code to see that it is working first.  I can not guarantee that it will work if you do not have a VRInsight Combo MCP but give it a try.

 

A little more explanation might help. The idea behind all real time systems that must interface with the real world is that all operations need to be completed at a regular iteration rate.  This is normally 50Hz with reacting to real world events, such as handling a navigation sensor, to as slow as 1Hz for display updates. In LINDA, the core code triggers the timer code (i.e. VRI_Timer) at fixed intervals, VRI_Timer then calls all the required functions to handle button pushes and switch selections and other functions.  All these functions must be short with no long loops that would prevent them exiting before the next timer event.  Otherwise, control is not handed over to LINDA to do its own functions (such as handling joysticks) and the system will appear to freeze.

 

In more sophisticated systems, there would be a heart beat timer that would force any overrunning code to be interrupted and hand control back to a scheduler. This allows longer code to be stopped, the data saved and restarted again until it reaches completion over multiple cycles.  This was especially the case in older, much slower systems of the past.

 

Andrew


Andrew Gransden

Scotland, UK

LINDA Support/Developer - VATSIM and BAVirtual - Airbus Flyer

i7 1TB SSD GTX980 - FSX/P3D - Aerosoft Airbus A318/A319/A320/A321 - FS2Crew

Share this post


Link to post
Share on other sites

Eureka! Once I enabled the MCP (although I don't have one connected) the timer worked!

 

Thanks for your help and the very useful information :)

 

I wasted nearly a week of my life for this! Thank you so much for helping me!!


Regards,

Patrick Krolzik

Share this post


Link to post
Share on other sites

Eureka! Once I enabled the MCP (although I don't have one connected) the timer worked!

 

Thanks for your help and the very useful information :)

 

I wasted nearly a week of my life for this! Thank you so much for helping me!!

 

You are most welcome.


Andrew Gransden

Scotland, UK

LINDA Support/Developer - VATSIM and BAVirtual - Airbus Flyer

i7 1TB SSD GTX980 - FSX/P3D - Aerosoft Airbus A318/A319/A320/A321 - FS2Crew

Share this post


Link to post
Share on other sites

Now it seems, that Linda doesn't always pass the button presses to the sim. Linda recognizes correctly each and every button press and switch toggle. But the switches sometimes don't get toggled in the AXE. I sometimes need to toggle them back and forth twice or thrice. I've tried with different pulses and delays in my Arcaze arx configuration file, but the result is always the same.


Regards,

Patrick Krolzik

Share this post


Link to post
Share on other sites

Hi Patrick

 

Sorry to hear that you are having problems.  This is where LINDA can come into its own when debugging problems. You need to split the problem into workable chunks.

 

Use the Tracer and Console options. In Tracer you have Start monitoring the Lvars you want to use to ensure that they are changing as expected.  When any of the watched parameters change they will appear in the Console with the latest value.  You can also use Tracer to toggle values to check that your LEDs are responding to changes to the relevant Lvar.  This will help your debugging.

 

I have found that ABX can use 2 separate Lvars for the same function.  Some are set momentarily on first selection while the other is more persistent (i.e. remembers the state under changed again).

 

Andrew


Andrew Gransden

Scotland, UK

LINDA Support/Developer - VATSIM and BAVirtual - Airbus Flyer

i7 1TB SSD GTX980 - FSX/P3D - Aerosoft Airbus A318/A319/A320/A321 - FS2Crew

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...