CirclingWind: eliminate attributes min_vector, max_vector
[xcsoar.git] / src / Computer / GPSClock.hpp
blob0da646b40e8537c3cb9c84b6c81d47f31b45ee95
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 #ifndef XCSOAR_GPS_CLOCK_HPP
25 #define XCSOAR_GPS_CLOCK_HPP
27 #include "Math/fixed.hpp"
29 /**
30 * Class for GPS-time based time intervals
32 class GPSClock {
33 private:
34 fixed last;
35 fixed dt;
37 public:
38 /**
39 * Initializes the object, setting the last time stamp to "0",
40 * i.e. a check() will always succeed. If you do not want this
41 * default behaviour, call update() immediately after creating the
42 * object.
44 GPSClock(const fixed _minstep):last(fixed(0)), dt(_minstep) {}
46 /**
47 * Resets the clock.
49 void Reset() {
50 last = fixed(0);
53 /**
54 * Updates the clock.
56 void Update(fixed now) {
57 last = now;
60 /**
61 * Checks whether the GPS time was reversed
62 * @param now Current time
63 * @return True if time has been reversed, False otherwise
65 bool CheckReverse(const fixed now) {
66 if (now<last) {
67 Update(now);
68 return true;
69 } else {
70 return false;
74 /**
75 * Set dt to a new value defined by _dt
76 * @param _dt The new value fot dt
78 void SetDT(const fixed _dt) {
79 dt = _dt;
82 /**
83 * Calls check_advance(fixed, fixed) with dt
84 * as the default value for dt
85 * @param now Current time
86 * @see check_advance(fixed, fixed)
88 bool CheckAdvance(const fixed now) {
89 return CheckAdvance(now, dt);
92 fixed DeltaAdvance(const fixed now) {
93 if (CheckReverse(now))
94 return fixed(-1);
96 // check if time has advanced past dt
97 if (now - last >= dt) {
98 fixed dt = now - last;
99 Update(now);
100 return dt;
101 } else {
102 return fixed(0);
107 * Checks whether the specified duration (dt) has passed since the last
108 * update. If yes, it updates the time stamp.
109 * @param now Current time
110 * @param dt The timestep in milliseconds
111 * @return
113 bool CheckAdvance(const fixed now, const fixed dt) {
114 if (CheckReverse(now))
115 return false;
117 if (now >= last + dt) {
118 Update(now);
119 return true;
120 } else
121 return false;
125 #endif