SectorZone: add attribute arc_boundary
[xcsoar.git] / src / CalculationThread.cpp
blobfee8d631b7d2cb25e698e40aeb30a7452df3bdf4
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 "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"
32 /**
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) {
40 void
41 CalculationThread::SetComputerSettings(const ComputerSettings &new_value)
43 ScopeLock protect(mutex);
44 settings_computer = new_value;
47 void
48 CalculationThread::SetScreenDistanceMeters(fixed new_value)
50 ScopeLock protect(mutex);
51 screen_distance_meters = new_value;
54 /**
55 * Main loop of the CalculationThread
57 void
58 CalculationThread::Tick()
60 const Validity previous_warning =
61 glide_computer.Calculated().airspace_warnings.latest;
63 bool gps_updated;
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());
75 bool force;
77 ScopeLock protect(mutex);
78 // Copy settings form ComputerSettingsBlackboard to GlideComputerBlackboard
79 glide_computer.ReadComputerSettings(settings_computer);
81 force = this->force;
82 if (force) {
83 this->force = false;
84 gps_updated = true;
88 glide_computer.Expire();
90 bool do_idle = false;
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());
104 // if (new GPS data)
105 if (gps_updated || force)
106 // inform map new data is ready
107 TriggerCalculatedUpdate();
109 if (do_idle) {
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();
126 void
127 CalculationThread::ForceTrigger()
129 mutex.Lock();
130 force = true;
131 mutex.Unlock();
133 WorkerThread::Trigger();