Board index FlightGear Support Hardware

Patch for adjusting throttle with the mouse wheel

Joysticks, pedals, monitors.

Patch for adjusting throttle with the mouse wheel

Postby rominet » Fri Aug 14, 2015 11:09 am

Hello,

Here is one of the patches that are most useful to me, for flying with the mouse (or a mouse + joystick combination for helicopters, as explained in this EC130 video).
Code: Select all
Description: Adjust throttle with the mouse wheel
 This patch allows one to adjust the throttle with the mouse wheel when flight
 controls mode is active. <Super>-<+> and <Super>-<-> allow one to change the
 amplitude of the increment or decrement step that is added for each mouse
 wheel tick.
 .
 The initial increment or decrement step used for adjusting the throttle when
 the mouse wheel is moved is determined by the
 /frougon/initial-mouse-wheel-throttle-step property
 (default: 0.05, suitable for planes such as the 777-200ER).
Author: Florent Rougon <f.rougon@free.fr>
Forwarded: no

Patch based on fgdata commit 454fa8df8f82fba1e7a98a3137dd02756506567
(branch 'next', dated Wed Aug 12 11:31:05 2015 +0300)

diff --git a/keyboard.xml b/keyboard.xml
index ce8dd61..ce5c6ec 100644
--- a/keyboard.xml
+++ b/keyboard.xml
@@ -35,6 +35,14 @@ top down before the key bindings are parsed.
           }
       }
 
+      # Value used to initialize flo_mouse_wheel_throttle_step
+      props.globals.initNode("frougon/initial-mouse-wheel-throttle-step",
+                             0.05, "DOUBLE");
+      # Increment or decrement step when throttle is adjusted with the
+      # mouse wheel
+      var flo_mouse_wheel_throttle_step = getprop(
+                                  "frougon/initial-mouse-wheel-throttle-step");
+
       ## uncomment this line to get keycode reports printed to the terminal window
       #setlistener("devices/status/keyboard/event", func(n) debug.dump(n.getValues()));
   </script>
@@ -390,6 +398,20 @@ top down before the key bindings are parsed.
     <command>nasal</command>
     <script>screen.msg_repeat()</script>
   </binding>
+  <mod-super>
+    <desc>Increase mouse wheel throttle step</desc>
+    <binding>
+       <command>nasal</command>
+       <script>
+         # Nothing really special about that 17 percent value, it is just
+         # large enough to be noticeable, but not too large.
+         flo_mouse_wheel_throttle_step = 1.17*flo_mouse_wheel_throttle_step;
+         gui.popupTip(sprintf("Mouse wheel throttle step: %.2g",
+                              flo_mouse_wheel_throttle_step),
+                      2);
+       </script>
+    </binding>
+  </mod-super>
  </key>
 
  <key n="44">
@@ -415,6 +437,19 @@ top down before the key bindings are parsed.
      <command>dialog-show</command>
      <dialog-name>chat-menu</dialog-name>
   </binding>
+  <mod-super>
+    <desc>Decrease mouse wheel throttle step</desc>
+    <binding>
+       <command>nasal</command>
+       <script>
+         # Inverse of a 17 % increase
+         flo_mouse_wheel_throttle_step = flo_mouse_wheel_throttle_step/1.17;
+         gui.popupTip(sprintf("Mouse wheel throttle step: %.2g",
+                              flo_mouse_wheel_throttle_step),
+                      2);
+       </script>
+    </binding>
+  </mod-super>
  </key>
 
  <key n="46">
diff --git a/mice.xml b/mice.xml
index dd58d03..4aa1a7e 100644
--- a/mice.xml
+++ b/mice.xml
@@ -84,22 +84,26 @@ current mode for each mouse is held in the
     </binding>
    </button>
 
-   <!-- extra buttons control elevator trim -->
+   <!-- extra buttons control throttle -->
    <!-- these are often assigned to mouse-wheel motion in Linux -->
    <button n="3">
-    <binding>
-     <command>property-adjust</command>
-     <property>/controls/flight/elevator-trim</property>
-     <step type="double">0.01</step>
-    </binding>
+     <desc>Increase throttle or autopilot autothrottle</desc>
+     <binding>
+       <command>nasal</command>
+       <script>
+         controls.incThrottle(__kbd.flo_mouse_wheel_throttle_step, 2.0)
+       </script>
+     </binding>
    </button>
 
    <button n="4">
-    <binding>
-     <command>property-adjust</command>
-     <property>/controls/flight/elevator-trim</property>
-     <step type="double">-0.01</step>
-    </binding>
+     <desc>Decrease throttle or autopilot autothrottle</desc>
+     <binding>
+       <command>nasal</command>
+       <script>
+         controls.incThrottle(-__kbd.flo_mouse_wheel_throttle_step, -2.0)
+       </script>
+     </binding>
    </button>
 
    <!-- Mouse left/right motion. -->


The patch only modifies the mouse wheel binding in “flight controls” mode (so you cannot adjust elevator trim anymore with the mouse wheel, but I don't find that useful when flying with the mouse, thus it is not a problem for me). The behavior doesn't change in other modes.

Save it to throttle-with-mouse-wheel.patch and apply it with:
Code: Select all
patch -p1 <throttle-with-mouse-wheel.patch

People using Git may apply it to fgdata with:
Code: Select all
git apply throttle-with-mouse-wheel.patch

but you would need to do that on your personal branch, otherwise you would have problems on the next 'git pull' unless using 'git reset --hard' (which would restore the branch to "official state", hence without the patch).

If you also use the patch posted at http://forum.flightgear.org/viewtopic.php?f=25&t=20547&start=15#p254016, then use this patch instead (context slightly adjusted), applied after the patch for customizable persistent views:
Code: Select all
Description: Adjust throttle with the mouse wheel
 This patch allows one to adjust the throttle with the mouse wheel when flight
 controls mode is active. <Super>-<+> and <Super>-<-> allow one to change the
 amplitude of the increment or decrement step that is added for each mouse
 wheel tick.
 .
 The initial increment or decrement step used for adjusting the throttle when
 the mouse wheel is moved is determined by the
 /frougon/initial-mouse-wheel-throttle-step property
 (default: 0.05, suitable for planes such as the 777-200ER).
Author: Florent Rougon <f.rougon@free.fr>
Forwarded: not-needed

diff --git a/keyboard.xml b/keyboard.xml
index eabaa23..2bd1b9e 100644
--- a/keyboard.xml
+++ b/keyboard.xml
@@ -49,6 +49,14 @@ top down before the key bindings are parsed.
                               ~ getprop("/sim/aircraft") ~ "-views.xml", node);
       });
 
+      # Value used to initialize flo_mouse_wheel_throttle_step
+      props.globals.initNode("frougon/initial-mouse-wheel-throttle-step",
+                             0.05, "DOUBLE");
+      # Increment or decrement step when throttle is adjusted with the
+      # mouse wheel
+      var flo_mouse_wheel_throttle_step = getprop(
+                                  "frougon/initial-mouse-wheel-throttle-step");
+
       ## uncomment this line to get keycode reports printed to the terminal window
       #setlistener("devices/status/keyboard/event", func(n) debug.dump(n.getValues()));
   </script>
@@ -404,6 +412,20 @@ top down before the key bindings are parsed.
     <command>nasal</command>
     <script>screen.msg_repeat()</script>
   </binding>
+  <mod-super>
+    <desc>Increase mouse wheel throttle step</desc>
+    <binding>
+       <command>nasal</command>
+       <script>
+         # Nothing really special about that 17 percent value, it is just
+         # large enough to be noticeable, but not too large.
+         flo_mouse_wheel_throttle_step = 1.17*flo_mouse_wheel_throttle_step;
+         gui.popupTip(sprintf("Mouse wheel throttle step: %.2g",
+                              flo_mouse_wheel_throttle_step),
+                      2);
+       </script>
+    </binding>
+  </mod-super>
  </key>
 
  <key n="44">
@@ -429,6 +451,19 @@ top down before the key bindings are parsed.
      <command>dialog-show</command>
      <dialog-name>chat-menu</dialog-name>
   </binding>
+  <mod-super>
+    <desc>Decrease mouse wheel throttle step</desc>
+    <binding>
+       <command>nasal</command>
+       <script>
+         # Inverse of a 17 % increase
+         flo_mouse_wheel_throttle_step = flo_mouse_wheel_throttle_step/1.17;
+         gui.popupTip(sprintf("Mouse wheel throttle step: %.2g",
+                              flo_mouse_wheel_throttle_step),
+                      2);
+       </script>
+    </binding>
+  </mod-super>
  </key>
 
  <key n="46">
diff --git a/mice.xml b/mice.xml
index a2e7a8a..c80ca84 100644
--- a/mice.xml
+++ b/mice.xml
@@ -84,22 +84,26 @@ current mode for each mouse is held in the
     </binding>
    </button>
 
-   <!-- extra buttons control elevator trim -->
+   <!-- extra buttons control throttle -->
    <!-- these are often assigned to mouse-wheel motion in Linux -->
    <button n="3">
-    <binding>
-     <command>property-adjust</command>
-     <property>/controls/flight/elevator-trim</property>
-     <step type="double">0.01</step>
-    </binding>
+     <desc>Increase throttle or autopilot autothrottle</desc>
+     <binding>
+       <command>nasal</command>
+       <script>
+         controls.incThrottle(__kbd.flo_mouse_wheel_throttle_step, 2.0)
+       </script>
+     </binding>
    </button>
 
    <button n="4">
-    <binding>
-     <command>property-adjust</command>
-     <property>/controls/flight/elevator-trim</property>
-     <step type="double">-0.01</step>
-    </binding>
+     <desc>Decrease throttle or autopilot autothrottle</desc>
+     <binding>
+       <command>nasal</command>
+       <script>
+         controls.incThrottle(-__kbd.flo_mouse_wheel_throttle_step, -2.0)
+       </script>
+     </binding>
    </button>
 
    <!-- Mouse left/right motion. -->


In order to automatically adjust the default sensitivity (i.e., on FG startup) when flying a helicopter, you can use something like this in your configuration if you use FFGo (cf. also this thread on the forum):

At the beginning:
Code: Select all
{  using_heli = aircraft in \
    ["alouette2", "alouette2F", "Alouette-III_sc", "bo105",
     "ec130b4", "ec135p2", "M-XE", "s55", "s76c", "uh1", "uh60", "rah-66"] }

and then, after the default, unconditional section (cf. FFGo conditional config documentation):
Code: Select all
[ using_heli ]
--prop:/frougon/initial-mouse-wheel-throttle-step=0.004

[ not using_heli ]
# You may set a value that is different from the default here, if the default
# is not fine for planes according to your taste.
# --prop:/frougon/initial-mouse-wheel-throttle-step=<value-for-planes>

HTH
rominet
 
Posts: 557
Joined: Sat Nov 01, 2014 1:33 pm
Callsign: F-KATS
Version: Git next
OS: Debian GNU/Linux

Return to Hardware

Who is online

Users browsing this forum: No registered users and 1 guest