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"
30 * Class for GPS-time based time intervals
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
44 GPSClock(const fixed _minstep
):last(fixed(0)), dt(_minstep
) {}
56 void Update(fixed now
) {
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
) {
75 * Set dt to a new value defined by _dt
76 * @param _dt The new value fot dt
78 void SetDT(const fixed _dt
) {
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
))
96 // check if time has advanced past dt
97 if (now
- last
>= dt
) {
98 fixed dt
= now
- last
;
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
113 bool CheckAdvance(const fixed now
, const fixed dt
) {
114 if (CheckReverse(now
))
117 if (now
>= last
+ dt
) {