Mercurial > public > ostc4
annotate 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 |
rev | line source |
---|---|
38 | 1 /** |
2 ****************************************************************************** | |
3 * @copyright heinrichs weikamp | |
4 * @file logbook_miniLive.c | |
5 * @author heinrichs weikamp gmbh | |
6 * @date 13-March-2015 | |
7 * @version V0.0.1 | |
8 * @since 13-March-2015 | |
9 * @brief little logbook for during the dive | |
10 * @bug | |
11 * @warning | |
12 ****************************************************************************** | |
13 * @attention | |
14 * | |
15 * <h2><center>© COPYRIGHT(c) 2015 heinrichs weikamp</center></h2> | |
16 * | |
17 ****************************************************************************** | |
18 */ | |
19 | |
20 /* Includes ------------------------------------------------------------------*/ | |
598 | 21 |
22 | |
23 #include <string.h> | |
38 | 24 #include "logbook_miniLive.h" |
25 #include "data_exchange.h" | |
598 | 26 #include "logbook.h" |
38 | 27 |
28 /* | |
29 ****************************************************************************** | |
30 * @brief t7_updateMiniLiveLogbook. / Create depth samples for view during dive | |
31 * @author heinrichs weikamp gmbh | |
32 * @version V0.0.1 | |
33 * @date 13-March-2015 | |
34 ****************************************************************************** | |
35 * | |
36 */ | |
37 | |
38 #define MLLsize (296) | |
300
5ca177d2df5d
cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
39 static uint16_t MLLdataDepth[MLLsize]; |
5ca177d2df5d
cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
40 static uint16_t MLLpointer = 0; |
5ca177d2df5d
cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
41 static uint8_t MLLtickIntervallSeconds = 2; |
598 | 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 */ | |
38 | 54 |
55 uint16_t *getMiniLiveLogbookPointerToData(void) | |
56 { | |
57 return MLLdataDepth; | |
58 } | |
59 | |
60 | |
61 uint16_t getMiniLiveLogbookActualDataLength(void) | |
62 { | |
63 return MLLpointer; | |
64 } | |
65 | |
598 | 66 void compressBuffer_uint16(uint16_t* pdata, uint16_t size) |
67 { | |
68 uint16_t* pTarget = pdata; | |
69 uint16_t* pSource = pdata; | |
38 | 70 |
598 | 71 uint16_t index = 0; |
38 | 72 |
598 | 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 | |
38 | 82 void updateMiniLiveLogbook( _Bool checkOncePerSecond) |
83 { | |
84 static uint8_t bDiveMode = 0; | |
85 static uint32_t last_second = 0; | |
86 static uint8_t secondsCount = 0; | |
598 | 87 static uint8_t historysecondsCount = 0; |
38 | 88 |
89 if(checkOncePerSecond) | |
90 { | |
91 uint32_t now = current_second(); | |
92 if( last_second == now) | |
93 return; | |
94 last_second = now; | |
95 } | |
96 secondsCount++; | |
598 | 97 historysecondsCount++; |
38 | 98 |
99 if(!bDiveMode) | |
100 { | |
101 if((stateUsed->mode == MODE_DIVE) && (stateUsed->lifeData.dive_time_seconds >= 5)) | |
102 { | |
103 secondsCount = 0; | |
104 MLLtickIntervallSeconds = 2; | |
105 bDiveMode = 1; | |
106 MLLpointer = 1; | |
107 for(int i=0;i<MLLsize;i++) | |
108 MLLdataDepth[i] = 0; | |
598 | 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 */ | |
38 | 117 } |
118 } | |
119 else if(stateUsed->mode == MODE_DIVE) | |
120 { | |
121 bDiveMode = 3; | |
122 // | |
123 if(secondsCount >= MLLtickIntervallSeconds) | |
124 { | |
125 secondsCount = 0; | |
598 | 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 */ |
38 | 127 if((MLLpointer >= MLLsize) && (MLLtickIntervallSeconds < 127)) |
128 { | |
129 MLLpointer = 0; | |
130 MLLtickIntervallSeconds *= 2; | |
598 | 131 |
132 compressBuffer_uint16(MLLdataDepth,MLLsize); | |
38 | 133 MLLpointer = MLLsize/2; |
134 } | |
135 if(MLLpointer < MLLsize) | |
136 MLLdataDepth[MLLpointer++] = (int)(stateUsed->lifeData.depth_meter * 10); | |
137 } | |
598 | 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); | |
149 } | |
38 | 150 } |
151 else if(bDiveMode == 3) | |
152 { | |
153 //End of Dive | |
154 for(int i=0;i<MLLsize;i++) | |
155 MLLdataDepth[i] = 0; | |
156 bDiveMode = 0; | |
157 } | |
158 } | |
159 | |
598 | 160 uint8_t prepareReplayLog(uint8_t StepBackwards) |
161 { | |
162 uint8_t retVal = 0; | |
163 uint16_t dataLength = 0; | |
38 | 164 |
598 | 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 } | |
38 | 233 |
234 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ |