Mercurial > public > ostc4
annotate 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 |
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 */ | |
602
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
44 #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
|
45 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
|
46 uint16_t liveDepthData[DEPTH_DATA_LENGTH]; |
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
47 static uint16_t lifeDataIndex = 0; |
598 | 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; | |
602
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
87 static uint8_t lifesecondsCount = 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++; | |
602
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
97 lifesecondsCount++; |
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 |
602
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
110 for(lifeDataIndex = 0; lifeDataIndex < DEPTH_DATA_LENGTH; lifeDataIndex++) |
598 | 111 { |
602
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
112 liveDepthData[lifeDataIndex] = 0xFFFF; |
598 | 113 } |
602
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
114 lifesecondsCount = 0; |
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
115 lifeDataIndex = 0; |
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
116 liveDepthData[lifeDataIndex++] = 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 } | |
602
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
138 if(lifesecondsCount >= ReplayDataResolution) |
598 | 139 { |
602
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
140 lifesecondsCount = 0; |
598 | 141 |
602
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
142 if(lifeDataIndex >= DEPTH_DATA_LENGTH) /* compress data */ |
598 | 143 { |
144 ReplayDataResolution *= 2; | |
602
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
145 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
|
146 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
|
147 lifeDataIndex = DEPTH_DATA_LENGTH / 2; |
598 | 148 } |
602
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
149 liveDepthData[lifeDataIndex++] = (int)(stateUsed->lifeData.depth_meter * 100); |
598 | 150 } |
38 | 151 } |
152 else if(bDiveMode == 3) | |
153 { | |
154 //End of Dive | |
155 for(int i=0;i<MLLsize;i++) | |
156 MLLdataDepth[i] = 0; | |
157 bDiveMode = 0; | |
158 } | |
159 } | |
160 | |
598 | 161 uint8_t prepareReplayLog(uint8_t StepBackwards) |
162 { | |
163 uint8_t retVal = 0; | |
164 uint16_t dataLength = 0; | |
38 | 165 |
598 | 166 SLogbookHeader logbookHeader; |
167 | |
168 if(ReplayDataOffset == StepBackwards) /* Entry already selected => reset selection */ | |
169 { | |
170 ReplayDataOffset = 0xFFFF; | |
171 ReplayDataResolution = 2; | |
602
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
172 ReplayDataLength = 0; |
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
173 ReplayDataMaxDepth = 0; |
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
174 ReplayDataMinutes = 0; |
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
175 |
598 | 176 retVal = 1; |
177 } | |
178 else | |
179 { | |
180 ReplayDataOffset = StepBackwards; | |
181 logbook_getHeader(StepBackwards ,&logbookHeader); | |
182 | |
602
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
183 dataLength = logbook_readSampleData(StepBackwards, DEPTH_DATA_LENGTH, ReplayDepthData,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); |
598 | 184 |
185 if( dataLength == DEPTH_DATA_LENGTH) /* log data has been compressed to fit into buffer */ | |
186 { | |
187 ReplayDataResolution = (logbookHeader.diveTimeMinutes * 60 + logbookHeader.diveTimeSeconds) / dataLength; | |
188 } | |
189 else | |
190 { | |
191 ReplayDataResolution = logbookHeader.samplingRate; | |
192 } | |
193 ReplayDataLength = dataLength; | |
194 ReplayDataMaxDepth = logbookHeader.maxDepth; | |
195 ReplayDataMinutes = logbookHeader.diveTimeMinutes; | |
196 if(dataLength != 0) | |
197 { | |
198 retVal = 1; | |
199 } | |
200 } | |
201 return retVal; | |
202 } | |
203 | |
204 uint8_t getReplayInfo(uint16_t** pReplayData, uint16_t* DataLength, uint16_t* MaxDepth, uint16_t* diveMinutes) | |
205 { | |
206 uint8_t retVal = 0; | |
207 | |
208 if((ReplayDataOffset != 0xFFFF) && (pReplayData != NULL) && (DataLength != NULL) && (MaxDepth != NULL)) | |
209 { | |
602
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
210 *pReplayData = ReplayDepthData; |
598 | 211 *DataLength = ReplayDataLength; |
212 *MaxDepth = ReplayDataMaxDepth; | |
213 *diveMinutes = ReplayDataMinutes; | |
214 retVal = 1; | |
215 } | |
216 | |
217 return retVal; | |
218 } | |
219 | |
220 uint16_t *getMiniLiveReplayPointerToData(void) | |
221 { | |
602
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
222 return liveDepthData; |
598 | 223 } |
224 uint16_t getMiniLiveReplayLength(void) | |
225 { | |
602
2cb0a97a07ad
Added replay data scaling in case life data is longer than replay block
Ideenmodellierer
parents:
598
diff
changeset
|
226 return lifeDataIndex; |
598 | 227 } |
228 | |
229 uint16_t getReplayOffset(void) | |
230 { | |
231 return ReplayDataOffset; | |
232 } | |
233 | |
234 uint16_t getReplayDataResolution(void) | |
235 { | |
236 return ReplayDataResolution; | |
237 } | |
38 | 238 |
239 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ |