diff Discovery/Src/t7.c @ 361:b111fc4250e9 MotionDetection

Pass action to customer vie update function. By intoducing shakes the reason for calling an update may not only be the middle button. To be able to handle positiv and negativ shake events the action is now provided to the update function
author Ideenmodellierer
date Tue, 11 Jun 2019 05:30:09 +0200
parents 3949781096d4
children c18aebb03fed
line wrap: on
line diff
--- a/Discovery/Src/t7.c	Fri May 24 22:01:46 2019 +0200
+++ b/Discovery/Src/t7.c	Tue Jun 11 05:30:09 2019 +0200
@@ -1479,9 +1479,10 @@
             selection_customview = settingsGetPointer()->tX_customViewPrimary;
 }
 
-void t7_change_customview(void)
+void t7_change_customview(uint8_t action)
 {
     const uint8_t *pViews;
+    uint8_t *pStartView,*pCurView, *pLastView;
     _Bool cv_disabled = 0;
 
     if(stateUsed->mode == MODE_DIVE)
@@ -1489,21 +1490,37 @@
     else
         pViews = customviewsSurface;
 
-    while((*pViews != CVIEW_END) && (*pViews != selection_customview))
-        {pViews++;}
-
-    if(*pViews < CVIEW_END)
-        pViews++;
-
-
-    if(*pViews == CVIEW_END)
+    pStartView = pViews;
+    /* set pointer to currently selected view and count number of entries */
+    while((*pViews != CVIEW_END))
+    {
+    	if (*pViews == selection_customview)
+    	{
+    		pCurView = pViews;
+    	}
+    	pViews++;
+    }
+    pLastView = pViews;
+    pViews = pCurView;
+
+    if((action == ACTION_BUTTON_ENTER) || (action == ACTION_SHAKE_POS))
     {
-        if(stateUsed->mode == MODE_DIVE)
-            pViews = customviewsDive;
-        else
-            pViews = customviewsSurface;
+		if(*pViews < CVIEW_END)
+			pViews++;
+
+		if(*pViews == CVIEW_END)
+		{
+			pViews = pStartView;
+		}
     }
-
+    else
+    {
+		pViews--;
+		if(pViews = pStartView)
+		{
+			pViews = pLastView - 1;
+		}
+    }
     if(stateUsed->mode == MODE_DIVE)
     {
         do
@@ -1524,16 +1541,24 @@
             	cv_disabled = 1;
             }
 
-            if(cv_disabled)
+            if(cv_disabled)		/* view is disabled => jump to next view */
             {
-                if(*pViews < CVIEW_END)
-                {
-                    pViews++;
-                }
-                else
-                {
-                    pViews = customviewsDive;
-                }
+            	if((action == ACTION_BUTTON_ENTER) || (action == ACTION_SHAKE_POS))
+            	{
+            		pViews++;
+					if(*pViews == CVIEW_END)
+					{
+						pViews = pStartView;
+					}
+            	}
+            	else
+            	{
+            		pViews--;
+            		if(pViews == pStartView)
+            		{
+            			pViews = pLastView - 1;
+            		}
+            	}
             }
         } while(cv_disabled);
     }
@@ -1570,11 +1595,11 @@
 	pSettings = settingsGetPointer();
 
     if((selection_customview == CVIEW_sensors) &&(stateUsed->diveSettings.ccrOption == 0))
-        t7_change_customview();
+        t7_change_customview(ACTION_BUTTON_ENTER);
     if((selection_customview == CVIEW_sensors_mV) &&(stateUsed->diveSettings.ccrOption == 0))
-        t7_change_customview();
+        t7_change_customview(ACTION_BUTTON_ENTER);
     if((selection_customview == CVIEW_sensors) &&(stateUsed->diveSettings.ccrOption == 0))
-        t7_change_customview();
+        t7_change_customview(ACTION_BUTTON_ENTER);
 
     switch(selection_customview)
     {