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 "InputEvents.hpp"
25 #include "Util/Macros.hpp"
26 #include "Language/Language.hpp"
27 #include "Message.hpp"
28 #include "Components.hpp"
29 #include "Interface.hpp"
30 #include "ActionInterface.hpp"
31 #include "Protection.hpp"
32 #include "Formatter/UserUnits.hpp"
33 #include "Formatter/LocalTimeFormatter.hpp"
34 #include "Units/Units.hpp"
35 #include "Profile/Profile.hpp"
36 #include "Profile/ProfileKeys.hpp"
37 #include "LocalPath.hpp"
38 #include "UIGlobals.hpp"
39 #include "Dialogs/Task/TaskDialogs.hpp"
40 #include "Dialogs/Waypoint/WaypointDialogs.hpp"
41 #include "Task/ProtectedTaskManager.hpp"
42 #include "Task/TaskFile.hpp"
43 #include "Engine/Task/Ordered/OrderedTask.hpp"
44 #include "Engine/Waypoint/Waypoints.hpp"
45 #include "Engine/Navigation/Aircraft.hpp"
47 #include <windef.h> /* for MAX_PATH */
52 if (!CommonInterface::Basic().location_available
)
58 // Controls waypoint advance trigger:
59 // on: Arms the advance trigger
60 // off: Disarms the advance trigger
61 // toggle: Toggles between armed and disarmed.
62 // show: Shows current armed state
64 InputEvents::eventArmAdvance(const TCHAR
*misc
)
66 if (protected_task_manager
== NULL
)
69 ProtectedTaskManager::ExclusiveLease
task_manager(*protected_task_manager
);
70 TaskAdvance
&advance
= task_manager
->SetTaskAdvance();
72 if (StringIsEqual(misc
, _T("on"))) {
73 advance
.SetArmed(true);
74 } else if (StringIsEqual(misc
, _T("off"))) {
75 advance
.SetArmed(false);
76 } else if (StringIsEqual(misc
, _T("toggle"))) {
77 advance
.ToggleArmed();
78 } else if (StringIsEqual(misc
, _T("show"))) {
79 switch (advance
.GetState()) {
80 case TaskAdvance::MANUAL
:
81 Message::AddMessage(_("Advance manually"));
83 case TaskAdvance::AUTO
:
84 Message::AddMessage(_("Advance automatically"));
86 case TaskAdvance::START_ARMED
:
87 Message::AddMessage(_("Ready to start"));
89 case TaskAdvance::START_DISARMED
:
90 Message::AddMessage(_("Hold start"));
92 case TaskAdvance::TURN_ARMED
:
93 Message::AddMessage(_("Ready to turn"));
95 case TaskAdvance::TURN_DISARMED
:
96 Message::AddMessage(_("Hold turn"));
101 /* quickly propagate the updated values from the TaskManager to the
102 InterfaceBlackboard, so they are available immediately */
103 task_manager
->UpdateCommonStatsTask();
104 CommonInterface::ReadCommonStats(task_manager
->GetCommonStats());
108 InputEvents::eventCalculator(gcc_unused
const TCHAR
*misc
)
110 dlgTaskManagerShowModal(UIGlobals::GetMainWindow());
116 InputEvents::eventGotoLookup(gcc_unused
const TCHAR
*misc
)
118 const NMEAInfo
&basic
= CommonInterface::Basic();
120 if (protected_task_manager
== NULL
)
123 const Waypoint
* wp
= ShowWaypointListDialog(basic
.location
);
125 protected_task_manager
->DoGoto(*wp
);
131 // Adjusts MacCready settings
132 // up, down, auto on, auto off, auto toggle, auto show
134 InputEvents::eventMacCready(const TCHAR
*misc
)
136 if (protected_task_manager
== NULL
)
139 const GlidePolar
&polar
=
140 CommonInterface::GetComputerSettings().polar
.glide_polar_task
;
141 fixed mc
= polar
.GetMC();
143 TaskBehaviour
&task_behaviour
= CommonInterface::SetComputerSettings().task
;
145 if (StringIsEqual(misc
, _T("up"))) {
146 const fixed step
= Units::ToSysVSpeed(GetUserVerticalSpeedStep());
147 ActionInterface::OffsetManualMacCready(step
);
148 } else if (StringIsEqual(misc
, _T("down"))) {
149 const fixed step
= Units::ToSysVSpeed(GetUserVerticalSpeedStep());
150 ActionInterface::OffsetManualMacCready(-step
);
151 } else if (StringIsEqual(misc
, _T("auto toggle"))) {
152 task_behaviour
.auto_mc
= !task_behaviour
.auto_mc
;
153 Profile::Set(ProfileKeys::AutoMc
, task_behaviour
.auto_mc
);
154 } else if (StringIsEqual(misc
, _T("auto on"))) {
155 task_behaviour
.auto_mc
= true;
156 Profile::Set(ProfileKeys::AutoMc
, true);
157 } else if (StringIsEqual(misc
, _T("auto off"))) {
158 task_behaviour
.auto_mc
= false;
159 Profile::Set(ProfileKeys::AutoMc
, false);
160 } else if (StringIsEqual(misc
, _T("auto show"))) {
161 if (task_behaviour
.auto_mc
) {
162 Message::AddMessage(_("Auto. MacCready on"));
164 Message::AddMessage(_("Auto. MacCready off"));
166 } else if (StringIsEqual(misc
, _T("show"))) {
168 FormatUserVerticalSpeed(mc
, Temp
, false);
169 Message::AddMessage(_("MacCready "), Temp
);
174 // Adjusts the active waypoint of the task
175 // next: selects the next waypoint, stops at final waypoint
176 // previous: selects the previous waypoint, stops at start waypoint
177 // nextwrap: selects the next waypoint, wrapping back to start after final
178 // previouswrap: selects the previous waypoint, wrapping to final after start
180 InputEvents::eventAdjustWaypoint(const TCHAR
*misc
)
182 if (protected_task_manager
== NULL
)
185 if (StringIsEqual(misc
, _T("next")))
186 protected_task_manager
->IncrementActiveTaskPoint(1); // next
187 else if (StringIsEqual(misc
, _T("nextwrap")))
188 protected_task_manager
->IncrementActiveTaskPoint(1); // next - with wrap
189 else if (StringIsEqual(misc
, _T("previous")))
190 protected_task_manager
->IncrementActiveTaskPoint(-1); // previous
191 else if (StringIsEqual(misc
, _T("previouswrap")))
192 protected_task_manager
->IncrementActiveTaskPoint(-1); // previous with wrap
193 else if (StringIsEqual(misc
, _T("nextarm")))
194 protected_task_manager
->IncrementActiveTaskPointArm(1); // arm sensitive next
195 else if (StringIsEqual(misc
, _T("previousarm")))
196 protected_task_manager
->IncrementActiveTaskPointArm(-1); // arm sensitive previous
199 /* quickly propagate the updated values from the TaskManager to
200 the InterfaceBlackboard, so they are available immediately */
201 ProtectedTaskManager::ExclusiveLease
tm(*protected_task_manager
);
202 tm
->UpdateCommonStatsTask();
203 CommonInterface::ReadCommonStats(tm
->GetCommonStats());
210 // Allows aborting and resuming of tasks
211 // abort: aborts the task if active
212 // resume: resumes the task if aborted
213 // toggle: toggles between abort and resume
214 // show: displays a status message showing the task abort status
216 InputEvents::eventAbortTask(const TCHAR
*misc
)
218 if (protected_task_manager
== NULL
)
221 ProtectedTaskManager::ExclusiveLease
task_manager(*protected_task_manager
);
223 if (StringIsEqual(misc
, _T("abort")))
224 task_manager
->Abort();
225 else if (StringIsEqual(misc
, _T("resume")))
226 task_manager
->Resume();
227 else if (StringIsEqual(misc
, _T("show"))) {
228 switch (task_manager
->GetMode()) {
229 case TaskType::ABORT
:
230 Message::AddMessage(_("Task aborted"));
233 Message::AddMessage(_("Go to target"));
235 case TaskType::ORDERED
:
236 Message::AddMessage(_("Ordered task"));
239 Message::AddMessage(_("No task"));
243 switch (task_manager
->GetMode()) {
245 case TaskType::ORDERED
:
246 task_manager
->Abort();
249 if (task_manager
->CheckOrderedTask()) {
250 task_manager
->Resume();
252 task_manager
->Abort();
255 case TaskType::ABORT
:
256 task_manager
->Resume();
261 /* quickly propagate the updated values from the TaskManager to the
262 InterfaceBlackboard, so they are available immediately */
263 task_manager
->UpdateCommonStatsTask();
264 CommonInterface::ReadCommonStats(task_manager
->GetCommonStats());
270 // Loads the task of the specified filename
272 InputEvents::eventTaskLoad(const TCHAR
*misc
)
274 if (protected_task_manager
== NULL
)
277 if (!StringIsEmpty(misc
)) {
278 TCHAR buffer
[MAX_PATH
];
279 LocalPath(buffer
, misc
);
281 OrderedTask
*task
= TaskFile::GetTask(buffer
,
282 CommonInterface::GetComputerSettings().task
,
286 ScopeSuspendAllThreads suspend
;
287 task
->CheckDuplicateWaypoints(way_points
);
288 way_points
.Optimise();
291 task
->FillMatPoints(way_points
);
292 protected_task_manager
->TaskCommit(*task
);
301 // Saves the task to the specified filename
303 InputEvents::eventTaskSave(const TCHAR
*misc
)
305 if (protected_task_manager
== NULL
)
308 if (!StringIsEmpty(misc
)) {
309 TCHAR buffer
[MAX_PATH
];
310 LocalPath(buffer
, misc
);
311 protected_task_manager
->TaskSave(buffer
);
316 InputEvents::eventTaskTransition(const TCHAR
*misc
)
318 if (protected_task_manager
== NULL
)
321 if (StringIsEqual(misc
, _T("start"))) {
322 AircraftState start_state
= protected_task_manager
->GetStartState();
328 FormatLocalTimeHHMM(TempTime
, (int)start_state
.time
,
329 CommonInterface::GetComputerSettings().utc_offset
);
330 FormatUserAltitude(start_state
.altitude
, TempAlt
, true);
331 FormatUserSpeed(start_state
.ground_speed
,TempSpeed
, true);
334 _stprintf(TempAll
, _T("\r\n%s: %s\r\n%s:%s\r\n%s: %s"),
335 _("Altitude"), TempAlt
,
336 _("Speed"), TempSpeed
,
337 _("Time"), TempTime
);
338 Message::AddMessage(_("Task start"), TempAll
);
339 } else if (StringIsEqual(misc
, _T("tp"))) {
340 Message::AddMessage(_("Next turnpoint"));
341 } else if (StringIsEqual(misc
, _T("finish"))) {
342 Message::AddMessage(_("Task finished"));
343 } else if (StringIsEqual(misc
, _T("ready"))) {
344 Message::AddMessage(_("In sector, arm advance when ready"));