Jump to content

Help Required Exporting Variables


Recommended Posts

I'm trying to export some data from DCS A-10C to get the LEDs on my G940 to light up based on in-game status settings. So far, I've gotten three of the LEDs to mimic the status of the gear indication lights using a bit of Lua code and morg's G940LED program for BS (http://forums.eagle.ru/showthread.php?t=45895) to control the LEDs themselves.

 

I'm having some difficulty trying to coax variables out of DCS. So far, I've worked out how to get indications from the main panel itself, but I am keen to use some of the simpler commands.

 

A simplified section of my code is below, to give you an idea of what I'm doing now. This is a coroutine which is run every 100ms:

function g940leds(t)
 local tNext = t
 local MainPanel = GetDevice(0)
 local c = g940socketsetup() -- Sets up a socket for morg's G940leds.exe
 while true do
   local flap_posn = math.abs(MainPanel:get_argument_value(653))
   local nose_gear = math.abs(MainPanel:get_argument_value(659))
   local left_gear = math.abs(MainPanel:get_argument_value(660))
   local right_gear = math.abs(MainPanel:get_argument_value(661))

   if nose_gear == 1 then
     c:send("SetLed=3g")  -- Set LED 3 to be Green
   else
     c:send("SetLed=3o")  -- Set LED 3 to be Off
   end

   if left_gear == 1 then
     c:send("SetLed=7g")  -- Set LED 7 to be Green
   else
     c:send("SetLed=7o")  -- Set LED 7 to be Off
   end

   if right_gear == 1 then
     c:send("SetLed=8g")  -- Set LED 8 to be Green
   else
     c:send("SetLed=8o")  -- Set LED 8 to be Off
   end

   if flap_posn < 0.05 then
     c:send("SetLed=4o") -- If flaps are up, Set LED 4 to be Off
   elseif flap_posn > 0.2 and flap_posn < 0.25 then
     c:send("SetLed=4g") -- If flaps are at 7°, Set LED 4 to be Green
   elseif flap_posn > 0.65 and flap_posn < 0.68 then
     c:send("SetLed=4a") -- If flaps are at 20°, Set LED 4 to be Amber
   else
     c:send("SetLed=4r") -- If flaps are in travel or abnormal, Set LED 4 to be Red
   end

   tNext = coroutine.yield();
 end
end

 

This is working fine for the time being, but I have noticed that there are some other functions in Export.lua which would make it easier to get more information out of the game. Eventually, I want to build an Android application so that I can use my phone in a similar way to some of the iPhone powered panels out there, so I will want to access some more complex info in the future.

 

A couple of examples of things that I can't use at the moment are:

LoGetMechInfo() -- This seems to have a lot of data which would be extremely useful, but whenever I try to use it, Lua returns 'nil'.

LoGetIndicatedAirspeed() appears to return nil.

 

Is anyone able to advise me whether these commands are correctly working in DCS, and if so, provide some example code on how to get data out of them?

Link to comment
Share on other sites

  • 2 months later...

Riske please share your config ,

there isn't any G940leds config for A10C (only for LO2 or BS).

I want to use my G940 colors in A10c

 

I tried to use your coroutine but G940leds.exe tells "Received unknow command, ....."

 

Thanx


Edited by PVI_Eagle

[sIGPIC][/sIGPIC]

Link to comment
Share on other sites

My config is heavily modified now, but I'll try to point you in the right direction:

 

Go to InstallDir\DCS A-10C\Config\Export, then in Config.lua, search for:

Coroutines = {}	-- global coroutines table
CoroutineIndex = 0	-- global last created coroutine index

 

Immediately below this, add:

dofile("./Config/Export/G940leds.lua")

CoroutineIndex = CoroutineIndex + 1
Coroutines[CoroutineIndex] = coroutine.create(g940leds_example)
LoCreateCoroutineActivity(CoroutineIndex, 0, 0.1) -- start directly and run every 0.1 seconds

 

Now you need to save the attached file (G940leds.lua) to InstallDir\DCS A-10C\Config\Export

 

This LUA file is run every 100ms, and is made to interface with G940leds.exe. You can play with it to map just about any game variable to your LEDs.

 

Hopefully this will fix your issue, but I haven't seen that error before and can't be sure. If you need a hand, please just let me know.

G940leds.lua

Link to comment
Share on other sites

It works fine!!!!!!!

Thank you Riske.

 

I modified your config, this is mine:

P2 - P5 - P7 gears, like your settings (off- green)

 

P1 Nosewheel (off-amber)

 

P3 Master Warning (off-flashing red)

 

P4 flaps UP (off-green)

P8 flaps down(off - green, amber , red, like your setting)

 

P6 eject (fixed red)

 

THANK YOU RISK!!!

 

All colors work fine

G940leds.lua


Edited by PVI_Eagle

[sIGPIC][/sIGPIC]

Link to comment
Share on other sites

No worries, PVI_Eagle. I'm glad it works.

 

In the example that you've given above, I've created a new variable called flap_posn and assigned it the value that DCS had for the flaps.

 

If you want to create your own variable, you can call it any string that you want. The list of available variables is in InstallDir\DCS A-10C\Scripts\Aircrafts\A-10C\Cockpit\mainpanel_init.lua

 

For example, if you wanted to set LED5 to green when the "Gun Ready" indicator is lit in-game, and set it to red when the gun is not ready, you would do the following:

 

  1. Open up mainpanel_init.lua and search for "gun". You should find the line below:
    caution_lamp(662,SystemsSignals.flag_GUN_READY)
     
    This is setting a new variable that you can use (argument 662).
     
     
  2. Open up G940leds.lua and add the line below where I define the different variables:
    local gun_status = math.abs(MainPanel:get_argument_value(662)) -- Returns 1.0 (ready) or 0.0 (not ready)


     
     

  3. Where I start sending info out in my code (below d:send("DisableAutoUpdate=;") ), add the following:
    --Set Gun Ready Indication on LED5
    if gun_status == 1 then
     d:send("SetLed=5g")
    else
     d:send("SetLed=5r")
    end


     
    When sending commands to G940leds.exe, I find the easiest command is the SetLed command. The argument sent to it (eg. 5g and 5r in the above case) is simply the LED number (5) and the colour you want it to be (o = off, r = red, a = amber, g = green).


Edited by RiSkE
Link to comment
Share on other sites

It should work in both. I'll check mine tonight to double-check, but I'm pretty sure that's all you need.

 

Edit: I just checked, and mine works fine in both singleplayer and multiplayer. I'm not sure what's causing your problem.


Edited by RiSkE
Link to comment
Share on other sites

  • 5 months later...

Hello guys. First of all thanks for your work on this.

 

Please can you confirm this is working with A10-C v 1.1.1.1 ?

I just did all steps but not able to make it working :/

 

- changed "EnableExportScript = false" to "EnableExportScript = true"

- propertly added lines to "Export.lua" (with notepad++):

dofile("./Config/Export/G940leds.lua")

 

CoroutineIndex = CoroutineIndex + 1

Coroutines[CoroutineIndex] = coroutine.create(g940leds_example)

LoCreateCoroutineActivity(CoroutineIndex, 0, 0.1) -- start directly and run every 0.1 seconds

- Copyied files "G940leds.lua" and "everyframe.lua" into the folder: DCS A-10C\Config\Export

- Copyied the executable "G940leds.exe" and launched before starting the simulator: DCS A10C

 

After running G940leds.exe it shows:

Found a Logitech G940 Joystick

Found a G940 throttle!

Listening on port 33331

 

All LEDs turns OFF and from that point nothing happends no matter what I am trying. :/ I am starting to be a little bit desperate :/

EDIT2:

 

heh I'm a programmer noob. But I figured out I have to delete " --[[ " at the begining of the script itself so... now it works!

I'm not sure how many G940 users there is, flying with A10-C, but soon I will post my updated config with working LED's and easy instructions to modify stuffs to own needs.

 

Thanks a lot anyway, without your knowledge it means no G940 led support for A10-C. Everybody will be in credits when done :book:


Edited by Hanzales

CPU: Intel Q9550 @2.83GHz | RAM: 4GB 1066MHz | GPU: Asus GTX 560 Ti | HDD: 1TB SataII | Keyb: Logitech G19 | Mouse: Logitech G9 | Knypl: Logitech G940 | OS: W7HE x64

Link to comment
Share on other sites

  • 1 month later...

I hope I finally make it finished this weekend :/

 

Just too much bussy last weeks and also new wheel+pedals so...

 

But after my weekend shifts I hope fruits will be there ;o)


Edited by Hanzales

CPU: Intel Q9550 @2.83GHz | RAM: 4GB 1066MHz | GPU: Asus GTX 560 Ti | HDD: 1TB SataII | Keyb: Logitech G19 | Mouse: Logitech G9 | Knypl: Logitech G940 | OS: W7HE x64

Link to comment
Share on other sites

  • 2 months later...

Hanzales! I am trying to get the profile to work for your Red Baron Profile.

 

Here is what ihave added so far(it is not much)

 

 

        

--Take average of nose gear to determine position.

       gear_total = nose_gear + left_gear + right_gear
       gear_total = gear_total / 3
              
--Set LED based on gear color.

       if gear_total == 1 then
           d:send("SetLed=5g")  -- Set LED5 to green
       elseif gear_total == 0 then 
           d:send("SetLed=5o")  -- Set LED5 to off
       else    
           d:send("SetLed=5r")  -- Set LED5 to red
       end

Link to comment
Share on other sites

  • 1 month later...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...