]> git.mxchange.org Git - flightgear.git/blob - src/Autopilot/logic.cxx
fix #416: reciprocal filter broken
[flightgear.git] / src / Autopilot / logic.cxx
1 // logic.cxx - Base class for logic components
2 //
3 // Written by Torsten Dreyer
4 //
5 // Copyright (C) 2004  Curtis L. Olson  - http://www.flightgear.org/~curt
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21
22 // for some obscure reason, MSVC needs this to compile
23 #ifdef _MSC_VER
24 #ifndef HAVE_CONFIG_H
25 #  include <config.h>
26 #endif
27 #include <simgear/math/SGMath.hxx>
28 #endif
29
30 #include "logic.hxx"
31
32 using namespace FGXMLAutopilot;
33
34 bool Logic::get_input() const
35 {
36   // return state of first configured condition
37   InputMap::const_iterator it = _input.begin();
38   if( it == _input.end() ) return false; // no inputs?
39   return (*it).second->test();
40 }
41
42 void Logic::set_output( bool value )
43 {
44   // respect global inverted flag
45   if( _inverted ) value = !value;
46
47   // set all outputs to the given value
48   for( OutputMap::iterator it = _output.begin(); it != _output.end(); it++ )
49     (*it).second->setValue( value );
50 }
51
52 bool Logic::get_output() const
53 {
54   OutputMap::const_iterator it = _output.begin();
55   bool q = it != _output.end() ? (*it).second->getValue() : false;
56   return _inverted ? !q : q;
57 }
58
59 void Logic::update( bool firstTime, double dt )
60 {
61   set_output( get_input() );
62 }
63