Advertisement
hamzaalloush

Warthog-Stick.xml

Mar 15th, 2017
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 10.01 KB | None | 0 0
  1. <?xml version="1.0"?>
  2. <!--
  3.     Copyright (c) 2011   Melchior FRANZ   mfranz # aon : at
  4.  
  5.     This driver supports joystick overlay files (see ./Warthog/README).
  6.  
  7.     TMS ... Target Management Switch (black, rippled cursor switch, left side)
  8.     DMS ... Data Management Switch (black cursor switch with flat cross on top, right side)
  9.     CMS ... Countermeasures Management Switch  (grey)
  10. -->
  11.  
  12. <PropertyList>
  13.     <name>Thustmaster Joystick - HOTAS Warthog</name>
  14.     <name>Thrustmaster Joystick - HOTAS Warthog</name> <!-- in case they ever manage to fix their name -->
  15.     <name>Joystick - HOTAS Warthog</name>
  16.  
  17.     <nasal>
  18.         <script>
  19.             var this = cmdarg().getParent();
  20.             var init = !contains(caller(0)[0], "init");
  21.             if (!contains(globals, "warthog"))
  22.                 io.load_nasal(getprop("/sim/fg-root") ~ "/Input/Joysticks/ThrustMaster/Warthog/warthog.nas");
  23.  
  24.             var jslistener = func init and call(setlistener, arg);
  25.             var popup = func gui.popupTip(call(sprintf, arg));
  26.             var is_helicopter = (func {(var n = props.globals.getNode("rotors", 0)) != nil and n.getAttribute("children")})();
  27.             var aircraft_type = getprop("/sim/type");
  28.  
  29.             var load_overlay = func(name) {
  30.                 foreach (var dir; [getprop("/sim/fg-home"), getprop("/sim/fg-root")]) {
  31.                     var file = dir ~ "/Input/Joysticks/ThrustMaster/Warthog/Stick/" ~ name ~ ".xml";
  32.                     if (io.stat(file) != nil) {
  33.                         printlog("info", "WARTHOG: loading overlay " ~ file);
  34.                         cmdarg().setValues({command: "nasal", script: ""});
  35.                         io.read_properties(file, this);
  36.                         props.runBinding(cmdarg());
  37.                         break;
  38.                     }
  39.                 }
  40.             }
  41.  
  42.             foreach (var b; this.getChildren("button")) {
  43.                 if (b.getAttribute("children") == 1) {
  44.                     var name = b.getNode("name", 1).getValue() or "??";
  45.                     b.setValues({binding: {command: "nasal", script: 'popup("' ~ name ~ '")'}});
  46.                 }
  47.             }
  48.  
  49.             var mod = 0;
  50.             var m = props.globals.initNode("/devices/status/joysticks/warthog/modifier", mod, "INT");
  51.             jslistener(m, func(n) mod = n.getValue());
  52.  
  53.             var trimstep = 0.75;
  54.             var viewstep = 1.5;
  55.             var button = {18: {id: 0}};
  56.  
  57.             var reset_zoom = func setprop("/sim/current-view/field-of-view", 55);
  58.             var viewdir = props.globals.getNode("/sim").getChildren("view");
  59.             forindex (var i; viewdir) {
  60.                 var t = viewdir[i].getNode("type");
  61.                 viewdir[i] = t != nil and t.getValue() == "lookat" ? 1 : -1;
  62.             }
  63.  
  64.             load_overlay("generic");
  65.             if (is_helicopter)
  66.                 load_overlay("helicopter");
  67.             if (aircraft_type)
  68.                 load_overlay(aircraft_type);
  69.             foreach (var o; split(":", getprop("/input/joysticks/overlays") or ""))
  70.                 load_overlay(o);
  71.             load_overlay(getprop("/sim/aircraft"));
  72.         </script>
  73.     </nasal>
  74.  
  75.     <axis n="0">
  76.         <name>X-axis</name>
  77.         <desc>aileron</desc>
  78.         <tolerance>0.00001</tolerance>
  79.         <binding>
  80.             <command>property-scale</command>
  81.             <property>/controls/flight/aileron</property>
  82.         </binding>
  83.     </axis>
  84.  
  85.     <axis n="1">
  86.         <name>Y-axis</name>
  87.         <desc>elevator</desc>
  88.         <tolerance>0.00001</tolerance>
  89.         <binding>
  90.             <command>property-scale</command>
  91.             <property>/controls/flight/elevator</property>
  92.             <factor type="double">-1.0</factor>
  93.         </binding>
  94.     </axis>
  95.  
  96.     <!--<axis n="2">
  97.         <name>Trim Hat Switch Left/Right</name>
  98.         <desc>adjust aileron trim,  +mod: reset aileron trim</desc>
  99.         <low>
  100.             <repeatable>true</repeatable>
  101.             <binding>
  102.                 <command>nasal</command>
  103.                 <script>
  104.                     if (mod)
  105.                         setprop("/controls/flight/aileron-trim", 0);
  106.                     else
  107.                         controls.aileronTrim(-1);
  108.                 </script>
  109.             </binding>
  110.         </low>
  111.         <high>
  112.             <repeatable>true</repeatable>
  113.             <binding>
  114.                 <command>nasal</command>
  115.                 <script>
  116.                     if (mod)
  117.                         setprop("/controls/flight/aileron-trim", 0);
  118.                     else
  119.                         controls.aileronTrim(1);
  120.                 </script>
  121.             </binding>
  122.         </high>
  123.     </axis>-->
  124.  
  125.     <axis n="7">
  126.         <name>Trim Hat Switch Down/Up</name>
  127.         <desc>adjust elevator trim,  +mod: reset elevator trim</desc>
  128.         <low>
  129.             <repeatable>true</repeatable>
  130.             <binding>
  131.                 <command>nasal</command>
  132.                 <script>
  133.                     if (mod)
  134.                         setprop("/controls/flight/elevator-trim", 0);
  135.                     else
  136.                         controls.elevatorTrim(-1);
  137.                 </script>
  138.             </binding>
  139.         </low>
  140.         <high>
  141.             <repeatable>true</repeatable>
  142.             <binding>
  143.                 <command>nasal</command>
  144.                 <script>
  145.                     if (mod)
  146.                         setprop("/controls/flight/elevator-trim", 0);
  147.                     else
  148.                         controls.elevatorTrim(1);
  149.                 </script>
  150.             </binding>
  151.         </high>
  152.     </axis>
  153.  
  154.     <button n="0">
  155.         <name>Trigger Button/Half Pushed</name>
  156.         <desc>camera oper</desc>
  157.     </button>
  158.  
  159.     <button n="1">
  160.         <name>Weapons Release</name>
  161.     </button>
  162.  
  163.     <button n="2">
  164.         <name>Nosewheel Steering Button</name>
  165.         <desc>toggle nosewheel steering/tailwheel lock</desc>
  166.         <binding>
  167.             <command>nasal</command>
  168.             <script>
  169.                 var i = !(getprop("/controls/gear/nose-wheel-steering") or 0);
  170.                 setprop("/controls/gear/nose-wheel-steering", i);
  171.                 setprop("/controls/gear/tailwheel-lock", !i);
  172.                 popup("Tail Wheel %sLOCKED!", i ? "UN" : "");
  173.             </script>
  174.         </binding>
  175.     </button>
  176.  
  177.     <button n="3">
  178.         <name>Paddle Switch</name>
  179.         <desc>modifier button</desc>
  180.         <binding>
  181.             <command>property-assign</command>
  182.             <property>/devices/status/joysticks/warthog/modifier</property>
  183.             <value>1</value>
  184.         </binding>
  185.         <mod-up>
  186.             <binding>
  187.                 <command>property-assign</command>
  188.                 <property>/devices/status/joysticks/warthog/modifier</property>
  189.                 <value>0</value>
  190.             </binding>
  191.         </mod-up>
  192.     </button>
  193.  
  194.     <button n="4">
  195.         <name>Master Mode Control Button</name>
  196.     </button>
  197.  
  198.     <button n="5">
  199.         <name>Trigger Button/Fully Pushed</name>
  200.         <desc>gun trigger</desc>
  201.         <binding>
  202.             <command>nasal</command>
  203.             <script>controls.trigger(1)</script>
  204.         </binding>
  205.         <mod-up>
  206.             <binding>
  207.                 <command>nasal</command>
  208.                 <script>controls.trigger(0)</script>
  209.             </binding>
  210.         </mod-up>
  211.     </button>
  212.  
  213.     <button n="6">
  214.         <name>left black curosr (TMS) up</name>
  215.         <desc>brakes,  +mod: toggle parking brake</desc>
  216.         <binding>
  217.             <command>nasal</command>
  218.             <script>controls.applyBrakes(1)</script>
  219.         </binding>
  220.         <mod-up>
  221.             <binding>
  222.                 <command>nasal</command>
  223.                 <script>
  224.                     if (mod) {
  225.                         var i = controls.applyParkingBrake(1);
  226.                         popup("Parking Brake %s", i ? "ON" : "OFF");
  227.                     }
  228.                     controls.applyBrakes(0)
  229.                 </script>
  230.             </binding>
  231.         </mod-up>
  232.     </button>
  233.  
  234.     <button n="7">
  235.         <name>left black cursor (TMS) right</name>
  236.         <desc>brakes right</desc>
  237.         <binding>
  238.             <command>nasal</command>
  239.             <script>controls.applyBrakes(1, 1)</script>
  240.         </binding>
  241.         <mod-up>
  242.             <binding>
  243.                 <command>nasal</command>
  244.                 <script>controls.applyBrakes(0, 1)</script>
  245.             </binding>
  246.         </mod-up>
  247.     </button>
  248.  
  249.     <button n="8">
  250.         <name>left black cursor (TMS) down</name>
  251.         <desc>brakes,  +mod: toggle parking brake</desc>
  252.         <binding>
  253.             <command>nasal</command>
  254.             <script>controls.applyBrakes(1)</script>
  255.         </binding>
  256.         <mod-up>
  257.             <binding>
  258.                 <command>nasal</command>
  259.                 <script>
  260.                     if (mod) {
  261.                         var i = controls.applyParkingBrake(1);
  262.                         popup("Parking Brake %s", i ? "ON" : "OFF");
  263.                     }
  264.                     controls.applyBrakes(0)
  265.                 </script>
  266.             </binding>
  267.         </mod-up>
  268.     </button>
  269.  
  270.     <button n="9">
  271.         <name>left black cursor (TMS) left</name>
  272.         <desc>brakes left</desc>
  273.         <binding>
  274.             <command>nasal</command>
  275.             <script>controls.applyBrakes(1, -1)</script>
  276.         </binding>
  277.         <mod-up>
  278.             <binding>
  279.                 <command>nasal</command>
  280.                 <script>controls.applyBrakes(0, -1)</script>
  281.             </binding>
  282.         </mod-up>
  283.     </button>
  284.  
  285.     <button n="10">
  286.         <name>right black cursor (DMS) up</name>
  287.         <desc>zoom in,  +mod: reset zoom</desc>
  288.         <repeatable>true</repeatable>
  289.         <binding>
  290.             <command>nasal</command>
  291.             <script>
  292.                 if (mod)
  293.                     reset_zoom();
  294.                 else
  295.                     view.decrease(1);
  296.             </script>
  297.         </binding>
  298.     </button>
  299.  
  300.     <button n="11">
  301.         <name>right black cursor (DMS) right</name>
  302.         <desc>next active view,  +mod: next view</desc>
  303.         <binding>
  304.             <command>nasal</command>
  305.             <script>view.stepView(1, mod)</script>
  306.         </binding>
  307.     </button>
  308.  
  309.     <button n="12">
  310.         <name>right black cursor (DMS) down</name>
  311.         <desc>zoom out,  +mod: reset zoom</desc>
  312.         <repeatable>true</repeatable>
  313.         <binding>
  314.             <command>nasal</command>
  315.             <script>
  316.                 if (mod)
  317.                     reset_zoom();
  318.                 else
  319.                     view.increase(1);
  320.             </script>
  321.         </binding>
  322.     </button>
  323.  
  324.     <button n="13">
  325.         <name>right black cursor (DMS) left</name>
  326.         <desc>previous active view,  +mod: previous view</desc>
  327.         <binding>
  328.             <command>nasal</command>
  329.             <script>view.stepView(-1, mod)</script>
  330.         </binding>
  331.     </button>
  332.  
  333.     <button n="14">
  334.         <name>grey cursor (CMS) up</name>
  335.         <desc>view up</desc>
  336.         <repeatable>true</repeatable>
  337.         <binding>
  338.             <command>nasal</command>
  339.             <script>view.panViewPitch(viewstep)</script>
  340.         </binding>
  341.     </button>
  342.  
  343.     <button n="15">
  344.         <name>grey cursor (CMS) right</name>
  345.         <desc>view right</desc>
  346.         <repeatable>true</repeatable>
  347.         <binding>
  348.             <command>nasal</command>
  349.             <script>view.panViewDir(viewdir[view.index] * viewstep)</script>
  350.         </binding>
  351.     </button>
  352.  
  353.     <button n="16">
  354.         <name>grey cursor (CMS) down</name>
  355.         <desc>view down</desc>
  356.         <repeatable>true</repeatable>
  357.         <binding>
  358.             <command>nasal</command>
  359.             <script>view.panViewPitch(-viewstep)</script>
  360.         </binding>
  361.     </button>
  362.  
  363.     <button n="17">
  364.         <name>grey cursor (CMS) left</name>
  365.         <desc>view left</desc>
  366.         <repeatable>true</repeatable>
  367.         <binding>
  368.             <command>nasal</command>
  369.             <script>view.panViewDir(-viewdir[view.index] * viewstep)</script>
  370.         </binding>
  371.     </button>
  372.  
  373.     <button n="18">
  374.         <name>grey cursor (CMS) push</name>
  375.         <desc>short: center view,  long (&gt;0.5 sec): centered cockpit view</desc>
  376.         <binding>
  377.             <command>nasal</command>
  378.             <script>
  379.                 (func(id) {
  380.                     settimer(func {
  381.                         if (id == button[18].id) {
  382.                             setprop("/sim/current-view/view-number", 0);
  383.                             view.resetView();
  384.                         }
  385.                     }, 0.5, 1);
  386.                 })(button[18].id += 1);
  387.             </script>
  388.         </binding>
  389.         <mod-up>
  390.             <binding>
  391.                 <command>nasal</command>
  392.                 <script>
  393.                     button[18].id += 1;
  394.                     view.resetView();
  395.                 </script>
  396.             </binding>
  397.         </mod-up>
  398.     </button>
  399. </PropertyList>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement