Driver/Volkslogger: rename function to ReadAllFlights()
[xcsoar.git] / src / ApplyExternalSettings.cpp
blobfbaa99e1f875db256d9e797c5122d499f3bc3fbc
1 /*
2 Copyright_License {
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 "ApplyExternalSettings.hpp"
25 #include "Interface.hpp"
26 #include "ActionInterface.hpp"
27 #include "Device/All.hpp"
28 #include "Operation/MessageOperationEnvironment.hpp"
30 static bool
31 BallastProcessTimer()
33 bool modified = false;
35 static Validity last_fraction, last_overload;
36 const ExternalSettings &settings = CommonInterface::Basic().settings;
37 const Plane &plane = CommonInterface::GetComputerSettings().plane;
38 if (settings.ballast_fraction_available.Modified(last_fraction)) {
39 ActionInterface::SetBallast(settings.ballast_fraction, false);
40 modified = true;
43 last_fraction = settings.ballast_fraction_available;
45 if (settings.ballast_overload_available.Modified(last_overload) &&
46 settings.ballast_overload >= fixed(1) &&
47 positive(plane.max_ballast)) {
48 fixed fraction = ((settings.ballast_overload - fixed(1)) *
49 plane.dry_mass) / plane.max_ballast;
50 ActionInterface::SetBallast(fraction, false);
51 modified = true;
54 last_overload = settings.ballast_overload_available;
56 return modified;
59 static bool
60 BugsProcessTimer()
62 bool modified = false;
64 static Validity last;
65 const ExternalSettings &settings = CommonInterface::Basic().settings;
67 if (settings.bugs_available.Modified(last)) {
68 ActionInterface::SetBugs(settings.bugs, false);
69 modified = true;
72 last = settings.bugs_available;
74 return modified;
77 static bool
78 QNHProcessTimer()
80 bool modified = false;
82 ComputerSettings &settings_computer =
83 CommonInterface::SetComputerSettings();
84 const NMEAInfo &basic = CommonInterface::Basic();
85 const DerivedInfo &calculated = CommonInterface::Calculated();
87 if (basic.settings.qnh_available.Modified(settings_computer.pressure_available)) {
88 settings_computer.pressure = basic.settings.qnh;
89 settings_computer.pressure_available = basic.settings.qnh_available;
90 modified = true;
93 if (calculated.pressure_available.Modified(settings_computer.pressure_available)) {
94 settings_computer.pressure = calculated.pressure;
95 settings_computer.pressure_available = calculated.pressure_available;
97 MessageOperationEnvironment env;
98 AllDevicesPutQNH(settings_computer.pressure, env);
100 modified = true;
103 return modified;
106 static bool
107 MacCreadyProcessTimer()
109 bool modified = false;
111 static ExternalSettings last_external_settings;
112 static Validity last_auto_mac_cready;
114 const NMEAInfo &basic = CommonInterface::Basic();
115 const DerivedInfo &calculated = CommonInterface::Calculated();
117 if (last_auto_mac_cready.Modified(calculated.auto_mac_cready_available)) {
118 /* time warp, reset */
119 last_auto_mac_cready.Clear();
120 modified = true;
123 if (basic.settings.mac_cready_available.Modified(last_external_settings.mac_cready_available)) {
124 ActionInterface::SetMacCready(basic.settings.mac_cready, false);
125 modified = true;
126 } else if (calculated.auto_mac_cready_available.Modified(last_auto_mac_cready)) {
127 last_auto_mac_cready = calculated.auto_mac_cready_available;
128 ActionInterface::SetMacCready(calculated.auto_mac_cready);
129 modified = true;
132 last_external_settings = basic.settings;
134 return modified;
137 bool
138 ApplyExternalSettings()
140 bool modified = false;
141 modified |= BallastProcessTimer();
142 modified |= BugsProcessTimer();
143 modified |= QNHProcessTimer();
144 modified |= MacCreadyProcessTimer();
145 return modified;