Mercurial > public > ostc4
annotate Discovery/Src/tCCR.c @ 626:3e1a0e267f38
Added option to select sensitivity of focus detection:
Depending on the location the computer is equiped during dive (arm wet/ dry suite, glove...) it is usefull to adapt the sensitivity of the focus detection. Technical it means the radius of the spot in which direction ray is projected may be changed in size.
The option has been added to the motion control menu.
author | Ideenmodellierer |
---|---|
date | Fri, 12 Feb 2021 21:37:50 +0100 |
parents | 64bf41faab83 |
children | 7c73f066cd16 |
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" |
38 | 37 |
38 /* Private types -------------------------------------------------------------*/ | |
39 typedef struct | |
40 { | |
41 uint8_t hud_firmwareVersion; | |
42 bit8_Type status_byte; | |
43 uint16_t sensor_voltage_100uV[3]; | |
44 uint8_t sensor_ppo2_cbar[3]; | |
45 uint8_t temp1; | |
46 uint16_t battery_voltage_mV; | |
47 uint16_t checksum; | |
48 } SIrLink; | |
49 | |
322
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
50 #define HUD_BABBLING_IDIOT (30u) /* 30 Bytes received without break */ |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
51 #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
|
52 #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
|
53 #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
|
54 /* Based on an assumed cycle time by the sensor of 1 second. Started at time of last RX */ |
38 | 55 |
449
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
56 #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
|
57 |
322
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
58 /* Private variables ---------------------------------------------------------*/ |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
59 static SIrLink receiveHUD[2]; |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
60 static uint8_t boolHUDdata = 0; |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
61 static uint8_t data_old__lost_connection_to_HUD = 1; |
38 | 62 |
322
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
63 static uint8_t receiveHUDraw[16]; |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
64 |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
65 static uint8_t StartListeningToUART_HUD = 0; |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
66 static uint16_t HUDTimeoutCount = 0; |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
67 |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
68 static __IO ITStatus UartReadyHUD = RESET; |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
69 static uint32_t LastReceivedTick_HUD = 0; |
38 | 70 |
71 /* Private variables with external access via get_xxx() function -------------*/ | |
72 | |
73 /* Private function prototypes -----------------------------------------------*/ | |
272
74a8296a2318
cleanup: simplify stateUsed usage
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
74 static void tCCR_fallbackToFixedSetpoint(void); |
38 | 75 |
76 #ifndef USART_IR_HUD | |
77 | |
78 void tCCR_init(void) | |
79 { | |
80 } | |
81 void tCCR_control(void) | |
82 { | |
83 } | |
84 void tCCR_test(void) | |
85 { | |
86 } | |
87 void tCCR_restart(void) | |
88 { | |
89 } | |
90 float get_ppO2Sensor_bar(uint8_t sensor_id) | |
91 { | |
92 } | |
93 float get_sensorVoltage_mV(uint8_t sensor_id) | |
94 { | |
95 } | |
96 float get_HUD_battery_voltage_V(void) | |
97 { | |
98 } | |
99 void tCCR_tick(void) | |
100 { | |
101 } | |
102 | |
103 #else | |
104 /* Exported functions --------------------------------------------------------*/ | |
105 | |
106 float get_ppO2Sensor_bar(uint8_t sensor_id) | |
107 { | |
108 if((sensor_id > 2) || data_old__lost_connection_to_HUD) | |
109 return 0; | |
110 | |
111 return (float)(receiveHUD[boolHUDdata].sensor_ppo2_cbar[sensor_id]) / 100.0f; | |
112 } | |
113 | |
114 float get_sensorVoltage_mV(uint8_t sensor_id) | |
115 { | |
116 if((sensor_id > 2) || data_old__lost_connection_to_HUD) | |
117 return 0; | |
118 | |
119 return (float)(receiveHUD[boolHUDdata].sensor_voltage_100uV[sensor_id]) / 10.0f; | |
120 } | |
121 | |
122 float get_HUD_battery_voltage_V(void) | |
123 { | |
124 if(data_old__lost_connection_to_HUD) | |
125 return 0; | |
126 | |
127 return (float)(receiveHUD[boolHUDdata].battery_voltage_mV) / 1000.0f; | |
128 } | |
129 | |
130 | |
563 | 131 void test_O2_sensor_values_outOfBounds(int8_t * outOfBouds1, int8_t * outOfBouds2, int8_t * outOfBouds3) |
38 | 132 { |
133 uint8_t sensorNotActiveBinary; | |
134 uint8_t sensorActive[3]; | |
135 | |
136 // test1: user deactivation | |
137 sensorNotActiveBinary = stateUsed->diveSettings.ppo2sensors_deactivated; | |
138 | |
139 for(int i=0;i<3;i++) | |
140 sensorActive[i] = 1; | |
141 | |
142 if(sensorNotActiveBinary) | |
143 { | |
144 if(sensorNotActiveBinary & 1) | |
145 sensorActive[0] = 0; | |
146 | |
147 if(sensorNotActiveBinary & 2) | |
148 sensorActive[1] = 0; | |
149 | |
150 if(sensorNotActiveBinary & 4) | |
151 sensorActive[2] = 0; | |
152 } | |
153 | |
154 // test2: mV of remaining sensors | |
155 for(int i=0;i<3;i++) | |
156 { | |
157 if(sensorActive[i]) | |
158 { | |
563 | 159 if( (stateUsed->lifeData.sensorVoltage_mV[i] < 8) || |
160 (stateUsed->lifeData.sensorVoltage_mV[i] > 250)) | |
38 | 161 { |
162 sensorActive[i] = 0; | |
163 switch(i) | |
164 { | |
165 case 0: | |
166 sensorNotActiveBinary |= 1; | |
167 break; | |
168 case 1: | |
169 sensorNotActiveBinary |= 2; | |
170 break; | |
171 case 2: | |
172 sensorNotActiveBinary |= 4; | |
173 break; | |
174 } | |
175 } | |
176 } | |
177 } | |
178 | |
179 *outOfBouds1 = 0; | |
180 *outOfBouds2 = 0; | |
181 *outOfBouds3 = 0; | |
182 | |
183 /* with two, one or no sensor, there is nothing to compare anymore | |
184 */ | |
185 if(sensorNotActiveBinary) | |
186 { | |
187 // set outOfBounds for both tests | |
188 if(!sensorActive[0]) | |
189 *outOfBouds1 = 1; | |
190 | |
191 if(!sensorActive[1]) | |
192 *outOfBouds2 = 1; | |
193 | |
194 if(!sensorActive[2]) | |
195 *outOfBouds3 = 1; | |
196 } | |
197 else | |
198 { | |
199 uint8_t sensor_id_ordered[3]; | |
563 | 200 float difference[2]; |
38 | 201 |
563 | 202 if((stateUsed->lifeData.ppO2Sensor_bar[1] > stateUsed->lifeData.ppO2Sensor_bar[0])) |
38 | 203 { |
204 sensor_id_ordered[0] = 0; | |
205 sensor_id_ordered[1] = 1; | |
206 } | |
207 else | |
208 { | |
209 sensor_id_ordered[0] = 1; | |
210 sensor_id_ordered[1] = 0; | |
211 } | |
563 | 212 if(stateUsed->lifeData.ppO2Sensor_bar[2] > stateUsed->lifeData.ppO2Sensor_bar[sensor_id_ordered[1]]) |
38 | 213 { |
214 sensor_id_ordered[2] = 2; | |
215 } | |
216 else | |
217 { | |
218 sensor_id_ordered[2] = sensor_id_ordered[1]; | |
563 | 219 if(stateUsed->lifeData.ppO2Sensor_bar[2] > stateUsed->lifeData.ppO2Sensor_bar[sensor_id_ordered[0]]) |
38 | 220 { |
221 sensor_id_ordered[1] = 2; | |
222 } | |
223 else | |
224 { | |
225 sensor_id_ordered[1] = sensor_id_ordered[0]; | |
226 sensor_id_ordered[0] = 2; | |
227 } | |
228 } | |
229 | |
563 | 230 difference[0] = stateUsed->lifeData.ppO2Sensor_bar[sensor_id_ordered[1]]- stateUsed->lifeData.ppO2Sensor_bar[sensor_id_ordered[0]]; |
231 difference[1] = stateUsed->lifeData.ppO2Sensor_bar[sensor_id_ordered[2]]- stateUsed->lifeData.ppO2Sensor_bar[sensor_id_ordered[1]]; | |
38 | 232 |
563 | 233 if((difference[0] > difference[1]) && (difference[0] > 0.15)) /* was 15cBar ==> 0.15 bar */ |
38 | 234 { |
235 switch(sensor_id_ordered[0]) | |
236 { | |
237 case 0: | |
238 *outOfBouds1 = 1; | |
239 break; | |
240 case 1: | |
241 *outOfBouds2 = 1; | |
242 break; | |
243 case 2: | |
244 *outOfBouds3 = 1; | |
245 break; | |
246 } | |
247 } | |
248 else | |
563 | 249 if((difference[0] < difference[1]) && (difference[1] > 0.15)) |
38 | 250 { |
251 switch(sensor_id_ordered[2]) | |
252 { | |
253 case 0: | |
254 *outOfBouds1 = 1; | |
255 break; | |
256 case 1: | |
257 *outOfBouds2 = 1; | |
258 break; | |
259 case 2: | |
260 *outOfBouds3 = 1; | |
261 break; | |
262 } | |
263 } | |
264 } | |
582
64bf41faab83
Show Fallback if no valid sensor value is available:
Ideenmodellierer
parents:
563
diff
changeset
|
265 |
38 | 266 } |
267 | |
268 | |
269 uint8_t get_ppO2SensorWeightedResult_cbar(void) | |
270 { | |
271 int8_t sensorOutOfBound[3]; | |
272 uint16_t result = 0; | |
273 uint8_t count = 0; | |
582
64bf41faab83
Show Fallback if no valid sensor value is available:
Ideenmodellierer
parents:
563
diff
changeset
|
274 uint8_t retVal = 0; |
38 | 275 |
563 | 276 test_O2_sensor_values_outOfBounds(&sensorOutOfBound[0], &sensorOutOfBound[1], &sensorOutOfBound[2]); |
38 | 277 |
278 for(int i=0;i<3;i++) | |
279 { | |
280 if(!sensorOutOfBound[i]) | |
281 { | |
563 | 282 result += stateUsed->lifeData.ppO2Sensor_bar[i] * 100.0; /* convert centibar used by HUB */ |
38 | 283 count++; |
284 } | |
285 } | |
286 if(count == 0) // all sensors out of bounds! | |
582
64bf41faab83
Show Fallback if no valid sensor value is available:
Ideenmodellierer
parents:
563
diff
changeset
|
287 { |
64bf41faab83
Show Fallback if no valid sensor value is available:
Ideenmodellierer
parents:
563
diff
changeset
|
288 set_warning_fallback(); |
64bf41faab83
Show Fallback if no valid sensor value is available:
Ideenmodellierer
parents:
563
diff
changeset
|
289 } |
38 | 290 else |
582
64bf41faab83
Show Fallback if no valid sensor value is available:
Ideenmodellierer
parents:
563
diff
changeset
|
291 { |
64bf41faab83
Show Fallback if no valid sensor value is available:
Ideenmodellierer
parents:
563
diff
changeset
|
292 retVal = (uint8_t)(result / count); |
64bf41faab83
Show Fallback if no valid sensor value is available:
Ideenmodellierer
parents:
563
diff
changeset
|
293 } |
64bf41faab83
Show Fallback if no valid sensor value is available:
Ideenmodellierer
parents:
563
diff
changeset
|
294 return retVal; |
38 | 295 } |
296 | |
297 | |
298 void tCCR_init(void) | |
299 { | |
449
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
300 uint8_t loop; |
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
301 |
38 | 302 StartListeningToUART_HUD = 1; |
449
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
303 |
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
304 SDiveState* pDiveData = stateRealGetPointerWrite(); |
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
305 for(loop=0;loop<(2*NUM_GASES+1);loop++) |
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
306 { |
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
307 pDiveData->lifeData.bottle_bar_age_MilliSeconds[loop] = BOTTLE_SENSOR_TIMEOUT; |
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
308 } |
38 | 309 } |
310 | |
311 | |
312 /* after 3 seconds without update from HUD | |
313 * data is considered old | |
314 */ | |
315 void tCCR_tick(void) | |
316 { | |
563 | 317 if(settingsGetPointer()->ppo2sensors_source == O2_SENSOR_SOURCE_OPTIC) |
318 { | |
319 if(HUDTimeoutCount < 3 * 10) | |
320 HUDTimeoutCount++; | |
321 else | |
322 { | |
323 data_old__lost_connection_to_HUD = 1; | |
324 if(HUDTimeoutCount < 20 * 10) | |
325 HUDTimeoutCount++; | |
326 else | |
327 tCCR_fallbackToFixedSetpoint(); | |
328 } | |
329 } | |
38 | 330 } |
331 | |
322
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
332 void tCCR_SetRXIndication(void) |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
333 { |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
334 static uint8_t floatingRXCount = 0; |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
335 |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
336 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
|
337 { |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
338 UartReadyHUD = SET; |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
339 LastReceivedTick_HUD = HAL_GetTick(); |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
340 floatingRXCount = 0; |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
341 } |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
342 else /* follow up of error handling */ |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
343 { |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
344 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
|
345 { |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
346 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
|
347 } |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
348 else |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
349 { |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
350 if(floatingRXCount++ < HUD_BABBLING_IDIOT) |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
351 { |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
352 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
|
353 } |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
354 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
|
355 { /* by not reactivation HUD RX, no recovery fromthis state */ |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
356 stateUsedWrite->diveSettings.ppo2sensors_deactivated = 0x07; /* Display deactivation */ |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
357 } |
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 } |
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 } |
38 | 362 |
363 void tCCR_restart(void) | |
364 { | |
322
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
365 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
|
366 StartListeningToUART_HUD = 1; |
38 | 367 } |
368 | |
369 | |
370 void tCCR_control(void) | |
371 { | |
446
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
372 uint16_t checksum = 0; |
457 | 373 #ifdef ENABLE_BOTTLE_SENSOR |
446
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
374 SDiveState *pLivedata = stateRealGetPointerWrite(); |
457 | 375 #endif |
322
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
376 |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
377 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
|
378 { |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
379 StartListeningToUART_HUD = 0; |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
380 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
|
381 } |
38 | 382 |
383 if(UartReadyHUD == SET) | |
384 { | |
385 UartReadyHUD = RESET; | |
322
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
386 StartListeningToUART_HUD = 1; |
38 | 387 |
446
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
388 /* check if received package is valid */ |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
389 for(int i=0;i<13;i++) |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
390 { |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
391 checksum += receiveHUDraw[i]; |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
392 } |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
393 receiveHUD[!boolHUDdata].checksum = receiveHUDraw[13] + (256 * receiveHUDraw[14]); |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
394 if(checksum == receiveHUD[!boolHUDdata].checksum) |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
395 { |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
396 #ifdef ENABLE_BOTTLE_SENSOR |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
397 if(receiveHUDraw[0] == 0xA5) /* code for pressure sensor */ |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
398 { |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
399 pLivedata->lifeData.bottle_bar[pLivedata->lifeData.actualGas.GasIdInSettings] = receiveHUDraw[10]; |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
400 pLivedata->lifeData.bottle_bar_age_MilliSeconds[pLivedata->lifeData.actualGas.GasIdInSettings] = 0; |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
401 } |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
402 else |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
403 #endif |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
404 /* handle O2 sensor data */ |
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 memcpy(&receiveHUD[!boolHUDdata], receiveHUDraw, 11); |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
407 receiveHUD[!boolHUDdata].battery_voltage_mV = receiveHUDraw[11] + (256 * receiveHUDraw[12]); |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
408 } |
38 | 409 |
446
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
410 boolHUDdata = !boolHUDdata; |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
411 HUDTimeoutCount = 0; |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
412 data_old__lost_connection_to_HUD = 0; |
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 else |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
415 { |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
416 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
|
417 { |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
418 HAL_UART_Receive_IT(&UartIR_HUD_Handle, receiveHUDraw, 1); |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
419 StartListeningToUART_HUD = 0; |
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 } |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
422 memset(receiveHUDraw,0,sizeof(receiveHUDraw)); |
38 | 423 } |
424 } | |
425 | |
426 #endif | |
427 /* Private functions ---------------------------------------------------------*/ | |
428 | |
272
74a8296a2318
cleanup: simplify stateUsed usage
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
429 static void tCCR_fallbackToFixedSetpoint(void) |
38 | 430 { |
431 if((stateUsed->mode == MODE_DIVE) && (stateUsed->diveSettings.diveMode == DIVEMODE_CCR) && (stateUsed->diveSettings.CCR_Mode == CCRMODE_Sensors) && (stateUsed->diveSettings.fallbackOption)) | |
432 { | |
433 uint8_t setpointCbar, actualGasID; | |
434 | |
272
74a8296a2318
cleanup: simplify stateUsed usage
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
435 setpointCbar = stateUsed->diveSettings.setpoint[1].setpoint_cbar; |
74a8296a2318
cleanup: simplify stateUsed usage
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
436 stateUsedWrite->diveSettings.CCR_Mode = CCRMODE_FixedSetpoint; |
38 | 437 |
272
74a8296a2318
cleanup: simplify stateUsed usage
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
438 actualGasID = stateUsed->lifeData.actualGas.GasIdInSettings; |
74a8296a2318
cleanup: simplify stateUsed usage
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
439 setActualGas_DM(&stateUsedWrite->lifeData,actualGasID,setpointCbar); |
38 | 440 |
441 set_warning_fallback(); | |
442 } | |
443 } |