-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.hh
324 lines (269 loc) · 7.97 KB
/
config.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
#ifndef CONFIG_HH
#define CONFIG_HH
#include <stdint.h>
#include "axlib/displays/fonts/fontlibrary.h"
#include "axlib/displays/display_buffer.hh"
#include "ui/ui_altimeter.hh"
struct Config
{
fontStyle_t *GetIntChangeFont() const;
typedef enum
{
AltitudeSensorOversampleRate1 = 0,
AltitudeSensorOversampleRate2 = 1,
AltitudeSensorOversampleRate4 = 2,
AltitudeSensorOversampleRate8 = 3,
AltitudeSensorOversampleRate16 = 4,
AltitudeSensorOversampleRate32 = 5,
AltitudeSensorOversampleRate64 = 6,
AltitudeSensorOversampleRate128 = 7,
AltitudeSensorOversampleRateNumberOfEnums = 8
} AltitudeSensorOversampleRate;
typedef enum
{
AltitudeUnitModeMeters = 0,
AltitudeUnitModeFeets = 1,
AltitudeUnitModeNumberOfEnums = 2
} AltitudeDisplayUnitMode;
typedef enum
{
AltitudeDisplayRoundModeNone = 0,
AltitudeDisplayRoundMode1 = 1,
AltitudeDisplayRoundMode5 = 2,
AltitudeDisplayRoundMode10 = 3,
AltitudeDisplayRoundModeNumberOfEnums = 4
} AltitudeDisplayRoundMode;
typedef enum
{
SpeedUnitModeMetersPerSecond = 0,
SpeedUnitModeKilometersPerHour = 1,
SpeedUnitModeFeetsPerSecond = 2,
SpeedUnitModeMilesPerHour = 3,
SpeedUnitModeNumberOfEnums = 4
} SpeedDisplayUnitMode;
typedef enum
{
TemperatureModeCelcius = 0,
TemperatureModeFahrenheit = 1,
TemperatureModeNumberOfEnums = 2
} TemperatureMode;
typedef enum
{
FontSizeSmall = 0,
FontSizeMedium = 1,
FontSizeLarge = 2,
FontSizeNumberOfEnums = 3
} FontSize;
typedef enum
{
DataSaveOff = 0,
DataSaveAll = 1,
DataSaveNormal = 2,
DataSaveNumberOfEnums = 3
} DataSaveMode;
struct AltitudeAlarm
{
typedef enum
{
AlarmAmplitudeWeak = 0,
AlarmAmplitudeMedium = 1,
AlarmAmplitudeStrong = 2,
AlarmAmplitudeNumberOfEnums = 3
} AlarmAmplitude;
typedef enum
{
AlarmTypeFreefallBeeps = 0,
AlarmTypeUntilOpen = 1,
AlarmTypeLastChange = 2,
AlarmTypeCanopyAltitude = 3,
AlarmTypeNumberOfEnums = 4,
} AlarmType;
AltitudeAlarm()
:
altitude(2000),
amplitude(AlarmAmplitudeMedium),
enabled(false),
type(AlarmTypeFreefallBeeps)
{
}
int16_t altitude;
AlarmAmplitude amplitude;
bool enabled;
AlarmType type;
};
struct Beeper
{
struct BeepOption
{
BeepOption()
:
amplitude(AltitudeAlarm::AlarmAmplitudeMedium),
enabled(true)
{
}
AltitudeAlarm::AlarmAmplitude amplitude;
bool enabled;
};
AltitudeAlarm alarms_freefall[3];
AltitudeAlarm alarms_canopy[3];
BeepOption at_plane;
BeepOption climb_altitude;
BeepOption at_freefall;
BeepOption at_canopy;
BeepOption at_ground;
};
struct Time
{
Time()
:
hour(0),
minute(0),
second(0)
{
}
uint8_t hour;
uint8_t minute;
uint8_t second;
};
struct Date
{
Date()
:
year(2014),
month(1),
day(1)
{
}
uint16_t year;
uint8_t month;
uint8_t day;
};
struct JumpLogInfo
{
struct JumpTime
{
JumpTime()
:
hours(0),
minutes(0),
seconds(0)
{
}
uint16_t hours;
uint8_t minutes;
uint8_t seconds;
};
JumpTime free_fall_time;
JumpTime canopy_time;
uint16_t next_jump_number;
};
struct SleepAlarm
{
SleepAlarm()
:
enabled(false)
{
}
Time alarm_time;
bool enabled;
};
Config()
:
magic_number(GetValidMagic()),
altitude_unit_mode(AltitudeUnitModeMeters),
speed_unit_mode(SpeedUnitModeMetersPerSecond),
temperature_mode(TemperatureModeCelcius),
display_orientation(axlib::DisplayBuffer::ROTATION_NONE),
menu_font_size(FontSizeMedium),
default_altimeter_ui_mode(UiAltimeter::ALTIMETER_UI_MODE_COMPLEX),
freefall_altimeter_ui_mode(UiAltimeter::ALTIMETER_UI_MODE_FREE_FALL),
canopy_altimeter_ui_mode(UiAltimeter::ALTIMETER_UI_MODE_COMPLEX),
climb_altimeter_ui_mode(UiAltimeter::ALTIMETER_UI_MODE_COMPLEX),
log_save_mode(DataSaveOff),
display_round_mode(AltitudeDisplayRoundMode5),
oversample_rate(AltitudeSensorOversampleRate32)
{
}
static bool IsValidConfig(const Config &conf)
{
return conf.magic_number == GetValidMagic();
}
static uint32_t GetValidMagic();
// Magic number is different for each version of config
uint32_t magic_number;
Time time;
Date date;
AltitudeDisplayUnitMode altitude_unit_mode;
SpeedDisplayUnitMode speed_unit_mode;
TemperatureMode temperature_mode;
axlib::DisplayBuffer::Rotation display_orientation;
Beeper beeper;
FontSize menu_font_size;
UiAltimeter::AltimeterUiMode default_altimeter_ui_mode;
UiAltimeter::AltimeterUiMode freefall_altimeter_ui_mode;
UiAltimeter::AltimeterUiMode canopy_altimeter_ui_mode;
UiAltimeter::AltimeterUiMode climb_altimeter_ui_mode;
DataSaveMode log_save_mode;
AltitudeDisplayRoundMode display_round_mode;
bool invert_colors;
AltitudeSensorOversampleRate oversample_rate;
}; //struct Config
template<typename T>
const char *ToString(const T en)
{
static const char str[] = "<error>";
return str;
}
template<>
const char *ToString(const Config::AltitudeDisplayUnitMode en);
template<>
const char *ToString(const Config::SpeedDisplayUnitMode en);
template<>
const char *ToString(const Config::TemperatureMode en);
template<>
const char *ToString(const axlib::DisplayBuffer::Rotation rot);
template<>
const char *ToString(const Config::AltitudeAlarm en);
template<>
const char *ToString(const Config::FontSize en);
template<>
const char *ToString(const Config::AltitudeAlarm::AlarmAmplitude en);
template<>
const char *ToString(const Config::AltitudeAlarm::AlarmType en);
template<>
const char *ToString(const UiAltimeter::AltimeterUiMode en);
template<>
const char *ToString(const Config::DataSaveMode en);
template<>
const char *ToString(const Config::AltitudeDisplayRoundMode en);
template<>
const char *ToString(const Config::AltitudeSensorOversampleRate en);
template<typename T>
T NextEnum(const T en)
{
return (T)0;
}
template<>
Config::AltitudeDisplayUnitMode NextEnum(const Config::AltitudeDisplayUnitMode en);
template<>
Config::SpeedDisplayUnitMode NextEnum(const Config::SpeedDisplayUnitMode en);
template<>
Config::TemperatureMode NextEnum(const Config::TemperatureMode en);
template<>
axlib::DisplayBuffer::Rotation NextEnum(const axlib::DisplayBuffer::Rotation en);
template<>
Config::AltitudeAlarm::AlarmAmplitude NextEnum(const Config::AltitudeAlarm::AlarmAmplitude en);
template<>
Config::AltitudeAlarm::AlarmType NextEnum(const Config::AltitudeAlarm::AlarmType en);
template<>
Config::FontSize NextEnum(const Config::FontSize en);
template<>
UiAltimeter::AltimeterUiMode NextEnum(const UiAltimeter::AltimeterUiMode en);
template<>
Config::DataSaveMode NextEnum(const Config::DataSaveMode en);
template<>
Config::AltitudeDisplayRoundMode NextEnum(const Config::AltitudeDisplayRoundMode en);
template<>
Config::AltitudeSensorOversampleRate NextEnum(const Config::AltitudeSensorOversampleRate en);
uint8_t GetVolume(const Config::AltitudeAlarm::AlarmAmplitude amp);
#endif //ifndef CONFIG_HH