Mercurial > public > ostc4
annotate Discovery/Src/logbook_miniLive.c @ 603:c56ed16dbd39
T3 profile view: Added visualization of deco data
author | Ideenmodellierer |
---|---|
date | Wed, 06 Jan 2021 19:41:43 +0100 |
parents | 2cb0a97a07ad |
children | ae7f8333c900 |
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" |
603
c56ed16dbd39
T3 profile view: Added visualization of deco data
Ideenmodellierer
parents:
602
diff
changeset
|
27 #include "tHome.h" |
38 | 28 |
29 /* | |
30 ****************************************************************************** | |
31 * @brief t7_updateMiniLiveLogbook. / Create depth samples for view during dive | |
32 * @author heinrichs weikamp gmbh | |
33 * @version V0.0.1 | |
34 * @date 13-March-2015 | |
35 ****************************************************************************** | |
36 * | |
37 */ | |
38 | |
39 #define MLLsize (296) | |
300
5ca177d2df5d
cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
40 static uint16_t MLLdataDepth[MLLsize]; |
5ca177d2df5d
cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
41 static uint16_t MLLpointer = 0; |
5ca177d2df5d
cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
42 static uint8_t MLLtickIntervallSeconds = 2; |
598 | 43 |
44 /* Replay Block data storage */ | |
602
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
45 #define DEPTH_DATA_LENGTH (1800u) /* Resolution: 1 hours dive, sampling every 2 seconds */ |
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
46 uint16_t ReplayDepthData[DEPTH_DATA_LENGTH]; |
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
47 uint16_t liveDepthData[DEPTH_DATA_LENGTH]; |
603
c56ed16dbd39
T3 profile view: Added visualization of deco data
Ideenmodellierer
parents:
602
diff
changeset
|
48 uint16_t liveDecoData[DEPTH_DATA_LENGTH]; |
602
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
49 static uint16_t lifeDataIndex = 0; |
598 | 50 |
51 static uint8_t ReplayDataResolution = 2; /* Time represented by one sample (second) */ | |
52 static uint16_t ReplayDataLength = 0; /* Number of data entries */ | |
53 static uint16_t ReplayDataMaxDepth = 0; | |
54 static uint16_t ReplayDataMinutes = 0; | |
55 static uint16_t ReplayDataOffset = 0xFFFF; /* Stepbackwards format used by log functions */ | |
38 | 56 |
57 uint16_t *getMiniLiveLogbookPointerToData(void) | |
58 { | |
59 return MLLdataDepth; | |
60 } | |
61 | |
62 | |
63 uint16_t getMiniLiveLogbookActualDataLength(void) | |
64 { | |
65 return MLLpointer; | |
66 } | |
67 | |
598 | 68 void compressBuffer_uint16(uint16_t* pdata, uint16_t size) |
69 { | |
70 uint16_t* pTarget = pdata; | |
71 uint16_t* pSource = pdata; | |
38 | 72 |
598 | 73 uint16_t index = 0; |
38 | 74 |
598 | 75 for(index = 0; index < size/2; index++) |
76 { | |
77 *pTarget = *pSource++; | |
78 *pTarget += *pSource++; | |
79 *pTarget++ /= 2; | |
80 } | |
81 memset(pTarget,0,size/2); | |
82 } | |
83 | |
38 | 84 void updateMiniLiveLogbook( _Bool checkOncePerSecond) |
85 { | |
86 static uint8_t bDiveMode = 0; | |
87 static uint32_t last_second = 0; | |
88 static uint8_t secondsCount = 0; | |
602
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
89 static uint8_t lifesecondsCount = 0; |
38 | 90 |
603
c56ed16dbd39
T3 profile view: Added visualization of deco data
Ideenmodellierer
parents:
602
diff
changeset
|
91 const SDecoinfo* pDecoinfo; |
c56ed16dbd39
T3 profile view: Added visualization of deco data
Ideenmodellierer
parents:
602
diff
changeset
|
92 uint8_t stopDepth = 0; |
c56ed16dbd39
T3 profile view: Added visualization of deco data
Ideenmodellierer
parents:
602
diff
changeset
|
93 uint16_t stopTime = 0; |
c56ed16dbd39
T3 profile view: Added visualization of deco data
Ideenmodellierer
parents:
602
diff
changeset
|
94 |
38 | 95 if(checkOncePerSecond) |
96 { | |
97 uint32_t now = current_second(); | |
98 if( last_second == now) | |
99 return; | |
100 last_second = now; | |
101 } | |
102 secondsCount++; | |
602
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
103 lifesecondsCount++; |
38 | 104 |
105 if(!bDiveMode) | |
106 { | |
107 if((stateUsed->mode == MODE_DIVE) && (stateUsed->lifeData.dive_time_seconds >= 5)) | |
108 { | |
109 secondsCount = 0; | |
110 MLLtickIntervallSeconds = 2; | |
111 bDiveMode = 1; | |
112 MLLpointer = 1; | |
113 for(int i=0;i<MLLsize;i++) | |
114 MLLdataDepth[i] = 0; | |
598 | 115 |
602
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
116 for(lifeDataIndex = 0; lifeDataIndex < DEPTH_DATA_LENGTH; lifeDataIndex++) |
598 | 117 { |
602
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
118 liveDepthData[lifeDataIndex] = 0xFFFF; |
603
c56ed16dbd39
T3 profile view: Added visualization of deco data
Ideenmodellierer
parents:
602
diff
changeset
|
119 liveDecoData[lifeDataIndex] = 0xFFFF; |
598 | 120 } |
602
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
121 lifesecondsCount = 0; |
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
122 lifeDataIndex = 0; |
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
123 liveDepthData[lifeDataIndex++] = 0; /* start at 0 */ |
38 | 124 } |
125 } | |
126 else if(stateUsed->mode == MODE_DIVE) | |
127 { | |
128 bDiveMode = 3; | |
129 // | |
130 if(secondsCount >= MLLtickIntervallSeconds) | |
131 { | |
132 secondsCount = 0; | |
598 | 133 /* 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 | 134 if((MLLpointer >= MLLsize) && (MLLtickIntervallSeconds < 127)) |
135 { | |
136 MLLpointer = 0; | |
137 MLLtickIntervallSeconds *= 2; | |
598 | 138 |
139 compressBuffer_uint16(MLLdataDepth,MLLsize); | |
38 | 140 MLLpointer = MLLsize/2; |
141 } | |
142 if(MLLpointer < MLLsize) | |
143 MLLdataDepth[MLLpointer++] = (int)(stateUsed->lifeData.depth_meter * 10); | |
144 } | |
602
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
145 if(lifesecondsCount >= ReplayDataResolution) |
598 | 146 { |
602
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
147 lifesecondsCount = 0; |
598 | 148 |
602
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
149 if(lifeDataIndex >= DEPTH_DATA_LENGTH) /* compress data */ |
598 | 150 { |
151 ReplayDataResolution *= 2; | |
602
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
152 compressBuffer_uint16(liveDepthData,DEPTH_DATA_LENGTH); |
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
153 compressBuffer_uint16(ReplayDepthData,DEPTH_DATA_LENGTH); /* also compress Replay data to siplify mapping between live and replay data */ |
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
154 lifeDataIndex = DEPTH_DATA_LENGTH / 2; |
598 | 155 } |
603
c56ed16dbd39
T3 profile view: Added visualization of deco data
Ideenmodellierer
parents:
602
diff
changeset
|
156 liveDepthData[lifeDataIndex] = (int)(stateUsed->lifeData.depth_meter * 100); |
c56ed16dbd39
T3 profile view: Added visualization of deco data
Ideenmodellierer
parents:
602
diff
changeset
|
157 if(stateUsed->diveSettings.deco_type.ub.standard == VPM_MODE) |
c56ed16dbd39
T3 profile view: Added visualization of deco data
Ideenmodellierer
parents:
602
diff
changeset
|
158 { |
c56ed16dbd39
T3 profile view: Added visualization of deco data
Ideenmodellierer
parents:
602
diff
changeset
|
159 pDecoinfo = &stateUsed->decolistVPM; |
c56ed16dbd39
T3 profile view: Added visualization of deco data
Ideenmodellierer
parents:
602
diff
changeset
|
160 } |
c56ed16dbd39
T3 profile view: Added visualization of deco data
Ideenmodellierer
parents:
602
diff
changeset
|
161 else |
c56ed16dbd39
T3 profile view: Added visualization of deco data
Ideenmodellierer
parents:
602
diff
changeset
|
162 { |
c56ed16dbd39
T3 profile view: Added visualization of deco data
Ideenmodellierer
parents:
602
diff
changeset
|
163 pDecoinfo = &stateUsed->decolistBuehlmann; |
c56ed16dbd39
T3 profile view: Added visualization of deco data
Ideenmodellierer
parents:
602
diff
changeset
|
164 } |
c56ed16dbd39
T3 profile view: Added visualization of deco data
Ideenmodellierer
parents:
602
diff
changeset
|
165 tHome_findNextStop(pDecoinfo->output_stop_length_seconds, &stopDepth, &stopTime); |
c56ed16dbd39
T3 profile view: Added visualization of deco data
Ideenmodellierer
parents:
602
diff
changeset
|
166 if(stopDepth) |
c56ed16dbd39
T3 profile view: Added visualization of deco data
Ideenmodellierer
parents:
602
diff
changeset
|
167 { |
c56ed16dbd39
T3 profile view: Added visualization of deco data
Ideenmodellierer
parents:
602
diff
changeset
|
168 liveDecoData[lifeDataIndex] = stopDepth * 100; |
c56ed16dbd39
T3 profile view: Added visualization of deco data
Ideenmodellierer
parents:
602
diff
changeset
|
169 } |
c56ed16dbd39
T3 profile view: Added visualization of deco data
Ideenmodellierer
parents:
602
diff
changeset
|
170 else |
c56ed16dbd39
T3 profile view: Added visualization of deco data
Ideenmodellierer
parents:
602
diff
changeset
|
171 { |
c56ed16dbd39
T3 profile view: Added visualization of deco data
Ideenmodellierer
parents:
602
diff
changeset
|
172 liveDecoData[lifeDataIndex] = 0xFFFF; |
c56ed16dbd39
T3 profile view: Added visualization of deco data
Ideenmodellierer
parents:
602
diff
changeset
|
173 } |
c56ed16dbd39
T3 profile view: Added visualization of deco data
Ideenmodellierer
parents:
602
diff
changeset
|
174 lifeDataIndex++; |
598 | 175 } |
38 | 176 } |
177 else if(bDiveMode == 3) | |
178 { | |
179 //End of Dive | |
180 for(int i=0;i<MLLsize;i++) | |
181 MLLdataDepth[i] = 0; | |
182 bDiveMode = 0; | |
183 } | |
184 } | |
185 | |
598 | 186 uint8_t prepareReplayLog(uint8_t StepBackwards) |
187 { | |
188 uint8_t retVal = 0; | |
189 uint16_t dataLength = 0; | |
38 | 190 |
598 | 191 SLogbookHeader logbookHeader; |
192 | |
193 if(ReplayDataOffset == StepBackwards) /* Entry already selected => reset selection */ | |
194 { | |
195 ReplayDataOffset = 0xFFFF; | |
196 ReplayDataResolution = 2; | |
602
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
197 ReplayDataLength = 0; |
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
198 ReplayDataMaxDepth = 0; |
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
199 ReplayDataMinutes = 0; |
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
200 |
598 | 201 retVal = 1; |
202 } | |
203 else | |
204 { | |
205 ReplayDataOffset = StepBackwards; | |
206 logbook_getHeader(StepBackwards ,&logbookHeader); | |
207 | |
602
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
208 dataLength = logbook_readSampleData(StepBackwards, DEPTH_DATA_LENGTH, ReplayDepthData,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); |
598 | 209 |
210 if( dataLength == DEPTH_DATA_LENGTH) /* log data has been compressed to fit into buffer */ | |
211 { | |
212 ReplayDataResolution = (logbookHeader.diveTimeMinutes * 60 + logbookHeader.diveTimeSeconds) / dataLength; | |
213 } | |
214 else | |
215 { | |
216 ReplayDataResolution = logbookHeader.samplingRate; | |
217 } | |
218 ReplayDataLength = dataLength; | |
219 ReplayDataMaxDepth = logbookHeader.maxDepth; | |
220 ReplayDataMinutes = logbookHeader.diveTimeMinutes; | |
221 if(dataLength != 0) | |
222 { | |
223 retVal = 1; | |
224 } | |
225 } | |
226 return retVal; | |
227 } | |
228 | |
229 uint8_t getReplayInfo(uint16_t** pReplayData, uint16_t* DataLength, uint16_t* MaxDepth, uint16_t* diveMinutes) | |
230 { | |
231 uint8_t retVal = 0; | |
232 | |
233 if((ReplayDataOffset != 0xFFFF) && (pReplayData != NULL) && (DataLength != NULL) && (MaxDepth != NULL)) | |
234 { | |
602
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
235 *pReplayData = ReplayDepthData; |
598 | 236 *DataLength = ReplayDataLength; |
237 *MaxDepth = ReplayDataMaxDepth; | |
238 *diveMinutes = ReplayDataMinutes; | |
239 retVal = 1; | |
240 } | |
241 | |
242 return retVal; | |
243 } | |
244 | |
245 uint16_t *getMiniLiveReplayPointerToData(void) | |
246 { | |
602
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
247 return liveDepthData; |
598 | 248 } |
603
c56ed16dbd39
T3 profile view: Added visualization of deco data
Ideenmodellierer
parents:
602
diff
changeset
|
249 uint16_t *getMiniLiveDecoPointerToData(void) |
c56ed16dbd39
T3 profile view: Added visualization of deco data
Ideenmodellierer
parents:
602
diff
changeset
|
250 { |
c56ed16dbd39
T3 profile view: Added visualization of deco data
Ideenmodellierer
parents:
602
diff
changeset
|
251 return liveDecoData; |
c56ed16dbd39
T3 profile view: Added visualization of deco data
Ideenmodellierer
parents:
602
diff
changeset
|
252 } |
598 | 253 uint16_t getMiniLiveReplayLength(void) |
254 { | |
602
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
255 return lifeDataIndex; |
598 | 256 } |
257 | |
258 uint16_t getReplayOffset(void) | |
259 { | |
260 return ReplayDataOffset; | |
261 } | |
262 | |
263 uint16_t getReplayDataResolution(void) | |
264 { | |
265 return ReplayDataResolution; | |
266 } | |
38 | 267 |
268 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ |