comparison Discovery/Src/logbook_miniLive.c @ 598:0a3836643173

New replay block for T3 profile: Added functionaly to mini logbook to allow the access to a stored log file and to display the life data in a view which does not automatically zoom the time line (only the max depth is adapted)
author Ideenmodellierer
date Mon, 04 Jan 2021 21:41:51 +0100
parents 5ca177d2df5d
children 2cb0a97a07ad
comparison
equal deleted inserted replaced
597:132e7e3d13a7 598:0a3836643173
16 * 16 *
17 ****************************************************************************** 17 ******************************************************************************
18 */ 18 */
19 19
20 /* Includes ------------------------------------------------------------------*/ 20 /* Includes ------------------------------------------------------------------*/
21
22
23 #include <string.h>
21 #include "logbook_miniLive.h" 24 #include "logbook_miniLive.h"
22 #include "data_exchange.h" 25 #include "data_exchange.h"
26 #include "logbook.h"
23 27
24 /* 28 /*
25 ****************************************************************************** 29 ******************************************************************************
26 * @brief t7_updateMiniLiveLogbook. / Create depth samples for view during dive 30 * @brief t7_updateMiniLiveLogbook. / Create depth samples for view during dive
27 * @author heinrichs weikamp gmbh 31 * @author heinrichs weikamp gmbh
33 37
34 #define MLLsize (296) 38 #define MLLsize (296)
35 static uint16_t MLLdataDepth[MLLsize]; 39 static uint16_t MLLdataDepth[MLLsize];
36 static uint16_t MLLpointer = 0; 40 static uint16_t MLLpointer = 0;
37 static uint8_t MLLtickIntervallSeconds = 2; 41 static uint8_t MLLtickIntervallSeconds = 2;
38 42
43 /* Replay Block data storage */
44 #define DEPTH_DATA_LENGTH (1800u) /* Resolution: 5 hours dive, sampling every 10 seconds */
45 uint16_t depthdata[DEPTH_DATA_LENGTH];
46 uint16_t livedepthdata[DEPTH_DATA_LENGTH * 2];
47 static uint16_t historyIndex = 0;
48
49 static uint8_t ReplayDataResolution = 2; /* Time represented by one sample (second) */
50 static uint16_t ReplayDataLength = 0; /* Number of data entries */
51 static uint16_t ReplayDataMaxDepth = 0;
52 static uint16_t ReplayDataMinutes = 0;
53 static uint16_t ReplayDataOffset = 0xFFFF; /* Stepbackwards format used by log functions */
39 54
40 uint16_t *getMiniLiveLogbookPointerToData(void) 55 uint16_t *getMiniLiveLogbookPointerToData(void)
41 { 56 {
42 return MLLdataDepth; 57 return MLLdataDepth;
43 } 58 }
46 uint16_t getMiniLiveLogbookActualDataLength(void) 61 uint16_t getMiniLiveLogbookActualDataLength(void)
47 { 62 {
48 return MLLpointer; 63 return MLLpointer;
49 } 64 }
50 65
51 66 void compressBuffer_uint16(uint16_t* pdata, uint16_t size)
52 67 {
68 uint16_t* pTarget = pdata;
69 uint16_t* pSource = pdata;
70
71 uint16_t index = 0;
72
73 for(index = 0; index < size/2; index++)
74 {
75 *pTarget = *pSource++;
76 *pTarget += *pSource++;
77 *pTarget++ /= 2;
78 }
79 memset(pTarget,0,size/2);
80 }
81
53 void updateMiniLiveLogbook( _Bool checkOncePerSecond) 82 void updateMiniLiveLogbook( _Bool checkOncePerSecond)
54 { 83 {
55 static uint8_t bDiveMode = 0; 84 static uint8_t bDiveMode = 0;
56 static uint32_t last_second = 0; 85 static uint32_t last_second = 0;
57 static uint8_t secondsCount = 0; 86 static uint8_t secondsCount = 0;
87 static uint8_t historysecondsCount = 0;
58 88
59 if(checkOncePerSecond) 89 if(checkOncePerSecond)
60 { 90 {
61 uint32_t now = current_second(); 91 uint32_t now = current_second();
62 if( last_second == now) 92 if( last_second == now)
63 return; 93 return;
64 last_second = now; 94 last_second = now;
65 } 95 }
66 secondsCount++; 96 secondsCount++;
97 historysecondsCount++;
67 98
68 if(!bDiveMode) 99 if(!bDiveMode)
69 { 100 {
70 if((stateUsed->mode == MODE_DIVE) && (stateUsed->lifeData.dive_time_seconds >= 5)) 101 if((stateUsed->mode == MODE_DIVE) && (stateUsed->lifeData.dive_time_seconds >= 5))
71 { 102 {
73 MLLtickIntervallSeconds = 2; 104 MLLtickIntervallSeconds = 2;
74 bDiveMode = 1; 105 bDiveMode = 1;
75 MLLpointer = 1; 106 MLLpointer = 1;
76 for(int i=0;i<MLLsize;i++) 107 for(int i=0;i<MLLsize;i++)
77 MLLdataDepth[i] = 0; 108 MLLdataDepth[i] = 0;
109
110 for(historyIndex = 0; historyIndex < DEPTH_DATA_LENGTH; historyIndex++)
111 {
112 livedepthdata[historyIndex] = 0xFFFF;
113 }
114 historysecondsCount = 0;
115 historyIndex = 0;
116 livedepthdata[historyIndex++] = 0; /* start at 0 */
78 } 117 }
79 } 118 }
80 else if(stateUsed->mode == MODE_DIVE) 119 else if(stateUsed->mode == MODE_DIVE)
81 { 120 {
82 bDiveMode = 3; 121 bDiveMode = 3;
83 // 122 //
84 if(secondsCount >= MLLtickIntervallSeconds) 123 if(secondsCount >= MLLtickIntervallSeconds)
85 { 124 {
86 secondsCount = 0; 125 secondsCount = 0;
126 /* in case of a buffer overrun the buffer is divided and the first half is filled with a compressed image of the complete buffer */
87 if((MLLpointer >= MLLsize) && (MLLtickIntervallSeconds < 127)) 127 if((MLLpointer >= MLLsize) && (MLLtickIntervallSeconds < 127))
88 { 128 {
89 MLLpointer = 0; 129 MLLpointer = 0;
90 MLLtickIntervallSeconds *= 2; 130 MLLtickIntervallSeconds *= 2;
91 for(int i=0;i<MLLsize/2;i++) 131
92 { 132 compressBuffer_uint16(MLLdataDepth,MLLsize);
93 MLLdataDepth[i] = MLLdataDepth[MLLpointer++];
94 MLLdataDepth[i] += MLLdataDepth[MLLpointer++];
95 MLLdataDepth[i] /= 2;
96 }
97 MLLpointer = MLLsize/2; 133 MLLpointer = MLLsize/2;
98 for(int i=MLLsize/2;i<MLLsize;i++)
99 MLLdataDepth[i] = 0;
100 } 134 }
101 if(MLLpointer < MLLsize) 135 if(MLLpointer < MLLsize)
102 MLLdataDepth[MLLpointer++] = (int)(stateUsed->lifeData.depth_meter * 10); 136 MLLdataDepth[MLLpointer++] = (int)(stateUsed->lifeData.depth_meter * 10);
137 }
138 if(historysecondsCount > ReplayDataResolution)
139 {
140 historysecondsCount = 0;
141
142 if(historyIndex >= 2*DEPTH_DATA_LENGTH) /* compress data */
143 {
144 ReplayDataResolution *= 2;
145 compressBuffer_uint16(livedepthdata,2*DEPTH_DATA_LENGTH);
146 historyIndex = DEPTH_DATA_LENGTH;
147 }
148 livedepthdata[historyIndex++] = (int)(stateUsed->lifeData.depth_meter * 100);
103 } 149 }
104 } 150 }
105 else if(bDiveMode == 3) 151 else if(bDiveMode == 3)
106 { 152 {
107 //End of Dive 153 //End of Dive
109 MLLdataDepth[i] = 0; 155 MLLdataDepth[i] = 0;
110 bDiveMode = 0; 156 bDiveMode = 0;
111 } 157 }
112 } 158 }
113 159
114 160 uint8_t prepareReplayLog(uint8_t StepBackwards)
161 {
162 uint8_t retVal = 0;
163 uint16_t dataLength = 0;
164
165 SLogbookHeader logbookHeader;
166
167 if(ReplayDataOffset == StepBackwards) /* Entry already selected => reset selection */
168 {
169 ReplayDataOffset = 0xFFFF;
170 ReplayDataResolution = 2;
171 retVal = 1;
172 }
173 else
174 {
175 ReplayDataOffset = StepBackwards;
176 logbook_getHeader(StepBackwards ,&logbookHeader);
177
178 dataLength = logbook_readSampleData(StepBackwards, DEPTH_DATA_LENGTH, depthdata,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
179
180 if( dataLength == DEPTH_DATA_LENGTH) /* log data has been compressed to fit into buffer */
181 {
182 ReplayDataResolution = (logbookHeader.diveTimeMinutes * 60 + logbookHeader.diveTimeSeconds) / dataLength;
183 }
184 else
185 {
186 ReplayDataResolution = logbookHeader.samplingRate;
187 }
188 ReplayDataLength = dataLength;
189 ReplayDataMaxDepth = logbookHeader.maxDepth;
190 ReplayDataMinutes = logbookHeader.diveTimeMinutes;
191 if(dataLength != 0)
192 {
193 retVal = 1;
194 }
195 }
196 return retVal;
197 }
198
199 uint8_t getReplayInfo(uint16_t** pReplayData, uint16_t* DataLength, uint16_t* MaxDepth, uint16_t* diveMinutes)
200 {
201 uint8_t retVal = 0;
202
203 if((ReplayDataOffset != 0xFFFF) && (pReplayData != NULL) && (DataLength != NULL) && (MaxDepth != NULL))
204 {
205 *pReplayData = depthdata;
206 *DataLength = ReplayDataLength;
207 *MaxDepth = ReplayDataMaxDepth;
208 *diveMinutes = ReplayDataMinutes;
209 retVal = 1;
210 }
211
212 return retVal;
213 }
214
215 uint16_t *getMiniLiveReplayPointerToData(void)
216 {
217 return livedepthdata;
218 }
219 uint16_t getMiniLiveReplayLength(void)
220 {
221 return historyIndex;
222 }
223
224 uint16_t getReplayOffset(void)
225 {
226 return ReplayDataOffset;
227 }
228
229 uint16_t getReplayDataResolution(void)
230 {
231 return ReplayDataResolution;
232 }
115 233
116 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ 234 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/