Mercurial > public > ostc4
annotate Discovery/Src/tMenuEditCvOption.c @ 1051:4b6afe5551e1 GasConsumption tip
Refactors CalcFletcher32 in OtherSources/firmwareEraseProgram.c to iterate over 16-bit words via a pointer instead of an index-based loop. Removes unused variables and returns the computed 32-bit Fletcher checksum directly. (mikeller)
| author | heinrichsweikamp |
|---|---|
| date | Thu, 20 Nov 2025 16:47:21 +0100 |
| parents | 195bfbdf961d |
| 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" | |
| 31 #include "tMenuEdit.h" | |
| 32 | |
| 33 #include "gfx_fonts.h" | |
| 34 #include "ostc.h" | |
| 35 #include "tMenuEdit.h" | |
| 36 #include "tHome.h" | |
| 37 | |
| 1032 | 38 #include "cv_heartbeat.h" |
| 39 | |
| 999 | 40 /* Private function prototypes -----------------------------------------------*/ |
| 41 static void openEdit_Timer(void); | |
| 42 void openEdit_Compass(void); | |
| 43 | |
| 44 /* Announced function prototypes -----------------------------------------------*/ | |
| 45 uint8_t OnAction_Compass (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); | |
| 46 static uint8_t OnAction_CompassDeclination(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); | |
| 47 uint8_t OnAction_Bearing (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); | |
| 48 uint8_t OnAction_BearingClear (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); | |
| 49 uint8_t OnAction_InertiaLevel (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); | |
| 50 static uint8_t OnAction_Timer(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); | |
| 51 | |
| 52 /* Exported functions --------------------------------------------------------*/ | |
| 53 | |
| 54 void openEdit_CvOption(uint8_t line) | |
| 55 { | |
| 56 set_globalState_Menu_Line(line); | |
| 57 | |
| 58 switch(line) | |
| 59 { | |
| 60 case 1: | |
| 1032 | 61 default: resetMenuEdit(CLUT_MenuPageHardware); |
| 62 openEdit_Compass(); | |
| 63 break; | |
| 64 case 2: openEdit_Timer(); | |
| 65 break; | |
| 1034 | 66 #ifdef ENABLE_PULSE_SENSOR_BT |
| 1032 | 67 case 3: openEdit_Heartbeat(); |
| 1034 | 68 #endif |
| 1032 | 69 break; |
| 999 | 70 } |
| 71 } | |
| 72 | |
| 73 /* Private functions ---------------------------------------------------------*/ | |
| 74 | |
| 75 static uint8_t OnAction_CompassDeclination(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) | |
| 76 { | |
| 77 SSettings *settings = settingsGetPointer(); | |
| 78 uint8_t digitContentNew; | |
| 79 switch (action) { | |
| 80 case ACTION_BUTTON_ENTER: | |
| 81 | |
| 82 return digitContent; | |
| 83 case ACTION_BUTTON_ENTER_FINAL: | |
| 84 { | |
| 85 int32_t compassDeclinationDeg; | |
| 86 evaluateNewString(editId, (uint32_t *)&compassDeclinationDeg, NULL, NULL, NULL); | |
| 87 | |
| 88 if (compassDeclinationDeg > 99) { | |
| 89 compassDeclinationDeg = 99; | |
| 90 } else if (compassDeclinationDeg < -99) { | |
| 91 compassDeclinationDeg = -99; | |
| 92 } | |
| 93 | |
| 94 settings->compassDeclinationDeg = compassDeclinationDeg; | |
| 95 | |
| 96 tMenuEdit_newInput(editId, ((input_u)compassDeclinationDeg).uint32, 0, 0, 0); | |
| 97 } | |
| 98 | |
| 99 break; | |
| 100 case ACTION_BUTTON_NEXT: | |
| 101 if (digitNumber == 0) { | |
| 102 digitContentNew = togglePlusMinus(digitContent); | |
| 103 } else { | |
| 104 digitContentNew = digitContent + 1; | |
| 105 if (digitContentNew > '9') { | |
| 106 digitContentNew = '0'; | |
| 107 } | |
| 108 } | |
| 109 | |
| 110 return digitContentNew; | |
| 111 case ACTION_BUTTON_BACK: | |
| 112 if (digitNumber == 0) { | |
| 113 digitContentNew = togglePlusMinus(digitContent); | |
| 114 } else { | |
| 115 digitContentNew = digitContent - 1; | |
| 116 if (digitContentNew < '0') { | |
| 117 digitContentNew = '9'; | |
| 118 } | |
| 119 } | |
| 120 | |
| 121 return digitContentNew; | |
| 122 } | |
| 123 | |
| 124 return UNSPECIFIC_RETURN; | |
| 125 } | |
| 126 | |
| 127 | |
| 128 static void showCompassDeclination(SSettings *settings, bool isRefresh) | |
| 129 { | |
| 130 char text[16]; | |
| 131 snprintf(text, 16, "%c%c:", TXT_2BYTE, TXT2BYTE_CompassDeclination); | |
| 132 write_label_var(30, 800, ME_Y_LINE6, &FontT48, text); | |
| 133 if (isRefresh) { | |
| 134 tMenuEdit_refresh_field(StMOption_Compass_Declination); | |
| 135 } else { | |
| 136 write_field_sdigit(StMOption_Compass_Declination, 500, 800, ME_Y_LINE6, &FontT48, "\034###`", settings->compassDeclinationDeg, 0, 0, 0); | |
| 137 } | |
| 138 } | |
| 139 | |
| 140 | |
| 141 void refresh_CompassEdit(void) | |
| 142 { | |
| 143 SSettings *settings = settingsGetPointer(); | |
| 144 | |
| 145 uint16_t heading; | |
| 146 char text[32]; | |
| 147 uint8_t textIndex = 0; | |
| 148 | |
| 149 text[0] = '\001'; | |
| 150 text[1] = TXT_2BYTE; | |
| 151 text[2] = TXT2BYTE_Compass; | |
| 152 text[3] = 0; | |
| 153 write_topline(text); | |
| 154 | |
| 155 if(settings->compassInertia) | |
| 156 { | |
| 157 heading = (uint16_t)compass_getCompensated(); | |
| 158 } | |
| 159 else | |
| 160 { | |
| 161 heading = (uint16_t)stateUsed->lifeData.compass_heading; | |
| 162 } | |
| 163 snprintf(text,32,"\001%03i`",heading); | |
| 164 write_label_var( 0, 800, ME_Y_LINE1, &FontT54, text); | |
| 165 | |
| 166 tMenuEdit_refresh_field(StMOption_Compass_SetCourse); | |
| 167 tMenuEdit_refresh_field(StMOption_Compass_Calibrate); | |
| 168 tMenuEdit_refresh_field(StMOption_Compass_ResetCourse); | |
| 169 text[textIndex++] = TXT_2BYTE; | |
| 170 text[textIndex++] = TXT2BYTE_CompassInertia; | |
| 171 text[textIndex++] = ':'; | |
| 172 text[textIndex++] = ' '; | |
| 173 text[textIndex++] = '0' + settings->compassInertia; | |
| 174 | |
| 175 write_label_var(30, 800, ME_Y_LINE5, &FontT48, text); | |
| 176 | |
| 177 showCompassDeclination(settings, true); | |
| 178 | |
| 179 write_buttonTextline(TXT2BYTE_ButtonBack,TXT2BYTE_ButtonEnter,TXT2BYTE_ButtonNext); | |
| 180 } | |
| 181 | |
| 182 | |
| 183 void openEdit_Compass(void) | |
| 184 { | |
| 185 SSettings *settings = settingsGetPointer(); | |
| 186 | |
| 187 char text[10]; | |
| 188 uint8_t textIndex = 0; | |
| 189 | |
| 190 | |
| 191 set_globalState(StMOption_Compass); | |
| 192 resetMenuEdit(CLUT_MenuPageHardware); | |
| 193 | |
| 194 text[textIndex++] = '\001'; | |
| 195 text[textIndex++] = TXT_2BYTE; | |
| 196 text[textIndex++] = TXT2BYTE_Compass; | |
| 197 text[textIndex++] = 0; | |
| 198 write_topline(text); | |
| 199 | |
| 200 text[0] = TXT_2BYTE; | |
| 201 text[2] = 0; | |
| 202 | |
| 203 text[1] = TXT2BYTE_SetBearing; | |
| 204 write_field_button(StMOption_Compass_SetCourse, 30, 800, ME_Y_LINE2, &FontT48, text); | |
| 205 | |
| 206 text[1] = TXT2BYTE_ResetBearing; | |
| 207 write_field_button(StMOption_Compass_ResetCourse, 30, 800, ME_Y_LINE3, &FontT48, text); | |
| 208 | |
| 209 text[1] = TXT2BYTE_CompassCalib; | |
| 210 write_field_button(StMOption_Compass_Calibrate, 30, 800, ME_Y_LINE4, &FontT48, text); | |
| 211 | |
| 212 text[1] = TXT2BYTE_CompassInertia; | |
| 213 textIndex = 2; | |
| 214 text[textIndex++] = ':'; | |
| 215 text[textIndex++] = ' '; | |
| 216 text[textIndex++] = '0' + settings->compassInertia; | |
| 217 text[textIndex++] = 0; | |
| 218 | |
| 219 write_field_button(StMOption_Compass_Inertia, 30, 800, ME_Y_LINE5, &FontT48, text); | |
| 220 | |
| 221 showCompassDeclination(settings, false); | |
| 222 | |
| 223 setEvent(StMOption_Compass_SetCourse, (uint32_t)OnAction_Bearing); | |
| 224 setEvent(StMOption_Compass_ResetCourse, (uint32_t)OnAction_BearingClear); | |
| 225 setEvent(StMOption_Compass_Calibrate, (uint32_t)OnAction_Compass); | |
| 226 setEvent(StMOption_Compass_Inertia, (uint32_t)OnAction_InertiaLevel); | |
| 227 setEvent(StMOption_Compass_Declination, (uint32_t)OnAction_CompassDeclination); | |
| 228 | |
| 229 tMenuEdit_select(StMOption_Compass_SetCourse); | |
| 230 | |
| 231 write_buttonTextline(TXT2BYTE_ButtonBack,TXT2BYTE_ButtonEnter,TXT2BYTE_ButtonNext); | |
| 232 } | |
| 233 | |
| 234 | |
| 235 uint8_t OnAction_Compass (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) | |
| 236 { | |
| 237 calibrateCompass(); | |
| 238 return EXIT_TO_INFO_COMPASS; | |
| 239 } | |
| 240 | |
| 241 | |
| 242 uint8_t OnAction_Bearing (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) | |
| 243 { | |
| 244 if((int16_t)stateUsed->lifeData.compass_heading != -1) | |
| 245 { | |
| 246 settingsGetPointer()->compassBearing = (int16_t)stateUsed->lifeData.compass_heading; | |
| 247 } | |
| 248 else | |
| 249 { | |
| 250 settingsGetPointer()->compassBearing = 0; | |
| 251 } | |
| 252 | |
| 253 if(settingsGetPointer()->compassBearing == 0) | |
| 254 settingsGetPointer()->compassBearing = 360; | |
| 255 return UPDATE_AND_EXIT_TO_MENU; | |
| 256 } | |
| 257 | |
| 258 | |
| 259 uint8_t OnAction_BearingClear (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) | |
| 260 { | |
| 261 settingsGetPointer()->compassBearing = 0; | |
| 262 return UPDATE_AND_EXIT_TO_MENU; | |
| 263 } | |
| 264 | |
| 265 | |
| 266 uint8_t OnAction_InertiaLevel (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) | |
| 267 { | |
| 268 uint8_t newLevel = 0; | |
| 269 | |
| 270 newLevel = settingsGetPointer()->compassInertia + 1; | |
| 271 if(newLevel > MAX_COMPASS_COMP) | |
| 272 { | |
| 273 newLevel = 0; | |
| 274 } | |
| 275 settingsGetPointer()->compassInertia = newLevel; | |
| 276 return UPDATE_DIVESETTINGS; | |
| 277 } | |
| 278 | |
| 279 static void openEdit_Timer(void) | |
| 280 { | |
| 281 SSettings *settings = settingsGetPointer(); | |
| 282 | |
| 283 char text[32]; | |
| 284 snprintf(text, 32, "\001%c%c", TXT_2BYTE, TXT2BYTE_Timer); | |
| 285 write_topline(text); | |
| 286 | |
|
1001
21142f4fa968
Cleanup menu structucture afer menu shift:
Ideenmodellierer
parents:
999
diff
changeset
|
287 set_globalState(StMOption_Timer); |
|
1005
85f7e19c6688
Switch menu position of Buzzer and flipdisplay option:
Ideenmodellierer
parents:
1001
diff
changeset
|
288 resetMenuEdit(CLUT_MenuPageCvOption); |
|
1001
21142f4fa968
Cleanup menu structucture afer menu shift:
Ideenmodellierer
parents:
999
diff
changeset
|
289 |
| 999 | 290 uint16_t yPos = ME_Y_LINE_BASE + get_globalState_Menu_Line() * ME_Y_LINE_STEP; |
| 291 snprintf(text, 32, "%c%c", TXT_2BYTE, TXT2BYTE_Timer); | |
| 292 write_label_var(30, 299, yPos, &FontT48, text); | |
|
1005
85f7e19c6688
Switch menu position of Buzzer and flipdisplay option:
Ideenmodellierer
parents:
1001
diff
changeset
|
293 write_field_udigit(StMOption_Timer_Value, 300, 392, yPos, &FontT48, "#:##", settings->timerDurationS / 60, settings->timerDurationS % 60, 0, 0); |
| 999 | 294 write_label_var(393, 800, yPos, &FontT48, "\016\016 [m:ss]\017"); |
| 295 | |
| 296 write_buttonTextline(TXT2BYTE_ButtonMinus, TXT2BYTE_ButtonEnter, TXT2BYTE_ButtonPlus); | |
| 297 | |
|
1005
85f7e19c6688
Switch menu position of Buzzer and flipdisplay option:
Ideenmodellierer
parents:
1001
diff
changeset
|
298 setEvent(StMOption_Timer_Value, (uint32_t)OnAction_Timer); |
| 999 | 299 startEdit(); |
| 300 } | |
| 301 static uint8_t OnAction_Timer(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) | |
| 302 { | |
| 303 SSettings *settings = settingsGetPointer(); | |
| 304 uint8_t digitContentNew; | |
| 305 switch (action) { | |
| 306 case ACTION_BUTTON_ENTER: | |
| 307 | |
| 308 return digitContent; | |
| 309 case ACTION_BUTTON_ENTER_FINAL: | |
| 310 { | |
| 311 uint32_t timerM; | |
| 312 uint32_t timerS; | |
| 313 evaluateNewString(editId, &timerM, &timerS, 0, 0); | |
| 314 if (timerM > 9) { | |
| 315 timerM = 9; | |
| 316 } | |
| 317 if (timerS > 59) { | |
| 318 timerS = 59; | |
| 319 } | |
| 320 | |
| 321 uint16_t timerDurationS = 60 * timerM + timerS; | |
| 322 | |
| 323 if (timerDurationS < 1) { | |
| 324 timerDurationS = 1; | |
| 325 } | |
| 326 | |
| 327 if (timerDurationS != settings->timerDurationS) { | |
| 328 settings->timerDurationS = timerDurationS; | |
| 329 | |
| 330 disableTimer(); | |
| 331 | |
| 332 tMenuEdit_newInput(editId, settings->timerDurationS / 60, settings->timerDurationS % 60, 0, 0); | |
| 333 } | |
| 334 | |
|
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
|
335 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
|
336 |
| 999 | 337 return EXIT_TO_MENU; |
| 338 } | |
| 339 case ACTION_BUTTON_NEXT: | |
| 340 digitContentNew = digitContent + 1; | |
| 341 if ((blockNumber == 1 && digitNumber == 0 && digitContentNew > '5') || digitContentNew > '9') { | |
| 342 digitContentNew = '0'; | |
| 343 } | |
| 344 | |
| 345 return digitContentNew; | |
| 346 case ACTION_BUTTON_BACK: | |
| 347 digitContentNew = digitContent - 1; | |
| 348 if (digitContentNew < '0') { | |
| 349 if (blockNumber == 1 && digitNumber == 0) { | |
| 350 digitContentNew = '5'; | |
| 351 } else { | |
| 352 digitContentNew = '9'; | |
| 353 } | |
| 354 } | |
| 355 | |
| 356 return digitContentNew; | |
| 357 } | |
| 358 | |
| 359 return EXIT_TO_MENU; | |
| 360 } | |
| 361 | |
| 362 |
