comparison Discovery/Src/tMenuEditXtra.c @ 774:6169309d6eb9

more menu items for the compass menu: Delete bearing, and reset to land based bearing. I have also re-enabled the real time bearing display in the menu - makes it easier to set the correct bearing. (mikeller)
author heinrichsweikamp
date Wed, 10 May 2023 16:25:39 +0200
parents 6b248bcdbf28
children 45b8f3c2acce
comparison
equal deleted inserted replaced
773:2c243233c999 774:6169309d6eb9
25 /// You should have received a copy of the GNU General Public License 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/>. 26 /// along with this program. If not, see <http://www.gnu.org/licenses/>.
27 ////////////////////////////////////////////////////////////////////////////// 27 //////////////////////////////////////////////////////////////////////////////
28 28
29 /* Includes ------------------------------------------------------------------*/ 29 /* Includes ------------------------------------------------------------------*/
30 #include <stdbool.h>
31
30 #include "tMenuEditXtra.h" 32 #include "tMenuEditXtra.h"
31 33
32 #include "gfx_fonts.h" 34 #include "gfx_fonts.h"
33 #include "simulation.h" 35 #include "simulation.h"
34 #include "timer.h" 36 #include "timer.h"
352 354
353 write_buttonTextline(TXT2BYTE_ButtonBack,TXT2BYTE_ButtonEnter,TXT2BYTE_ButtonNext); 355 write_buttonTextline(TXT2BYTE_ButtonBack,TXT2BYTE_ButtonEnter,TXT2BYTE_ButtonNext);
354 } 356 }
355 #endif 357 #endif
356 358
359
360 static uint8_t OnAction_CompassHeadingClear(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
361 {
362 stateUsedWrite->diveSettings.compassHeading = 0;
363
364 exitMenuEdit_to_Home_with_Menu_Update();
365
366 return EXIT_TO_HOME;
367 }
368
369
370 static uint8_t OnAction_CompassHeadingReset(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
371 {
372 stateUsedWrite->diveSettings.compassHeading = settingsGetPointer()->compassBearing;
373
374 exitMenuEdit_to_Home_with_Menu_Update();
375
376 return EXIT_TO_HOME;
377 }
378
379
380 static void drawCompassHeadingMenu(bool doInitialise)
381 {
382 char text[32];
383 snprintf(text, 32, "\001%c%c", TXT_2BYTE, TXT2BYTE_CompassHeading);
384 write_topline(text);
385
386 uint16_t heading = (uint16_t)stateUsed->lifeData.compass_heading;
387 snprintf(text,32,"\001%03i`",heading);
388 write_label_var(0, 800, ME_Y_LINE1, &FontT54, text);
389
390 if (doInitialise) {
391 snprintf(text, 32, "%c%c", TXT_2BYTE, TXT2BYTE_Set);
392 write_field_button(StMXTRA_CompassHeading, 20, 800, ME_Y_LINE2, &FontT48, text);
393 } else {
394 tMenuEdit_refresh_field(StMXTRA_CompassHeading);
395 }
396
397 bool headingIsSet = stateUsed->diveSettings.compassHeading;
398 snprintf(text, 32, "%s%c%c", makeGrey(!headingIsSet), TXT_2BYTE, TXT2BYTE_Clear);
399 if (headingIsSet) {
400 if (doInitialise) {
401 write_field_button(StMXTRA_CompassHeadingClear, 20, 800, ME_Y_LINE3, &FontT48, text);
402 } else {
403 tMenuEdit_refresh_field(StMXTRA_CompassHeadingClear);
404 }
405 } else {
406 write_label_var(20, 800, ME_Y_LINE3, &FontT48, text);
407 }
408
409 int16_t compassBearing = settingsGetPointer()->compassBearing;
410 bool canSetBearing = compassBearing && compassBearing != stateUsed->diveSettings.compassHeading;
411 snprintf(text, 32, "%s%c%c (%03u`)", makeGrey(!canSetBearing), TXT_2BYTE, TXT2BYTE_Reset, compassBearing);
412 if (canSetBearing) {
413 if (doInitialise) {
414 write_field_button(StMXTRA_CompassHeadingReset, 20, 800, ME_Y_LINE4, &FontT48, text);
415 } else {
416 tMenuEdit_refresh_field(StMXTRA_CompassHeadingReset);
417 }
418 } else {
419 write_label_var(20, 800, ME_Y_LINE4, &FontT48, text);
420 }
421
422 if (doInitialise) {
423 setEvent(StMXTRA_CompassHeading, (uint32_t)OnAction_CompassHeading);
424 setEvent(StMXTRA_CompassHeadingClear, (uint32_t)OnAction_CompassHeadingClear);
425 setEvent(StMXTRA_CompassHeadingReset, (uint32_t)OnAction_CompassHeadingReset);
426 }
427
428 write_buttonTextline(TXT2BYTE_ButtonBack, TXT2BYTE_ButtonEnter, TXT2BYTE_ButtonNext);
429 }
430
431
357 void refresh_CompassHeading(void) 432 void refresh_CompassHeading(void)
358 { 433 {
359 uint16_t heading; 434 drawCompassHeadingMenu(false);
360 char text[32]; 435 }
361 436
362 text[0] = '\001';
363 text[1] = TXT_2BYTE;
364 text[2] = TXT2BYTE_CompassHeading;
365 text[3] = 0;
366 write_topline(text);
367
368 heading = (uint16_t)stateUsed->lifeData.compass_heading;
369 snprintf(text,32,"\001%03i`",heading);
370 write_label_var( 0, 800, ME_Y_LINE1, &FontT54, text);
371
372 tMenuEdit_refresh_field(StMXTRA_CompassHeading);
373 }
374 437
375 void refresh_CO2Data(void) 438 void refresh_CO2Data(void)
376 { 439 {
377 char text[32]; 440 char text[32];
378 441
389 tMenuEdit_refresh_field(StMXTRA_CO2_Sensor_Calib); 452 tMenuEdit_refresh_field(StMXTRA_CO2_Sensor_Calib);
390 } 453 }
391 454
392 void openEdit_CompassHeading(void) 455 void openEdit_CompassHeading(void)
393 { 456 {
394 write_field_button(StMXTRA_CompassHeading,20, 800, ME_Y_LINE4, &FontT48, "Set"); 457 drawCompassHeadingMenu(true);
395 setEvent(StMXTRA_CompassHeading, (uint32_t)OnAction_CompassHeading);
396 } 458 }
397 459
398 460
399 uint8_t OnAction_CompassHeading (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) 461 uint8_t OnAction_CompassHeading (uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
400 { 462 {
401 stateUsedWrite->diveSettings.compassHeading = (uint16_t)stateUsed->lifeData.compass_heading; 463 setCompassHeading((uint16_t)stateUsed->lifeData.compass_heading);
402 exitMenuEdit_to_Home_with_Menu_Update(); 464 exitMenuEdit_to_Home_with_Menu_Update();
403 return EXIT_TO_HOME; 465 return EXIT_TO_HOME;
404 } 466 }
405 467
406 468