Mercurial > public > ostc4
annotate Discovery/Src/tMenuEditCvOption.c @ 1007:65d35e66efb9 GasConsumption
Improve compass calibration dialog:
The previous calibration dialog showed some "magic" numbers and a 60 second count down. The new version is trying to guide the user through the calibration process: first rotate pitch, then roll and at last yaw angle. A step to the next angle is taken when enough data per angle is collected (change from red to green). To enable the yaw visualization a simple calibration is done while rotating the axis.
The function behind the calibration was not modified => the suggested process can be ignored and the same handling as the with old dialog may be applied. With the new process the dialog may be left early. Anyhow it will still be left after 60 seconds and the fine calibration is performed in the same way as before.
author | Ideenmodellierer |
---|---|
date | Mon, 05 May 2025 21:02:34 +0200 (3 months ago) |
parents | 85f7e19c6688 |
children | 8c0134a287da |
rev | line source |
---|---|
999 | 1 /////////////////////////////////////////////////////////////////////////////// |
2 /// -*- coding: UTF-8 -*- | |
3 /// | |
4 /// \file Discovery/Src/tMenuEditCvOption.c | |
5 /// \brief Menu for configuration depended items | |
6 /// \author heinrichs weikamp gmbh | |
7 /// \date 24-Apr-2025 | |
8 /// | |
9 /// \details | |
10 /// | |
11 /// $Id$ | |
12 /////////////////////////////////////////////////////////////////////////////// | |
13 /// \par Copyright (c) 2014-2025 Heinrichs Weikamp gmbh | |
14 /// | |
15 /// This program is free software: you can redistribute it and/or modify | |
16 /// it under the terms of the GNU General Public License as published by | |
17 /// the Free Software Foundation, either version 3 of the License, or | |
18 /// (at your option) any later version. | |
19 /// | |
20 /// This program is distributed in the hope that it will be useful, | |
21 /// but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
23 /// GNU General Public License for more details. | |
24 /// | |
25 /// You should have received a copy of the GNU General Public License | |
26 /// along with this program. If not, see <http://www.gnu.org/licenses/>. | |
27 ////////////////////////////////////////////////////////////////////////////// | |
28 | |
29 /* Includes ------------------------------------------------------------------*/ | |
30 #include "tMenuEditCvOption.h" | |
31 #include "tMenuEdit.h" | |
32 | |
33 #include "gfx_fonts.h" | |
34 #include "ostc.h" | |
35 #include "tMenuEdit.h" | |
36 #include "tHome.h" | |
37 | |
38 /* Private function prototypes -----------------------------------------------*/ | |
39 static void openEdit_Timer(void); | |
40 void openEdit_Compass(void); | |
41 | |
42 /* Announced function prototypes -----------------------------------------------*/ | |
43 uint8_t OnAction_Compass (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); | |
44 static uint8_t OnAction_CompassDeclination(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); | |
45 uint8_t OnAction_Bearing (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); | |
46 uint8_t OnAction_BearingClear (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); | |
47 uint8_t OnAction_InertiaLevel (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); | |
48 static uint8_t OnAction_Timer(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); | |
49 | |
50 /* Exported functions --------------------------------------------------------*/ | |
51 | |
52 void openEdit_CvOption(uint8_t line) | |
53 { | |
54 set_globalState_Menu_Line(line); | |
55 | |
56 switch(line) | |
57 { | |
58 case 1: | |
59 default: | |
60 resetMenuEdit(CLUT_MenuPageHardware); | |
61 openEdit_Compass(); | |
62 break; | |
63 case 2: | |
64 openEdit_Timer(); | |
65 break; | |
66 } | |
67 } | |
68 | |
69 /* Private functions ---------------------------------------------------------*/ | |
70 | |
71 static uint8_t OnAction_CompassDeclination(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) | |
72 { | |
73 SSettings *settings = settingsGetPointer(); | |
74 uint8_t digitContentNew; | |
75 switch (action) { | |
76 case ACTION_BUTTON_ENTER: | |
77 | |
78 return digitContent; | |
79 case ACTION_BUTTON_ENTER_FINAL: | |
80 { | |
81 int32_t compassDeclinationDeg; | |
82 evaluateNewString(editId, (uint32_t *)&compassDeclinationDeg, NULL, NULL, NULL); | |
83 | |
84 if (compassDeclinationDeg > 99) { | |
85 compassDeclinationDeg = 99; | |
86 } else if (compassDeclinationDeg < -99) { | |
87 compassDeclinationDeg = -99; | |
88 } | |
89 | |
90 settings->compassDeclinationDeg = compassDeclinationDeg; | |
91 | |
92 tMenuEdit_newInput(editId, ((input_u)compassDeclinationDeg).uint32, 0, 0, 0); | |
93 } | |
94 | |
95 break; | |
96 case ACTION_BUTTON_NEXT: | |
97 if (digitNumber == 0) { | |
98 digitContentNew = togglePlusMinus(digitContent); | |
99 } else { | |
100 digitContentNew = digitContent + 1; | |
101 if (digitContentNew > '9') { | |
102 digitContentNew = '0'; | |
103 } | |
104 } | |
105 | |
106 return digitContentNew; | |
107 case ACTION_BUTTON_BACK: | |
108 if (digitNumber == 0) { | |
109 digitContentNew = togglePlusMinus(digitContent); | |
110 } else { | |
111 digitContentNew = digitContent - 1; | |
112 if (digitContentNew < '0') { | |
113 digitContentNew = '9'; | |
114 } | |
115 } | |
116 | |
117 return digitContentNew; | |
118 } | |
119 | |
120 return UNSPECIFIC_RETURN; | |
121 } | |
122 | |
123 | |
124 static void showCompassDeclination(SSettings *settings, bool isRefresh) | |
125 { | |
126 char text[16]; | |
127 snprintf(text, 16, "%c%c:", TXT_2BYTE, TXT2BYTE_CompassDeclination); | |
128 write_label_var(30, 800, ME_Y_LINE6, &FontT48, text); | |
129 if (isRefresh) { | |
130 tMenuEdit_refresh_field(StMOption_Compass_Declination); | |
131 } else { | |
132 write_field_sdigit(StMOption_Compass_Declination, 500, 800, ME_Y_LINE6, &FontT48, "\034###`", settings->compassDeclinationDeg, 0, 0, 0); | |
133 } | |
134 } | |
135 | |
136 | |
137 void refresh_CompassEdit(void) | |
138 { | |
139 SSettings *settings = settingsGetPointer(); | |
140 | |
141 uint16_t heading; | |
142 char text[32]; | |
143 uint8_t textIndex = 0; | |
144 | |
145 text[0] = '\001'; | |
146 text[1] = TXT_2BYTE; | |
147 text[2] = TXT2BYTE_Compass; | |
148 text[3] = 0; | |
149 write_topline(text); | |
150 | |
151 if(settings->compassInertia) | |
152 { | |
153 heading = (uint16_t)compass_getCompensated(); | |
154 } | |
155 else | |
156 { | |
157 heading = (uint16_t)stateUsed->lifeData.compass_heading; | |
158 } | |
159 snprintf(text,32,"\001%03i`",heading); | |
160 write_label_var( 0, 800, ME_Y_LINE1, &FontT54, text); | |
161 | |
162 tMenuEdit_refresh_field(StMOption_Compass_SetCourse); | |
163 tMenuEdit_refresh_field(StMOption_Compass_Calibrate); | |
164 tMenuEdit_refresh_field(StMOption_Compass_ResetCourse); | |
165 text[textIndex++] = TXT_2BYTE; | |
166 text[textIndex++] = TXT2BYTE_CompassInertia; | |
167 text[textIndex++] = ':'; | |
168 text[textIndex++] = ' '; | |
169 text[textIndex++] = '0' + settings->compassInertia; | |
170 | |
171 write_label_var(30, 800, ME_Y_LINE5, &FontT48, text); | |
172 | |
173 showCompassDeclination(settings, true); | |
174 | |
175 write_buttonTextline(TXT2BYTE_ButtonBack,TXT2BYTE_ButtonEnter,TXT2BYTE_ButtonNext); | |
176 } | |
177 | |
178 | |
179 void openEdit_Compass(void) | |
180 { | |
181 SSettings *settings = settingsGetPointer(); | |
182 | |
183 char text[10]; | |
184 uint8_t textIndex = 0; | |
185 | |
186 | |
187 set_globalState(StMOption_Compass); | |
188 resetMenuEdit(CLUT_MenuPageHardware); | |
189 | |
190 text[textIndex++] = '\001'; | |
191 text[textIndex++] = TXT_2BYTE; | |
192 text[textIndex++] = TXT2BYTE_Compass; | |
193 text[textIndex++] = 0; | |
194 write_topline(text); | |
195 | |
196 text[0] = TXT_2BYTE; | |
197 text[2] = 0; | |
198 | |
199 text[1] = TXT2BYTE_SetBearing; | |
200 write_field_button(StMOption_Compass_SetCourse, 30, 800, ME_Y_LINE2, &FontT48, text); | |
201 | |
202 text[1] = TXT2BYTE_ResetBearing; | |
203 write_field_button(StMOption_Compass_ResetCourse, 30, 800, ME_Y_LINE3, &FontT48, text); | |
204 | |
205 text[1] = TXT2BYTE_CompassCalib; | |
206 write_field_button(StMOption_Compass_Calibrate, 30, 800, ME_Y_LINE4, &FontT48, text); | |
207 | |
208 text[1] = TXT2BYTE_CompassInertia; | |
209 textIndex = 2; | |
210 text[textIndex++] = ':'; | |
211 text[textIndex++] = ' '; | |
212 text[textIndex++] = '0' + settings->compassInertia; | |
213 text[textIndex++] = 0; | |
214 | |
215 write_field_button(StMOption_Compass_Inertia, 30, 800, ME_Y_LINE5, &FontT48, text); | |
216 | |
217 showCompassDeclination(settings, false); | |
218 | |
219 setEvent(StMOption_Compass_SetCourse, (uint32_t)OnAction_Bearing); | |
220 setEvent(StMOption_Compass_ResetCourse, (uint32_t)OnAction_BearingClear); | |
221 setEvent(StMOption_Compass_Calibrate, (uint32_t)OnAction_Compass); | |
222 setEvent(StMOption_Compass_Inertia, (uint32_t)OnAction_InertiaLevel); | |
223 setEvent(StMOption_Compass_Declination, (uint32_t)OnAction_CompassDeclination); | |
224 | |
225 tMenuEdit_select(StMOption_Compass_SetCourse); | |
226 | |
227 write_buttonTextline(TXT2BYTE_ButtonBack,TXT2BYTE_ButtonEnter,TXT2BYTE_ButtonNext); | |
228 } | |
229 | |
230 | |
231 uint8_t OnAction_Compass (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) | |
232 { | |
233 calibrateCompass(); | |
234 return EXIT_TO_INFO_COMPASS; | |
235 } | |
236 | |
237 | |
238 uint8_t OnAction_Bearing (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) | |
239 { | |
240 if((int16_t)stateUsed->lifeData.compass_heading != -1) | |
241 { | |
242 settingsGetPointer()->compassBearing = (int16_t)stateUsed->lifeData.compass_heading; | |
243 } | |
244 else | |
245 { | |
246 settingsGetPointer()->compassBearing = 0; | |
247 } | |
248 | |
249 if(settingsGetPointer()->compassBearing == 0) | |
250 settingsGetPointer()->compassBearing = 360; | |
251 return UPDATE_AND_EXIT_TO_MENU; | |
252 } | |
253 | |
254 | |
255 uint8_t OnAction_BearingClear (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) | |
256 { | |
257 settingsGetPointer()->compassBearing = 0; | |
258 return UPDATE_AND_EXIT_TO_MENU; | |
259 } | |
260 | |
261 | |
262 uint8_t OnAction_InertiaLevel (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) | |
263 { | |
264 uint8_t newLevel = 0; | |
265 | |
266 newLevel = settingsGetPointer()->compassInertia + 1; | |
267 if(newLevel > MAX_COMPASS_COMP) | |
268 { | |
269 newLevel = 0; | |
270 } | |
271 settingsGetPointer()->compassInertia = newLevel; | |
272 return UPDATE_DIVESETTINGS; | |
273 } | |
274 | |
275 static void openEdit_Timer(void) | |
276 { | |
277 SSettings *settings = settingsGetPointer(); | |
278 | |
279 char text[32]; | |
280 snprintf(text, 32, "\001%c%c", TXT_2BYTE, TXT2BYTE_Timer); | |
281 write_topline(text); | |
282 | |
1001
21142f4fa968
Cleanup menu structucture afer menu shift:
Ideenmodellierer
parents:
999
diff
changeset
|
283 set_globalState(StMOption_Timer); |
1005
85f7e19c6688
Switch menu position of Buzzer and flipdisplay option:
Ideenmodellierer
parents:
1001
diff
changeset
|
284 resetMenuEdit(CLUT_MenuPageCvOption); |
1001
21142f4fa968
Cleanup menu structucture afer menu shift:
Ideenmodellierer
parents:
999
diff
changeset
|
285 |
999 | 286 uint16_t yPos = ME_Y_LINE_BASE + get_globalState_Menu_Line() * ME_Y_LINE_STEP; |
287 snprintf(text, 32, "%c%c", TXT_2BYTE, TXT2BYTE_Timer); | |
288 write_label_var(30, 299, yPos, &FontT48, text); | |
1005
85f7e19c6688
Switch menu position of Buzzer and flipdisplay option:
Ideenmodellierer
parents:
1001
diff
changeset
|
289 write_field_udigit(StMOption_Timer_Value, 300, 392, yPos, &FontT48, "#:##", settings->timerDurationS / 60, settings->timerDurationS % 60, 0, 0); |
999 | 290 write_label_var(393, 800, yPos, &FontT48, "\016\016 [m:ss]\017"); |
291 | |
292 write_buttonTextline(TXT2BYTE_ButtonMinus, TXT2BYTE_ButtonEnter, TXT2BYTE_ButtonPlus); | |
293 | |
1005
85f7e19c6688
Switch menu position of Buzzer and flipdisplay option:
Ideenmodellierer
parents:
1001
diff
changeset
|
294 setEvent(StMOption_Timer_Value, (uint32_t)OnAction_Timer); |
999 | 295 startEdit(); |
296 } | |
297 static uint8_t OnAction_Timer(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) | |
298 { | |
299 SSettings *settings = settingsGetPointer(); | |
300 uint8_t digitContentNew; | |
301 switch (action) { | |
302 case ACTION_BUTTON_ENTER: | |
303 | |
304 return digitContent; | |
305 case ACTION_BUTTON_ENTER_FINAL: | |
306 { | |
307 uint32_t timerM; | |
308 uint32_t timerS; | |
309 evaluateNewString(editId, &timerM, &timerS, 0, 0); | |
310 if (timerM > 9) { | |
311 timerM = 9; | |
312 } | |
313 if (timerS > 59) { | |
314 timerS = 59; | |
315 } | |
316 | |
317 uint16_t timerDurationS = 60 * timerM + timerS; | |
318 | |
319 if (timerDurationS < 1) { | |
320 timerDurationS = 1; | |
321 } | |
322 | |
323 if (timerDurationS != settings->timerDurationS) { | |
324 settings->timerDurationS = timerDurationS; | |
325 | |
326 disableTimer(); | |
327 | |
328 tMenuEdit_newInput(editId, settings->timerDurationS / 60, settings->timerDurationS % 60, 0, 0); | |
329 } | |
330 | |
331 return EXIT_TO_MENU; | |
332 } | |
333 case ACTION_BUTTON_NEXT: | |
334 digitContentNew = digitContent + 1; | |
335 if ((blockNumber == 1 && digitNumber == 0 && digitContentNew > '5') || digitContentNew > '9') { | |
336 digitContentNew = '0'; | |
337 } | |
338 | |
339 return digitContentNew; | |
340 case ACTION_BUTTON_BACK: | |
341 digitContentNew = digitContent - 1; | |
342 if (digitContentNew < '0') { | |
343 if (blockNumber == 1 && digitNumber == 0) { | |
344 digitContentNew = '5'; | |
345 } else { | |
346 digitContentNew = '9'; | |
347 } | |
348 } | |
349 | |
350 return digitContentNew; | |
351 } | |
352 | |
353 return EXIT_TO_MENU; | |
354 } | |
355 | |
356 |