Jump to content

Recommended Posts

Posted (edited)

Hi all,

 

I've been wanting to make use of the LED lights on my warthog for a while. I finally got some time to do so. The idea is to have the lights react to in-game events via the Export.lua file.

 

Here is the relevant part of my Export.lua

local aircraft  = LoGetObjectById(LoGetPlayerPlaneId())
local aircraft_id ="0"
local MainPanel = GetDevice(0)
local LED0, LED1, LED2, LED3, LED4, LED5 = 0, 0, 0, 0, 0, 0

function LuaExportActivityNextEvent(t)

 if (aircraft.Name == "A-10C") then
   aircraft_id ="W"
   --Console backlight
   LED0 = math.ceil(MainPanel:get_argument_value(297))

   --Master Caution Light
   LED1 = MainPanel:get_argument_value(404)

   --Launch Warning Light
   LED2 = MainPanel:get_argument_value(372)

   --(HOTAS Pinkie Switch)
   LED3 = 0

   --Flaps
   LED4 = math.ceil(MainPanel:get_argument_value(653))

   --Gear Lock Lights
   LED5 = (MainPanel:get_argument_value(659) and MainPanel:get_argument_value(660) and MainPanel:get_argument_value(661))

 elseif (aircraft.Name == "M-2000C") then
   aircraft_id ="M"
   --Console backlight
   LED0 = math.abs(math.ceil(MainPanel:get_argument_value(642)))

   --Master Caution Light
   LED1 = (MainPanel:get_argument_value(199) or MainPanel:get_argument_value(200))

   --(Not Used)
   LED2 = 0

   --Police light Switch
   LED3 = MainPanel:get_argument_value(449)

   --Conf Warning
   LED4 = MainPanel:get_argument_value(553)

   --Gear Lock Lights
   LED5 = (MainPanel:get_argument_value(417) and MainPanel:get_argument_value(418) and MainPanel:get_argument_value(419))

 end

 default_output_file = io.open(lfs.writedir().."/Logs/TargetScript.log", "w")
 default_output_file:write(string.format("%s", aircraft_id))
 default_output_file:write(string.format("%d%d%d%d%d%d", LED0, LED1, LED2, LED3, LED4, LED5))
 default_output_file:close()

return t + 0.1
end
--------------------------------------------------------------
function LuaExportStop()
 default_output_file = io.open(lfs.writedir().."/Logs/TargetScript.log", "w")
 default_output_file:write("U000000")
default_output_file:close()
end

 

What it does is create a file "../Logs/TargetScript.log" and write some info to it. I chose to write the plane type aswell as the status of some systems like the launch warning indicator, gear lock lights, flaps status, etc. This can be customized to whichever systems you want your LEDs to interract with.

 

Now here is the function I use in my TARGET Script to identify the plane and light the LEDs

int led_update()
{
int file;
char L0, L1, L2, L3, L4, L5, aircraft_id;

   file = fopen("...//Saved Games//DCS.openbeta//Logs//TargetScript.log", "r");
   
aircraft_id =fgetc(file);  
   L0 =fgetc(file);
   L1 =fgetc(file);
   L2 =fgetc(file);
   L3 =fgetc(file);
   L4=fgetc(file);
   L5=fgetc(file);
   
   fclose(file);
   
   if ((aircraft_id =='W') & (Throttle[PSF] | Throttle[PSB]))
   L3 ='1';
   //else if ((aircraft_id =='M') & (Throttle[PSF] | Throttle[PSB]))
   //L3 ='1';
   
   if (L0 =='1')
   ActKey(PULSE+KEYON+LED(&Throttle, LED_ONOFF, LED_CURRENT+LED0));
   else
   ActKey(PULSE+KEYON+LED(&Throttle, LED_ONOFF, LED_CURRENT-LED0));
   
   if (L1 =='1')
   ActKey(PULSE+KEYON+LED(&Throttle, LED_ONOFF, LED_CURRENT+LED1));
   else
   ActKey(PULSE+KEYON+LED(&Throttle, LED_ONOFF, LED_CURRENT-LED1));
   
   if (L2 =='1')
   ActKey(PULSE+KEYON+LED(&Throttle, LED_ONOFF, LED_CURRENT+LED2));
   else
   ActKey(PULSE+KEYON+LED(&Throttle, LED_ONOFF, LED_CURRENT-LED2));
   
   if (L3 =='1')
   ActKey(PULSE+KEYON+LED(&Throttle, LED_ONOFF, LED_CURRENT+LED3));
   else
   ActKey(PULSE+KEYON+LED(&Throttle, LED_ONOFF, LED_CURRENT-LED3));
   
   if (L4 =='1')
   ActKey(PULSE+KEYON+LED(&Throttle, LED_ONOFF, LED_CURRENT+LED4));
   else
   ActKey(PULSE+KEYON+LED(&Throttle, LED_ONOFF, LED_CURRENT-LED4));
   
   if (L5 =='1')
   ActKey(PULSE+KEYON+LED(&Throttle, LED_ONOFF, LED_CURRENT+LED5));
   else
   ActKey(PULSE+KEYON+LED(&Throttle, LED_ONOFF, LED_CURRENT-LED5));

}

 

What it does is read the info in "../Logs/TargetScript.log", identify which plane I'm flying and turn some LEDs On/Off. Only downside is it doesn't work in multiplayer. I believe this is because exports are disabled on most servers (any workarounds to this ?).

 

Any comments welcome !

Edited by BlackSharkAce
Posted

Video of it in action?

Windows 10 Pro, Ryzen 2700X @ 4.6Ghz, 32GB DDR4-3200 GSkill (F4-3200C16D-16GTZR x2),

ASRock X470 Taichi Ultimate, XFX RX6800XT Merc 310 (RX-68XTALFD9)

3x ASUS VS248HP + Oculus HMD, Thrustmaster Warthog HOTAS + MFDs

Posted (edited)

Operating the Warthog LEDs throught the DCS Export lua Script

 

Video of it in action?

 

 

 

Good idea, I was feeling lazy :music_whistling:

 

Here is a video demonstrating it with the Mirage : https://dl.dropboxusercontent.com/u/32783018/Warthog%20LED%20DCS%20Interraction%20Demo.mov (85MB)

 

Pardon my narrative skills and turn that volume up !

 

Note that the placement of the LEDs makes it a little hard to see them while playing.

Edited by BlackSharkAce
  • 1 month later...
Posted

it is possible, it's been years i didn't play with it.

 

example using some exported data form dcs.

 

 

//program startup

int main()

{

if(Init(&EventHandle)) return 1; // declare the event handler, return on error

 

RegisterGameCallback(4593, &GameCallback);

 

}

 

//event handler

int EventHandle(int type, alias o, int x)

{

DefaultMapping(&o, x);

 

//add event handling code here

}

 

struct gamedata

{

float speed;

int altitude;

};

 

gamedata game;

 

int GameCallback(int data, int size)

{

Map(&game, data);

printf("data[%d]: speed:%8f altitude:%d\xa", size, game.speed, game.altitude);

}

 

 

Posted (edited)

Hmm.. I've been tinkering with these TCP connections and I can't seem to get it to work. I found an example here where someone managed to create a tcp socket and send data from a target script. This is useful since I'd like to eventually do that to interface my script with dcsexportcore.

 

I'm trying to connect my target script with dcexportcore through tcp localhost:12800: https://github.com/jboecker/dcs-export-core

 

When I type localhost:12800 in my address bar on chrome I can see data coming in periodically that looks like this:

{"data":{"_UNITTYPE":"M-2000C"},"msg_type":"newdata"}
{"data":{"_UNITTYPE":"M-2000C"},"msg_type":"newdata"}
{"data":{"_UNITTYPE":"M-2000C"},"msg_type":"newdata"}

But when I try to hook up my target script to localhost:12800 I don't get anything.

 

I simply use:

 

 

In my main I have:

RegisterGameCallback(12800, &TCPCallback);

And my callback is:

int TCPCallback(int data, int size)
{
printf("TCPCallback, ");
Map(&data, data);
printf("data: %d\xa", data);
}

 

 

 

Any clue about what's going wrong ?

Edited by BlackSharkAce
Posted

This is so cool, I'd really love to implement something like this on my next throttle. I'd love to have some gear lights near my gear switch.

Light the tires kick the fires!

 

[sIGPIC][/sIGPIC]

  • Recently Browsing   0 members

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