4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "BallastDumpManager.hpp"
25 #include "Engine/GlideSolvers/GlidePolar.hpp"
28 BallastDumpManager::Start()
33 // Update ballast_clock for the next call to BallastDumpManager::Update()
34 ballast_clock
.Update();
38 BallastDumpManager::Stop()
45 BallastDumpManager::SetEnabled(bool _enabled
)
47 if (_enabled
&& !IsEnabled())
49 else if (!_enabled
&& IsEnabled())
54 BallastDumpManager::Update(GlidePolar
&glide_polar
, unsigned dump_time
)
58 // We don't know how fast the water is flowing so don't pretend that we do
64 // Milliseconds since last ballast_clock.Update() call
65 int dt
= ballast_clock
.Elapsed();
67 // Update ballast_clock for the next call to BallastDumpManager::Update()
68 ballast_clock
.Update();
70 // How many percent of the max. ballast do we dump in one millisecond
71 fixed percent_per_millisecond
= fixed(1) / (1000 * dump_time
);
73 // Calculate the new ballast percentage
74 fixed ballast
= glide_polar
.GetBallast() - dt
* percent_per_millisecond
;
76 // Check if the plane is dry now
77 if (negative(ballast
)) {
79 glide_polar
.SetBallastLitres(fixed(0));
84 glide_polar
.SetBallast(ballast
);