Download [Script Editor basics - v1.5] 700 KB

Transcript
We will keep our toggling SEQuence but the “autopilot ON” keystrokes are going to be replaced by a function
linked to the LASTE toggle switch. The result of this function will depend on the LASTE Toggle switch position.
include "target.tmh"
int main()
{
if(Init(&EventHandle)) return 1;
int autopilot = SEQ(EXEC("ap_ON_output();"), PULSE+L_ALT+'9');//defining the autopilot function
MapKey(&Throttle, APENG, autopilot);
MapKey(&Throttle, LTB, autopilot);
}
//notice that the next function is built out of the main program
int ap_ON_output() //naming the function
{
if(Throttle[APPAT]) ActKey(KEYON+PULSE+L_ALT+'6');
else if(Throttle[APALT]) ActKey(KEYON+PULSE+L_ALT+'4');
else ActKey(KEYON+PULSE+L_ALT+'2'); //if it's not the 2 others, it can only be APAH
}
int EventHandle(int type, alias o, int x)
{
DefaultMapping(&o, x);
}
Let’s take care of another setting: the Autopilot Alt mode can use Barometric or Radar. This is chosen according
to the position of the RDR ALTM toggle switch. This adds a new variable in our function. We will not create a new
function to manage this, but simply use a logic filter inside our function. We only have to use the “&” operator.
int apkey()
{
if(Throttle[APPAT]) ActKey(KEYON+PULSE+L_ALT+'6');
else if(Throttle[APALT] & Throttle[RDRDIS]) ActKey(KEYON+PULSE+L_ALT+'4');
else if (Throttle[APALT] & Throttle[RDRNRM]) ActKey(KEYON+PULSE+L_ALT+'5');
else ActKey(KEYON+PULSE+L_ALT+'2');
}
For the same function, using macros, things are much easier to read:
int apkey()
{
if(Throttle[APPAT]) ActKey(KEYON+PULSE+Autopilot_Route_following);
else if(Throttle[APALT] & Throttle[RDRDIS]) ActKey(KEYON+PULSE+Autopilot_Barometric_Altitude_Hold);
else if (Throttle[APALT] & Throttle[RDRNRM]) ActKey(KEYON+PULSE+Autopilot_Radar_Altitude_Hold);
else ActKey(KEYON+PULSE+Autopilot_Altitude_And_Roll_Hold);
}
Another example, using more code: an indexed list.
This one is a little bit complicated.
We have a list of 8 flight modes and we want to select them with just 2 buttons. We could cheat using SEQuence;
it may make the things very easy to write. But what we want is a little bit more complex. We want to have our list
of modes act like a sequence, but with the ability to choose the direction of the SEQuence. For this we need to
use a custom function and an index.
We will create a function called listmode that contains the SEQuence. And we will use the index to jump between
each event in the SEQuence.
50/60 - T.A.R.G.E.T Script Editor Basics User Manual v1.5