Afterburn Posted September 8, 2011 Posted September 8, 2011 (edited) *Edit: See third post for the most specific question that will answer my needs* I have a GroovyGameGear GP-Wiz40. I'm trying to model the CMSP rotary switch (among other things). Problem is I'm out of inputs so I decided to try the ROTO-X technology they are advertising to eliminate one wire (3 inputs instead of 4 for the CMSP Mode switch). See bottom paragraph for how roto-x works. I hope it's clear... Now to the nitty-gritty. I want to increment the CMSP mode switch each time button "a" is pressed and decrement each time button "b" is pressed. So, I need something to the effect of this: if(cmsp.mode == OFF and button.a == on) then cmsp.mode = stby end if ... if(cmsp.mode == semi and button.a == on) then cmsp.mode = auto end if .... if(cmsp.mode == man and button.b == on) then cmsp.mode = stby end if etc. etc. Problem is I have no idea how to do this in the .lua file. :huh: If anyone can help, it would be greatly appreciated! Thanks, Joe FYI roto-x converts a rotary switch from individual contacts to a button pulse for either clockwise ore counterclockwise rotation of the rotary. It takes three inputs on the controller, and you wire your rotary switch in multiples of three to those three inputs (so for a 6-way rotary you wire K-M-O-K-M-O terminals on the board to 1-2-3-4-5-6 on the switch). These three inputs are used to determine the direction of rotation of the rotary switch, thus outputting one of two joystick presses through the USB (one press for each clockwise click of the rotary, and the other button for counterclockwise). Edited September 13, 2011 by Afterburn
Afterburn Posted September 9, 2011 Author Posted September 9, 2011 TL;DR: Is there a way to control a rotary knob like the CMSP mode knob with two momentary buttons? Hope this simplifies my request :thumbup:
Afterburn Posted September 13, 2011 Author Posted September 13, 2011 Just a slight bump with a slightly different question maybe someone can answer. Is there a function in LUA to get the state of a control (on or off)? This would allow me to complete what I'm trying to do.
Speed Posted September 13, 2011 Posted September 13, 2011 (edited) There is no third party software that does this already? If not, my first gut reaction is that you need to edit your Config/Export/Export.lua file. Some programming examples are here: http://www.digitalcombatsimulator.com/en/dev_journal/lua-export/ There may be better ways of doing this, but the way to do it that I can think of right off the bat would be something like this: 1) External app that sends commands to DCS over a socket 2) Modify the OnNextFrame (or however it's spelled) Lua function in Export to receive commands over the socket, and then execute the command in the jet. High-level Pseudocode: External app: While dcs.exe is running do { if switch incremented then { Until command received do { send switch incremented command string over socket } } if switch decremented then { Until command received do { send switch decremented command string over socket } } } In export Lua environment of DCS: if Luasocket doesn't exist, load Luasocket if it doesn't exist, create the Luasocket UDP socket for receiving command [i]in the OnNextFrame function[/i]: local command_table = {} do until timeout is true: { Receive data on socket, timeout of like, no more than 10 ms Insert commands into command_table } for i = 1 to size of command_table do { if command_table[i] == command to increment switch { do set switch position command that increments switch } if command_table[i] == command to decrement switch { do set switch position command that decrements switch } } Anyway, that's pseudocode that kinda illustrates how I think this should be done. Keep in mind I don't know much about Luasocket, and I have never attempted to do anything like what you are wanting to do. But this is how I would first attempt to go about doing what you want to do. As far as editing code in export.lua, you might be better off doing this from the net environment and using the net.dostring_in function. Make yourself a separate file that loads last of all, and make it modify the OnNextFrame function... something like this works great, IIRC: OnNextFrameOld = OnNextFrame OnNextFrame = function () OnNextFrameOld() --your code end As long as your mod is loaded last, your mod should not interfere with any other mod that might use OnNextFrame. Oh and BTW, I'm not even sure the function is called "OnNextFrame", it's probably called something slightly different. Regardless, the point of OnNextFrame is it's a export environment function that is called on every simulation frame, so it's a great place to put code. Edited September 13, 2011 by Speed Intelligent discourse can only begin with the honest admission of your own fallibility. Member of the Virtual Tactical Air Group: http://vtacticalairgroup.com/ Lua scripts and mods: MIssion Scripting Tools (Mist): http://forums.eagle.ru/showthread.php?t=98616 Slmod version 7.0 for DCS: World: http://forums.eagle.ru/showthread.php?t=80979 Now includes remote server administration tools for kicking, banning, loading missions, etc.
ivanwfr Posted September 13, 2011 Posted September 13, 2011 Some other info that may help here: Olgerd's User files A-10C Cockpit arguments and this Speed's LUA thread post of mine about Exporting to TARGET socket attached solution (...that worked quite well before 1.1.0.9 patch ... )
Recommended Posts