Mercurial > public > ostc4
annotate Discovery/Src/tMenuEditCvOption.c @ 1080:b02311fbb1e1 Icon_Integration tip
Added MUX operation for HUD:
Instead of adding some new detection steps to the autodetection loop (which would be another copy paste implementation) the detection loop has been reworked. Instead of having a several individual steps per sensor type the steps are now related to mux channels. A structure is used to identify the type which shall be handled during the uart channel iteration. This make the code better readable and maintanance easier.
| author | Ideenmodellierer |
|---|---|
| date | Sun, 08 Mar 2026 21:08:33 +0100 |
| parents | 082825daccb5 |
| children |
| 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" | |
| 1071 | 31 #include "tMenuCvOptionText.h" |
|
1073
734f84b72b30
CV Option Menu added sub menus for O2 and CO2 sensors:
Ideenmodellierer
parents:
1071
diff
changeset
|
32 #include "tMenuEditHardware.h" |
| 999 | 33 #include "tMenuEdit.h" |
| 34 | |
| 35 #include "gfx_fonts.h" | |
| 36 #include "ostc.h" | |
| 37 #include "tMenuEdit.h" | |
| 38 #include "tHome.h" | |
| 39 | |
| 1032 | 40 #include "cv_heartbeat.h" |
| 41 | |
| 1071 | 42 |
| 43 static openFunc_t openFctPointerTable[MAXLINES]; /* function pointer for refresh */ | |
| 44 | |
| 999 | 45 /* Private function prototypes -----------------------------------------------*/ |
| 46 static void openEdit_Timer(void); | |
| 47 void openEdit_Compass(void); | |
| 48 | |
| 49 /* Announced function prototypes -----------------------------------------------*/ | |
| 50 uint8_t OnAction_Compass (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); | |
| 51 static uint8_t OnAction_CompassDeclination(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); | |
| 52 uint8_t OnAction_Bearing (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); | |
| 53 uint8_t OnAction_BearingClear (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); | |
| 54 uint8_t OnAction_InertiaLevel (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); | |
| 55 static uint8_t OnAction_Timer(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); | |
| 56 | |
| 57 /* Exported functions --------------------------------------------------------*/ | |
| 58 | |
| 1071 | 59 |
| 60 void tMCvOption_SetOpenFnct(uint8_t cvOptId, uint8_t index) | |
| 61 { | |
| 62 if(index < MAXLINES) | |
| 63 { | |
| 64 switch(cvOptId) | |
| 65 { | |
| 66 case CVOPT_Compass: openFctPointerTable[index] = openEdit_Compass; | |
| 67 break; | |
| 68 case CVOPT_Timer: openFctPointerTable[index] = openEdit_Timer; | |
| 69 break; | |
| 70 case CVOPT_END: openFctPointerTable[index] = NULL; | |
| 71 break; | |
|
1073
734f84b72b30
CV Option Menu added sub menus for O2 and CO2 sensors:
Ideenmodellierer
parents:
1071
diff
changeset
|
72 case CVOPT_O2_Sensor: openFctPointerTable[index] = openEdit_SensorsO2; |
|
734f84b72b30
CV Option Menu added sub menus for O2 and CO2 sensors:
Ideenmodellierer
parents:
1071
diff
changeset
|
73 break; |
|
734f84b72b30
CV Option Menu added sub menus for O2 and CO2 sensors:
Ideenmodellierer
parents:
1071
diff
changeset
|
74 case CVOPT_CO2_Sensor: openFctPointerTable[index] = openEdit_SensorsCO2; |
| 1078 | 75 break; |
| 76 case CVOPT_HUD: openFctPointerTable[index] = openEdit_SensorsHUD; | |
| 77 break; | |
|
1073
734f84b72b30
CV Option Menu added sub menus for O2 and CO2 sensors:
Ideenmodellierer
parents:
1071
diff
changeset
|
78 default: |
|
734f84b72b30
CV Option Menu added sub menus for O2 and CO2 sensors:
Ideenmodellierer
parents:
1071
diff
changeset
|
79 break; |
| 1071 | 80 } |
| 81 } | |
| 82 } | |
| 83 | |
| 84 | |
| 999 | 85 void openEdit_CvOption(uint8_t line) |
| 86 { | |
| 1071 | 87 if(openFctPointerTable[line - 1] != NULL) |
| 999 | 88 { |
| 1071 | 89 openFctPointerTable[line - 1](); |
| 999 | 90 } |
| 91 } | |
| 92 | |
| 93 /* Private functions ---------------------------------------------------------*/ | |
| 94 | |
| 95 static uint8_t OnAction_CompassDeclination(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) | |
| 96 { | |
| 97 SSettings *settings = settingsGetPointer(); | |
| 98 uint8_t digitContentNew; | |
| 99 switch (action) { | |
| 100 case ACTION_BUTTON_ENTER: | |
| 101 | |
| 102 return digitContent; | |
| 103 case ACTION_BUTTON_ENTER_FINAL: | |
| 104 { | |
| 105 int32_t compassDeclinationDeg; | |
| 106 evaluateNewString(editId, (uint32_t *)&compassDeclinationDeg, NULL, NULL, NULL); | |
| 107 | |
| 108 if (compassDeclinationDeg > 99) { | |
| 109 compassDeclinationDeg = 99; | |
| 110 } else if (compassDeclinationDeg < -99) { | |
| 111 compassDeclinationDeg = -99; | |
| 112 } | |
| 113 | |
| 114 settings->compassDeclinationDeg = compassDeclinationDeg; | |
| 115 | |
| 116 tMenuEdit_newInput(editId, ((input_u)compassDeclinationDeg).uint32, 0, 0, 0); | |
| 117 } | |
| 118 | |
| 119 break; | |
| 120 case ACTION_BUTTON_NEXT: | |
| 121 if (digitNumber == 0) { | |
| 122 digitContentNew = togglePlusMinus(digitContent); | |
| 123 } else { | |
| 124 digitContentNew = digitContent + 1; | |
| 125 if (digitContentNew > '9') { | |
| 126 digitContentNew = '0'; | |
| 127 } | |
| 128 } | |
| 129 | |
| 130 return digitContentNew; | |
| 131 case ACTION_BUTTON_BACK: | |
| 132 if (digitNumber == 0) { | |
| 133 digitContentNew = togglePlusMinus(digitContent); | |
| 134 } else { | |
| 135 digitContentNew = digitContent - 1; | |
| 136 if (digitContentNew < '0') { | |
| 137 digitContentNew = '9'; | |
| 138 } | |
| 139 } | |
| 140 | |
| 141 return digitContentNew; | |
| 142 } | |
| 143 | |
| 144 return UNSPECIFIC_RETURN; | |
| 145 } | |
| 146 | |
| 147 | |
| 148 static void showCompassDeclination(SSettings *settings, bool isRefresh) | |
| 149 { | |
| 150 char text[16]; | |
| 151 snprintf(text, 16, "%c%c:", TXT_2BYTE, TXT2BYTE_CompassDeclination); | |
| 152 write_label_var(30, 800, ME_Y_LINE6, &FontT48, text); | |
| 153 if (isRefresh) { | |
| 154 tMenuEdit_refresh_field(StMOption_Compass_Declination); | |
| 155 } else { | |
| 156 write_field_sdigit(StMOption_Compass_Declination, 500, 800, ME_Y_LINE6, &FontT48, "\034###`", settings->compassDeclinationDeg, 0, 0, 0); | |
| 157 } | |
| 158 } | |
| 159 | |
| 160 | |
| 161 void refresh_CompassEdit(void) | |
| 162 { | |
| 163 SSettings *settings = settingsGetPointer(); | |
| 164 | |
| 165 uint16_t heading; | |
| 166 char text[32]; | |
| 167 uint8_t textIndex = 0; | |
| 168 | |
| 169 text[0] = '\001'; | |
| 170 text[1] = TXT_2BYTE; | |
| 171 text[2] = TXT2BYTE_Compass; | |
| 172 text[3] = 0; | |
| 173 write_topline(text); | |
| 174 | |
| 175 if(settings->compassInertia) | |
| 176 { | |
| 177 heading = (uint16_t)compass_getCompensated(); | |
| 178 } | |
| 179 else | |
| 180 { | |
| 181 heading = (uint16_t)stateUsed->lifeData.compass_heading; | |
| 182 } | |
| 183 snprintf(text,32,"\001%03i`",heading); | |
| 184 write_label_var( 0, 800, ME_Y_LINE1, &FontT54, text); | |
| 185 | |
| 186 tMenuEdit_refresh_field(StMOption_Compass_SetCourse); | |
| 187 tMenuEdit_refresh_field(StMOption_Compass_Calibrate); | |
| 188 tMenuEdit_refresh_field(StMOption_Compass_ResetCourse); | |
| 189 text[textIndex++] = TXT_2BYTE; | |
| 190 text[textIndex++] = TXT2BYTE_CompassInertia; | |
| 191 text[textIndex++] = ':'; | |
| 192 text[textIndex++] = ' '; | |
| 193 text[textIndex++] = '0' + settings->compassInertia; | |
| 194 | |
| 195 write_label_var(30, 800, ME_Y_LINE5, &FontT48, text); | |
| 196 | |
| 197 showCompassDeclination(settings, true); | |
| 198 | |
| 199 write_buttonTextline(TXT2BYTE_ButtonBack,TXT2BYTE_ButtonEnter,TXT2BYTE_ButtonNext); | |
| 200 } | |
| 201 | |
| 202 | |
| 203 void openEdit_Compass(void) | |
| 204 { | |
| 205 SSettings *settings = settingsGetPointer(); | |
| 206 | |
| 207 char text[10]; | |
| 208 uint8_t textIndex = 0; | |
| 209 | |
| 210 | |
| 211 set_globalState(StMOption_Compass); | |
| 212 resetMenuEdit(CLUT_MenuPageHardware); | |
| 213 | |
| 214 text[textIndex++] = '\001'; | |
| 215 text[textIndex++] = TXT_2BYTE; | |
| 216 text[textIndex++] = TXT2BYTE_Compass; | |
| 217 text[textIndex++] = 0; | |
| 218 write_topline(text); | |
| 219 | |
| 220 text[0] = TXT_2BYTE; | |
| 221 text[2] = 0; | |
| 222 | |
| 223 text[1] = TXT2BYTE_SetBearing; | |
| 224 write_field_button(StMOption_Compass_SetCourse, 30, 800, ME_Y_LINE2, &FontT48, text); | |
| 225 | |
| 226 text[1] = TXT2BYTE_ResetBearing; | |
| 227 write_field_button(StMOption_Compass_ResetCourse, 30, 800, ME_Y_LINE3, &FontT48, text); | |
| 228 | |
| 229 text[1] = TXT2BYTE_CompassCalib; | |
| 230 write_field_button(StMOption_Compass_Calibrate, 30, 800, ME_Y_LINE4, &FontT48, text); | |
| 231 | |
| 232 text[1] = TXT2BYTE_CompassInertia; | |
| 233 textIndex = 2; | |
| 234 text[textIndex++] = ':'; | |
| 235 text[textIndex++] = ' '; | |
| 236 text[textIndex++] = '0' + settings->compassInertia; | |
| 237 text[textIndex++] = 0; | |
| 238 | |
| 239 write_field_button(StMOption_Compass_Inertia, 30, 800, ME_Y_LINE5, &FontT48, text); | |
| 240 | |
| 241 showCompassDeclination(settings, false); | |
| 242 | |
| 243 setEvent(StMOption_Compass_SetCourse, (uint32_t)OnAction_Bearing); | |
| 244 setEvent(StMOption_Compass_ResetCourse, (uint32_t)OnAction_BearingClear); | |
| 245 setEvent(StMOption_Compass_Calibrate, (uint32_t)OnAction_Compass); | |
| 246 setEvent(StMOption_Compass_Inertia, (uint32_t)OnAction_InertiaLevel); | |
| 247 setEvent(StMOption_Compass_Declination, (uint32_t)OnAction_CompassDeclination); | |
| 248 | |
| 249 tMenuEdit_select(StMOption_Compass_SetCourse); | |
| 250 | |
| 251 write_buttonTextline(TXT2BYTE_ButtonBack,TXT2BYTE_ButtonEnter,TXT2BYTE_ButtonNext); | |
| 252 } | |
| 253 | |
| 254 | |
| 255 uint8_t OnAction_Compass (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) | |
| 256 { | |
| 257 calibrateCompass(); | |
| 258 return EXIT_TO_INFO_COMPASS; | |
| 259 } | |
| 260 | |
| 261 | |
| 262 uint8_t OnAction_Bearing (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) | |
| 263 { | |
| 264 if((int16_t)stateUsed->lifeData.compass_heading != -1) | |
| 265 { | |
| 266 settingsGetPointer()->compassBearing = (int16_t)stateUsed->lifeData.compass_heading; | |
| 267 } | |
| 268 else | |
| 269 { | |
| 270 settingsGetPointer()->compassBearing = 0; | |
| 271 } | |
| 272 | |
| 273 if(settingsGetPointer()->compassBearing == 0) | |
| 274 settingsGetPointer()->compassBearing = 360; | |
| 275 return UPDATE_AND_EXIT_TO_MENU; | |
| 276 } | |
| 277 | |
| 278 | |
| 279 uint8_t OnAction_BearingClear (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) | |
| 280 { | |
| 281 settingsGetPointer()->compassBearing = 0; | |
| 282 return UPDATE_AND_EXIT_TO_MENU; | |
| 283 } | |
| 284 | |
| 285 | |
| 286 uint8_t OnAction_InertiaLevel (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) | |
| 287 { | |
| 288 uint8_t newLevel = 0; | |
| 289 | |
| 290 newLevel = settingsGetPointer()->compassInertia + 1; | |
| 291 if(newLevel > MAX_COMPASS_COMP) | |
| 292 { | |
| 293 newLevel = 0; | |
| 294 } | |
| 295 settingsGetPointer()->compassInertia = newLevel; | |
| 296 return UPDATE_DIVESETTINGS; | |
| 297 } | |
| 298 | |
| 299 static void openEdit_Timer(void) | |
| 300 { | |
| 301 SSettings *settings = settingsGetPointer(); | |
| 302 | |
| 303 char text[32]; | |
| 304 snprintf(text, 32, "\001%c%c", TXT_2BYTE, TXT2BYTE_Timer); | |
| 305 write_topline(text); | |
| 306 | |
|
1001
21142f4fa968
Cleanup menu structucture afer menu shift:
Ideenmodellierer
parents:
999
diff
changeset
|
307 set_globalState(StMOption_Timer); |
|
1005
85f7e19c6688
Switch menu position of Buzzer and flipdisplay option:
Ideenmodellierer
parents:
1001
diff
changeset
|
308 resetMenuEdit(CLUT_MenuPageCvOption); |
|
1001
21142f4fa968
Cleanup menu structucture afer menu shift:
Ideenmodellierer
parents:
999
diff
changeset
|
309 |
| 999 | 310 uint16_t yPos = ME_Y_LINE_BASE + get_globalState_Menu_Line() * ME_Y_LINE_STEP; |
| 311 snprintf(text, 32, "%c%c", TXT_2BYTE, TXT2BYTE_Timer); | |
| 312 write_label_var(30, 299, yPos, &FontT48, text); | |
|
1005
85f7e19c6688
Switch menu position of Buzzer and flipdisplay option:
Ideenmodellierer
parents:
1001
diff
changeset
|
313 write_field_udigit(StMOption_Timer_Value, 300, 392, yPos, &FontT48, "#:##", settings->timerDurationS / 60, settings->timerDurationS % 60, 0, 0); |
| 999 | 314 write_label_var(393, 800, yPos, &FontT48, "\016\016 [m:ss]\017"); |
| 315 | |
| 316 write_buttonTextline(TXT2BYTE_ButtonMinus, TXT2BYTE_ButtonEnter, TXT2BYTE_ButtonPlus); | |
| 317 | |
|
1005
85f7e19c6688
Switch menu position of Buzzer and flipdisplay option:
Ideenmodellierer
parents:
1001
diff
changeset
|
318 setEvent(StMOption_Timer_Value, (uint32_t)OnAction_Timer); |
| 999 | 319 startEdit(); |
| 320 } | |
| 321 static uint8_t OnAction_Timer(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) | |
| 322 { | |
| 323 SSettings *settings = settingsGetPointer(); | |
| 324 uint8_t digitContentNew; | |
| 325 switch (action) { | |
| 326 case ACTION_BUTTON_ENTER: | |
| 327 | |
| 328 return digitContent; | |
| 329 case ACTION_BUTTON_ENTER_FINAL: | |
| 330 { | |
| 331 uint32_t timerM; | |
| 332 uint32_t timerS; | |
| 333 evaluateNewString(editId, &timerM, &timerS, 0, 0); | |
| 334 if (timerM > 9) { | |
| 335 timerM = 9; | |
| 336 } | |
| 337 if (timerS > 59) { | |
| 338 timerS = 59; | |
| 339 } | |
| 340 | |
| 341 uint16_t timerDurationS = 60 * timerM + timerS; | |
| 342 | |
| 343 if (timerDurationS < 1) { | |
| 344 timerDurationS = 1; | |
| 345 } | |
| 346 | |
| 347 if (timerDurationS != settings->timerDurationS) { | |
| 348 settings->timerDurationS = timerDurationS; | |
| 349 | |
| 350 disableTimer(); | |
| 351 | |
| 352 tMenuEdit_newInput(editId, settings->timerDurationS / 60, settings->timerDurationS % 60, 0, 0); | |
| 353 } | |
| 354 | |
|
1014
8c0134a287da
Add a log data event to the scrubber timer at the start of the dive and every time the timer (in minutes)
heinrichsweikamp
parents:
1005
diff
changeset
|
355 settings->cv_configuration |= (1 << CVIEW_Timer); |
|
8c0134a287da
Add a log data event to the scrubber timer at the start of the dive and every time the timer (in minutes)
heinrichsweikamp
parents:
1005
diff
changeset
|
356 |
| 999 | 357 return EXIT_TO_MENU; |
| 358 } | |
| 359 case ACTION_BUTTON_NEXT: | |
| 360 digitContentNew = digitContent + 1; | |
| 361 if ((blockNumber == 1 && digitNumber == 0 && digitContentNew > '5') || digitContentNew > '9') { | |
| 362 digitContentNew = '0'; | |
| 363 } | |
| 364 | |
| 365 return digitContentNew; | |
| 366 case ACTION_BUTTON_BACK: | |
| 367 digitContentNew = digitContent - 1; | |
| 368 if (digitContentNew < '0') { | |
| 369 if (blockNumber == 1 && digitNumber == 0) { | |
| 370 digitContentNew = '5'; | |
| 371 } else { | |
| 372 digitContentNew = '9'; | |
| 373 } | |
| 374 } | |
| 375 | |
| 376 return digitContentNew; | |
| 377 } | |
| 378 | |
| 379 return EXIT_TO_MENU; | |
| 380 } | |
| 381 | |
| 382 |
