diff Discovery/Src/t3.c @ 758:b6d8a6fbf4fd

- Colours for scrubber display when time remaining falls below a threshold value - Display negative values when time is up and diving continues; - count down remaining scrubber time only when the dive computer is not set to bailout - after all, there is not much point in counting down time if the diver is not breathing through the scrubber.
author heinrichsweikamp
date Wed, 15 Mar 2023 09:18:07 +0100
parents 92bf7bf9fb8a
children 4abfb8a2a435
line wrap: on
line diff
--- a/Discovery/Src/t3.c	Tue Mar 07 22:14:20 2023 +0100
+++ b/Discovery/Src/t3.c	Wed Mar 15 09:18:07 2023 +0100
@@ -27,6 +27,8 @@
 //////////////////////////////////////////////////////////////////////////////
 
 /* Includes ------------------------------------------------------------------*/
+#include <stdbool.h>
+
 #include "t3.h"
 
 #include "data_exchange_main.h"
@@ -1312,15 +1314,9 @@
                  snprintf(text,TEXTSIZE,"\032\002\f%c",TXT_ScrubTime);
                  GFX_write_string(&FontT42,tXc1,text,0);
 
-            	textpointer = 0;
-                if(settingsGetPointer()->scrubTimerMode == SCRUB_TIMER_MINUTES)
-                {
-                	textpointer += snprintf(&text[textpointer],10,"\020\002%3u'",  pSettings->scrubberData[pSettings->scubberActiveId].TimerCur);
-                }
-                else
-                {
-                	textpointer += snprintf(&text[textpointer],20,"\020\002%u\016\016%%\017", (uint16_t)(pSettings->scrubberData[pSettings->scubberActiveId].TimerCur * 100 / pSettings->scrubberData[pSettings->scubberActiveId].TimerMax));
-                }
+                textpointer = 0;
+                text[textpointer++] = '\002';
+                textpointer += printScrubberText(&text[textpointer], 10, pSettings);
                 GFX_write_string(&FontT105,tXc1,text,1);
             }
         }
@@ -1972,3 +1968,20 @@
 {
     return t3_selection_customview;
 }
+
+int printScrubberText(char *text, size_t size, SSettings *settings)
+{
+    int16_t currentTimerMinutes = settings->scrubberData[settings->scubberActiveId].TimerCur;
+    char colour = '\020';
+    if (currentTimerMinutes <= 0) {
+        colour = '\025';
+    } else if (currentTimerMinutes <= 30) {
+        colour = '\024';
+    }
+
+    if (settings->scrubTimerMode == SCRUB_TIMER_MINUTES || currentTimerMinutes < 0) {
+        return snprintf(text, size, "%c%3i'", colour, currentTimerMinutes);
+    } else {
+        return snprintf(text, size, "%c%u\016\016%%\017", colour, currentTimerMinutes * 100 / settingsGetPointer()->scrubberData[settings->scubberActiveId].TimerMax);
+    }
+}