<?xml version="1.0"?>
<PropertyList>
    
    <logic>
        <name>Throttles at idle</name>
         <input>
            <and>
                <!-- engine 1 -->
                <or>
                    <less-than>
                        <property>/controls/engines/engine[0]/throttle</property>
                        <property>/autopilot/autospoilers/config/idle-throttle</property>
                    </less-than>
                    <property>/controls/engines/engine[0]/reverser</property>
                </or>
                <!-- engine 3 -->
                <or>
                    <less-than>
                        <property>/controls/engines/engine[2]/throttle</property>
                        <property>/autopilot/autospoilers/config/idle-throttle</property>
                    </less-than>
                    <property>/controls/engines/engine[2]/reverser</property>
                </or>
            </and>
        </input>
        <output>/autopilot/autospoilers/throttles-at-idle</output>
    </logic>
    
    <logic>
        <name>RTO sensed</name>
         <input>
            <or>
                <and>
                    <less-than>
                        <property>/controls/engines/engine[0]/throttle</property>
                        <property>/autopilot/autospoilers/config/idle-throttle</property>
                    </less-than>
                    <property>/controls/engines/engine[1]/reverser</property>
                </and>
                <and>
                    <less-than>
                        <property>/controls/engines/engine[2]/throttle</property>
                        <property>/autopilot/autospoilers/config/idle-throttle</property>
                    </less-than>
                    <property>/controls/engines/engine[3]/reverser</property>
                </and>
            </or>
        </input>
        <output>/autopilot/autospoilers/rto-sensed</output>
    </logic>

    <logic>
        <name>Airborne</name>
        <input>
            <or>
                <not><property>/gear/gear[1]/wow</property></not>
                <not><property>/gear/gear[2]/wow</property></not>
                <not><property>/gear/gear[3]/wow</property></not>
                <not><property>/gear/gear[4]/wow</property></not>
            </or>
        </input>
        <output>/autopilot/autospoilers/airborne</output>
    </logic>
    
    <filter>
        <name>After takeoff</name>
        <type>gain</type>
        <gain>1.0</gain>
        <!-- Speedbrake lever stop, prevents it from moving to UP in air -->
        <input>
            <condition>
                <property>/autopilot/autospoilers/airborne</property>
            </condition>
            <value>1</value>
        </input>
        <input>
            <condition>
                <and>
                    <property>/autopilot/autospoilers/after-takeoff</property>
                    <not><property>/autopilot/autospoilers/airborne</property></not>
                </and>
            </condition>
            <value>1</value>
        </input>
        <input>
            <condition>
                <and>
                    <not><property>/autopilot/autospoilers/after-takeoff</property></not>
                    <not><property>/autopilot/autospoilers/airborne</property></not>
                </and>
            </condition>
            <value>0</value>
        </input>
        <output>/autopilot/autospoilers/after-takeoff</output>
    </filter>
    
    <filter>
        <name>Speedbrake lever</name>
        <type>gain</type>
        <gain>1.0</gain>
        <!-- Speedbrake lever stop, prevents it from moving to UP in air -->
        <input>
            <condition>
                <and>
                    <equals>
                        <property>/autopilot/autospoilers/step</property>
                        <value>3</value>
                    </equals>
                    <property>/autopilot/autospoilers/airborne</property>
                </and>
            </condition>
            <value>2</value>
        </input>
        <!-- Arm -->
        <input>
            <condition>
                <and>
                    <equals>
                        <property>/autopilot/autospoilers/step</property>
                        <value>1</value>
                    </equals>
                    <property>/autopilot/autospoilers/throttles-at-idle</property>
                    <property>/autopilot/autospoilers/after-takeoff</property>
                    <not><property>/autopilot/autospoilers/airborne</property></not>
                </and>
            </condition>
            <value>3</value>
        </input>
        <!-- RTO -->
        <input>
            <condition>
                <and>
                    <equals>
                        <property>/autopilot/autospoilers/step</property>
                        <value>0</value>
                    </equals>
                    <property>/autopilot/autospoilers/rto-sensed</property>
                    <not><property>/autopilot/autospoilers/airborne</property></not>
                </and>
            </condition>
            <value>3</value>
        </input>
        <!-- Go-around -->
        <input>
            <condition>
                <and>
                    <equals>
                        <property>/controls/flight/speedbrakes</property>
                        <value>2</value>
                    </equals>
                    <not><property>/autopilot/autospoilers/throttles-at-idle</property></not>
                </and>
            </condition>
            <value>0</value>
        </input>
        <!-- default input -->
        <input>
            <property>/autopilot/autospoilers/step</property>
        </input>
        <output>/autopilot/autospoilers/step</output>
    </filter>
    
    <!-- output summer -->
    <filter>
        <name>Output Summer</name>
        <type>gain</type>
        <gain>1.0</gain>
        <input>
            <condition>
                <equals>
                    <property>/autopilot/autospoilers/step</property>
                    <value>0</value>
                </equals>
            </condition>
            <value>0</value>
        </input>
        <input>
            <condition>
                <equals>
                    <property>/autopilot/autospoilers/step</property>
                    <value>2</value>
                </equals>
            </condition>
            <value>1</value>
        </input>
        <input>
            <condition>
                <equals>
                    <property>/autopilot/autospoilers/step</property>
                    <value>3</value>
                </equals>
            </condition>
            <value>2</value>
        </input>
        <!-- default input -->
        <input>
            <property>/controls/flight/speedbrakes</property>
        </input>
        <output>/controls/flight/speedbrakes</output>
    </filter>
        
</PropertyList>