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 "CalculationThread.hpp"
25 #include "Computer/GlideComputer.hpp"
26 #include "Protection.hpp"
27 #include "Screen/Blank.hpp"
28 #include "Blackboard/DeviceBlackboard.hpp"
29 #include "Components.hpp"
30 #include "GlideSolvers/GlidePolar.hpp"
33 * Constructor of the CalculationThread class
34 * @param _glide_computer The GlideComputer used for the CalculationThread
36 CalculationThread::CalculationThread(GlideComputer
&_glide_computer
)
37 :WorkerThread(450, 100, 50), force(false), glide_computer(_glide_computer
) {
41 CalculationThread::SetComputerSettings(const ComputerSettings
&new_value
)
43 ScopeLock
protect(mutex
);
44 settings_computer
= new_value
;
48 CalculationThread::SetScreenDistanceMeters(fixed new_value
)
50 ScopeLock
protect(mutex
);
51 screen_distance_meters
= new_value
;
55 * Main loop of the CalculationThread
58 CalculationThread::Tick()
60 const Validity previous_warning
=
61 glide_computer
.Calculated().airspace_warnings
.latest
;
65 // update and transfer master info to glide computer
67 ScopeLock
protect(device_blackboard
->mutex
);
69 gps_updated
= device_blackboard
->Basic().location_available
.Modified(glide_computer
.Basic().location_available
);
71 // Copy data from DeviceBlackboard to GlideComputerBlackboard
72 glide_computer
.ReadBlackboard(device_blackboard
->Basic());
77 ScopeLock
protect(mutex
);
78 // Copy settings form ComputerSettingsBlackboard to GlideComputerBlackboard
79 glide_computer
.ReadComputerSettings(settings_computer
);
88 glide_computer
.Expire();
92 if (gps_updated
|| force
)
93 // perform idle call if time advanced and slow calculations need to be updated
94 do_idle
|= glide_computer
.ProcessGPS(force
);
96 // values changed, so copy them back now: ONLY CALCULATED INFO
97 // should be changed in DoCalculations, so we only need to write
98 // that one back (otherwise we may write over new data)
100 ScopeLock
protect(device_blackboard
->mutex
);
101 device_blackboard
->ReadBlackboard(glide_computer
.Calculated());
105 if (gps_updated
|| force
)
106 // inform map new data is ready
107 TriggerCalculatedUpdate();
110 // do slow calculations last, to minimise latency
111 glide_computer
.ProcessIdle();
113 if (glide_computer
.Calculated().airspace_warnings
.latest
!= previous_warning
) {
114 /* there's a new airspace warning */
117 ScopeLock
protect(device_blackboard
->mutex
);
118 device_blackboard
->ReadBlackboard(glide_computer
.Calculated());
121 TriggerAirspaceWarning();
127 CalculationThread::ForceTrigger()
133 WorkerThread::Trigger();