<?xml version="1.0" encoding="UTF-8"?>
<!--
**************************************************************************

Beagle Pup Filters

Copyright (c) 2015 Richard Senior

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

**************************************************************************
-->

<PropertyList>

  <!--===================================================================-->
  <!-- ALS SECONDARY LIGHTS                                              -->
  <!--===================================================================-->

  <logic>
    <input>
      <and>
        <property>systems/electrical/outputs/landing-lights</property>
        <property>sim/current-view/internal</property>
      </and>
    </input>
    <output>sim/rendering/als-secondary-lights/use-landing-light</output>
  </logic>

  <logic>
    <input>
      <and>
        <property>systems/electrical/outputs/taxi-light</property>
        <property>sim/current-view/internal</property>
      </and>
    </input>
    <output>sim/rendering/als-secondary-lights/use-alt-landing-light</output>
  </logic>

  <!--===================================================================-->
  <!-- STALL WARNING                                                     -->
  <!--===================================================================-->

  <!-- The reason for these filters is that Flightgear seems to record
       spurious values of airspeed when switching views. Only consider
       a stall warning if the conditions are met for a duration
  -->
  <logic>
    <input>
      <and>
        <not>
          <or>
            <property>gear/gear[1]/wow</property>
            <property>gear/gear[2]/wow</property>
          </or>
        </not>
        <or>
          <and>
            <greater-than>
              <property>fdm/jsbsim/fcs/flap-pos-norm</property>
              <value>0.36</value>
            </greater-than>
            <less-than>
              <property>velocities/airspeed-kt</property>
              <value>55</value>
            </less-than>
          </and>
          <and>
            <less-than>
              <property>fdm/jsbsim/fcs/flap-pos-norm</property>
              <value>0.36</value>
            </less-than>
            <less-than>
              <property>velocities/airspeed-kt</property>
              <value>65</value>
            </less-than>
          </and>
        </or>
      </and>
    </input>
    <output>hazards/stall/conditions-met</output>
  </logic>

  <flipflop>
    <type>monostable</type>
    <inverted type="bool">true</inverted>
    <S>
      <not>
        <property>hazards/stall/conditions-met</property>
      </not>
    </S>
    <time>
      <value>0.5</value>
    </time>
    <output>hazards/stall/stall-warning</output>
  </flipflop>

  <!--===================================================================-->
  <!-- ADDITIONAL  PROPERTIES                                            -->
  <!--===================================================================-->

  <filter>
    <type>gain</type>
    <gain>1.0</gain>
    <input>
      <expression>
        <fabs>
          <difference>
            <property>instrumentation/altimeter/indicated-altitude-ft</property>
            <property>position/altitude-ft</property>
          </difference>
        </fabs>
      </expression>
    </input>
    <output>instrumentation/altimeter/absolute-altitude-error-ft</output>
  </filter>

  <filter>
    <type>gain</type>
    <gain>1.0</gain>
    <input>
      <expression>
        <fabs>
          <difference>
            <property>instrumentation/heading-indicator/indicated-heading-deg</property>
            <property>orientation/heading-magnetic-deg</property>
          </difference>
        </fabs>
      </expression>
    </input>
    <output>instrumentation/heading-indicator/absolute-heading-error-deg</output>
  </filter>

  <logic>
    <input>
      <greater-than>
        <property>systems/vacuum/suction-inhg</property>
        <value>1.0</value>
      </greater-than>
    </input>
    <output>systems/vacuum/vacuum-norm</output>
  </logic>

  <logic>
    <input>
      <and>
        <greater-than>
          <property>systems/electrical/outputs/bus-dc</property>
          <value>6.0</value>
        </greater-than>
        <less-than>
          <property>systems/electrical/outputs/bus-dc</property>
          <value>24.0</value>
        </less-than>
      </and>
    </input>
    <output>systems/electrical/outputs/generator-warn</output>
  </logic>

  <logic>
    <input>
      <greater-than>
        <property>systems/electrical/outputs/starter</property>
        <value>6.0</value>
      </greater-than>
    </input>
    <output>systems/electrical/outputs/starter-norm</output>
  </logic>

  <!--===================================================================-->
  <!-- PANEL GAUGES                                                      -->
  <!--===================================================================-->

  <!-- Carb Temp -->

  <filter>
    <type>gain</type>
    <gain>1.0</gain>
    <input>
      <condition>
        <greater-than>
          <property>systems/electrical/outputs/carb-temp-gauge</property>
          <value>0</value>
        </greater-than>
      </condition>
      <property>engines/engine/carb-temp-degc</property>
    </input>
    <input>
      <value>0</value>
    </input>
    <output>instrumentation/carb-temp/carb-temp-degc</output>
  </filter>

  <filter>
    <type>exponential</type>
    <filter-time>0.4</filter-time>
    <input>instrumentation/carb-temp/carb-temp-degc</input>
    <output>instrumentation/carb-temp/carb-temp-degc-filtered</output>
  </filter>

  <!-- CHT Gauge -->

  <filter>
    <type>gain</type>
    <gain>
      <condition>
        <greater-than>
          <property>systems/electrical/outputs/cht-gauge</property>
          <value>0</value>
        </greater-than>
      </condition>
      <value>1</value>
    </gain>
    <gain>0</gain>
    <input>engines/engine/cht-degc</input>
    <output>instrumentation/cht/cht-degc</output>
  </filter>

  <filter>
    <type>exponential</type>
    <filter-time>0.4</filter-time>
    <input>instrumentation/cht/cht-degc</input>
    <output>instrumentation/cht/cht-degc-filtered</output>
  </filter>

  <!-- Exhaust Gas Temperature -->

  <filter>
    <type>gain</type>
    <gain>
      <condition>
        <greater-than>
          <property>systems/electrical/outputs/egt-gauge</property>
          <value>0</value>
        </greater-than>
      </condition>
      <value>1</value>
    </gain>
    <gain>0</gain>
    <input>engines/engine/egt-degf</input>
    <output>instrumentation/egt/egt-degf</output>
  </filter>

  <filter>
    <type>exponential</type>
    <filter-time>0.33</filter-time>
    <input>instrumentation/egt/egt-degf</input>
    <output>instrumentation/egt/egt-degf-filtered</output>
  </filter>

  <!-- Outside Air Temperature -->

  <filter>
    <type>gain</type>
    <gain>
      <condition>
        <greater-than>
          <property>systems/electrical/outputs/oat-gauge</property>
          <value>0</value>
        </greater-than>
      </condition>
      <value>1</value>
    </gain>
    <gain>0</gain>
    <input>environment/temperature-degc</input>
    <output>instrumentation/oat/oat-degc</output>
  </filter>

  <filter>
    <type>exponential</type>
    <filter-time>0.33</filter-time>
    <input>instrumentation/oat/oat-degc</input>
    <output>instrumentation/oat/oat-degc-filtered</output>
  </filter>

  <!-- Fuel Gauge -->

  <filter>
    <type>gain</type>
    <gain>
      <condition>
        <greater-than>
          <property>systems/electrical/outputs/fuel-gauge</property>
          <value>0</value>
        </greater-than>
      </condition>
      <value>1</value>
    </gain>
    <gain>0</gain>
    <input>
      <condition>
        <equals>
          <property>instrumentation/fuel-gauge/tank-select</property>
          <value>0</value>
        </equals>
      </condition>
      <property>consumables/fuel/tank[1]/level-gal_imp</property>
    </input>
    <input>
      <condition>
        <equals>
          <property>instrumentation/fuel-gauge/tank-select</property>
          <value>1</value>
        </equals>
      </condition>
      <property>consumables/fuel/tank[2]/level-gal_imp</property>
    </input>
    <output>instrumentation/fuel-gauge/level-gal_imp</output>
  </filter>

  <filter>
    <type>exponential</type>
    <filter-time>0.4</filter-time>
    <input>instrumentation/fuel-gauge/level-gal_imp</input>
    <output>instrumentation/fuel-gauge/level-gal_imp-filtered</output>
  </filter>

  <!-- Fuel Pressure -->

  <filter>
    <type>gain</type>
    <gain>
      <condition>
        <greater-than>
          <property>systems/electrical/outputs/fuel-pressure-gauge</property>
          <value>0</value>
        </greater-than>
      </condition>
      <value>1</value>
    </gain>
    <gain>0</gain>
    <input>fdm/jsbsim/propulsion/tank/fuel-pressure-psi</input>
    <output>instrumentation/fuel/fuel-pressure-psi</output>
  </filter>

  <filter>
    <type>double-exponential</type>
    <filter-time>0.67</filter-time>
    <input>instrumentation/fuel/fuel-pressure-psi</input>
    <output>instrumentation/fuel/fuel-pressure-psi-filtered</output>
  </filter>

  <!-- Oil Pressure -->

  <filter>
    <type>gain</type>
    <gain>
      <condition>
        <greater-than>
          <property>systems/electrical/outputs/oil-pressure-gauge</property>
          <value>0</value>
        </greater-than>
      </condition>
      <value>1</value>
    </gain>
    <gain>0</gain>
    <input>engines/engine/oil-pressure-psi</input>
    <output>instrumentation/oil/oil-pressure-psi</output>
  </filter>

  <filter>
    <type>double-exponential</type>
    <filter-time>0.67</filter-time>
    <input>instrumentation/oil/oil-pressure-psi</input>
    <output>instrumentation/oil/oil-pressure-psi-filtered</output>
  </filter>

  <!-- Oil Temp -->

  <filter>
    <type>gain</type>
    <gain>
      <condition>
        <greater-than>
          <property>systems/electrical/outputs/oil-temp-gauge</property>
          <value>0</value>
        </greater-than>
      </condition>
      <value>1</value>
    </gain>
    <gain>0</gain>
    <input>engines/engine/oil-temperature-degc</input>
    <output>instrumentation/oil/oil-temperature-degc</output>
  </filter>

  <filter>
    <type>exponential</type>
    <filter-time>0.4</filter-time>
    <input>instrumentation/oil/oil-temperature-degc</input>
    <output>instrumentation/oil/oil-temperature-degc-filtered</output>
  </filter>

  <!-- Gyro Suction -->

  <filter>
    <type>gain</type>
    <gain>
      <condition>
        <greater-than>
          <property>systems/electrical/outputs/suction-gauge</property>
          <value>0</value>
        </greater-than>
      </condition>
      <value>1</value>
    </gain>
    <gain>0</gain>
    <input>systems/vacuum/suction-inhg</input>
    <output>instrumentation/vacuum/suction-inhg</output>
  </filter>

  <filter>
    <type>exponential</type>
    <filter-time>0.4</filter-time>
    <input>instrumentation/vacuum/suction-inhg</input>
    <output>instrumentation/vacuum/suction-inhg-filtered</output>
  </filter>

</PropertyList>
