Jump to content

Recommended Posts

Posted (edited)

sure, first I override the print function

 

dofile("./Scripts/Aircrafts/A-10C/Cockpit/devices.lua")
dofile("./Scripts/Aircrafts/A-10C/Cockpit/command_defs.lua")

function print(printObj)
function recurse(printObj, level)
	if level > 10 then return "" end
	if type(printObj) == "string" then
		return printObj;
	elseif type(printObj) == "number" then
		return string.format("%.7g", printObj);
	elseif type(printObj) == "boolean" then
		if printObj then return "true" else return "false" end
	elseif type(printObj) == "table" then
		local tblStr = "{\n";
		for k,v in pairs(printObj) do
			-- prevent recursion issues
			if (v ~= printObj and not (level > 1 and k == "_G") and
				not (level > 2 and k == "package"))
			then
				tblStr = tblStr..string.rep("\t",level)..k.." = "..recurse(v, level+1).."\n";
			end
		end
		return tblStr .. string.rep("\t",level-1) .. "}";
	elseif type(printObj) == "userdata" then
		local mt = getmetatable(printObj);
		if mt then return recurse(mt, level) end
		return tostring(printObj);
	else
		return tostring(printObj);
	end
end
writeStr = recurse(printObj,1);
if (writeStr) then
	file:write(writeStr);
	file:flush();
end
end

function println(val)
print(val);
print("\n");
end

devices["MAIN_PANEL"] = 0

 

then to dump all devices I would do this

 

for k,v in pairs(devices) do
local dev = GetDevice(v);
local mDev = getmetatable(dev);
print("devices."..k.." = ");
println(mDev);
end

 

and to dump the global table is also very simple

 

println(_G);

 

I like to use the optional semicolon when I write lua as you can see :music_whistling:

 

I haven't had a chance to check out beta 4 yet, I'm out of town for a few more days, can't wait to see it though.

 

edit: I should also mention that the print function assumes a global var "file" is open for writing, so change as appropriate

Edited by y2kiah
Posted

Actual that function works fine. Turns out that GetDevice(0) is randomly failing when connected as a client which was causing LuaExportActivityNextEvent to exit without returning the next execution cycle.

  • 4 months later...
Posted

Hey guys,

 

big thanks to Y2kiah and Gadroc for this thread - it has helped immensely.

 

I finally got a simple toggle switch to turn the Battery Power switch on and off tonight. I'm using the Arduino boards after stuffing around for weeks constructing my own - with much frustration.

 

One thing which had me puzzled for a few nights. The Battery Power switch I thought based on the clickabledata.lua script was "242". But turns out it is actually "3006".

 

The way I found this out was I found a file called "Macro_sequences.lua" which has a section "start_sequence_full" which has the first command as "device = 1, action = 3006, value = 1.000000". Battery Power is the first switch you flick so I plugged in 3006 and it started working.

 

Can anyone explain what the "242" for the Battery Power switch in "clickabledata.lua" refers to?

 

Thanks,

Ken.

Posted

For those of you using Arduino boards, how do they "talk" to the sim? I saw on the Arduino site that you have to code what you want it to do (called sketches I believe). Does that code allow you to send commands directly to the sim or is something else involved?

Posted

Hi Pitbldr,

 

Arduino comes with its own developer environment and "C like" language. This is used to program the firmware onto the board. There are quite a few demo firmware "sketches" around that are a good help when learning (a fair few are in the developer environment you get from their website).

 

The most common ways to get an Arduino board to communicate with a PC is via USB or Ethernet (some new boards coming have the Ethernet built in I believe, the older ones require the Ardiuno Ethernet shield adapter).

 

If you go with the USB boards (which I'm testing with at the moment). They show up as a serial COM port on your PC. So in my tests I have a toggle switch on digital inputs on the Arduino and the firmware I have sends a string command to the PC when the toggle switch's state changes. I then have a C# application which listens on that COM port. I was a C programmer in a former life, but the C# code to communicate via serial COM port or network socket is just more convenient and I haven't seen CPU load issues in the testing between C# and C/C++ versions on an I7. The C# app reads the string command from the Arduino and sends the command to the LUA export script running from A-10C.

 

I believe others are using the Ethernet Shields with Arduinos and talking straight to the LUA Export script - bypassing the need for a middleware app like my C# one. I'm in 2 minds at the moment myself - although I like the idea of a board talking straight over the network - I think it might scale better. Interested to hear other people's experiences on the pros and cons?

 

Thanks,

KEn.

Posted

I believe others are using the Ethernet Shields with Arduinos and talking straight to the LUA Export script - bypassing the need for a middleware app like my C# one. I'm in 2 minds at the moment myself - although I like the idea of a board talking straight over the network - I think it might scale better. Interested to hear other people's experiences on the pros and cons?

 

Actually it might not scale as well as you think. The packet overhead on an Ethernet frame will dwarf the actual data you send in this context and you'll be sending it several times per second. On a big beefy PC with all it's ram and 100Mbit to Gigabit ethernet this is no big deal (and many times it doesn't even hit them for loopback). It may be more difficult for an 8-bit microprocessor with 2MB of ram especially after you realize there are well over 300-400 digital inputs to poll and hundreds of LEDs to drive in a full cockpit.

 

This is all theory until someone gets a full setup up and running.

Posted
Hey guys,

 

big thanks to Y2kiah and Gadroc for this thread - it has helped immensely.

 

I finally got a simple toggle switch to turn the Battery Power switch on and off tonight. I'm using the Arduino boards after stuffing around for weeks constructing my own - with much frustration.

 

One thing which had me puzzled for a few nights. The Battery Power switch I thought based on the clickabledata.lua script was "242". But turns out it is actually "3006".

 

The way I found this out was I found a file called "Macro_sequences.lua" which has a section "start_sequence_full" which has the first command as "device = 1, action = 3006, value = 1.000000". Battery Power is the first switch you flick so I plugged in 3006 and it started working.

 

Can anyone explain what the "242" for the Battery Power switch in "clickabledata.lua" refers to?

 

Thanks,

Ken.

 

Ok. You need to understand the difference between argument and action.

 

Argument number is the ID you use to look up current state of that switch in the simulation. You never modify it directly. You could roughly think of argument as the variable name you use to look up the data. You always lookup arguments based on the Main panel device.

 

Action is the ID of the function used to tell the simulation a button or switch was pressed. Think of action as the method you call to modify the value of the argument. The value you pass in to the action will be processed by the action and the simulation will decide how to change the argument. You call the action on the device which that switch belongs to.

 

Hope that helps.

Posted

What Gadroc mentions is one of the reasons I chose not to go with a UDP multicast solution, sending all data to all boards all the time. The "middleware" server in my setup will have a configuration file telling it which data needs to be routed to which boards. A lot less overhead on the network, and a lot shorter messages for the slow MCUs to parse.

 

Having a central server also allows for loose coupling of export.lua and mcu firmware. Prevents export.lua from having to act like a server, listening for connections and whatnot. I also have an embedded Lua environment in the server where extra pit functionality can be developed if the sim that I'm interfacing with doesn't implement it. I'm thinking FSX and XPlane on that one. So Levinski, even if you switch to ethernet, I would recommend keeping the middle tier.

Posted

Having a central server also allows for loose coupling of export.lua and mcu firmware. Prevents export.lua from having to act like a server, listening for connections and whatnot. I also have an embedded Lua environment in the server where extra pit functionality can be developed if the sim that I'm interfacing with doesn't implement it. I'm thinking FSX and XPlane on that one. So Levinski, even if you switch to ethernet, I would recommend keeping the middle tier.

 

This is exactly the role Helios was designed to do. It's first application was the glass cockpit side of it. Some aspects of Helios around the trigger/action mechanisms are more complex in order to support some of the scenarios where you have a mix of physical pit interfacing along side touch screen and gauge rendering.

  • 6 months later...
Posted

Hi y2kiah,

Hi all,

 

I began my project of my A-10C cockpit building. It's a wide project for me.

 

For french speakers, my web site is here : http://www.tacnoworld.fr.

For no french speakers, as I have not yet translated the site in English, you can use Google Translate :-)

 

To send status from DCS to panel, I use device command with Olgred files from http://files.digitalcombatsimulator.com/en/84654/ (Thank Olgred for sharing) :thumbup:

 

Now, I want to use "performClickableAction" command in export.lua file to send status from panel to DCS.

 

And I look for parameters for this command : device number and action number...

I don't find anythink interresting on Web, or I don't know where to look for... :(

 

Does a table exist, with device , panel , action ?

Or how can I create this table ?

 

Thank all

 

Tacno

UniversRadio for DCS : http://universradio.fr

Homepit on eagle.ru forum :http://forums.eagle.ru/showpost.php?p=1547848&postcount=1 (more details : http://www.tacnoworld.fr)

3rd-Wing.net/75th vFighter "Tiger Sharks"/S-01 Tacno (squadron commander)

Posted (edited)

Hi all,

 

How to use performClickableAction command ?

 

In lua script I'll write this command as :

deviceNumber:performClickableAction ( buttonNumber , Value )

 

Let's take TPG ON/OFF for example.

 

In devices.lua file, I can get the deviceNumber of AHCP panel:

devices["AHCP"] = counter()--7

 

 

deviceNumber is 7

 

In clickabledata.lua file, I can get values of TGP ON/OFF switch :

elements["PNT-TMB-AHCP-TGP"] = {class = {class_type.TUMB,class_type.TUMB}, hint = _("Targeting Pod Power On/Off"), device = devices.AHCP, action = {device_commands.Button_4,device_commands.Button_4}, arg = {378,378}, arg_value = {1.0,-1.0}, arg_lim = {{0.0, 1.0},{0.0, 1.0}}}

 

Value is 0.0 to put switch off and 1.0 to put switch off.

 

But where can I find the buttonNumber, the first parameter of performClickableAction command ?

 

 

Thanks

 

Tacno

Edited by tacno

UniversRadio for DCS : http://universradio.fr

Homepit on eagle.ru forum :http://forums.eagle.ru/showpost.php?p=1547848&postcount=1 (more details : http://www.tacnoworld.fr)

3rd-Wing.net/75th vFighter "Tiger Sharks"/S-01 Tacno (squadron commander)

Posted

Add 3000 to the button number. (Ex: Button_4 = 3004, Button_1 = 3001, Button_10 = 3010)

 

Also you have to get the device first.

 

local ahcp = GetDevice(7)
ahcp:performClickableAction(3004, 1)

  • Recently Browsing   0 members

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