Mercurial > public > ostc4
comparison Discovery/Src/tMenuEditXtra.c @ 776:45b8f3c2acce
Add support for a configurable compass declination in a range of -99 to 99 degrees.
This allows the displayed compass reading to be configured to take into account the compass declination (difference between the measured magnetic North direction and the actual geographical North direction) that has different values for different locations around the globe. See https://magnetic-declination.com/ for more information. (mikeller)
author | heinrichsweikamp |
---|---|
date | Thu, 18 May 2023 09:49:17 +0200 |
parents | 6169309d6eb9 |
children | 9da81033ad44 |
comparison
equal
deleted
inserted
replaced
775:46c6d2380d4e | 776:45b8f3c2acce |
---|---|
375 | 375 |
376 return EXIT_TO_HOME; | 376 return EXIT_TO_HOME; |
377 } | 377 } |
378 | 378 |
379 | 379 |
380 static void drawCompassHeadingMenu(bool doInitialise) | 380 static void drawCompassHeadingMenu(bool isRefresh) |
381 { | 381 { |
382 SSettings *settings = settingsGetPointer(); | |
383 | |
382 char text[32]; | 384 char text[32]; |
383 snprintf(text, 32, "\001%c%c", TXT_2BYTE, TXT2BYTE_CompassHeading); | 385 snprintf(text, 32, "\001%c%c", TXT_2BYTE, TXT2BYTE_CompassHeading); |
384 write_topline(text); | 386 write_topline(text); |
385 | 387 |
386 uint16_t heading = (uint16_t)stateUsed->lifeData.compass_heading; | 388 uint16_t heading; |
389 if (settings->compassInertia) { | |
390 heading = (uint16_t)compass_getCompensated(); | |
391 } else { | |
392 heading = (uint16_t)stateUsed->lifeData.compass_heading; | |
393 } | |
387 snprintf(text,32,"\001%03i`",heading); | 394 snprintf(text,32,"\001%03i`",heading); |
388 write_label_var(0, 800, ME_Y_LINE1, &FontT54, text); | 395 write_label_var(0, 800, ME_Y_LINE1, &FontT54, text); |
389 | 396 |
390 if (doInitialise) { | 397 if (!isRefresh) { |
391 snprintf(text, 32, "%c%c", TXT_2BYTE, TXT2BYTE_Set); | 398 snprintf(text, 32, "%c%c", TXT_2BYTE, TXT2BYTE_Set); |
392 write_field_button(StMXTRA_CompassHeading, 20, 800, ME_Y_LINE2, &FontT48, text); | 399 write_field_button(StMXTRA_CompassHeading, 20, 800, ME_Y_LINE2, &FontT48, text); |
393 } else { | 400 } else { |
394 tMenuEdit_refresh_field(StMXTRA_CompassHeading); | 401 tMenuEdit_refresh_field(StMXTRA_CompassHeading); |
395 } | 402 } |
396 | 403 |
397 bool headingIsSet = stateUsed->diveSettings.compassHeading; | 404 bool headingIsSet = stateUsed->diveSettings.compassHeading; |
398 snprintf(text, 32, "%s%c%c", makeGrey(!headingIsSet), TXT_2BYTE, TXT2BYTE_Clear); | 405 snprintf(text, 32, "%s%c%c", makeGrey(!headingIsSet), TXT_2BYTE, TXT2BYTE_Clear); |
399 if (headingIsSet) { | 406 if (headingIsSet) { |
400 if (doInitialise) { | 407 if (!isRefresh) { |
401 write_field_button(StMXTRA_CompassHeadingClear, 20, 800, ME_Y_LINE3, &FontT48, text); | 408 write_field_button(StMXTRA_CompassHeadingClear, 20, 800, ME_Y_LINE3, &FontT48, text); |
402 } else { | 409 } else { |
403 tMenuEdit_refresh_field(StMXTRA_CompassHeadingClear); | 410 tMenuEdit_refresh_field(StMXTRA_CompassHeadingClear); |
404 } | 411 } |
405 } else { | 412 } else { |
406 write_label_var(20, 800, ME_Y_LINE3, &FontT48, text); | 413 write_label_var(20, 800, ME_Y_LINE3, &FontT48, text); |
407 } | 414 } |
408 | 415 |
409 int16_t compassBearing = settingsGetPointer()->compassBearing; | 416 int16_t compassBearing = settings->compassBearing; |
410 bool canSetBearing = compassBearing && compassBearing != stateUsed->diveSettings.compassHeading; | 417 bool canSetBearing = compassBearing && compassBearing != stateUsed->diveSettings.compassHeading; |
411 snprintf(text, 32, "%s%c%c (%03u`)", makeGrey(!canSetBearing), TXT_2BYTE, TXT2BYTE_Reset, compassBearing); | 418 snprintf(text, 32, "%s%c%c (%03u`)", makeGrey(!canSetBearing), TXT_2BYTE, TXT2BYTE_Reset, compassBearing); |
412 if (canSetBearing) { | 419 if (canSetBearing) { |
413 if (doInitialise) { | 420 if (!isRefresh) { |
414 write_field_button(StMXTRA_CompassHeadingReset, 20, 800, ME_Y_LINE4, &FontT48, text); | 421 write_field_button(StMXTRA_CompassHeadingReset, 20, 800, ME_Y_LINE4, &FontT48, text); |
415 } else { | 422 } else { |
416 tMenuEdit_refresh_field(StMXTRA_CompassHeadingReset); | 423 tMenuEdit_refresh_field(StMXTRA_CompassHeadingReset); |
417 } | 424 } |
418 } else { | 425 } else { |
419 write_label_var(20, 800, ME_Y_LINE4, &FontT48, text); | 426 write_label_var(20, 800, ME_Y_LINE4, &FontT48, text); |
420 } | 427 } |
421 | 428 |
422 if (doInitialise) { | 429 if (!isRefresh) { |
423 setEvent(StMXTRA_CompassHeading, (uint32_t)OnAction_CompassHeading); | 430 setEvent(StMXTRA_CompassHeading, (uint32_t)OnAction_CompassHeading); |
424 setEvent(StMXTRA_CompassHeadingClear, (uint32_t)OnAction_CompassHeadingClear); | 431 setEvent(StMXTRA_CompassHeadingClear, (uint32_t)OnAction_CompassHeadingClear); |
425 setEvent(StMXTRA_CompassHeadingReset, (uint32_t)OnAction_CompassHeadingReset); | 432 setEvent(StMXTRA_CompassHeadingReset, (uint32_t)OnAction_CompassHeadingReset); |
426 } | 433 } |
427 | 434 |
429 } | 436 } |
430 | 437 |
431 | 438 |
432 void refresh_CompassHeading(void) | 439 void refresh_CompassHeading(void) |
433 { | 440 { |
434 drawCompassHeadingMenu(false); | 441 drawCompassHeadingMenu(true); |
435 } | 442 } |
436 | 443 |
437 | 444 |
438 void refresh_CO2Data(void) | 445 void refresh_CO2Data(void) |
439 { | 446 { |
452 tMenuEdit_refresh_field(StMXTRA_CO2_Sensor_Calib); | 459 tMenuEdit_refresh_field(StMXTRA_CO2_Sensor_Calib); |
453 } | 460 } |
454 | 461 |
455 void openEdit_CompassHeading(void) | 462 void openEdit_CompassHeading(void) |
456 { | 463 { |
457 drawCompassHeadingMenu(true); | 464 drawCompassHeadingMenu(false); |
458 } | 465 } |
459 | 466 |
460 | 467 |
461 uint8_t OnAction_CompassHeading (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) | 468 uint8_t OnAction_CompassHeading (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) |
462 { | 469 { |