diff Discovery/Src/tMenuEditSystem.c @ 805:dd7ce655db26

Adds a simple countdown timer, available as a custom view in surface and dive mode. This can be used to time safety stops, or to prebreathe a CCR (or to boil your breakfast eggs if you are so inclined). The duration of the timer is configurable from 1 second to 9:59 minutes in the System menu. The timer is started by switching to the custom view, and remaining on it until a 10 second delay has elapsed. Once the timer has started the custom view can be changed and the timer will continue running in the background. After the timer has run out 'Finished' will be shown for 10 seconds in the timer custom view, and then automatic switching of custom views (if configured) resumes. In surface mode the dive computer will not go to sleep while the timer is running, and a mini timer will be shown when the timer custom view is not showing. (mikeller)
author heinrichsweikamp
date Mon, 21 Aug 2023 17:20:07 +0200
parents 9c65d226f4f6
children e04d7dd199fb
line wrap: on
line diff
--- a/Discovery/Src/tMenuEditSystem.c	Thu Aug 10 21:35:34 2023 +0200
+++ b/Discovery/Src/tMenuEditSystem.c	Mon Aug 21 17:20:07 2023 +0200
@@ -101,6 +101,87 @@
 
 /* Exported functions --------------------------------------------------------*/
 
+static uint8_t OnAction_Timer(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
+{
+    SSettings *settings = settingsGetPointer();
+    uint8_t digitContentNew;
+    switch (action) {
+    case ACTION_BUTTON_ENTER:
+
+        return digitContent;
+    case ACTION_BUTTON_ENTER_FINAL:
+        {
+            uint32_t timerM;
+            uint32_t timerS;
+            evaluateNewString(editId, &timerM, &timerS, 0, 0);
+            if (timerM > 9) {
+                timerM = 9;
+            }
+            if (timerS > 59) {
+                timerS = 59;
+            }
+
+            uint16_t timerDurationS = 60 * timerM + timerS;
+
+            if (timerDurationS < 1) {
+                timerDurationS = 1;
+            }
+
+            if (timerDurationS != settings->timerDurationS) {
+                settings->timerDurationS = timerDurationS;
+
+                disableTimer();
+
+                tMenuEdit_newInput(editId, settings->timerDurationS / 60, settings->timerDurationS % 60, 0, 0);
+            }
+
+            return EXIT_TO_MENU;
+        }
+    case ACTION_BUTTON_NEXT:
+        digitContentNew = digitContent + 1;
+        if ((blockNumber == 1 && digitNumber == 0 && digitContentNew > '5') || digitContentNew > '9') {
+            digitContentNew = '0';
+        }
+
+        return digitContentNew;
+    case ACTION_BUTTON_BACK:
+        digitContentNew = digitContent - 1;
+        if (digitContentNew < '0') {
+            if (blockNumber == 1 && digitNumber == 0) {
+                digitContentNew = '5';
+            } else {
+                digitContentNew = '9';
+            }
+        }
+
+        return digitContentNew;
+    }
+
+    return EXIT_TO_MENU;
+}
+
+
+static void openEdit_Timer(void)
+{
+    SSettings *settings = settingsGetPointer();
+
+    char text[32];
+    snprintf(text, 32, "\001%c%c", TXT_2BYTE, TXT2BYTE_Timer);
+    write_topline(text);
+
+    uint16_t yPos = ME_Y_LINE_BASE + get_globalState_Menu_Line() * ME_Y_LINE_STEP;
+    snprintf(text, 32, "%c%c", TXT_2BYTE, TXT2BYTE_Timer);
+    write_label_var(30, 299, yPos, &FontT48, text);
+    write_field_udigit(StMSYS_Timer, 300, 392, yPos, &FontT48, "#:##", settings->timerDurationS / 60, settings->timerDurationS % 60, 0, 0);
+    write_label_var(393, 800, yPos, &FontT48, "\016\016 [m:ss]\017");
+
+    write_buttonTextline(TXT2BYTE_ButtonMinus, TXT2BYTE_ButtonEnter, TXT2BYTE_ButtonPlus);
+
+    setEvent(StMSYS_Timer, (uint32_t)OnAction_Timer);
+    startEdit();
+}
+
+
 void openEdit_System(uint8_t line)
 {
     set_globalState_Menu_Line(line);
@@ -115,15 +196,18 @@
             openEdit_DateTime();
         break;
         case 2:
+            openEdit_Timer();
+        break;
+        case 3:
             openEdit_Language();
         break;
-        case 3:
+        case 4:
             openEdit_Design();
         break;
-        case 4:
+        case 5:
             openEdit_Information();
         break;
-        case 5:
+        case 6:
             openEdit_Reset();
         break;
 /*