I have written for my external HW an xml file like
/flightgear/fgdata/Input/Joysticks/Local/Arduino_2.xml
I have more than one Aircraft that is mapped to one Button, So for example AP Button can be used for C172, C182, Twinotter, A320, etc. This is done in an external nasal script .
For the Twinotter its give us No. 3 .
If you use only one A/C you dont need it. Than forget the code
if ( AirCraftType==3 ) {
.
}
1) nasal script
- Code: Select all
<?xml version="1.0"?>
<nasal>
<script><![CDATA[
var AirCraftType=0;
var Version=0;
io.load_nasal(getprop("/sim/fg-home") ~"/Nasal/joystick_pow.nas", "joystick_pow");
AirCraftType = joystick_pow.aircraftversion();
print("AirCraftType INCLUDE : ", AirCraftType);
# ==============================================================
# dhc6
# ==============================================================
var dhc6_ALTMODE=0;
var dhc6_HDGMODE=0;
var dhc6_AP_init=0;
var dhc6AllAPOff=func() {
setprop("controls/autopilot/settings/apflag",0) ;
# HDG off
setprop("controls/autopilot/settings/hdgflag",0) ;
setprop("controls/autopilot/settings/hdgsetflag",0) ;
setprop("controls/autopilot/settings/navsetflag",0) ;
# ALT off
setprop("controls/autopilot/settings/altflag",0) ;
setprop("controls/autopilot/settings/altsetflag",0) ;
setprop("controls/autopilot/settings/gssetflag",0) ;
setprop("controls/autopilot/settings/vssetflag",0) ;
dhc6_ALTMODE=0;
dhc6_HDGMODE=0;
gui.popupTip("AP off");
}
# =========================================================
var Dhc6APOnOff2020=func() {
print("Dhc6APOnOff2020 "); #debug
setprop("/autopilot/locks/altitude", "") ;
setprop("/autopilot/locks/speed", "") ;
setprop("/autopilot/locks/heading", "") ;
setprop("/controls/autopilot/settings/altflag", 0) ;
setprop("controls/autopilot/settings/altsetflag",0) ;
setprop("/controls/autopilot/settings/vssetflag", 0) ;
setprop("/controls/autopilot/settings/gssetflag", 0) ;
setprop("/controls/autopilot/settings/hdgsetflag", 0) ;
setprop("/controls/autopilot/settings/navsetflag", 0) ;
setprop("controls/autopilot/settings/hdgflag",0) ;
}
# =========================================================
var Dhc6_AP_Hdg=func() {
setprop("autopilot/locks/heading", "wing-leveler") ;
if ( getprop("controls/autopilot/settings/hdgflag") == 0 ) {
setprop("autopilot/locks/heading", "") ;
}
if ( getprop("controls/autopilot/settings/hdgflag") == 0 ){
setprop("autopilot/locks/heading", "") ;
}
setprop("controls/autopilot/settings/hdgsetflag", 0) ;
setprop("controls/autopilot/settings/navsetflag", 0) ;
setprop("autopilot/locks/passive-mode", 0) ;
}
# =========================================================
var Dhc6_AP_Altitude=func() {
#line
print("Dhc6_AP_Altitude=func");
if ( getprop("controls/autopilot/settings/iasflag") == 0) {
setprop("autopilot/locks/altitude", "");
}
setprop("controls/autopilot/settings/altsetflag", 0) ;
setprop("controls/autopilot/settings/vssetflag", 0) ;
setprop("controls/autopilot/settings/gssetflag", 0) ;
setprop("autopilot/locks/passive-mode", 0) ;
}
# =========================================================
# AP-Speed
var Dhc6_AP_Speed=func() {
print("AP-Speed");
# Speed-toggle
if ( ( getprop("controls/autopilot/settings/apflag") == 1 )
and
(getprop("position/altitude-agl-ft") > 100.0 )) {
setprop("controls/autopilot/settings/iasflag", 1) ;
gui.popupTip("IAS Speed on");
} else {
setprop("controls/autopilot/settings/iasflag", 0) ;
gui.popupTip("IAS Speed off or Altitude to Low ");
}
setprop("controls/autopilot/settings/altsetflag", 0) ;
setprop("/controls/autopilot/settings/gssetflag", 0) ;
setprop("/controls/autopilot/settings/vssetflag", 0) ;
# sp DHC6
setprop("autopilot/locks/passive-mode", 0) ;
}
]]></script>
</nasal>
2) AP On/OFF
- Code: Select all
<button n="1"> <!-- Autopilot -->
<desc>Autopilot Toggle</desc>
<repeatable type="bool">false</repeatable>
# 3: dhc6
<binding>
<command>nasal</command>
<script>
if ( AirCraftType == 3 ) {
print(" AirCraftType == 3 ");
print(" apflag ", getprop("controls/autopilot/settings/apflag"));
if (dhc6_AP_init ==0 ) {
Dhc6APOnOff2020();
print(" dhc6_AP_init ");
setprop("controls/autopilot/settings/apflag",1);
dhc6_AP_init = 1;
}
else {
if ( getprop("controls/autopilot/settings/apflag") == 0 ) {
setprop("controls/autopilot/settings/apflag",1);
print(" dhc6 ap on ");
Dhc6APOnOff2020();
print("powo_dhc6AllAPOff on "); #debug
gui.popupTip("AP on");
} else if ( getprop("controls/autopilot/settings/apflag") == 1 ){
setprop("controls/autopilot/settings/apflag",0) ;
print(" dhc6 ap off ");
Dhc6APOnOff2020();
print("powo_dhc6AllAPOff off "); #debug
gui.popupTip("AP off");
}
}
}
</script>
</binding>
</button>
3) HDG
- Code: Select all
# ========================================================================
# dhc6 HDG on ok button n="4"
# ========================================================================
<button n="1">
<repeatable type="bool">false</repeatable>
<desc>Autopilot HDG mode toggle </desc>
# dhc6 hdg on off
<binding>
<command>nasal</command>
<script>
<!--
if ( AirCraftType == 3 and ( getprop("controls/autopilot/settings/apflag") == 1 ) ) {
if ( getprop("controls/autopilot/settings/hdgflag") == 0 ) {
setprop("controls/autopilot/settings/hdgflag",1);
gui.popupTip("HDG on");
} else {
setprop("controls/autopilot/settings/hdgflag",0) ;
setprop("controls/autopilot/settings/hdgsetflag",0) ;
setprop("controls/autopilot/settings/navsetflag",0) ;
gui.popupTip("HDG off");
}
}
-->
if ( (AirCraftType == 3) and ( getprop("controls/autopilot/settings/apflag") == 1 ) ) {
if ( getprop("controls/autopilot/settings/hdgflag") == 0 ) {
setprop("controls/autopilot/settings/hdgflag",1);
# mist 6
Dhc6_AP_Hdg();
gui.popupTip("HDG on");
#mist
} else if ( getprop("controls/autopilot/settings/hdgflag") == 1 ) {
setprop("controls/autopilot/settings/hdgflag",0) ;
# line 12
Dhc6_AP_Hdg();
gui.popupTip("HDG off");
}
}
</script>
</binding>
</button>
4) dhc6 SWITCH hdg nav Mode
I think there must be some fault in there .
If hdg is on and switch to nav alt mode should switch of after dhc find nav path
- Code: Select all
# ========================================================================
# dhc6 SWITCH hdg nav Mode
# ========================================================================
<button n="2">
<repeatable type="bool">false</repeatable>
<desc>Autopilot PITCH mode </desc>
# dhc6 SWITCH hdg nav Mode
<binding>
<command>nasal</command>
<script>
if ( (AirCraftType == 3)
and
( getprop("controls/autopilot/settings/apflag") == 1 )
and
( getprop("controls/autopilot/settings/hdgflag") == 1 ) ) {
# hdg ON
if ( dhc6_HDGMODE == 0 ) {
setprop("controls/autopilot/settings/hdgsetflag",1);
setprop("autopilot/locks/heading", "dg-heading-hold") ;
setprop("controls/autopilot/settings/navsetflag",0) ;
gui.popupTip("HDG-set Mode");
print("HDG-set Mode");
}
# nav ON
if ( dhc6_HDGMODE == 1 ) {
setprop("controls/autopilot/settings/hdgsetflag",0); # disable check in fg9adc button 9
setprop("controls/autopilot/settings/navsetflag",1) ;
if ( getprop("instrumentation/nav[0]/crs-catched") == 1 ){
setprop("controls/autopilot/settings/hdgsetflag", 0) ;
}
if ( getprop("controls/autopilot/settings/hdgflag") == 1 ){
setprop("autopilot/locks/heading", "nav1-hold") ;
}
gui.popupTip("NAV-set Mode");
print("NAV-set Mode");
}
# hdg nav OFF
if ( dhc6_HDGMODE == 2 ) {
setprop("controls/autopilot/settings/hdgsetflag",0);
setprop("controls/autopilot/settings/navsetflag",0) ;
setprop("autopilot/locks/heading", "wing-leveler") ;
gui.popupTip("HDG Mode ");
print("HDG Mode" );
}
dhc6_HDGMODE = dhc6_HDGMODE + 1;
if (dhc6_HDGMODE == 3) {dhc6_HDGMODE = 0;}
}
</script>
</binding>
</button>
5) ALT
- Code: Select all
# ========================================================================
# dhc6 ALT on off
# ========================================================================
<button n="3">
<repeatable type="bool">false</repeatable>
<desc>Autopilot ALT mode</desc>
# dhc6 ALT on off
<binding>
<command>nasal</command>
<script>
if ( (AirCraftType == 3)
and
( getprop("controls/autopilot/settings/apflag") == 1 ) ) {
if (getprop("controls/autopilot/settings/altflag") == 0 ) {
setprop("controls/autopilot/settings/altflag",1);
Dhc6_AP_Altitude();
gui.popupTip("AP Altitude on");
} else if (getprop("controls/autopilot/settings/altflag") == 1 ) {
setprop("controls/autopilot/settings/altflag",0) ;
Dhc6_AP_Altitude();
gui.popupTip("AP Altitude off");
} else {
gui.popupTip("dhc6 AP Altitude Wrong");
}
}
</script>
</binding>
</button>
6) dhc6 ALT Switch mode altitude-hold . gs1-hold . vertical-speed-hold
I think there must be some fault in there .
If alt hold is on and switch to gs1 hold alt mode should switch of after dhc find gs path
- Code: Select all
# ========================================================================
# dhc6 ALT Switch mode altitude-hold . gs1-hold . vertical-speed-hold
# ========================================================================
<button n="4">
<repeatable type="bool">false</repeatable>
<desc>KAP140: NAV ; CENTURYIII:Move Hdg select button to the right (wrap)</desc>
# dhc6 ALT Switch mode altitude-hold . gs1-hold . vertical-speed-hold
<binding>
<command>nasal</command>
<script>
if ( (AirCraftType == 3) and
( getprop("controls/autopilot/settings/apflag") == 1 )
and
( getprop("controls/autopilot/settings/altflag") == 1 )
) {
setprop("controls/autopilot/settings/iasflag",0);
setprop("controls/autopilot/settings/vssetflag",0) ;
# altitude-hold
if ( dhc6_ALTMODE == 0 ) {
setprop("controls/autopilot/settings/altsetflag",1);
setprop("controls/autopilot/settings/gssetflag",0) ;
setprop("controls/autopilot/settings/vssetflag",0) ;
setprop("/controls/autopilot/settings/iasflag", 0) ;
setprop("autopilot/locks/altitude", "altitude-hold") ;
gui.popupTip("altitude-hold");
}
# Gs-set mode
if ( dhc6_ALTMODE == 1 ) {
setprop("controls/autopilot/settings/altsetflag",0);
if ( ( getprop("instrumentation/nav[0]/gs-in-range") == 1 )
and
(getprop("controls/autopilot/settings/altflag") == 1 )) {
setprop("controls/autopilot/settings/gssetflag", 1) ;
}
if ( getprop("instrumentation/nav[0]/gs-catched") == 1 ){
setprop("controls/autopilot/settings/altsetflag", 0) ;
setprop("controls/autopilot/settings/iasflag", 0) ;
setprop("controls/autopilot/settings/vssetflag", 0) ;
}
if ( getprop("controls/autopilot/settings/altflag") == 1 ){
setprop("autopilot/locks/altitude", "gs1-hold") ;
}
gui.popupTip("GS-hold");
}
# Vs-set mode
if ( dhc6_ALTMODE == 2 ) {
setprop("controls/autopilot/settings/vssetflag",1) ;
setprop("/autopilot/locks/altitude", "vertical-speed-hold") ;
setprop("controls/autopilot/settings/altsetflag",0);
setprop("controls/autopilot/settings/gssetflag",0) ;
setprop("/controls/autopilot/settings/iasflag", 0) ;
gui.popupTip("VS-hold");
}
dhc6_ALTMODE = dhc6_ALTMODE + 1;
if (dhc6_ALTMODE == 3) {dhc6_ALTMODE = 0;}
}
</script>
</binding>
</button>
7) IAS
- Code: Select all
# ========================================================================
# dhc6 IAS on off Speed
# ========================================================================
<button n="5">
<repeatable type="bool">false</repeatable>
<desc>IAS</desc>
# 3: dhc6 IAS on off Speed change nur wenn Airplane fliegt
<binding>
<command>nasal</command>
<script>
print("dhc6 IAS");
if ( (AirCraftType == 3)
and
( getprop("controls/autopilot/settings/apflag") == 1 )) {
if ( getprop("controls/autopilot/settings/iasflag") == 0 ) {
Dhc6_AP_Speed();
#gui.popupTip("IAS Speed on");
} else {
#setprop("controls/autopilot/settings/iasflag",0) ;
Dhc6_AP_Speed();
#gui.popupTip("IAS Speed off");
}
}
</script>
</binding>
</button>
dhc6 AP Vertical Speed # dhc6 AP Vertical Speed -100
- Code: Select all
<binding>
<command>property-adjust</command>
<property>autopilot/settings/vertical-speed-fpm</property>
<factor>-100</factor>
<min>-6000</min>
<max>6000</max>
<wrap>false</wrap>
</binding>
# dhc6 AP Vertical Speed +100
- Code: Select all
# dhc6 AP Vertical Speed
<binding>
<command>property-adjust</command>
<property>autopilot/settings/vertical-speed-fpm</property>
<factor>100</factor>
<min>-6000</min>
<max>6000</max>
<wrap>false</wrap>
</binding>
9) # dhc6 alt.dwn interval 0.2 sec
- Code: Select all
# dhc6 alt.dwn
<interval-sec>0.2</interval-sec>
<binding>
<command>property-adjust</command>
<property>autopilot/settings/target-altitude-ft</property>
<step>-100/</step>
<min>1000</min>
<max>30000</max>
<wrap>false</wrap>
</binding>
<binding>
<command>nasal</command>
<script>
# showroll();
</script>
</binding>
# dhc6 alt.up interval 0.2 sec
- Code: Select all
# dhc6 alt.up
<interval-sec>0.2</interval-sec>
<binding>
<command>property-adjust</command>
<property>autopilot/settings/target-altitude-ft</property>
<step>100</step>
<min>1000</min>
<max>30000</max>
<wrap>false</wrap>
</binding>