# HG changeset patch
# User Ideenmodellierer
# Date 1693757029 -7200
# Node ID ce8f71217f456aa6ca98a1c54f60657ec32691a4
# Parent  26ae9e8f24fdb5621c341c8644f32605b2250a95
Bugfix CustomView selection during dive mode:
The CustomView selection during dive mode was limited to two pages, while meanwhile three are needed to show all options. The problem did not showup in surface mode selection. Rootcause was a static definition instead of the dynamic one used in surface mode. In addition with every page shift a new page was created which might cause display errors after some times. To solve this the pages are now updated instead of rebuilding the pages.

diff -r 26ae9e8f24fd -r ce8f71217f45 Discovery/Inc/tMenu.h
--- a/Discovery/Inc/tMenu.h	Sun Sep 03 17:58:12 2023 +0200
+++ b/Discovery/Inc/tMenu.h	Sun Sep 03 18:03:49 2023 +0200
@@ -87,6 +87,7 @@
 
 void selectPage(uint32_t selection);
 
+void resetLineMask(uint32_t lineId);
 void disableLine(uint32_t lineId);
 void enableLine(uint32_t lineId);
 
diff -r 26ae9e8f24fd -r ce8f71217f45 Discovery/Inc/tStructure.h
--- a/Discovery/Inc/tStructure.h	Sun Sep 03 17:58:12 2023 +0200
+++ b/Discovery/Inc/tStructure.h	Sun Sep 03 18:03:49 2023 +0200
@@ -340,6 +340,13 @@
 #define StMSYS5_ResetBluetooth	_MB(2,8,6,12,0)
 #define StMSYS5_SetSampleIndx   _MB(2,8,6,13,0)
 
+#define StMSYS_Custom0			_MB(2,8,1,0,0)
+#define StMSYS_Custom1			_MB(2,8,2,0,0)
+#define StMSYS_Custom2			_MB(2,8,3,0,0)
+#define StMSYS_Custom3			_MB(2,8,4,0,0)
+#define StMSYS_Custom4			_MB(2,8,5,0,0)
+#define StMSYS_Custom5			_MB(2,8,6,0,0)
+
  /* PAGE 9 */
 
  # define StMCustom 	_MB(2,9,0,0,0)
diff -r 26ae9e8f24fd -r ce8f71217f45 Discovery/Src/tMenu.c
--- a/Discovery/Src/tMenu.c	Sun Sep 03 17:58:12 2023 +0200
+++ b/Discovery/Src/tMenu.c	Sun Sep 03 18:03:49 2023 +0200
@@ -252,6 +252,15 @@
 	}
 }
 
+void resetLineMask(uint32_t lineId)
+{
+	SStateList idList;
+	get_idSpecificStateList(lineId, &idList);
+	if(idList.page < MAXPAGES)
+	{
+		menu.disableLineMask[idList.page] = 0;
+	}
+}
 void enableLine(uint32_t lineId)
 {
 	SStateList idList;
@@ -480,9 +489,13 @@
     if(line == 0)
         line = 1;
 
-    if(menu.disableLineMask[page] & ( 1 << line))
+    while(menu.disableLineMask[page] & ( 1 << line))
     {
     	line++;
+    	if(line > menu.linesAvailableForPage[page])
+    	{
+    	    line = 1;
+    	}
     }
 
     if(line > menu.linesAvailableForPage[page])
@@ -712,6 +725,11 @@
         tMSP_refresh(text, &tabPosition, subtext);
         update_content_with_new_frame(page, text, tabPosition, subtext);
         break;
+    case StMSYS:
+    	tMSystem_refresh(0, text, &tabPosition, NULL);
+    	update_content_with_new_frame(page, text, tabPosition, subtext);
+    	break;
+
     default:
         break;
     }
diff -r 26ae9e8f24fd -r ce8f71217f45 Discovery/Src/tMenuEditCustom.c
--- a/Discovery/Src/tMenuEditCustom.c	Sun Sep 03 17:58:12 2023 +0200
+++ b/Discovery/Src/tMenuEditCustom.c	Sun Sep 03 18:03:49 2023 +0200
@@ -44,7 +44,6 @@
 
 
 #define CV_PER_PAGE  		(5u)	/* number of cv selections shown at one page */
-#define CV_SUBPAGE_MAX		(2u)	/* max number of customer view selection pages */
 #define MAX_BACKLIGHT_BOOST (2u)	/* max number of backlight levels which may be increased during focus state */
 
 #define MAX_FOCUS_LIMITER	(2u)	/* max number for reducing the spot used for focus detection */
@@ -930,22 +929,19 @@
 {
 	static uint8_t customviewsSubpage = 0;
 	SSettings *pSettings = settingsGetPointer();
-	char text[MAX_PAGE_TEXTSIZE];
-	uint16_t tabPosition;
-	uint32_t id;
 
+	customviewsSubpageMax = (tHome_getNumberOfAvailableCVs(cv_changelist) / CV_PER_PAGE) + 1;
 
 	if((line == 6) || (cv_changelist[customviewsSubpage * 5 + line-1] == CVIEW_END))		/* select next set of views */
 	{
 		customviewsSubpage++;
-		if(customviewsSubpage == CV_SUBPAGE_MAX)
+		if(customviewsSubpage == customviewsSubpageMax)
 		{
 			customviewsSubpage = 0;
 		}
 		set_CustomsviewsSubpage(customviewsSubpage);
 		/* rebuild the selection page with the next set of customer views */
-		id = tMSystem_refresh(0, text, &tabPosition, NULL);
-		tM_build_page(id, text, tabPosition, NULL);
+		updateSpecificMenu(StMSYS);
 		openMenu(0);
 	}
 	else
diff -r 26ae9e8f24fd -r ce8f71217f45 Discovery/Src/tMenuSystem.c
--- a/Discovery/Src/tMenuSystem.c	Sun Sep 03 17:58:12 2023 +0200
+++ b/Discovery/Src/tMenuSystem.c	Sun Sep 03 18:03:49 2023 +0200
@@ -59,6 +59,8 @@
     *tab = 300;
     *subtext = 0;
 
+    resetLineMask(StMSYS);
+
     // dive mode
     if(actual_menu_content != MENU_SURFACE)
     {
@@ -80,17 +82,34 @@
 					TXT_2BYTE, customview_TXT2BYTE_helper(id));
         	}
         }
-        text[textPointer++] = TXT_2BYTE;
-        text[textPointer++] = TXT2BYTE_ButtonNext;
-        text[textPointer] = 0;
 
         for(;i<5;i++)	/* clear empty lines in case menu shows less than 5 entries */
         {
         	text[textPointer++]='\n';
         	text[textPointer++]='\r';
         	text[textPointer] = 0;
+        	switch(i)
+			{
+        		case 0:	disableLine(StMSYS_Custom0);
+        			break;
+        		case 1:	disableLine(StMSYS_Custom1);
+        		    break;
+        		case 2:	disableLine(StMSYS_Custom2);
+        			break;
+        		case 3:	disableLine(StMSYS_Custom3);
+        		    break;
+        		case 4:	disableLine(StMSYS_Custom4);
+        		    break;
+        		default:
+        		case 5:	disableLine(StMSYS_Custom5);
+        		    break;
+			}
         }
 
+        text[textPointer++] = TXT_2BYTE;
+        text[textPointer++] = TXT2BYTE_ButtonNext;
+        text[textPointer] = 0;
+
         return StMSYS;
     }