Logical Devices
Logical devices are used for timers, etc. so that the rest of the script
can find out what state they are in. There are a total of 256 of these
devices available. They are referenced as "D1" through "D256". The ID
is assigned when the device function is referenced. That ID is then
used by the rest of the script to reference the state of that device.
There are currently six types of devices available. Four are timers,
the fifth is used to generate a short pulse when a given condition becomes
TRUE, and the sixth is used to generate a "toggle" function when its input
changes state. This section discusses the operation of these devices.
Timer Devices
Timer Devices are controlled by a single bit value (which may be an
expression, of course). There are currently four types of timers recognized
by the CMS utility. They provide the timing functions most often needed
in a scrip, and can be combined with other devices to produce more
elaborate timing sequences if necessary.
On Delay Timer
The first of these is the On-Delay timer. These set their associated Device
Variable TRUE a specified amount of time after the expression that controls
the timer (its "input") becomes TRUE. Once the Device Variable is set, it
remains on until the input becomes FALSE. At that time, the Device Variable
turns FALSE and the timer gets reset. Any subsequent activation will restart
the delay.
For example:
TIMER( ONDELAY, D5, 10 ) = JS1.B2;
The first parameter (ONDELAY) specifies the timer type. The second parameter
(D5) designates the Device Variable that the rest of the script uses to
reference this timer. The third parameter (10) gives the time period in
units based on the Character Rate set on the GUI Program Settings tab.
JS1.B2 is the input. When it becomes TRUE, the time period starts. If
JS1.B2 remains on for at least the specified time period, then Variable
D5 will turn TRUE and will remain TRUE until JS1.B2 is released. If
JS1.B2 is released before the time period has elapsed, then D5 will
not become TRUE at all.
For the timer to be useful, D5 must then be referenced somewhere else in
the script. For example:
SCRIPT
TIMER( ONDELAY, D5, 10 ) = JS1.B2;
CMS.B1 = D5;
ENDSCRIPT
would have the effect of turning CMS.B1 on 10 time units or about
half a second after JS1.B2 is pressed and held. If JS1.B2 is released before
the time period has elapsed, the timer is reset and CMS.B1 doesn't get set.
Off Delay Timer
The second type of timer is the Off-Delay. An Off-Delay time sets it
s Device Variable TRUE immediately when its input becomes TRUE and
it stays TRUE so long as the input is TRUE. When the input goes FALSE,
the specified time delay starts. At the end of the delay, the Device
Variable goes FALSE. If the input goes TRUE again before the time delay
has elapsed, the timer is reset and when the input goes FALSE again the
time period will start all over.
The Off-Delay is declared more or less identically to the On-Delay:
TIMER( OFFDELAY, D3, 20 ) = JS2.B3;
The first parameter defines it as an OFFDELAY, the second parameter
designates the Device Variable, and the third parameter set the length
of the time delay. In the above example, D3 would be TRUE immediately
when JS2.B3 was pressed. It would stay TRUE until JS2.B3 was released,
then the time period, about 1 second would start. At the end of the
time period, D3 would be set FALSE.
This is useful in a variety of operations. In a combat flight simulation,
for example, you might want to have your trigger activate a gun camera
when the trigger is pressed, then keep the camera running for a period
of time after the trigger is released. A script to accomplish that might
look like this:
SCRIPT
TIMER( OFFDELAY, D1, 200 ) = JS1.B1;
CMS.B1 = D1;
ENDSCRIPT
D1, and thus CMS.B1, would be set TRUE as soon as you pulled the trigger
and would remain TRUE until about 10 seconds after the trigger was released.
In the GUI, you would program CMS.B1 to send the "Start Camera"
character when it was pressed and the "Stop Camera" character when it
was released using the Press and Release strings.
Period Timer
The third available timer type is the Period timer. This type turns TRUE
immediately when its input turns TRUE. It remains TRUE for the specified
length of time regardless of what the input does. If the Period timer is
set for a time of 2 seconds for example, its output will be TRUE for
2 seconds whether the input is TRUE for 1/10th of a second or 100 seconds.
The declaration is similar to the other timer types. It looks like this:
The parameters have essentially the same meaning as in the ONDELAY and
OFFDELAY timers. In the above, "PERIOD" is used to define the timer type,
"D3" to define the Device ID, and "20" to set the period.
Interval Timer
The last type of timer is the Interval timer. This is like a flasher, it
turns its Device Variable TRUE and then FALSE continuously while its
input is TRUE. It is declared similarly to the On-Delay and Off-Delay, but
requires a second time period be specified. It might look like this:
TIMER( INTERVAL, D7, 30, 40 ) = JS2.B4;
The first two parameter are the usual definitions of timer type and
Device Variable. The second two parameter define the TRUE time and the
FALSE time respectively. The timer starts TRUE when the input initially
comes TRUE, delays for the first time period, then turns
FALSE, delays for the second time period, then turns TRUE again repeats
the cycle. It will continue this so long as JS2.B4 is pressed.
This type of timer is useful for implementing a number of different
functions. One example might be a "slow trim" function:
SCRIPT
TIMER( INTERVAL, D1, 20, 100 ) = JS1.B2;
TIMER( INTERVAL, D2, 20, 100 ) = JS1.B3;
CMS.B1 = D1;
CMS.B2 = D2;
ENDSCRIPT
The above generates a pulse on D1 about every 5 seconds while JS1.B2
is pressed and a pulse on D2 about every 5 seconds while JS1.B3 is
pressed. If CMS.B1 is mapped to the "Trim Up" key and CMS.B2 is mapped
to the "Trim Down" key in the GUI, then holding one of these buttons
down will result in a fairly slow trimming of the aircraft in one
direction or another.
Toggle Device
The Toggle Device changes its state from FALSE to TRUE or from TRUE
to FALSE whenever the input changes from FALSE to TRUE. It's useful in
generating "Push-On/Push-Off types of function. The declaration looks
something like this:
TOGGLE( D3 ) = JS1.B2;
Every time that JS1.B2 is pressed, D3 will change state.
Pulse Device
The sixth type of device is the "Pulse" device. It sets its Device
Variable TRUE when its input goes from FALSE to TRUE. The Device
Variable remains TRUE for one complete loop through the script at which
time it sets itself FALSE again regardless of what the input does. The
input must go FALSE and then TRUE again to generate another pulse. Thus
the pulse lasts for exactly one loop through the CMS script. The Pulse
is useful when other parts of the script need to know that an event has
happened, but keeping the Device Variable TRUE for multiple scans would
create problems.
To declare a Pulse device, the code looks like this:
PULSE( D2 ) = B1;
In this example, D2 (the Device Variable) would turn TRUE during the loop
through the script where B1 was first seen as being TRUE. On the next loop
through the scrip, it would turn FALSE again and it would remain FALSE until
B1 had itself gone first FALSE and then turned TRUE again. It generates a
pulse only on the FALSE-to-TRUE transition of the input variable (B1).
The Pulse device is not suitable for sending characters directly. They
are generally too brief to be picked up correctly by the character
processor. To stretch the pulse out so it will be seen, you can use
an Off-Delay Timer:
SCRIPT
PULSE( D2 ) = B1;
TIMER( OFFDELAY, D3, 10 ) = D2;
CMS.B1 = D3;
ENDSCRIPT
In this case, the brief pulse on D2 triggers Off-Delay D3. D3 turns
TRUE right away, and since D2 turns FALSE on the subsequent scan, D3
starts timing essentially immediately. The Off-Delay is tied to the
character rate, though, and so stays on long enough that the character
processor will recognize it. CMS.B1 can be programmed in the GUI to
send the needed character. If the action does get missed, try either
increasing the Character Rate in the Program Settings
or by increasing the time value in the Off-Delay statement itself.