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 "MergeThread.hpp"
25 #include "Blackboard/DeviceBlackboard.hpp"
26 #include "Protection.hpp"
27 #include "NMEA/MoreData.hpp"
28 #include "Audio/VarioGlue.hpp"
29 #include "Device/All.hpp"
31 MergeThread::MergeThread(DeviceBlackboard
&_device_blackboard
)
32 :WorkerThread(150, 50, 20),
33 device_blackboard(_device_blackboard
)
40 MergeThread::Process()
42 assert(!IsDefined() || IsInside());
44 device_blackboard
.Merge();
46 const MoreData
&basic
= device_blackboard
.Basic();
47 const ComputerSettings
&settings_computer
=
48 device_blackboard
.GetComputerSettings();
50 computer
.Fill(device_blackboard
.SetMoreData(), settings_computer
);
51 computer
.Compute(device_blackboard
.SetMoreData(), last_any
, last_fix
,
52 device_blackboard
.Calculated());
54 flarm_computer
.Process(device_blackboard
.SetBasic().flarm
,
55 last_fix
.flarm
, basic
);
61 bool gps_updated
, calculated_updated
;
63 #ifdef HAVE_PCM_PLAYER
69 ScopeLock
protect(device_blackboard
.mutex
);
73 const MoreData
&basic
= device_blackboard
.Basic();
75 /* call Driver::OnSensorUpdate() on all devices */
76 AllDevicesNotifySensorUpdate(basic
);
78 /* trigger update if gps has become available or dropped out */
79 gps_updated
= last_any
.location_available
!= basic
.location_available
;
81 /* trigger a redraw when the connection was just lost, to show the
82 new state; when no GPS is connected, no other entity triggers
83 the redraw, so we have to do it */
84 calculated_updated
= (bool)last_any
.alive
!= (bool)basic
.alive
||
85 (bool)last_any
.location_available
!= (bool)basic
.location_available
;
87 #ifdef HAVE_PCM_PLAYER
88 vario_available
= basic
.brutto_vario_available
;
89 vario
= vario_available
? basic
.brutto_vario
: fixed(0);
92 /* update last_any in every iteration */
95 /* update last_fix only when a new GPS fix was received */
96 if ((basic
.time_available
&&
97 (!last_fix
.time_available
|| basic
.time
!= last_fix
.time
)) ||
98 basic
.location_available
!= last_fix
.location_available
)
102 #ifdef HAVE_PCM_PLAYER
104 AudioVarioGlue::SetValue(vario
);
106 AudioVarioGlue::NoValue();
112 if (calculated_updated
)
113 TriggerCalculatedUpdate();
115 TriggerVarioUpdate();