Mercurial > public > ostc4
annotate Discovery/Src/tCCR.c @ 656:3ccf13af4651
Added visualization of scrubber time:
The remaining scrubber timer may be displayed in minutes or percentage of maximum time (both countdown). The value is displayed in the lower left corner, the overview custom view in T7 display as well as in the O2 Monitor view of the T3 display.
author | Ideenmodellierer |
---|---|
date | Sun, 25 Apr 2021 20:47:01 +0200 |
parents | 980b4aa60a0e |
children | 1b995079c045 |
rev | line source |
---|---|
38 | 1 /////////////////////////////////////////////////////////////////////////////// |
2 /// -*- coding: UTF-8 -*- | |
3 /// | |
4 /// \file Discovery/Src/tCCR.c | |
5 /// \brief HUD data via optical port | |
6 /// \author Heinrichs Weikamp gmbh | |
7 /// \date 18-Dec-2014 | |
8 /// | |
9 /// \details | |
10 /// | |
11 /// $Id$ | |
12 /////////////////////////////////////////////////////////////////////////////// | |
13 /// \par Copyright (c) 2014-2018 Heinrichs Weikamp gmbh | |
14 /// | |
15 /// This program is free software: you can redistribute it and/or modify | |
16 /// it under the terms of the GNU General Public License as published by | |
17 /// the Free Software Foundation, either version 3 of the License, or | |
18 /// (at your option) any later version. | |
19 /// | |
20 /// This program is distributed in the hope that it will be useful, | |
21 /// but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
23 /// GNU General Public License for more details. | |
24 /// | |
25 /// You should have received a copy of the GNU General Public License | |
26 /// along with this program. If not, see <http://www.gnu.org/licenses/>. | |
27 ////////////////////////////////////////////////////////////////////////////// | |
28 | |
29 /* Includes ------------------------------------------------------------------*/ | |
30 #include <string.h> | |
31 #include "tCCR.h" | |
32 #include "ostc.h" | |
33 #include "data_central.h" | |
34 #include "data_exchange.h" | |
35 #include "check_warning.h" | |
446
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
36 #include "configuration.h" |
634 | 37 #include <math.h> |
38 | 38 |
39 /* Private types -------------------------------------------------------------*/ | |
40 typedef struct | |
41 { | |
42 uint8_t hud_firmwareVersion; | |
43 bit8_Type status_byte; | |
44 uint16_t sensor_voltage_100uV[3]; | |
45 uint8_t sensor_ppo2_cbar[3]; | |
46 uint8_t temp1; | |
47 uint16_t battery_voltage_mV; | |
48 uint16_t checksum; | |
49 } SIrLink; | |
50 | |
634 | 51 typedef enum |
52 { | |
53 sensorOK = 0, | |
54 sensorSuspect, | |
55 SensorOutOfBounds | |
56 } sensorTrustState_t; | |
57 | |
58 | |
322
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
59 #define HUD_BABBLING_IDIOT (30u) /* 30 Bytes received without break */ |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
60 #define HUD_RX_FRAME_LENGTH (15u) /* Length of a HUD data frame */ |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
61 #define HUD_RX_FRAME_BREAK_MS (100u) /* Time used to detect a gap between two byte receptions => frame start */ |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
62 #define HUD_RX_START_DELAY_MS (500u) /* Delay for start of RX function to avoid start of reception while a transmission is ongoing. */ |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
63 /* Based on an assumed cycle time by the sensor of 1 second. Started at time of last RX */ |
38 | 64 |
449
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
65 #define BOTTLE_SENSOR_TIMEOUT (6000u) /* signal pressure budget as not received after 10 minutes (6000 * 100ms) */ |
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
66 |
634 | 67 #define MAX_SENSOR_COMPARE_DEVIATION (0.15f) /* max deviation between two sensors allowed before their results are rated as suspect */ |
68 | |
322
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
69 /* Private variables ---------------------------------------------------------*/ |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
70 static SIrLink receiveHUD[2]; |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
71 static uint8_t boolHUDdata = 0; |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
72 static uint8_t data_old__lost_connection_to_HUD = 1; |
38 | 73 |
322
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
74 static uint8_t receiveHUDraw[16]; |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
75 |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
76 static uint8_t StartListeningToUART_HUD = 0; |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
77 static uint16_t HUDTimeoutCount = 0; |
655 | 78 static uint16_t ScrubberTimeoutCount = 0; |
322
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
79 |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
80 static __IO ITStatus UartReadyHUD = RESET; |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
81 static uint32_t LastReceivedTick_HUD = 0; |
38 | 82 |
83 /* Private variables with external access via get_xxx() function -------------*/ | |
84 | |
85 /* Private function prototypes -----------------------------------------------*/ | |
635 | 86 static uint8_t tCCR_fallbackToFixedSetpoint(void); |
38 | 87 |
88 #ifndef USART_IR_HUD | |
89 | |
90 void tCCR_init(void) | |
91 { | |
92 } | |
93 void tCCR_control(void) | |
94 { | |
95 } | |
96 void tCCR_test(void) | |
97 { | |
98 } | |
99 void tCCR_restart(void) | |
100 { | |
101 } | |
102 float get_ppO2Sensor_bar(uint8_t sensor_id) | |
103 { | |
104 } | |
105 float get_sensorVoltage_mV(uint8_t sensor_id) | |
106 { | |
107 } | |
108 float get_HUD_battery_voltage_V(void) | |
109 { | |
110 } | |
111 void tCCR_tick(void) | |
112 { | |
113 } | |
114 | |
115 #else | |
116 /* Exported functions --------------------------------------------------------*/ | |
117 | |
118 float get_ppO2Sensor_bar(uint8_t sensor_id) | |
119 { | |
120 if((sensor_id > 2) || data_old__lost_connection_to_HUD) | |
121 return 0; | |
122 | |
123 return (float)(receiveHUD[boolHUDdata].sensor_ppo2_cbar[sensor_id]) / 100.0f; | |
124 } | |
125 | |
126 float get_sensorVoltage_mV(uint8_t sensor_id) | |
127 { | |
128 if((sensor_id > 2) || data_old__lost_connection_to_HUD) | |
129 return 0; | |
130 | |
131 return (float)(receiveHUD[boolHUDdata].sensor_voltage_100uV[sensor_id]) / 10.0f; | |
132 } | |
133 | |
134 float get_HUD_battery_voltage_V(void) | |
135 { | |
136 if(data_old__lost_connection_to_HUD) | |
137 return 0; | |
138 | |
139 return (float)(receiveHUD[boolHUDdata].battery_voltage_mV) / 1000.0f; | |
140 } | |
141 | |
142 | |
563 | 143 void test_O2_sensor_values_outOfBounds(int8_t * outOfBouds1, int8_t * outOfBouds2, int8_t * outOfBouds3) |
38 | 144 { |
145 uint8_t sensorNotActiveBinary; | |
146 uint8_t sensorActive[3]; | |
634 | 147 sensorTrustState_t sensorState[3]; |
148 uint8_t index; | |
149 | |
38 | 150 |
151 // test1: user deactivation | |
152 sensorNotActiveBinary = stateUsed->diveSettings.ppo2sensors_deactivated; | |
153 | |
154 for(int i=0;i<3;i++) | |
155 sensorActive[i] = 1; | |
156 | |
157 if(sensorNotActiveBinary) | |
158 { | |
159 if(sensorNotActiveBinary & 1) | |
160 sensorActive[0] = 0; | |
161 | |
162 if(sensorNotActiveBinary & 2) | |
163 sensorActive[1] = 0; | |
164 | |
165 if(sensorNotActiveBinary & 4) | |
166 sensorActive[2] = 0; | |
167 } | |
168 | |
169 // test2: mV of remaining sensors | |
170 for(int i=0;i<3;i++) | |
171 { | |
634 | 172 sensorState[i] = sensorOK; |
173 | |
38 | 174 if(sensorActive[i]) |
175 { | |
563 | 176 if( (stateUsed->lifeData.sensorVoltage_mV[i] < 8) || |
177 (stateUsed->lifeData.sensorVoltage_mV[i] > 250)) | |
38 | 178 { |
179 sensorActive[i] = 0; | |
180 switch(i) | |
181 { | |
182 case 0: | |
183 sensorNotActiveBinary |= 1; | |
184 break; | |
185 case 1: | |
186 sensorNotActiveBinary |= 2; | |
187 break; | |
188 case 2: | |
189 sensorNotActiveBinary |= 4; | |
190 break; | |
191 } | |
192 } | |
193 } | |
194 } | |
195 | |
196 *outOfBouds1 = 0; | |
197 *outOfBouds2 = 0; | |
198 *outOfBouds3 = 0; | |
199 | |
200 /* with two, one or no sensor, there is nothing to compare anymore | |
201 */ | |
202 if(sensorNotActiveBinary) | |
203 { | |
204 // set outOfBounds for both tests | |
205 if(!sensorActive[0]) | |
206 *outOfBouds1 = 1; | |
207 | |
208 if(!sensorActive[1]) | |
209 *outOfBouds2 = 1; | |
210 | |
211 if(!sensorActive[2]) | |
212 *outOfBouds3 = 1; | |
213 } | |
214 else | |
215 { | |
634 | 216 /* Check two or more of Three */ |
217 /* compare every sensor with each other. If there is only one mismatch the value might be OK. In case both comparisons fail the sensor is out of bounds */ | |
218 if(fabsf(stateUsed->lifeData.ppO2Sensor_bar[0] - stateUsed->lifeData.ppO2Sensor_bar[1]) > MAX_SENSOR_COMPARE_DEVIATION) | |
38 | 219 { |
634 | 220 sensorState[0]++; |
221 sensorState[1]++; | |
38 | 222 } |
634 | 223 if(fabsf(stateUsed->lifeData.ppO2Sensor_bar[0] - stateUsed->lifeData.ppO2Sensor_bar[2]) > MAX_SENSOR_COMPARE_DEVIATION) |
38 | 224 { |
634 | 225 sensorState[0]++; |
226 sensorState[2]++; | |
227 } | |
228 if(fabsf(stateUsed->lifeData.ppO2Sensor_bar[1] - stateUsed->lifeData.ppO2Sensor_bar[2]) > MAX_SENSOR_COMPARE_DEVIATION) | |
229 { | |
230 sensorState[1]++; | |
231 sensorState[2]++; | |
38 | 232 } |
634 | 233 for(index = 0; index < 3; index++) |
38 | 234 { |
634 | 235 if(sensorState[index] == SensorOutOfBounds) |
236 { | |
237 switch(index) | |
238 { | |
239 case 0: | |
240 *outOfBouds1 = 1; | |
241 break; | |
242 case 1: | |
243 *outOfBouds2 = 1; | |
244 break; | |
245 case 2: | |
246 *outOfBouds3 = 1; | |
247 break; | |
248 default: | |
249 break; | |
250 } | |
251 } | |
38 | 252 } |
253 } | |
254 } | |
255 | |
635 | 256 /* this function is called out of the 100ms callback => to be considered for debouncing */ |
38 | 257 uint8_t get_ppO2SensorWeightedResult_cbar(void) |
258 { | |
634 | 259 static uint8_t lastValidValue = 0; |
38 | 260 int8_t sensorOutOfBound[3]; |
261 uint16_t result = 0; | |
262 uint8_t count = 0; | |
582
64bf41faab83
Show Fallback if no valid sensor value is available:
Ideenmodellierer
parents:
563
diff
changeset
|
263 uint8_t retVal = 0; |
38 | 264 |
563 | 265 test_O2_sensor_values_outOfBounds(&sensorOutOfBound[0], &sensorOutOfBound[1], &sensorOutOfBound[2]); |
38 | 266 |
267 for(int i=0;i<3;i++) | |
268 { | |
269 if(!sensorOutOfBound[i]) | |
270 { | |
563 | 271 result += stateUsed->lifeData.ppO2Sensor_bar[i] * 100.0; /* convert centibar used by HUB */ |
38 | 272 count++; |
273 } | |
274 } | |
634 | 275 if(count == 0) /* all sensors out of bounds! => return last valid value as workaround till diver takes action */ |
582
64bf41faab83
Show Fallback if no valid sensor value is available:
Ideenmodellierer
parents:
563
diff
changeset
|
276 { |
635 | 277 if(debounce_warning_fallback(100)) |
278 { | |
279 set_warning_fallback(); | |
280 retVal = tCCR_fallbackToFixedSetpoint(); /* this function only changes setpoint if option is enabled */ | |
281 } | |
282 if(retVal == 0) | |
283 { | |
284 retVal = lastValidValue; | |
285 } | |
582
64bf41faab83
Show Fallback if no valid sensor value is available:
Ideenmodellierer
parents:
563
diff
changeset
|
286 } |
38 | 287 else |
582
64bf41faab83
Show Fallback if no valid sensor value is available:
Ideenmodellierer
parents:
563
diff
changeset
|
288 { |
635 | 289 reset_debounce_warning_fallback(); |
290 retVal = (uint8_t)(result / count); | |
291 lastValidValue = retVal; | |
582
64bf41faab83
Show Fallback if no valid sensor value is available:
Ideenmodellierer
parents:
563
diff
changeset
|
292 } |
64bf41faab83
Show Fallback if no valid sensor value is available:
Ideenmodellierer
parents:
563
diff
changeset
|
293 return retVal; |
38 | 294 } |
295 | |
296 | |
297 void tCCR_init(void) | |
298 { | |
449
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
299 uint8_t loop; |
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
300 |
38 | 301 StartListeningToUART_HUD = 1; |
449
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
302 |
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
303 SDiveState* pDiveData = stateRealGetPointerWrite(); |
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
304 for(loop=0;loop<(2*NUM_GASES+1);loop++) |
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
305 { |
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
306 pDiveData->lifeData.bottle_bar_age_MilliSeconds[loop] = BOTTLE_SENSOR_TIMEOUT; |
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
307 } |
38 | 308 } |
309 | |
310 | |
311 /* after 3 seconds without update from HUD | |
312 * data is considered old | |
313 */ | |
314 void tCCR_tick(void) | |
315 { | |
655 | 316 SSettings* pSettings = settingsGetPointer(); |
317 | |
318 if(pSettings->ppo2sensors_source == O2_SENSOR_SOURCE_OPTIC) | |
563 | 319 { |
320 if(HUDTimeoutCount < 3 * 10) | |
321 HUDTimeoutCount++; | |
322 else | |
323 { | |
324 data_old__lost_connection_to_HUD = 1; | |
325 if(HUDTimeoutCount < 20 * 10) | |
326 HUDTimeoutCount++; | |
327 else | |
328 tCCR_fallbackToFixedSetpoint(); | |
329 } | |
330 } | |
655 | 331 |
332 /* decrease scrubber timer only in real dive mode */ | |
333 if((pSettings->scrubTimerMode != SCRUB_TIMER_OFF) && (pSettings->dive_mode == DIVEMODE_CCR) && (stateUsed->mode == MODE_DIVE) && (stateUsed == stateRealGetPointer())) | |
334 { | |
335 ScrubberTimeoutCount++; | |
336 if(ScrubberTimeoutCount >= 600) /* resolution is minutes */ | |
337 { | |
338 ScrubberTimeoutCount = 0; | |
339 if(pSettings->scrubTimerCur > 0) | |
340 { | |
341 pSettings->scrubTimerCur--; | |
342 } | |
343 } | |
344 } | |
38 | 345 } |
346 | |
322
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
347 void tCCR_SetRXIndication(void) |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
348 { |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
349 static uint8_t floatingRXCount = 0; |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
350 |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
351 if((UartIR_HUD_Handle.RxXferSize == HUD_RX_FRAME_LENGTH) || (UartIR_HUD_Handle.RxXferSize == HUD_RX_FRAME_LENGTH - 1)) /* we expected a complete frame */ |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
352 { |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
353 UartReadyHUD = SET; |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
354 LastReceivedTick_HUD = HAL_GetTick(); |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
355 floatingRXCount = 0; |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
356 } |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
357 else /* follow up of error handling */ |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
358 { |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
359 if(time_elapsed_ms(LastReceivedTick_HUD, HAL_GetTick()) > HUD_RX_FRAME_BREAK_MS) /* Reception took a while => frame start detected */ |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
360 { |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
361 HAL_UART_Receive_IT(&UartIR_HUD_Handle, &receiveHUDraw[1], 14); /* We have already the first byte => get the missing 14 */ |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
362 } |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
363 else |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
364 { |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
365 if(floatingRXCount++ < HUD_BABBLING_IDIOT) |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
366 { |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
367 HAL_UART_Receive_IT(&UartIR_HUD_Handle, receiveHUDraw, 1); /* Start polling of incoming bytes */ |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
368 } |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
369 else /* Significant amount of data comming in without break => disable input */ |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
370 { /* by not reactivation HUD RX, no recovery fromthis state */ |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
371 stateUsedWrite->diveSettings.ppo2sensors_deactivated = 0x07; /* Display deactivation */ |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
372 } |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
373 } |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
374 } |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
375 |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
376 } |
38 | 377 |
378 void tCCR_restart(void) | |
379 { | |
322
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
380 HAL_UART_AbortReceive_IT(&UartIR_HUD_Handle); /* Called by the error handler. RX will be restarted by control function */ |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
381 StartListeningToUART_HUD = 1; |
38 | 382 } |
383 | |
384 | |
385 void tCCR_control(void) | |
386 { | |
446
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
387 uint16_t checksum = 0; |
457 | 388 #ifdef ENABLE_BOTTLE_SENSOR |
446
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
389 SDiveState *pLivedata = stateRealGetPointerWrite(); |
457 | 390 #endif |
322
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
391 |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
392 if((UartReadyHUD == RESET) && StartListeningToUART_HUD && (time_elapsed_ms(LastReceivedTick_HUD, HAL_GetTick()) > HUD_RX_START_DELAY_MS)) |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
393 { |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
394 StartListeningToUART_HUD = 0; |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
395 HAL_UART_Receive_IT(&UartIR_HUD_Handle, receiveHUDraw, HUD_RX_FRAME_LENGTH); |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
396 } |
38 | 397 |
398 if(UartReadyHUD == SET) | |
399 { | |
400 UartReadyHUD = RESET; | |
322
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
401 StartListeningToUART_HUD = 1; |
38 | 402 |
446
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
403 /* check if received package is valid */ |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
404 for(int i=0;i<13;i++) |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
405 { |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
406 checksum += receiveHUDraw[i]; |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
407 } |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
408 receiveHUD[!boolHUDdata].checksum = receiveHUDraw[13] + (256 * receiveHUDraw[14]); |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
409 if(checksum == receiveHUD[!boolHUDdata].checksum) |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
410 { |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
411 #ifdef ENABLE_BOTTLE_SENSOR |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
412 if(receiveHUDraw[0] == 0xA5) /* code for pressure sensor */ |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
413 { |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
414 pLivedata->lifeData.bottle_bar[pLivedata->lifeData.actualGas.GasIdInSettings] = receiveHUDraw[10]; |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
415 pLivedata->lifeData.bottle_bar_age_MilliSeconds[pLivedata->lifeData.actualGas.GasIdInSettings] = 0; |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
416 } |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
417 else |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
418 #endif |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
419 /* handle O2 sensor data */ |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
420 { |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
421 memcpy(&receiveHUD[!boolHUDdata], receiveHUDraw, 11); |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
422 receiveHUD[!boolHUDdata].battery_voltage_mV = receiveHUDraw[11] + (256 * receiveHUDraw[12]); |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
423 } |
38 | 424 |
446
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
425 boolHUDdata = !boolHUDdata; |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
426 HUDTimeoutCount = 0; |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
427 data_old__lost_connection_to_HUD = 0; |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
428 } |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
429 else |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
430 { |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
431 if(data_old__lost_connection_to_HUD) /* we lost connection, maybe due to RX shift => start single byte read to resynchronize */ |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
432 { |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
433 HAL_UART_Receive_IT(&UartIR_HUD_Handle, receiveHUDraw, 1); |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
434 StartListeningToUART_HUD = 0; |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
435 } |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
436 } |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
437 memset(receiveHUDraw,0,sizeof(receiveHUDraw)); |
38 | 438 } |
439 } | |
440 | |
441 #endif | |
442 /* Private functions ---------------------------------------------------------*/ | |
443 | |
635 | 444 static uint8_t tCCR_fallbackToFixedSetpoint(void) |
38 | 445 { |
635 | 446 uint8_t retVal = 0; |
38 | 447 if((stateUsed->mode == MODE_DIVE) && (stateUsed->diveSettings.diveMode == DIVEMODE_CCR) && (stateUsed->diveSettings.CCR_Mode == CCRMODE_Sensors) && (stateUsed->diveSettings.fallbackOption)) |
448 { | |
449 uint8_t setpointCbar, actualGasID; | |
450 | |
272
74a8296a2318
cleanup: simplify stateUsed usage
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
451 setpointCbar = stateUsed->diveSettings.setpoint[1].setpoint_cbar; |
74a8296a2318
cleanup: simplify stateUsed usage
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
452 stateUsedWrite->diveSettings.CCR_Mode = CCRMODE_FixedSetpoint; |
38 | 453 |
272
74a8296a2318
cleanup: simplify stateUsed usage
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
454 actualGasID = stateUsed->lifeData.actualGas.GasIdInSettings; |
74a8296a2318
cleanup: simplify stateUsed usage
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
455 setActualGas_DM(&stateUsedWrite->lifeData,actualGasID,setpointCbar); |
38 | 456 |
457 set_warning_fallback(); | |
635 | 458 retVal = stateUsed->diveSettings.setpoint[1].setpoint_cbar; |
38 | 459 } |
635 | 460 return retVal; |
38 | 461 } |