MapItemListDialog: add airspace ack button (#2139)
[xcsoar.git] / src / Computer / Events.cpp
blobd7afdb19d9d4649c195fd62befa0cb6139ab21e0
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 "Events.hpp"
25 #include "Input/InputQueue.hpp"
26 #include "NMEA/MoreData.hpp"
27 #include "NMEA/Derived.hpp"
28 #include "ComputerSettings.hpp"
30 void
31 GlideComputerEvents::Reset()
33 last_flying = false;
34 last_circling = false;
35 last_final_glide = false;
36 last_traffic = 0;
37 last_new_traffic.Clear();
38 last_teammate_in_sector = false;
41 void
42 GlideComputerEvents::OnCalculatedUpdate(const MoreData &basic,
43 const DerivedInfo &calculated)
45 /* check for take-off and landing */
47 if (calculated.flight.flying != last_flying) {
48 last_flying = calculated.flight.flying;
49 if (calculated.flight.flying)
50 InputEvents::processGlideComputer(GCE_TAKEOFF);
51 else
52 InputEvents::processGlideComputer(GCE_LANDING);
55 /* check the climb state */
57 if (calculated.circling != last_circling) {
58 last_circling = calculated.circling;
59 if (calculated.circling)
60 InputEvents::processGlideComputer(GCE_FLIGHTMODE_CLIMB);
61 else
62 InputEvents::processGlideComputer(GCE_FLIGHTMODE_CRUISE);
65 /* check for new traffic */
67 const FlarmData &flarm = basic.flarm;
68 if (flarm.status.available) {
69 if (flarm.status.rx > 0 && last_traffic == 0)
70 // traffic has appeared..
71 InputEvents::processGlideComputer(GCE_FLARM_TRAFFIC);
72 else if (flarm.status.rx == 0 && last_traffic > 0)
73 // traffic has disappeared..
74 InputEvents::processGlideComputer(GCE_FLARM_NOTRAFFIC);
75 last_traffic = flarm.status.rx;
77 if (flarm.traffic.new_traffic.Modified(last_new_traffic)) {
78 // new traffic has appeared
79 last_new_traffic = flarm.traffic.new_traffic;
80 InputEvents::processGlideComputer(GCE_FLARM_NEWTRAFFIC);
82 } else
83 last_traffic = 0;
85 /* check team mate */
87 if (enable_team) {
88 // Hysteresis for GlideComputerEvent
89 // If (closer than 100m to the teammates last position and "event" not reset)
90 if (calculated.teammate_vector.distance < fixed(100) &&
91 !last_teammate_in_sector) {
92 last_teammate_in_sector = true;
93 // Raise GCE_TEAM_POS_REACHED event
94 InputEvents::processGlideComputer(GCE_TEAM_POS_REACHED);
95 } else if (calculated.teammate_vector.distance > fixed(300)) {
96 // Reset "event" when distance is greater than 300m again
97 last_teammate_in_sector = false;
101 /* check for final glide */
103 const bool final_glide = calculated.task_stats.flight_mode_final_glide;
104 if (final_glide != last_final_glide) {
105 last_final_glide = final_glide;
107 InputEvents::processGlideComputer(final_glide
108 ? GCE_FLIGHTMODE_FINALGLIDE
109 : GCE_FLIGHTMODE_CRUISE);
113 void
114 GlideComputerEvents::OnComputerSettingsUpdate(const ComputerSettings &settings)
116 enable_team = settings.team_code.team_flarm_id.IsDefined() ||
117 settings.team_code.team_code.IsDefined();