changeset 610:ae7f8333c900

Added access to logbook marker data: In previous version event data could only be stored in memory but read back and usage in the OSTC itself was not supported. After the events like a marker set by the diver may be retrieved from the log. Added visualization of markers to T3_Profile view
author Ideenmodellierer
date Thu, 14 Jan 2021 20:38:28 +0100
parents 1b243c6c7067
children 916998f90e39
files Discovery/Inc/logbook.h Discovery/Inc/logbook_miniLive.h Discovery/Src/logbook.c Discovery/Src/logbook_miniLive.c Discovery/Src/show_logbook.c Discovery/Src/t3.c
diffstat 6 files changed, 149 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/Discovery/Inc/logbook.h	Thu Jan 14 19:17:28 2021 +0100
+++ b/Discovery/Inc/logbook.h	Thu Jan 14 20:38:28 2021 +0100
@@ -212,7 +212,7 @@
 uint8_t logbook_getHeader(uint8_t StepBackwards,SLogbookHeader* pLogbookHeader);
 uint16_t logbook_readSampleData(uint8_t StepBackwards, uint16_t length,uint16_t* depth, uint8_t*  gasid, int16_t* temperature, uint16_t* ppo2,
 							    uint16_t* setpoint, uint16_t* sensor1, uint16_t* sensor2, uint16_t* sensor3, uint16_t* cns, uint8_t* bailout,
-								uint16_t* decostopDepth, uint16_t* tank);
+								uint16_t* decostopDepth, uint16_t* tank, uint8_t* event);
 void logbook_test(void);
 void logbook_InitAndWrite(const SDiveState* pStateReal);
 void logbook_recover_brokenlog(uint8_t headerId);
--- a/Discovery/Inc/logbook_miniLive.h	Thu Jan 14 19:17:28 2021 +0100
+++ b/Discovery/Inc/logbook_miniLive.h	Thu Jan 14 20:38:28 2021 +0100
@@ -40,7 +40,7 @@
 uint16_t* getMiniLiveDecoPointerToData(void);
 uint16_t getMiniLiveReplayLength(void);
 uint8_t prepareReplayLog(uint8_t StepBackwards);
-uint8_t getReplayInfo(uint16_t** pReplayData, uint16_t* DataLength, uint16_t* MaxDepth, uint16_t* diveMinutes);
+uint8_t getReplayInfo(uint16_t** pReplayData, uint8_t** pReplayMarker, uint16_t* DataLength, uint16_t* MaxDepth, uint16_t* diveMinutes);
 uint16_t getReplayDataResolution(void);
 uint16_t getReplayOffset(void);
 
--- a/Discovery/Src/logbook.c	Thu Jan 14 19:17:28 2021 +0100
+++ b/Discovery/Src/logbook.c	Thu Jan 14 20:38:28 2021 +0100
@@ -679,7 +679,7 @@
   * @return bytes read / 0 = reading Error
   */
 static uint16_t readSample(int32_t* depth, int16_t * gasid, int16_t* setpoint_cbar, int32_t* temperature, int32_t* sensor1, int32_t* sensor2,
-						   int32_t* sensor3, int32_t* cns, SManualGas* manualGas, int16_t* bailout, int16_t* decostopDepth, uint16_t* tank)
+						   int32_t* sensor3, int32_t* cns, SManualGas* manualGas, int16_t* bailout, int16_t* decostopDepth, uint16_t* tank, uint8_t* event)
 {
 	int length = 0;
 	_Bool bEvent = 0;
@@ -738,32 +738,37 @@
 
 			length--;
 
+			/* marker */
+			if(eventByte1.ub.bit1 && eventByte1.ub.bit2 && event != NULL)
+			{
+				*event = 1;
+			}
+
 			//second event byte
 			if(eventByte1.ub.bit7)
-      {
-        ext_flash_read_next_sample_part( &eventByte2.uw, 1);
-        bytesRead ++;
-        length--;
-      }
+			{
+				ext_flash_read_next_sample_part( &eventByte2.uw, 1);
+				bytesRead ++;
+				length--;
+			}
 			else
 			{
 				eventByte2.uw = 0;
 			}
 		
 			//manual Gas Set
-      if( eventByte1.ub.bit4)
+			if( eventByte1.ub.bit4)
 			{
           //Evaluate manual Gas
-					ext_flash_read_next_sample_part( (uint8_t*)&tempU8, 1);
-					bytesRead +=1;
-					length -= 1;
-           manualGas->percentageO2 = tempU8;
-          ext_flash_read_next_sample_part( (uint8_t*)&tempU8, 1);
-					bytesRead +=1;
-					length -= 1;
-          manualGas->percentageHe = tempU8;
-					if(gasid)
-							*gasid = 0;
+				ext_flash_read_next_sample_part( (uint8_t*)&tempU8, 1);
+				bytesRead +=1;
+				length -= 1;
+				manualGas->percentageO2 = tempU8;
+				ext_flash_read_next_sample_part( (uint8_t*)&tempU8, 1);
+				bytesRead +=1;
+				length -= 1;
+				manualGas->percentageHe = tempU8;
+				if(gasid) *gasid = 0;
 			}
 			//gas change
 			if( eventByte1.ub.bit5)
@@ -944,7 +949,7 @@
   */
 uint16_t logbook_readSampleData(uint8_t StepBackwards, uint16_t length,uint16_t* depth, uint8_t*  gasid, int16_t* temperature, uint16_t* ppo2,
 							    uint16_t* setpoint, uint16_t* sensor1, uint16_t* sensor2, uint16_t* sensor3, uint16_t* cns, uint8_t* bailout,
-								uint16_t* decostopDepth, uint16_t* tank)
+								uint16_t* decostopDepth, uint16_t* tank, uint8_t* event)
 {
      //Test read
     //SLogbookHeader header;
@@ -980,6 +985,7 @@
 	int16_t decostepDepthLast = 0;
 	uint16_t tankVal = 0;
 	uint32_t small_profileLength = 0;
+	uint8_t eventdata;
 
      SManualGas manualGasVal;
      SManualGas manualGasLast;
@@ -1060,7 +1066,7 @@
 				ext_flash_set_entry_point();
 				divisorBackup = divisor;
 				retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal,
-									&bailoutVal, &decostepDepthVal, &tankVal);
+									&bailoutVal, &decostepDepthVal, &tankVal, &eventdata);
 
 				if(retVal == 0)
 				{
@@ -1068,7 +1074,7 @@
 						ext_flash_reopen_read_sample_at_entry_point();
 						divisor = divisorBackup;
 						retVal = readSample(&depthVal,&gasidVal,&setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal,
-											&manualGasVal, &bailoutVal, &decostepDepthVal, &tankVal);
+											&manualGasVal, &bailoutVal, &decostepDepthVal, &tankVal, &eventdata);
 
 						if(retVal == 0)
 								break;
@@ -1188,6 +1194,12 @@
 						sensor3[iNum] = (sensor3Val / 0xFFFF) & 0xFF;
 					iNum++;
 					counter = 0;
+
+					if(event)
+					{
+						event[iNum] = eventdata;
+						eventdata = 0;
+					}
 				}
 		}
 	}
@@ -1778,20 +1790,20 @@
 
         ext_flash_set_entry_point();
         divisorBackup = divisor;
-				retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, &bailoutVal, NULL, NULL);
+				retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, &bailoutVal, NULL, NULL, NULL);
         if(retVal == 0)
         {
           //Error try to read again!!!
           ext_flash_reopen_read_sample_at_entry_point();
           divisor = divisorBackup;
-					retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, &bailoutVal, NULL, NULL);
+					retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, &bailoutVal, NULL, NULL, NULL);
 
           if(retVal == 0)
           {
               //Error try to read again!!!
               ext_flash_reopen_read_sample_at_entry_point();
               divisor = divisorBackup;
-							retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, &bailoutVal, NULL, NULL);
+							retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, &bailoutVal, NULL, NULL, NULL);
 
               if(retVal == 0)
               {
--- a/Discovery/Src/logbook_miniLive.c	Thu Jan 14 19:17:28 2021 +0100
+++ b/Discovery/Src/logbook_miniLive.c	Thu Jan 14 20:38:28 2021 +0100
@@ -44,6 +44,7 @@
 /* Replay Block data storage */
 #define DEPTH_DATA_LENGTH	(1800u)				/* Resolution: 1 hours dive, sampling every 2 seconds */
 uint16_t ReplayDepthData[DEPTH_DATA_LENGTH];
+uint8_t ReplayMarkerData[DEPTH_DATA_LENGTH];
 uint16_t liveDepthData[DEPTH_DATA_LENGTH];
 uint16_t liveDecoData[DEPTH_DATA_LENGTH];
 static uint16_t lifeDataIndex = 0;
@@ -69,6 +70,7 @@
 {
 	uint16_t* pTarget = pdata;
 	uint16_t* pSource = pdata;
+	uint16_t  result = 0;
 	
 	uint16_t index = 0;
 	
@@ -76,7 +78,15 @@
 	{
 		*pTarget = *pSource++;
 		*pTarget += *pSource++;
-		*pTarget++ /= 2;
+		result = *pTarget /= 2;
+		if((*pTarget != 0) && (result == 0))	/* avoid termination of information by round up to 1 */
+		{
+			*pTarget++ = 1;
+		}
+		else
+		{
+			*pTarget++ = result;
+		}
 	}
 	memset(pTarget,0,size/2);
 }
@@ -186,7 +196,9 @@
 uint8_t prepareReplayLog(uint8_t StepBackwards)
 {
 	uint8_t retVal = 0;
+	uint16_t index = 0;
 	uint16_t dataLength = 0;
+	uint8_t markerDetected = 0;
 
     SLogbookHeader logbookHeader;
 
@@ -205,7 +217,21 @@
     	ReplayDataOffset = StepBackwards;
 		logbook_getHeader(StepBackwards ,&logbookHeader);
 
-		dataLength = logbook_readSampleData(StepBackwards, DEPTH_DATA_LENGTH, ReplayDepthData,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+		dataLength = logbook_readSampleData(StepBackwards, DEPTH_DATA_LENGTH, ReplayDepthData,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, ReplayMarkerData);
+
+	/* check if a marker is provided. If not disable marker functionality for the replay block */
+		for(index = 0; index < dataLength; index++)
+		{
+			if(ReplayMarkerData[index] != 0)
+			{
+				markerDetected = 1;
+				break;
+			}
+		}
+		if(markerDetected == 0)
+		{
+			ReplayMarkerData[0] = 0xFF;
+		}
 
 		if( dataLength == DEPTH_DATA_LENGTH)		/* log data has been compressed to fit into buffer */
 		{
@@ -226,13 +252,14 @@
 	return retVal;
 }
 
-uint8_t getReplayInfo(uint16_t** pReplayData, uint16_t* DataLength, uint16_t* MaxDepth, uint16_t* diveMinutes)
+uint8_t getReplayInfo(uint16_t** pReplayData, uint8_t** pReplayMarker, uint16_t* DataLength, uint16_t* MaxDepth, uint16_t* diveMinutes)
 {
 	uint8_t retVal = 0;
 
-	if((ReplayDataOffset != 0xFFFF) && (pReplayData != NULL) && (DataLength != NULL) && (MaxDepth != NULL))
+	if((ReplayDataOffset != 0xFFFF) && (pReplayData != NULL) && (DataLength != NULL) && (MaxDepth != NULL) && (pReplayMarker != 0))
 	{
 		*pReplayData = ReplayDepthData;
+		*pReplayMarker = ReplayMarkerData;
 		*DataLength = ReplayDataLength;
 		*MaxDepth = ReplayDataMaxDepth;
 		*diveMinutes = ReplayDataMinutes;
--- a/Discovery/Src/show_logbook.c	Thu Jan 14 19:17:28 2021 +0100
+++ b/Discovery/Src/show_logbook.c	Thu Jan 14 20:38:28 2021 +0100
@@ -450,7 +450,7 @@
 #endif
 
     uint16_t dataLength = 0;
-    dataLength = logbook_readSampleData(StepBackwards, 1000, depthdata,gasdata, tempdata, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tankdata);
+    dataLength = logbook_readSampleData(StepBackwards, 1000, depthdata,gasdata, tempdata, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tankdata,NULL);
 
     //Print Date
     uint8_t year = logbookHeader.dateYear;
@@ -736,7 +736,7 @@
     uint16_t decoDepthdata[1000];
     uint16_t *pDecoDepthData = 0;
 
-    dataLength = logbook_readSampleData(StepBackwards, 1000, depthdata,gasdata, tempdata, NULL, NULL, NULL, NULL, NULL, NULL, NULL, decoDepthdata, NULL);
+    dataLength = logbook_readSampleData(StepBackwards, 1000, depthdata,gasdata, tempdata, NULL, NULL, NULL, NULL, NULL, NULL, NULL, decoDepthdata, NULL, NULL);
 
         for(int i = 0; i<dataLength; i++)
         {
@@ -903,7 +903,7 @@
     uint16_t dataLength = 0;
     uint16_t depthdata[1000];
     uint8_t  gasdata[1000];
-    dataLength = logbook_readSampleData(StepBackwards, 1000, depthdata,gasdata, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+    dataLength = logbook_readSampleData(StepBackwards, 1000, depthdata,gasdata, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
 
     //--- print coordinate system & depth graph with gaschanges ---
     show_logbook_draw_depth_graph(hgfx, StepBackwards, &wintemp, 1, dataLength, depthdata, gasdata, NULL);
@@ -961,13 +961,13 @@
 
 
         if(logbookHeader.diveMode != DIVEMODE_CCR)
-            dataLength = logbook_readSampleData(StepBackwards, 1000, depthdata,gasdata, NULL, ppO2data, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+            dataLength = logbook_readSampleData(StepBackwards, 1000, depthdata,gasdata, NULL, ppO2data, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
         else
         {
             if(logbookHeader.CCRmode == CCRMODE_FixedSetpoint)
-                dataLength = logbook_readSampleData(StepBackwards, 1000, depthdata, gasdata, NULL, NULL, setpoint, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+                dataLength = logbook_readSampleData(StepBackwards, 1000, depthdata, gasdata, NULL, NULL, setpoint, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
             else
-                dataLength = logbook_readSampleData(StepBackwards, 1000, depthdata, gasdata, NULL, NULL, NULL, sensor1, sensor2, sensor3, NULL, NULL, NULL, NULL);
+                dataLength = logbook_readSampleData(StepBackwards, 1000, depthdata, gasdata, NULL, NULL, NULL, sensor1, sensor2, sensor3, NULL, NULL, NULL, NULL, NULL);
         }
 
 
--- a/Discovery/Src/t3.c	Thu Jan 14 19:17:28 2021 +0100
+++ b/Discovery/Src/t3.c	Thu Jan 14 20:38:28 2021 +0100
@@ -180,6 +180,75 @@
 	}
 }
 
+void t3_drawMarker(GFX_DrawCfgScreen *hgfx, const  SWindowGimpStyle *window, uint8_t *data, uint16_t datalength, uint8_t color)
+{
+	uint16_t line = 0;
+	uint16_t dataIndex = 0;
+	uint16_t lastDataIndex = 0;
+	uint16_t windowWidth = 0;
+	int16_t factor = 0;
+	uint8_t setMarker = 0;
+
+	 point_t start;
+	 point_t stop;
+
+
+	if( (window->bottom <= 479)
+		&& (window->top <= 479)
+		&& (window->right <= 799)
+		&& (window->left <= 799)
+		&& (window->right >= 0)
+		&& (window->left >= 0)
+		&& (window->bottom > window->top)
+		&& (window->right > window->left))
+	{
+		windowWidth = window->right - window->left;
+		if(settingsGetPointer()->FlipDisplay)
+		{
+			start.y = window->bottom;
+			stop.y = window->top;
+		}
+		else
+		{
+			start.y = 479 - window->bottom;
+			stop.y = 479 - window->top;
+		}
+
+		while((line <= windowWidth) && (dataIndex < datalength))
+		{
+			factor = (10 * line * (long)datalength)/windowWidth;
+			dataIndex = factor/10;
+		/* check if a marker is set in the intervall which is bypassed because of data reduction */
+			setMarker = 0;
+			while(lastDataIndex <= dataIndex)
+			{
+				lastDataIndex++;
+				if(data[lastDataIndex] != 0)
+				{
+					setMarker = 1;
+					break;
+				}
+			}
+			lastDataIndex = dataIndex;
+			int rest = factor - dataIndex*10;
+			if(rest >= 5)
+				dataIndex++;
+
+			if((datalength - 1) < dataIndex)
+				dataIndex = datalength-1;
+
+			if((line > 0) && (setMarker))		/* draw marker line */
+			{
+				start.x = line;
+				stop.x = line;
+				GFX_draw_line(hgfx, start, stop, color);
+			}
+			line++;
+			dataIndex++;
+		}
+	}
+}
+
 void t3_miniLiveLogProfile(void)
 {
     SWindowGimpStyle wintemp;
@@ -187,6 +256,7 @@
     uint16_t liveDataLength = 0;
     uint16_t drawDataLength = 0;
     uint16_t* pReplayData;
+    uint8_t* pReplayMarker;
     uint16_t max_depth = 10;
     char text[TEXTSIZE];
     point_t start, stop;
@@ -206,7 +276,7 @@
 
    	if(getReplayOffset() != 0xFFFF)
    	{
-		getReplayInfo(&pReplayData, &replayDataLength, &max_depth, &diveMinutes);
+		getReplayInfo(&pReplayData, &pReplayMarker, &replayDataLength, &max_depth, &diveMinutes);
    	}
 
    	if(max_depth < (uint16_t)(stateUsed->lifeData.max_depth_meter * 100))
@@ -242,6 +312,10 @@
 	if(replayDataLength != 0)
 	{
 		GFX_graph_print(&t3screen, &wintemp, 0,1,0, max_depth, pReplayData, drawDataLength, CLUT_Font031, NULL);
+		if(pReplayMarker[0] != 0xFF)
+		{
+			t3_drawMarker(&t3screen, &wintemp, pReplayMarker, drawDataLength, CLUT_CompassUserHeadingTick);
+		}
 	}
 
     if(liveDataLength > 3)