diff Discovery/Src/tMenuEditSystem.c @ 949:c6b858f2e025 Evo_2_23 tip

GNSS UTC in Date-Time menu: The UTC time provided by the gnss module is not shown in the date-time settings menu. If a valid time signal is available then the OSTC RTC may be set to it by selecting the UTC menu entry. The time zone has to be selected manually. This is possible using a separate edit line.
author Ideenmodellierer
date Sun, 22 Dec 2024 21:19:21 +0100
parents 44599695df41
children
line wrap: on
line diff
--- a/Discovery/Src/tMenuEditSystem.c	Sun Dec 22 21:15:05 2024 +0100
+++ b/Discovery/Src/tMenuEditSystem.c	Sun Dec 22 21:19:21 2024 +0100
@@ -66,6 +66,8 @@
 uint8_t OnAction_MMDDYY				(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
 uint8_t OnAction_YYMMDD				(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
 uint8_t OnAction_DST					(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
+uint8_t OnAction_UTC				(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
+uint8_t OnAction_SetGnss			(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
 uint8_t OnAction_English			(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
 uint8_t OnAction_German				(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
 uint8_t OnAction_French				(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action);
@@ -235,15 +237,104 @@
 /* Private functions ---------------------------------------------------------*/
 
 
+void refresh_DateTime()
+{
+    RTC_DateTypeDef Sdate;
+    RTC_TimeTypeDef Stime;
+    uint8_t day,month,year,hour,minute;
+    char text[32];
+    char formatStr[20];
+    SSettings *pSettings;
+    const SFirmwareData *pFirmwareInfo;
+#if defined ENABLE_GNSS_SUPPORT || defined ENABLE_GPIO_V2
+    uint8_t localHours = 0;
+    uint8_t localMinutes = 0;
+#endif
+    pFirmwareInfo = firmwareDataGetPointer();
+    const SDiveState * pStateReal = stateRealGetPointer();
+
+    pSettings = settingsGetPointer();
+
+    translateDate(pStateReal->lifeData.dateBinaryFormat, &Sdate);
+    translateTime(pStateReal->lifeData.timeBinaryFormat, &Stime);
+    year = Sdate.Year;
+    month = Sdate.Month;
+    day = Sdate.Date;
+    hour = Stime.Hours;
+    minute= Stime.Minutes;
+
+    if(year < pFirmwareInfo->release_year)
+        year = pFirmwareInfo->release_year;
+
+    if(month < 1)
+        month = 1;
+
+    if(day < 1)
+        day = 1;
+
+    getStringOfFormat_DDMMYY(formatStr, 20);
+
+    text[0] = '\001';
+    text[1] = TXT_DateAndTime;
+    text[2] = 0;
+
+    write_topline(text);
+
+    write_label_fix(  20, 340, ME_Y_LINE1, &FontT42, TXT_TimeConfig);
+    write_label_fix(  20, 340, ME_Y_LINE2, &FontT42, TXT_Format);
+    write_label_fix(  20, 340, ME_Y_LINE3, &FontT42, TXT_DateConfig);
+    write_label_fix(  20, 790, ME_Y_LINE4, &FontT42, TXT_Format);
+#if defined ENABLE_GNSS_SUPPORT || defined ENABLE_GPIO_V2
+    write_label_var(  20, 340, ME_Y_LINE5, &FontT42, "GNSS");
+    snprintf(text, 32, "%c%c", TXT_2BYTE, TXT2BYTE_TIMEZONE);
+    write_label_var(  20, 340, ME_Y_LINE6, &FontT42, text);
+#endif
+
+
+    tMenuEdit_newInput(StMSYS1_Time, hour, minute, 0, 0);
+    tMenuEdit_set_on_off(StMSYS1_12HR, pSettings->amPMTime);
+
+    switch(pSettings->date_format)
+    {
+    	default:
+    	case DDMMYY:  tMenuEdit_newInput(StMSYS1_Date, day, month, year, 0);
+    		break;
+    	case MMDDYY:  tMenuEdit_newInput(StMSYS1_Date, month, day, year, 0);
+    		break;
+    	case YYMMDD:  tMenuEdit_newInput(StMSYS1_Date, year, month, day, 0);
+    		break;
+    }
+    tMenuEdit_newButtonText(StMSYS1_FORMAT, formatStr);
+
+#if defined ENABLE_GNSS_SUPPORT || defined ENABLE_GPIO_V2
+    if(pStateReal->lifeData.gnssData.alive & GNSS_ALIVE_STATE_TIME)
+    {
+        convertUTCToLocal(pStateReal->lifeData.gnssData.DateTime.hour, pStateReal->lifeData.gnssData.DateTime.min, &localHours, &localMinutes);
+        convertStringOfDate_DDMMYY(formatStr, 20, pStateReal->lifeData.gnssData.DateTime.day
+        										, pStateReal->lifeData.gnssData.DateTime.month
+    											, pStateReal->lifeData.gnssData.DateTime.year);
+        snprintf(text, 32, "%02d:%02d - %s", localHours, localMinutes, formatStr);
+        tMenuEdit_newButtonText(StMSYS1_GNSSDT, text);
+    }
+    else
+    {
+    	snprintf(text, 32, "--:--");
+    	write_label_var(  320, 790, ME_Y_LINE5, &FontT42, text);
+    }
+    tMenuEdit_newInput(StMSYS1_ZONE, pSettings->timeZone.hours, pSettings->timeZone.minutes, 0, 0);
+#endif
+    write_buttonTextline(TXT2BYTE_ButtonBack,TXT2BYTE_ButtonEnter,TXT2BYTE_ButtonNext);
+}
 void openEdit_DateTime(void)
 {
     RTC_DateTypeDef Sdate;
     RTC_TimeTypeDef Stime;
     uint8_t day,month,year,hour,minute;
     char text[32];
-    char formatStr[10];
+    char formatStr[20];
     SSettings *pSettings;
     const SFirmwareData *pFirmwareInfo;
+
     pFirmwareInfo = firmwareDataGetPointer();
     const SDiveState * pStateReal = stateRealGetPointer();
 
@@ -269,18 +360,7 @@
     if(day < 1)
         day = 1;
 
-//	daylightsaving = Stime.DayLightSaving;
-
-    switch(pSettings->date_format)
-    {
-    	default:
-    	case DDMMYY: snprintf(formatStr,10,"DDMMYY");
-    		break;
-    	case MMDDYY: snprintf(formatStr,10,"MMDDYY");
-    		break;
-    	case YYMMDD: snprintf(formatStr,10,"YYMMDD");
-    	    break;
-    };
+    getStringOfFormat_DDMMYY(formatStr, 20);
 
     text[0] = '\001';
     text[1] = TXT_DateAndTime;
@@ -292,6 +372,11 @@
     write_label_fix(  20, 340, ME_Y_LINE2, &FontT42, TXT_Format);
     write_label_fix(  20, 340, ME_Y_LINE3, &FontT42, TXT_DateConfig);
     write_label_fix(  20, 790, ME_Y_LINE4, &FontT42, TXT_Format);
+#if defined ENABLE_GNSS_SUPPORT || defined ENABLE_GPIO_V2
+    write_label_var(  20, 340, ME_Y_LINE5, &FontT42, "GNSS");
+    snprintf(text, 32, "%c%c", TXT_2BYTE, TXT2BYTE_TIMEZONE);
+    write_label_var(  20, 340, ME_Y_LINE6, &FontT42, text);
+#endif
 
     write_field_2digit(StMSYS1_Time,		320, 780, ME_Y_LINE1,  &FontT48, "##:##", (uint32_t)hour, (uint32_t)minute, 0, 0);
     write_field_on_off(StMSYS1_12HR,		320, 790, ME_Y_LINE2,  &FontT48, "12 HR", pSettings->amPMTime);
@@ -307,15 +392,22 @@
     		break;
     }
 
+    write_field_button(StMSYS1_FORMAT, 320, 790, ME_Y_LINE4,  &FontT48, formatStr);
 
-    write_field_button(StMSYS1_FORMAT, 320, 790, ME_Y_LINE4,  &FontT48, formatStr);
+#if defined ENABLE_GNSS_SUPPORT || defined ENABLE_GPIO_V2
+	snprintf(text, 32, "--:--");
+	write_field_button(StMSYS1_GNSSDT, 320, 790, ME_Y_LINE5,  &FontT48, text);
+    write_field_sdigit(StMSYS1_ZONE, 320, 780, ME_Y_LINE6,  &FontT48, "UTC: ###:###", pSettings->timeZone.hours, pSettings->timeZone.minutes,0,0);
+#endif
 
     setEvent(StMSYS1_Date, 		(uint32_t)OnAction_Date);
     setEvent(StMSYS1_Time, 		(uint32_t)OnAction_Time);
     setEvent(StMSYS1_12HR,      (uint32_t)OnAction_12HR);
     setEvent(StMSYS1_FORMAT,	(uint32_t)OnAction_Format);
-//	setEvent(StMSYS1_DST,			(uint32_t)OnAction_DST);
-
+#if defined ENABLE_GNSS_SUPPORT || defined ENABLE_GPIO_V2
+   	setEvent(StMSYS1_GNSSDT, (uint32_t)OnAction_SetGnss);
+	setEvent(StMSYS1_ZONE,		(uint32_t)OnAction_UTC);
+#endif
     write_buttonTextline(TXT2BYTE_ButtonBack,TXT2BYTE_ButtonEnter,TXT2BYTE_ButtonNext);
 }
 
@@ -552,6 +644,32 @@
     return UNSPECIFIC_RETURN;
 }
 
+uint8_t OnAction_SetGnss(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
+{
+    RTC_DateTypeDef sdatestructure;
+    RTC_TimeTypeDef stimestructure;
+    uint8_t localHours = 0;
+    uint8_t localMinutes = 0;
+
+    const SDiveState * pStateReal = stateRealGetPointer();
+
+    if(pStateReal->lifeData.gnssData.alive & GNSS_ALIVE_STATE_TIME)
+    {
+        convertUTCToLocal(pStateReal->lifeData.gnssData.DateTime.hour, pStateReal->lifeData.gnssData.DateTime.min, &localHours, &localMinutes);
+        stimestructure.Hours = localHours;
+        stimestructure.Minutes = localMinutes;
+        stimestructure.Seconds = 0;
+        setTime(stimestructure);
+
+        sdatestructure.Date = pStateReal->lifeData.gnssData.DateTime.day;
+        sdatestructure.Month = pStateReal->lifeData.gnssData.DateTime.month;
+        sdatestructure.Year = pStateReal->lifeData.gnssData.DateTime.year;
+        setWeekday(&sdatestructure);
+        setDate(sdatestructure);
+    }
+    return UNSPECIFIC_RETURN;
+}
+
 void openEdit_DateFormat(void)
 {
     char text[32];
@@ -649,6 +767,81 @@
     return UNSPECIFIC_RETURN;
 }
 
+uint8_t OnAction_UTC(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
+{
+    SSettings *settings = settingsGetPointer();
+    const SDiveState * pStateReal = stateRealGetPointer();
+    int32_t utcHour;
+    uint32_t utcMinutes;
+    uint8_t digitContentNew;
+    uint8_t localHours = 0;
+    uint8_t localMinutes = 0;
+    char text[32];
+    char timeStr[20];
+
+    switch (action) {
+    case ACTION_BUTTON_ENTER:
+
+        return digitContent;
+    case ACTION_BUTTON_ENTER_FINAL:
+        {
+
+            evaluateNewString(editId, (uint32_t *)&utcHour, &utcMinutes, NULL, NULL);
+
+            if (utcHour > 14) {
+            	utcHour = 14;
+            } else if (utcHour < -12) {
+            	utcHour = -12;
+            }
+
+            if (utcMinutes % 15 != 0)
+            {
+            	utcMinutes = (utcMinutes / 15) * 15;
+            }
+            if(utcMinutes > 45)
+            {
+            	utcMinutes = 45;
+            } else if (utcMinutes < 0) {
+            	utcMinutes = 0;
+            }
+            settings->timeZone.hours = utcHour;
+            settings->timeZone.minutes = utcMinutes;
+
+            tMenuEdit_newInput(editId, ((input_u)utcHour).uint32, utcMinutes, 0, 0);
+            convertUTCToLocal(pStateReal->lifeData.gnssData.DateTime.hour, pStateReal->lifeData.gnssData.DateTime.min, &localHours, &localMinutes);
+            convertStringOfDate_DDMMYY(timeStr, 20, pStateReal->lifeData.gnssData.DateTime.day
+            										, pStateReal->lifeData.gnssData.DateTime.month
+        											, pStateReal->lifeData.gnssData.DateTime.year);
+            snprintf(text, 32, "%2d:%2d - %s", localHours, localMinutes, timeStr);
+            tMenuEdit_newButtonText(StMSYS1_GNSSDT, text);
+        }
+
+        break;
+    case ACTION_BUTTON_NEXT:
+        if ((blockNumber == 0) && (digitNumber == 0)) {
+            digitContentNew = togglePlusMinus(digitContent);
+        } else {
+            digitContentNew = digitContent + 1;
+            if (digitContentNew > '9') {
+                digitContentNew = '0';
+            }
+        }
+
+        return digitContentNew;
+    case ACTION_BUTTON_BACK:
+    	if ((blockNumber == 0) && (digitNumber == 0)) {
+            digitContentNew = togglePlusMinus(digitContent);
+        } else {
+            digitContentNew = digitContent - 1;
+            if (digitContentNew < '0') {
+                digitContentNew = '9';
+            }
+        }
+        return digitContentNew;
+    }
+    return UNSPECIFIC_RETURN;
+}
+
 
 uint8_t OnAction_DST(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action)
 {