config / .fgfs / Input / Joysticks / T-Flight-Stick-X.xml /
Sébastien MARQUE add PTT
ca7e3b1 4 years ago
1 contributor
346 lines | 9.621kb
<?xml version="1.0"?>

<PropertyList>
  <nasal>
    <script><![CDATA[
      var skipFlightControls = props.globals.getNode("/sim/mouse/skip-flight-controls-mode");
      setlistener("/sim/signals/fdm-initilized", func {
          skipFlightControls.setBoolValue(1);
          print("JOYSTICK set mouse flight control OFF: ", skipFlightControls.getValue());
      }, 1 );
      setlistener("/sim/signals/save", func {
          skipFlightControls.setBoolValue(0);
          print("JOYSTICK save mouse flight control ON: ", skipFlightControls.getValue());
      } );

      # determine Nasal namespace for this joystick
      # stored in js[0]
      string.scanf(cmdarg().getNode("module").getValue(), "__js%u", var js = []);

      # array with prop path for each button status
      var pressed_button = [];
      for (var i = 0; i < 12; i += 1)
        append(pressed_button, "/devices/status/joysticks/joystick[" ~ js[0] ~ "]/button[" ~ i ~ "]");

      var previousMouseMode = 0;
      var locked_view = 0;

      var chinese_hat = func (heading, pitch) {
        if (getprop(pressed_button[0])) {
          if    (pitch   > 0) view.decrease();
          elsif (pitch   < 0) view.increase();
          elsif (heading > 0){view.resetViewDir();view.resetFOV();}
          elsif (heading < 0) view.resetFOV();
        }
        elsif (getprop(pressed_button[10])) {
          if (pitch)
            controls.elevatorTrim(pitch);
          else
            controls.rudderTrim(heading);
        }
        elsif (getprop(pressed_button[11]) and heading) {
          controls.aileronTrim(heading);
        }
        else {
          if (heading) {
            fgcommand("property-adjust", {
              property : "/sim/current-view/goal-heading-offset-deg",
              step : 2.0 * heading
            });
          }
          elsif (pitch) {
            fgcommand("property-adjust", {
              property : "/sim/current-view/goal-pitch-offset-deg",
              step : 2.0 * pitch
            });
          }
        }
      }

      var addSelectedEngine = func (i) {
        controls.engines[i].selected.setBoolValue(1);
        printf("engine %d added to joystick controls", i);
        gui.popupTip("engine " ~ i ~ " joystick controlled");
      }

      var removeSelectedEngine = func (i) {
        controls.engines[i].selected.setBoolValue(0);
        printf("engine %d removed from joystick controls", i);
        gui.popupTip("engine " ~ i ~ " joystick uncontrolled");
      }

      # key = button identifier as displayed on joystick
      joystick_button = {
        2 : func (pressed) {
          if (pressed) {
            if (getprop("/sim/current-view/view-number") > 1 or locked_view)
              return;
            previousMouseMode = getprop("/devices/status/mice/mouse[0]/mode");
            setprop("/devices/status/mice/mouse[0]/mode", 2);
          }
          elsif (getprop(pressed_button[0])) {
            locked_view = 1;
            return;
          }
          else {
            locked_view = 0;
            setprop("/devices/status/mice/mouse[0]/mode", previousMouseMode);
          }
          setprop("/sim/current-view/view-number", pressed);
        },

        3 : func (pressed) {
          controls.applyBrakes(pressed)
        },

        4 : func (pressed) {
          if (pressed) {
            var comm = getprop(pressed_button[0]) + 1;
            controls.ptt(comm);
            gui.popupTip("PTT COMM " ~ comm);
          }
          else {
            controls.ptt(0);
            gui.popupTip("PTT COMM ends", 0.5);
          }

        },

        5 : func {
          controls.flapsDown(1)
        },

        6 : func {
          if    (getprop(pressed_button[10])) {
            for (var i = 0; i < 4; i += 1)
              controls.engines[i].selected.setBoolValue(1);
            printf("all engines added to joystick controls");
            gui.popupTip("joystick controls all engines");
          }
          elsif (getprop(pressed_button[11])) {
            for (var i = 0; i < 4; i += 1)
              controls.engines[i].selected.setBoolValue(0);
            printf("joystick controls no engines", i);
            gui.popupTip("joystick controls no engine");
          }
          else
            controls.flapsDown(-1)
        },

        7 : func {
          if    (getprop(pressed_button[10])) addSelectedEngine(2);
          elsif (getprop(pressed_button[11])) removeSelectedEngine(2);
          else controls.adjMixture(1);
        },

        8 : func {
          if    (getprop(pressed_button[10])) addSelectedEngine(3);
          elsif (getprop(pressed_button[11])) removeSelectedEngine(3);
          else controls.adjMixture(-1);
        },

        9 : func {
          if    (getprop(pressed_button[10])) addSelectedEngine(1);
          elsif (getprop(pressed_button[11])) removeSelectedEngine(1);
          else controls.adjPropeller(1);
        },

        10 : func {
          if    (getprop(pressed_button[10])) addSelectedEngine(0);
          elsif (getprop(pressed_button[11])) removeSelectedEngine(0);
          else controls.adjPropeller(-1);
        },
      }
    ]]></script>
  </nasal>

  <name type="string">T.Flight Stick X</name>
  <name type="string">Thrustmaster T.Flight Stick X</name>

  <axis n="0">
    <desc>Aileron</desc>
    <binding>
      <command>property-scale</command>
      <property>/controls/flight/aileron</property>
      <squared type="bool">true</squared>
    </binding>
  </axis>

  <axis n="1">
    <desc>Elevator</desc>
    <binding>
      <command>property-scale</command>
      <property>/controls/flight/elevator</property>
      <factor type="double">-1.0</factor>
      <squared type="bool">true</squared>
    </binding>
  </axis>

  <axis>
    <number>
      <windows>2</windows>
      <unix>3</unix>
    </number>
    <desc>Increase/Reduce Throttle</desc>
    <binding>
      <command>nasal</command>
      <script>controls.throttleAxis()</script>
    </binding>
  </axis>

  <axis>
    <number>
      <windows>3</windows>
      <unix>2</unix>
    </number>
    <desc>Rudder Left/Right</desc>
    <binding>
      <command>property-scale</command>
      <property>/controls/flight/rudder</property>
      <factor type="double">1.0</factor>
    </binding>
  </axis>

  <axis>
    <number>
      <windows>6</windows>
      <unix>4</unix>
    </number>
    <desc>View Direction | reset FoV | reset view direction</desc>
    <low>
      <repeatable>true</repeatable>
      <binding>
        <command>nasal</command>
        <script>chinese_hat(1, 0)</script>
      </binding>
    </low>
    <high>
      <repeatable>true</repeatable>
      <binding>
        <command>nasal</command>
        <script>chinese_hat(-1, 0)</script>
      </binding>
    </high>
  </axis>

  <axis>
    <number>
      <windows>7</windows>
      <unix>5</unix>
    </number>
    <desc>Orientation up or down / Increase or decrease FoV</desc>
    <low>
      <repeatable>true</repeatable>
      <binding>
        <command>nasal</command>
        <script>chinese_hat(0, 1)</script>
      </binding>
    </low>
    <high>
      <repeatable>true</repeatable>
      <binding>
        <command>nasal</command>
        <script>chinese_hat(0, -1)</script>
      </binding>
    </high>
  </axis>

  <button n="1">
    <desc>Swap first and second views</desc>
    <binding>
      <command>nasal</command>
      <script>joystick_button[2](1)</script>
    </binding>
    <mod-up>
      <binding>
        <command>nasal</command>
        <script>joystick_button[2](0)</script>
      </binding>
    </mod-up>
  </button>

  <button n="2">
    <desc>Apply brakes</desc>
    <binding>
      <command>nasal</command>
      <script>joystick_button[3](0)</script>
    </binding>
    <mod-up>
      <binding>
        <command>nasal</command>
        <script>joystick_button[3](1)</script>
      </binding>
    </mod-up>
  </button>

  <button n="3">
    <desc>PTT - Push To Talk (via FGCom)</desc>
    <binding>
      <command>nasal</command>
      <script>joystick_button[4](1)</script>
    </binding>
    <mod-up>
      <binding>
        <command>nasal</command>
        <script>joystick_button[4](0)</script>
      </binding>
    </mod-up>
  </button>

  <button n="4">
    <desc>Extend Flaps Incrementally</desc>
    <repeatable>false</repeatable>
    <binding>
      <command>nasal</command>
      <script>joystick_button[5]()</script>
    </binding>
  </button>

  <button n="5">
    <desc>Retract Flaps Incrementally</desc>
    <repeatable>false</repeatable>
    <binding>
      <command>nasal</command>
      <script>joystick_button[6]()</script>
    </binding>
  </button>

  <button n="6">
    <desc>Handle mixture | add or remove engine 0</desc>
    <repeatable>true</repeatable>
    <binding>
      <command>nasal</command>
      <script>joystick_button[7]()</script>
    </binding>
  </button>

  <button n="7">
    <desc>Handle mixture | add or remove engine 1</desc>
    <repeatable>true</repeatable>
    <binding>
      <command>nasal</command>
      <script>joystick_button[8]()</script>
    </binding>
  </button>

  <button n="8">
    <desc>Handle mixture | add or remove engine 2</desc>
    <repeatable>true</repeatable>
    <binding>
      <command>nasal</command>
      <script>joystick_button[9]()</script>
    </binding>
  </button>

  <button n="9">
    <desc>Handle mixture | add or remove engine 3</desc>
    <repeatable>true</repeatable>
    <binding>
      <command>nasal</command>
      <script>joystick_button[10]()</script>
    </binding>
  </button>

</PropertyList>

<!-- end of T.Flight Stick X.xml -->