changeset 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 39ff186b6f98
children 9825dcf50675
files Common/Inc/settings.h Discovery/Inc/t3.h Discovery/Src/settings.c Discovery/Src/t3.c Discovery/Src/t7.c Discovery/Src/tCCR.c Discovery/Src/tMenuEditXtra.c
diffstat 7 files changed, 53 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/Common/Inc/settings.h	Tue Mar 07 22:14:20 2023 +0100
+++ b/Common/Inc/settings.h	Wed Mar 15 09:18:07 2023 +0100
@@ -77,6 +77,7 @@
 #define MAX_VIEWPORT_MODE 		(0x7F)
 
 #define MAX_SCRUBBER_TIME 		(999u)
+#define MIN_SCRUBBER_TIME       -99
 #define MIN_PPO2_SP_CBAR		(40u)
 
 #define PSCR_MAX_O2_DROP		(15u)
@@ -163,7 +164,7 @@
 typedef struct
 {
 	uint16_t TimerMax;
-	uint16_t TimerCur;
+	int16_t TimerCur;
 	RTC_DateTypeDef lastDive;
 } SScrubberData;
 
--- a/Discovery/Inc/t3.h	Tue Mar 07 22:14:20 2023 +0100
+++ b/Discovery/Inc/t3.h	Wed Mar 15 09:18:07 2023 +0100
@@ -31,6 +31,7 @@
 /* Includes ------------------------------------------------------------------*/
 #include "stm32f4xx_hal.h"
 #include "gfx_engine.h"
+#include "settings.h"
 
 /* Exported functions --------------------------------------------------------*/
 void t3_init(void);
@@ -42,4 +43,6 @@
 void t3_set_customview_to_primary(void);
 uint8_t t3_customview_disabled(uint8_t view);
 
+int printScrubberText(char *text, size_t size, SSettings *settings);
+
 #endif /* T3_H */
--- a/Discovery/Src/settings.c	Tue Mar 07 22:14:20 2023 +0100
+++ b/Discovery/Src/settings.c	Wed Mar 15 09:18:07 2023 +0100
@@ -1497,13 +1497,13 @@
     	Settings.scubberActiveId = 0;
     	corrections++;
     }
-    if((Settings.scrubberData[0].TimerMax > MAX_SCRUBBER_TIME) || (Settings.scrubberData[0].TimerCur > MAX_SCRUBBER_TIME))
+    if((Settings.scrubberData[0].TimerMax > MAX_SCRUBBER_TIME) || Settings.scrubberData[0].TimerCur < MIN_SCRUBBER_TIME || (Settings.scrubberData[0].TimerCur > MAX_SCRUBBER_TIME))
     {
     	Settings.scrubberData[0].TimerMax = 0;
     	Settings.scrubberData[0].TimerCur = 0;
     	corrections++;
     }
-    if((Settings.scrubberData[1].TimerMax > MAX_SCRUBBER_TIME) || (Settings.scrubberData[1].TimerCur > MAX_SCRUBBER_TIME))
+    if((Settings.scrubberData[1].TimerMax > MAX_SCRUBBER_TIME) || Settings.scrubberData[1].TimerCur < MIN_SCRUBBER_TIME || (Settings.scrubberData[1].TimerCur > MAX_SCRUBBER_TIME))
     {
     	Settings.scrubberData[1].TimerMax = 0;
     	Settings.scrubberData[1].TimerCur = 0;
--- 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);
+    }
+}
--- a/Discovery/Src/t7.c	Tue Mar 07 22:14:20 2023 +0100
+++ b/Discovery/Src/t7.c	Wed Mar 15 09:18:07 2023 +0100
@@ -2919,14 +2919,9 @@
     case LLC_ScrubberTime:
     	tinyHeaderFont = 1;
         headerText[2] = TXT_ScrubTime;
-        if(settingsGetPointer()->scrubTimerMode == SCRUB_TIMER_MINUTES)
-        {
-        	snprintf(text,TEXTSIZE,"\020%3u'",pSettings->scrubberData[pSettings->scubberActiveId].TimerCur);
-        }
-        else
-        {
-        	snprintf(text,TEXTSIZE,"\020%u\016\016%%\017", (pSettings->scrubberData[pSettings->scubberActiveId].TimerCur * 100 / settingsGetPointer()->scrubberData[pSettings->scubberActiveId].TimerMax));
-        }
+
+        printScrubberText(text, TEXTSIZE, pSettings);
+
 		break;
 #ifdef ENABLE_PSCR_MODE
     case LCC_SimPpo2:
@@ -3676,14 +3671,8 @@
         text[textpointer++] = '\n';
         text[textpointer++] = '\r';
         text[textpointer++] = '\t';
-        if(settingsGetPointer()->scrubTimerMode == SCRUB_TIMER_MINUTES)
-        {
-        	textpointer += snprintf(&text[textpointer],10,"\020%3u'", pSettings->scrubberData[pSettings->scubberActiveId].TimerCur);
-        }
-        else
-        {
-        	textpointer += snprintf(&text[textpointer],10,"\020%u\016\016%%\017", (pSettings->scrubberData[pSettings->scubberActiveId].TimerCur * 100 / pSettings->scrubberData[pSettings->scubberActiveId].TimerMax));
-        }
+
+        textpointer += printScrubberText(&text[textpointer], 10, pSettings);
     }
     text[textpointer++] = 0;
     t7_colorscheme_mod(text);
--- a/Discovery/Src/tCCR.c	Tue Mar 07 22:14:20 2023 +0100
+++ b/Discovery/Src/tCCR.c	Wed Mar 15 09:18:07 2023 +0100
@@ -337,14 +337,14 @@
 		}
 	}
 
-	/* decrease scrubber timer only in real dive mode */
-    if((pSettings->scrubTimerMode != SCRUB_TIMER_OFF) && (isLoopMode(pSettings->dive_mode)) && (stateUsed->mode == MODE_DIVE)) // && (stateUsed == stateRealGetPointer()))
+	/* decrease scrubber timer only in real dive mode, and if we are not bailed out */
+    if((pSettings->scrubTimerMode != SCRUB_TIMER_OFF) && (isLoopMode(pSettings->dive_mode)) && (stateUsed->mode == MODE_DIVE) && isLoopMode(stateUsed->diveSettings.diveMode)) // && (stateUsed == stateRealGetPointer()))
     {
     	ScrubberTimeoutCount++;
     	if(ScrubberTimeoutCount >= 600)		/* resolution is minutes */
     	{
     		ScrubberTimeoutCount = 0;
-    		if(pSettings->scrubberData[pSettings->scubberActiveId].TimerCur > 0)
+    		if(pSettings->scrubberData[pSettings->scubberActiveId].TimerCur > MIN_SCRUBBER_TIME)
     		{
     			pSettings->scrubberData[pSettings->scubberActiveId].TimerCur--;
     		}
--- a/Discovery/Src/tMenuEditXtra.c	Tue Mar 07 22:14:20 2023 +0100
+++ b/Discovery/Src/tMenuEditXtra.c	Wed Mar 15 09:18:07 2023 +0100
@@ -204,6 +204,19 @@
 }
 
 
+static void printScrubberResetText(char *text, SSettings *settings)
+{
+    int16_t currentTimerMinutes = settings->scrubberData[settings->scubberActiveId].TimerCur;
+    char colour = '\020';
+    if (currentTimerMinutes <= 0) {
+        colour = '\025';
+    } else if (currentTimerMinutes <= 30) {
+        colour = '\024';
+    }
+    snprintf(text, 32, "%c\002%c%03i\016\016 %c\017", TXT_ScrubTimeReset, colour, currentTimerMinutes, TXT_Minutes);
+}
+
+
 static void openEdit_Scrubber(void)
 {
 	char text[32];
@@ -235,12 +248,7 @@
 
     write_field_udigit(StMXTRA_ScrubTimer_Max,	 610, 780, ME_Y_LINE2,  &FontT48, text,localScrubTimer, 0, 0, 0);
 
-    snprintf(&text[0], 32,\
-                     "%c\002%03u\016\016 %c\017"
-                     ,TXT_ScrubTimeReset
-                     ,pSettings->scrubberData[pSettings->scubberActiveId].TimerCur
-                     ,TXT_Minutes);
-
+    printScrubberResetText(text, pSettings);
     write_field_button(StMXTRA_ScrubTimer_Reset, 20, 780, ME_Y_LINE3,  &FontT48, text);
 
     if(pSettings->scrubberData[pSettings->scubberActiveId].lastDive.WeekDay != 0)
@@ -420,11 +428,7 @@
     snprintf(&text[0], 32,"%c \002#%d",TXT_ScrubTime,pSettings->scubberActiveId);
     tMenuEdit_newButtonText(StMXTRA_ScrubTimer, text);
 
-    snprintf(&text[0], 32,\
-                     "%c\002%03u\016\016 %c\017"
-                     ,TXT_ScrubTimeReset
-                     ,pSettings->scrubberData[pSettings->scubberActiveId].TimerCur
-                     ,TXT_Minutes);
+    printScrubberResetText(text, pSettings);
     tMenuEdit_newButtonText(StMXTRA_ScrubTimer_Reset, text);
 
     tMenuEdit_newInput(StMXTRA_ScrubTimer_Max, pSettings->scrubberData[pSettings->scubberActiveId].TimerMax,  0,  0, 0);
@@ -495,12 +499,7 @@
     pSettings->scrubberData[pSettings->scubberActiveId].TimerCur = pSettings->scrubberData[pSettings->scubberActiveId].TimerMax;
     pSettings->scrubberData[pSettings->scubberActiveId].lastDive.WeekDay = 0;	/* invalidate date */
 
-    snprintf(&text[0], 32,\
-                     "%c\002%03u\016\016 %c\017"
-                     ,TXT_ScrubTimeReset
-                     ,pSettings->scrubberData[pSettings->scubberActiveId].TimerCur
-                     ,TXT_Minutes);
-
+    printScrubberResetText(text, pSettings);
     tMenuEdit_newButtonText(StMXTRA_ScrubTimer_Reset, text);
 
    	snprintf(&text[0], 32,"%c%c\002   --.--.--", TXT_2BYTE, TXT2BYTE_SimDiveTime);