android/GlueIOIOPort: fix spurious errors after IOIO baud rate change
[xcsoar.git] / src / Units / Units.hpp
blob788f4631b7d5b87b6ca37bd511b5de8d4007fe56
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_UNITS_HPP
25 #define XCSOAR_UNITS_HPP
27 #include "Units/Settings.hpp"
28 #include "Units/System.hpp"
29 #include "Math/fixed.hpp"
30 #include "Compiler.h"
32 #include <tchar.h>
34 class AtmosphericPressure;
36 #define DEG "°"
38 /**
39 * Namespace to manage unit conversions.
40 * internal system units are (metric SI).
42 namespace Units
44 extern UnitSetting current;
46 void SetConfig(const UnitSetting &new_config);
48 /**
49 * Returns the user-specified unit for a horizontal distance
50 * @return The user-specified unit for a horizontal distance
52 gcc_pure
53 Unit GetUserDistanceUnit();
55 /**
56 * Returns the user-specified unit for an altitude
57 * @return The user-specified unit for an altitude
59 gcc_pure
60 Unit GetUserAltitudeUnit();
62 /**
63 * Returns the user-specified unit for a temperature
64 * @return The user-specified unit for a temperature
66 gcc_pure
67 Unit GetUserTemperatureUnit();
69 /**
70 * Returns the user-specified unit for a horizontal speed
71 * @return The user-specified unit for a horizontal speed
73 gcc_pure
74 Unit GetUserSpeedUnit();
76 /**
77 * Returns the user-specified unit for a task speed
78 * @return The user-specified unit for a task speed
80 gcc_pure
81 Unit GetUserTaskSpeedUnit();
83 /**
84 * Returns the user-specified unit for a vertical speed
85 * @return The user-specified unit for a vertical speed
87 gcc_pure
88 Unit GetUserVerticalSpeedUnit();
90 /**
91 * Returns the user-specified unit for a wind speed
92 * @return The user-specified unit for a wind speed
94 gcc_pure
95 Unit GetUserWindSpeedUnit();
97 /**
98 * Returns the user-specified unit for a pressure
99 * @return The user-specified unit for a pressure
101 gcc_pure
102 Unit GetUserPressureUnit();
104 gcc_pure
105 Unit GetUserUnitByGroup(UnitGroup group);
107 gcc_pure
108 const TCHAR *GetSpeedName();
110 gcc_pure
111 const TCHAR *GetVerticalSpeedName();
113 gcc_pure
114 const TCHAR *GetWindSpeedName();
116 gcc_pure
117 const TCHAR *GetDistanceName();
119 gcc_pure
120 const TCHAR *GetAltitudeName();
122 gcc_pure
123 const TCHAR *GetTemperatureName();
125 gcc_pure
126 const TCHAR *GetTaskSpeedName();
128 gcc_pure
129 const TCHAR *GetPressureName();
131 static inline fixed
132 ToUserAltitude(fixed value)
134 return ToUserUnit(value, current.altitude_unit);
137 static inline fixed
138 ToSysAltitude(fixed value)
140 return ToSysUnit(value, current.altitude_unit);
143 static inline fixed
144 ToUserTemperature(fixed value)
146 return ToUserUnit(value, current.temperature_unit);
149 static inline fixed
150 ToSysTemperature(fixed value)
152 return ToSysUnit(value, current.temperature_unit);
155 static inline fixed
156 ToUserDistance(fixed value)
158 return ToUserUnit(value, current.distance_unit);
161 static inline fixed
162 ToSysDistance(fixed value)
164 return ToSysUnit(value, current.distance_unit);
167 static inline fixed
168 ToUserSpeed(fixed value)
170 return ToUserUnit(value, current.speed_unit);
173 static inline fixed
174 ToSysSpeed(fixed value)
176 return ToSysUnit(value, current.speed_unit);
179 static inline fixed
180 ToUserVSpeed(fixed value)
182 return ToUserUnit(value, current.vertical_speed_unit);
185 static inline fixed
186 ToSysVSpeed(fixed value)
188 return ToSysUnit(value, current.vertical_speed_unit);
191 static inline fixed
192 ToUserTaskSpeed(fixed value)
194 return ToUserUnit(value, current.task_speed_unit);
197 static inline fixed
198 ToSysTaskSpeed(fixed value)
200 return ToSysUnit(value, current.task_speed_unit);
203 static inline fixed
204 ToUserWindSpeed(fixed value)
206 return ToUserUnit(value, current.wind_speed_unit);
209 static inline fixed
210 ToSysWindSpeed(fixed value)
212 return ToSysUnit(value, current.wind_speed_unit);
215 static inline fixed
216 ToUserPressure(fixed Value)
218 return ToUserUnit(Value, current.pressure_unit);
221 gcc_const
222 fixed
223 ToUserPressure(AtmosphericPressure value);
225 static inline fixed
226 ToSysPressure(fixed Value)
228 return ToSysUnit(Value, current.pressure_unit);
232 * Convert a pressure value from the user unit to an
233 * #AtmosphericPressure object.
235 gcc_const
236 AtmosphericPressure
237 FromUserPressure(fixed value);
240 #endif