y2kiah Posted December 26, 2010 Author Posted December 26, 2010 (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 December 26, 2010 by y2kiah
Gadroc Posted December 28, 2010 Posted December 28, 2010 In beta 4 every device has a listen_event and listen_command function now, other wise identical to the beta 3 dump.
y2kiah Posted December 28, 2010 Author Posted December 28, 2010 nice, that should allow us to push events instead of having to poll for changes, have you tried it yet?
Gadroc Posted December 30, 2010 Posted December 30, 2010 Be aware that LuaExportActivityNextEvent does not function properly when in mutliplayer when connected as a client.
Gadroc Posted December 31, 2010 Posted December 31, 2010 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.
Levinsky Posted May 12, 2011 Posted May 12, 2011 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.
pitbldr Posted May 12, 2011 Posted May 12, 2011 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?
Levinsky Posted May 12, 2011 Posted May 12, 2011 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.
Gadroc Posted May 12, 2011 Posted May 12, 2011 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.
Gadroc Posted May 12, 2011 Posted May 12, 2011 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.
y2kiah Posted May 12, 2011 Author Posted May 12, 2011 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.
Gadroc Posted May 12, 2011 Posted May 12, 2011 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.
tacno Posted December 8, 2011 Posted December 8, 2011 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)
Gadroc Posted December 8, 2011 Posted December 8, 2011 You have to parse the clickabedata.lua file for those items. I have several posts explaining how to do so if you do some searching.
tacno Posted December 8, 2011 Posted December 8, 2011 Thank Gadroc, I'll check your posts (~500) 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)
tacno Posted December 10, 2011 Posted December 10, 2011 (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 December 10, 2011 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)
Gadroc Posted December 10, 2011 Posted December 10, 2011 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)
tacno Posted December 11, 2011 Posted December 11, 2011 Great ! Thanks for all Gadroc :thumbup: 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)
Recommended Posts