Changing repeat rate of joystick buttons: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
(Created page with "{{WIP}} If you are new to writing Nasal functions for joysticks, read Using a Nasal file with a joystick first. Category:Howto Category:Hardware")
 
mNo edit summary
Line 2: Line 2:


If you are new to writing Nasal functions for joysticks, read [[Using a Nasal file with a joystick]] first.
If you are new to writing Nasal functions for joysticks, read [[Using a Nasal file with a joystick]] first.
==  Background ==
Sometimes the repeat rate of joystick buttons is too high. The value changes so fast that you can't set it accurately. You could use
  <desc>whatever</desc>
  <interval-sec>x.xx</interval-sec>
where x.xx is the time between button action repeats. This has the problem that the delay is implemented at the start of the button press, as well as between repeats. It is also not as versatile as using this method.
==  Changes (additions) to the Nasal file ==
You must have set up everything according to [[Using a Nasal file with a joystick]].
Assume that the button in question is labelled "C". The property we want to change with the button is '''/mythical/telescope-colour'''. It has an integer value. Our nas file is called mynasfile.nas. We will use a flag called busyTelescope to control the repeat rate.
Start off by adding the function for the button
  var adjTelescopeColour = func {
        if (getprop("/mythical/busyTelescope")) return;
 
        setprop("/mythical/busyTelescope", 1);
 
        ... Code to adjust telescope property goes here  ..
   
}




[[Category:Howto]]
[[Category:Howto]]
[[Category:Hardware]]
[[Category:Hardware]]

Revision as of 07:37, 3 February 2013

WIP.png Work in progress
This article or section will be worked on in the upcoming hours or days.
See history for the latest developments.

If you are new to writing Nasal functions for joysticks, read Using a Nasal file with a joystick first.

Background

Sometimes the repeat rate of joystick buttons is too high. The value changes so fast that you can't set it accurately. You could use

 <desc>whatever</desc>
 <interval-sec>x.xx</interval-sec>

where x.xx is the time between button action repeats. This has the problem that the delay is implemented at the start of the button press, as well as between repeats. It is also not as versatile as using this method.


Changes (additions) to the Nasal file

You must have set up everything according to Using a Nasal file with a joystick.

Assume that the button in question is labelled "C". The property we want to change with the button is /mythical/telescope-colour. It has an integer value. Our nas file is called mynasfile.nas. We will use a flag called busyTelescope to control the repeat rate.

Start off by adding the function for the button

 var adjTelescopeColour = func {
       if (getprop("/mythical/busyTelescope")) return;
 
       setprop("/mythical/busyTelescope", 1);
 
       ... Code to adjust telescope property goes here  ..
   

}