How to set up toggle switches (a tutorial) - ED Forums
 


Notices

Reply
 
Thread Tools Display Modes
Old 05-27-2012, 09:01 AM   #1
Spy Guy
Junior Member
 
Spy Guy's Avatar
 
Join Date: Jan 2012
Posts: 48
Lightbulb How to set up toggle switches (a tutorial)

Foreword

Hi all.
I noticed that some people have had some trouble setting up their TM Warthog's toggle switches (myself included) in games apart from A-10C.
Basically, when toggled to the ON state, they act as a button (that's being held down). On toggling them OFF, said button is released.

This is all fairly simple, but the result is that you have to flick the switch twice in order to toggle the function again.

This annoyed me, so I have gone poking around in the control Lua files and I can happily say I found a solution to these problems.
I posted these in another thread, but I feel it warrants a thread of its own to help others in my situation.

I will assume you're all familiar with how to bind keys and switches in the simulator itself, and that you are familiar with a text editor of your choice.

These examples focus on the TM Warthog, however, you could also use another input device with toggle switches, in case you're building your own cockpit, etc. The methodology is the same no matter what you're using. (unless the ON and OFF states are two separate buttons in your setup)

The methods are slightly different between P-51D, A-10C and Black Shark 2.

So, without further ado, let's get started:

P-51D
The situation:
In this case, we want to bind the APU Switch on the TM Warthog Throttle to set the Ignition Switch to BOTH when flicked up and to set it to OFF when flicked down.

-----------------

First of all, have the key you want bound to the On state of the thing you want toggleable, in this case "Ignition Switch BOTH"

Second of all, you need to find the lua file in question. I'm on Vista and can find it here:
C:\Users\[NAME]\Saved Games\DCS\Config\Input\P-51D\joystick

In that folder there will be a file named "Throttle - Hotas Warthog", open that in either Notepad or for best results Notepad++ (I use the latter).


Marvel at all the gibberish for a second, then find a line that looks like this (Note, JOY_BTN20 is the APU Switch, it'll look different if you use some other switch):

Code:
{combos = {{key = "JOY_BTN20"}, }, down = 3002, cockpit_device_id = 13, value_down = 0.3, name = "Ignition switch BOTH", category = "Front Switch Box"},
This is the code that basically tells the sim that "When this button is pushed down, set the value of button 3002 (The Ignition Switch) on cockpit_device_id 13 (which is the Front Switch Box) to value_down = 0.3 (0.3, which corresponds to the BOTH setting)"

This is where the funsies start. You can edit the line to add "up = 3002," and "value_up = 0," to make it switch to OFF when the button is released.
In other words, make the line look like this:

Code:
{combos = {{key = "JOY_BTN20"}, }, down = 3002, up = 3002, cockpit_device_id = 13, value_down = 0.3, value_up = 0, name = "Ignition switch BOTH", category = "Front Switch Box"},
This will tell it that when JOY_BTN20 is released, set the value of Button 3002 on cockpit_device_id 13 to value_up = 0, while retaining the original function.

The logic behind this can be found on the "Ignition Switch OFF" line:

Code:
{combos = {{key = "JOY_BTN24"}, }, down = 3002, cockpit_device_id = 13, value_down = 0, name = "Ignition switch OFF", category = "Front Switch Box"},
Note that I bound it to a key in order to highlight it during editing. This line will most likely look different to you.

This tells it to set the value of the Ignition Switch to 0, which logically means that 0 is the OFF setting.

This obviously applies to every switch in the simulator, where you can find a separate option for each item. Just follow the logic described here and you shall succeed.
Black Shark 2 & A-10C

The Situation:

In this case, we want to toggle the Laser Standby switch with each flick of the APU Start switch on the TM Warthog Throttle.

---------------

As before, start out by binding the ON state of the switch you want to use to the function you want it to perform.

After that you can find the Lua file you need to edit there, on Vista.
C:\Users\[NAME]\Saved Games\DCS\Config\Input\ka-50\joystick

In that folder there will be a file named "Throttle - Hotas Warthog", open that in either Notepad or for best results Notepad++ (I use the latter).

Code:
{combos = {{key = "JOY_BTN20"}, }, down = iCommandPlaneLaserRangerOnOff, name = "Laser standby On/Off switch", category = "Ins Targeting Mode Controls Panel PVR"},
It looks very different from the code for P-51D. Instead of setting the value of various cockpit switches, button down sends the command iCommandPlaneLaserRangerOnOff which, fairly intuitively, toggles the laser standby switch.

HOWEVER!
Here is where BS2 is vastly inferior to A-10C and P-51D... there is no individual command for the On / Off state of these buttons (to my knowledge anyway, I deeply wish I am wrong), so the following is the best one can do:
Code:
{combos = {{key = "JOY_BTN20"}, }, down = iCommandPlaneLaserRangerOnOff, up = iCommandPlaneLaserRangerOnOff, name = "Laser standby On/Off switch", category = "Ins Targeting Mode Controls Panel PVR"},
By adding this bit: "up = iCommandPlaneLaserRangerOnOff," to the command in question, you are basically having it send the command again when you flip the APU switch OFF.
Notes on the difference between BS2 and A-10C
If you have a TM Warthog, chances are you won't want to edit the default settings, what with them being both accurate and awesome, but I'm throwing this in here anyway for the sake of completeness.

The Lua files you need can be found under:
C:\Users\[NAME]\Saved Games\DCS\Config\Input\A-10C\joystick
(there's a pattern here, but clarity is always good)

The main difference is that A-10C tends to have different button commands for different states of the switches. Demonstrated below by an excerpt from the Lua file controlling the venerable APU Switch.

Code:
{down = iCommandPlane_APU_Off, name = "APU Off", category = "Engine Control Panel"},
{down = iCommandPlane_APU_Start, name = "APU Start", category = "Engine Control Panel"},
{down = iCommandPlane_APU_Start, up = iCommandPlane_APU_Off, name = "APU Start/Off", category = "Engine Control Panel"},
As you can see, it works by sending commands in A-10C as well, but you have more of them to play with.

In the Black Shark example, we sent the iCommandPlaneLaserRangerOnOff command twice in order to emulate the actual effect of flicking the switch On and Off. But this has the disadvantage of risking that the switch becomes desynchronized on startup.
I.e the Off position on the physical switch can correspond to the On position in-Sim, and vice versa.

If this was in the style A-10C, we'd have the ability to tell it that "down = iCommandPlaneLaserRangerOn" and "up = iCommandPlaneLaserRangerOff" which avoids this problem and increases precision.
Now, I'm not 100% positive every switch in A-10C is set up in this manner, in which case a Black-Shark like solution is needed.

Closing notes

I hope this has been useful to you all, please leave feedback, positive comments and questions.

The clarifications regarding the different numerical codes and their meaning in the P-51D is based on logical conclusions I drew when staring at the file. I may very well be wrong, but the stuff mentioned in this file works, and has been tested by yours truly.

Finally, the mandatory thanks to ED for these simulators. I may be bashing Black Shark fairly liberally due to some lacking features which has induced hair-pulling and headscratching on some occasions.

I remember reading about the Black Shark for the first time in Swedish PC Gamer and I was like "Hmm, study sim... not for me.", but when I read about A-10C I was more like "I must have this!". On finding it on Steam, I bought it and promptly fell in love with it.

On finding out they were made by the same people I got Black Shark pretty much right away and found I loved it.
A-10C was my first flight simulator ever, and I tried others after it, but no. I have become spoiled by the sheer quality of these things.
So, thanks ED and everyone involved with making these awesome simulators.



Spy Guy is offline   Reply With Quote
Old 05-29-2012, 11:24 AM   #2
Nereid
Member
 
Nereid's Avatar
 
Join Date: Apr 2012
Location: Kiel, Germany
Posts: 211
Thumbs up

if I understand your solution correctly, this will work for every device with switches, that binds them to joystick buttons. I have searched for a similar solution for myself, but didn't found any. if this will work, this would be of great benefit for many users - not only warthog owners. Even for me, because I'm currently building my own input panel with switches and X-keys (some kind of a "universal-mini-cockpit" with integrated MFCDs).

I have also asked the DCS support, if they know about a solution and they told me, they didn't support this...

Last edited by Nereid; 05-29-2012 at 11:32 AM.
Nereid is offline   Reply With Quote
Old 05-29-2012, 11:41 AM   #3
Spy Guy
Junior Member
 
Spy Guy's Avatar
 
Join Date: Jan 2012
Posts: 48
Default

Yes, this should work for every device like that. I just used the Warthog as an example (and because that's what I used for experimentation).
__________________
Problems setting up switches on the HOTAS Warthog or similar?
Tutorial Here
Spy Guy is offline   Reply With Quote
Old 05-31-2012, 03:20 PM   #4
TheDoctor
Junior Member
 
Join Date: Jun 2009
Posts: 36
Thumbs up You really made my day...

Having both, the DCS P-51 and, fresh from the shelf, the A2A P-51 for FSX I'm in the process of setting up my controllers for both of then as identical as it gets...

DCS P-51 was first so I did this profile first...

...but then in FSX (with a registered copy of FSUIPC) I found a way set up toggle switches, exactly like you...
...and was grumbling "...if I only could do the same in DCS "

And there comes deus ex machina, ...ehhrrr Spy Guy and has already solved the problem...

Thanks !!!
TheDoctor is offline   Reply With Quote
Old 05-31-2012, 06:20 PM   #5
LawnDart
Senior Member
 
LawnDart's Avatar
 
Join Date: Mar 2005
Posts: 1,058
Default

Good info!

While I use the preset controls for A-10 for the most part, TARGET is my preferred way to program toggle switches in other sims/planes.

It's great to see that much of the same can be achieved within DCS itself though for those who'd rather do it that way (or don't own a HOTAS Hog).
__________________
http://www.virtualthunderbirds.com/Signatures/sig_LD.jpg
Virtual Thunderbirds, LLC | Sponsored by Thrustmaster

Corsair 750D Case | Corsair RM850i PSU | ASUS ROG MAXIMUS X CODE | 32GB Corsair DDR4 3200 |
Intel i7-8086K | Corsair Hydro H100i v2 Cooler | EVGA GTX 1080 Ti FTW | Oculus Rift |
X-Fi Titanium Fatal1ty | Samsung SSD 970 EVO 1TB NVMe | Samsung SSD 850 EVO 1TB | WD Caviar Black 2 x 1TB |
TM HOTAS Warthog | TM Pendular Rudder | TM MFD Cougar Pack | 40" LG 1080p LED | Win10 |
LawnDart is offline   Reply With Quote
Old 06-16-2012, 07:31 PM   #6
BIGNEWY
Senior
 
BIGNEWY's Avatar
 
Join Date: Aug 2011
Location: Hereford, UK
Posts: 14,762
Default

Great post helped me with my panel project and my DPDT toggle on off on switches
__________________
Currently on a break, please contact NineLine for assistance. Thanks
BIGNEWY is offline   Reply With Quote
Old 06-16-2012, 08:15 PM   #7
Double_D
Senior Member
 
Double_D's Avatar
 
Join Date: Apr 2012
Location: Ramitelli,Italy
Posts: 1,319
Default

yes very informative..thanks...
__________________
http://forums.eagle.ru/signaturepics/sigpic89949_15.gif
Recruiting for Aerobatic Team/Fighter Group...
Double_D is offline   Reply With Quote
Old 07-14-2012, 01:40 PM   #8
BIGNEWY
Senior
 
BIGNEWY's Avatar
 
Join Date: Aug 2011
Location: Hereford, UK
Posts: 14,762
Default

Noticed a slight change with DCS:WORLD 1.2.0

Example master arm A-10C with my controller button 19
Original
Code:
510 {combos = {{key = "JOY_BTN19"}, }, down = iCommandPlaneAHCPMasterArm, name = "Master switch ARM", category = "Armament HUD Control Panel"},

511 {down = iCommandPlaneAHCPMasterSafe, name = "Master switch SAFE", category = "Armament HUD Control Panel"},

Modified to release when button up for SAFE
Code:
510 {combos = {{key = "JOY_BTN19"}, }, down = iCommandPlaneAHCPMasterArm, up = iCommandPlaneAHCPMasterSafe, name = "Master switch ARM", category = "Armament HUD Control Panel"},

511 {down = iCommandPlaneAHCPMasterSafe, name = "Master switch SAFE", category = "Armament HUD Control Panel"},

-----------------------------------------------


Now a simple on off switch

Code:
{combos = {{key = "JOY_BTN1"}, }, down = iCommandPowerGeneratorLeft, up = iCommandPowerGeneratorLeft, name = "AC generator power left", category = "Electrical power control panel"},


I still need to finish my panel settings, but I hope this helps anyone using toggles in there pit's, I am still trying to work out the rest, it seems to have changed a lot more than I thought
__________________
Currently on a break, please contact NineLine for assistance. Thanks

Last edited by BIGNEWY; 07-14-2012 at 03:45 PM.
BIGNEWY is offline   Reply With Quote
Old 07-15-2012, 05:07 PM   #9
Spy Guy
Junior Member
 
Spy Guy's Avatar
 
Join Date: Jan 2012
Posts: 48
Default

I'm sorry, Bignewy... but I can't tell the difference, except for the line numbering...?

Code:
510 {combos = {{key = "JOY_BTN19"}, }, down = iCommandPlaneAHCPMasterArm, name = "Master switch ARM", category = "Armament HUD Control Panel"},
Do you mean this bit:
Code:
[...] combos = {{key = "JOY_BTN19"}, } [...]
?

If you do, then I was a bit unclear in the section for the A-10C. The combos section denotes (fairly clearly) which button is bound to the action in question, and the lack of that bit only indicates the button is unbound on the device you're looking at.

Am I missing something now, or did I miss something when I wrote the tutorial?
__________________
Problems setting up switches on the HOTAS Warthog or similar?
Tutorial Here
Spy Guy is offline   Reply With Quote
Old 07-17-2012, 02:22 PM   #10
sungsam
Member
 
sungsam's Avatar
 
Join Date: Sep 2009
Location: Hellas
Posts: 430
Default

So how can I make press switches behave like toggle ones ?

e.g Landing gear has also a toggle functionality Key binding but not EAC for example. Is there any way to create one for EAC etc ?
__________________
DCS F16C 52+ w JHMCS ! DCS AH64D Longbow !

Last edited by sungsam; 07-17-2012 at 02:26 PM.
sungsam is offline   Reply With Quote
Reply

Tags
controls, lua, tm warthog, toggle switches, tutorials

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 08:14 AM. vBulletin Skin by ForumMonkeys. Powered by vBulletin®.
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.