comparison Discovery/Src/logbook_miniLive.c @ 602:2cb0a97a07ad

Added replay data scaling in case life data is longer than replay block Minor: variable name changes
author Ideenmodellierer
date Tue, 05 Jan 2021 20:35:01 +0100
parents 0a3836643173
children c56ed16dbd39
comparison
equal deleted inserted replaced
601:7ef2d310287d 602:2cb0a97a07ad
39 static uint16_t MLLdataDepth[MLLsize]; 39 static uint16_t MLLdataDepth[MLLsize];
40 static uint16_t MLLpointer = 0; 40 static uint16_t MLLpointer = 0;
41 static uint8_t MLLtickIntervallSeconds = 2; 41 static uint8_t MLLtickIntervallSeconds = 2;
42 42
43 /* Replay Block data storage */ 43 /* Replay Block data storage */
44 #define DEPTH_DATA_LENGTH (1800u) /* Resolution: 5 hours dive, sampling every 10 seconds */ 44 #define DEPTH_DATA_LENGTH (1800u) /* Resolution: 1 hours dive, sampling every 2 seconds */
45 uint16_t depthdata[DEPTH_DATA_LENGTH]; 45 uint16_t ReplayDepthData[DEPTH_DATA_LENGTH];
46 uint16_t livedepthdata[DEPTH_DATA_LENGTH * 2]; 46 uint16_t liveDepthData[DEPTH_DATA_LENGTH];
47 static uint16_t historyIndex = 0; 47 static uint16_t lifeDataIndex = 0;
48 48
49 static uint8_t ReplayDataResolution = 2; /* Time represented by one sample (second) */ 49 static uint8_t ReplayDataResolution = 2; /* Time represented by one sample (second) */
50 static uint16_t ReplayDataLength = 0; /* Number of data entries */ 50 static uint16_t ReplayDataLength = 0; /* Number of data entries */
51 static uint16_t ReplayDataMaxDepth = 0; 51 static uint16_t ReplayDataMaxDepth = 0;
52 static uint16_t ReplayDataMinutes = 0; 52 static uint16_t ReplayDataMinutes = 0;
82 void updateMiniLiveLogbook( _Bool checkOncePerSecond) 82 void updateMiniLiveLogbook( _Bool checkOncePerSecond)
83 { 83 {
84 static uint8_t bDiveMode = 0; 84 static uint8_t bDiveMode = 0;
85 static uint32_t last_second = 0; 85 static uint32_t last_second = 0;
86 static uint8_t secondsCount = 0; 86 static uint8_t secondsCount = 0;
87 static uint8_t historysecondsCount = 0; 87 static uint8_t lifesecondsCount = 0;
88 88
89 if(checkOncePerSecond) 89 if(checkOncePerSecond)
90 { 90 {
91 uint32_t now = current_second(); 91 uint32_t now = current_second();
92 if( last_second == now) 92 if( last_second == now)
93 return; 93 return;
94 last_second = now; 94 last_second = now;
95 } 95 }
96 secondsCount++; 96 secondsCount++;
97 historysecondsCount++; 97 lifesecondsCount++;
98 98
99 if(!bDiveMode) 99 if(!bDiveMode)
100 { 100 {
101 if((stateUsed->mode == MODE_DIVE) && (stateUsed->lifeData.dive_time_seconds >= 5)) 101 if((stateUsed->mode == MODE_DIVE) && (stateUsed->lifeData.dive_time_seconds >= 5))
102 { 102 {
105 bDiveMode = 1; 105 bDiveMode = 1;
106 MLLpointer = 1; 106 MLLpointer = 1;
107 for(int i=0;i<MLLsize;i++) 107 for(int i=0;i<MLLsize;i++)
108 MLLdataDepth[i] = 0; 108 MLLdataDepth[i] = 0;
109 109
110 for(historyIndex = 0; historyIndex < DEPTH_DATA_LENGTH; historyIndex++) 110 for(lifeDataIndex = 0; lifeDataIndex < DEPTH_DATA_LENGTH; lifeDataIndex++)
111 { 111 {
112 livedepthdata[historyIndex] = 0xFFFF; 112 liveDepthData[lifeDataIndex] = 0xFFFF;
113 } 113 }
114 historysecondsCount = 0; 114 lifesecondsCount = 0;
115 historyIndex = 0; 115 lifeDataIndex = 0;
116 livedepthdata[historyIndex++] = 0; /* start at 0 */ 116 liveDepthData[lifeDataIndex++] = 0; /* start at 0 */
117 } 117 }
118 } 118 }
119 else if(stateUsed->mode == MODE_DIVE) 119 else if(stateUsed->mode == MODE_DIVE)
120 { 120 {
121 bDiveMode = 3; 121 bDiveMode = 3;
133 MLLpointer = MLLsize/2; 133 MLLpointer = MLLsize/2;
134 } 134 }
135 if(MLLpointer < MLLsize) 135 if(MLLpointer < MLLsize)
136 MLLdataDepth[MLLpointer++] = (int)(stateUsed->lifeData.depth_meter * 10); 136 MLLdataDepth[MLLpointer++] = (int)(stateUsed->lifeData.depth_meter * 10);
137 } 137 }
138 if(historysecondsCount > ReplayDataResolution) 138 if(lifesecondsCount >= ReplayDataResolution)
139 { 139 {
140 historysecondsCount = 0; 140 lifesecondsCount = 0;
141 141
142 if(historyIndex >= 2*DEPTH_DATA_LENGTH) /* compress data */ 142 if(lifeDataIndex >= DEPTH_DATA_LENGTH) /* compress data */
143 { 143 {
144 ReplayDataResolution *= 2; 144 ReplayDataResolution *= 2;
145 compressBuffer_uint16(livedepthdata,2*DEPTH_DATA_LENGTH); 145 compressBuffer_uint16(liveDepthData,DEPTH_DATA_LENGTH);
146 historyIndex = DEPTH_DATA_LENGTH; 146 compressBuffer_uint16(ReplayDepthData,DEPTH_DATA_LENGTH); /* also compress Replay data to siplify mapping between live and replay data */
147 lifeDataIndex = DEPTH_DATA_LENGTH / 2;
147 } 148 }
148 livedepthdata[historyIndex++] = (int)(stateUsed->lifeData.depth_meter * 100); 149 liveDepthData[lifeDataIndex++] = (int)(stateUsed->lifeData.depth_meter * 100);
149 } 150 }
150 } 151 }
151 else if(bDiveMode == 3) 152 else if(bDiveMode == 3)
152 { 153 {
153 //End of Dive 154 //End of Dive
166 167
167 if(ReplayDataOffset == StepBackwards) /* Entry already selected => reset selection */ 168 if(ReplayDataOffset == StepBackwards) /* Entry already selected => reset selection */
168 { 169 {
169 ReplayDataOffset = 0xFFFF; 170 ReplayDataOffset = 0xFFFF;
170 ReplayDataResolution = 2; 171 ReplayDataResolution = 2;
172 ReplayDataLength = 0;
173 ReplayDataMaxDepth = 0;
174 ReplayDataMinutes = 0;
175
171 retVal = 1; 176 retVal = 1;
172 } 177 }
173 else 178 else
174 { 179 {
175 ReplayDataOffset = StepBackwards; 180 ReplayDataOffset = StepBackwards;
176 logbook_getHeader(StepBackwards ,&logbookHeader); 181 logbook_getHeader(StepBackwards ,&logbookHeader);
177 182
178 dataLength = logbook_readSampleData(StepBackwards, DEPTH_DATA_LENGTH, depthdata,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); 183 dataLength = logbook_readSampleData(StepBackwards, DEPTH_DATA_LENGTH, ReplayDepthData,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
179 184
180 if( dataLength == DEPTH_DATA_LENGTH) /* log data has been compressed to fit into buffer */ 185 if( dataLength == DEPTH_DATA_LENGTH) /* log data has been compressed to fit into buffer */
181 { 186 {
182 ReplayDataResolution = (logbookHeader.diveTimeMinutes * 60 + logbookHeader.diveTimeSeconds) / dataLength; 187 ReplayDataResolution = (logbookHeader.diveTimeMinutes * 60 + logbookHeader.diveTimeSeconds) / dataLength;
183 } 188 }
200 { 205 {
201 uint8_t retVal = 0; 206 uint8_t retVal = 0;
202 207
203 if((ReplayDataOffset != 0xFFFF) && (pReplayData != NULL) && (DataLength != NULL) && (MaxDepth != NULL)) 208 if((ReplayDataOffset != 0xFFFF) && (pReplayData != NULL) && (DataLength != NULL) && (MaxDepth != NULL))
204 { 209 {
205 *pReplayData = depthdata; 210 *pReplayData = ReplayDepthData;
206 *DataLength = ReplayDataLength; 211 *DataLength = ReplayDataLength;
207 *MaxDepth = ReplayDataMaxDepth; 212 *MaxDepth = ReplayDataMaxDepth;
208 *diveMinutes = ReplayDataMinutes; 213 *diveMinutes = ReplayDataMinutes;
209 retVal = 1; 214 retVal = 1;
210 } 215 }
212 return retVal; 217 return retVal;
213 } 218 }
214 219
215 uint16_t *getMiniLiveReplayPointerToData(void) 220 uint16_t *getMiniLiveReplayPointerToData(void)
216 { 221 {
217 return livedepthdata; 222 return liveDepthData;
218 } 223 }
219 uint16_t getMiniLiveReplayLength(void) 224 uint16_t getMiniLiveReplayLength(void)
220 { 225 {
221 return historyIndex; 226 return lifeDataIndex;
222 } 227 }
223 228
224 uint16_t getReplayOffset(void) 229 uint16_t getReplayOffset(void)
225 { 230 {
226 return ReplayDataOffset; 231 return ReplayDataOffset;