Mercurial > public > ostc4
annotate Discovery/Src/tCCR.c @ 1007:65d35e66efb9 GasConsumption
Improve compass calibration dialog:
The previous calibration dialog showed some "magic" numbers and a 60 second count down. The new version is trying to guide the user through the calibration process: first rotate pitch, then roll and at last yaw angle. A step to the next angle is taken when enough data per angle is collected (change from red to green). To enable the yaw visualization a simple calibration is done while rotating the axis.
The function behind the calibration was not modified => the suggested process can be ignored and the same handling as the with old dialog may be applied. With the new process the dialog may be left early. Anyhow it will still be left after 60 seconds and the fine calibration is performed in the same way as before.
| author | Ideenmodellierer |
|---|---|
| date | Mon, 05 May 2025 21:02:34 +0200 |
| parents | 5a690195b6b7 |
| children | 8c0134a287da |
| 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 */ |
| 662 | 68 #define MAX_SENSOR_VOLTAGE_MV (250u) /* max allowed voltage value for a sensor measurement */ |
| 69 | |
| 70 #ifdef ENABLE_ALTERNATIVE_SENSORTYP | |
| 71 #define MIN_SENSOR_VOLTAGE_MV (3u) /* min allowed voltage value for a sensor measurement (Inspiration, Submatix, Sentinel Typ) */ | |
| 72 #else | |
| 73 #define MIN_SENSOR_VOLTAGE_MV (8u) /* min allowed voltage value for a sensor measurement (legacy OSTC TYP) */ | |
| 74 #endif | |
| 634 | 75 |
|
322
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
76 /* Private variables ---------------------------------------------------------*/ |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
77 static SIrLink receiveHUD[2]; |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
78 static uint8_t boolHUDdata = 0; |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
79 static uint8_t data_old__lost_connection_to_HUD = 1; |
| 38 | 80 |
|
322
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
81 static uint8_t receiveHUDraw[16]; |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
82 |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
83 static uint8_t StartListeningToUART_HUD = 0; |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
84 static uint16_t HUDTimeoutCount = 0; |
| 655 | 85 static uint16_t ScrubberTimeoutCount = 0; |
|
322
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
86 |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
87 static __IO ITStatus UartReadyHUD = RESET; |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
88 static uint32_t LastReceivedTick_HUD = 0; |
| 38 | 89 |
| 90 /* Private variables with external access via get_xxx() function -------------*/ | |
| 91 | |
| 92 /* Private function prototypes -----------------------------------------------*/ | |
| 635 | 93 static uint8_t tCCR_fallbackToFixedSetpoint(void); |
| 38 | 94 |
| 95 #ifndef USART_IR_HUD | |
| 96 | |
| 97 void tCCR_init(void) | |
| 98 { | |
| 99 } | |
| 100 void tCCR_control(void) | |
| 101 { | |
| 102 } | |
| 103 void tCCR_test(void) | |
| 104 { | |
| 105 } | |
| 106 void tCCR_restart(void) | |
| 107 { | |
| 108 } | |
| 109 float get_ppO2Sensor_bar(uint8_t sensor_id) | |
| 110 { | |
| 111 } | |
| 112 float get_sensorVoltage_mV(uint8_t sensor_id) | |
| 113 { | |
| 114 } | |
| 115 float get_HUD_battery_voltage_V(void) | |
| 116 { | |
| 117 } | |
| 118 void tCCR_tick(void) | |
| 119 { | |
| 120 } | |
| 121 | |
| 122 #else | |
| 123 /* Exported functions --------------------------------------------------------*/ | |
| 124 | |
| 125 float get_ppO2Sensor_bar(uint8_t sensor_id) | |
| 126 { | |
| 127 if((sensor_id > 2) || data_old__lost_connection_to_HUD) | |
| 128 return 0; | |
| 129 | |
| 130 return (float)(receiveHUD[boolHUDdata].sensor_ppo2_cbar[sensor_id]) / 100.0f; | |
| 131 } | |
| 132 | |
| 133 float get_sensorVoltage_mV(uint8_t sensor_id) | |
| 134 { | |
| 135 if((sensor_id > 2) || data_old__lost_connection_to_HUD) | |
| 136 return 0; | |
| 137 | |
| 138 return (float)(receiveHUD[boolHUDdata].sensor_voltage_100uV[sensor_id]) / 10.0f; | |
| 139 } | |
| 140 | |
| 141 float get_HUD_battery_voltage_V(void) | |
| 142 { | |
| 143 if(data_old__lost_connection_to_HUD) | |
| 144 return 0; | |
| 145 | |
| 146 return (float)(receiveHUD[boolHUDdata].battery_voltage_mV) / 1000.0f; | |
| 147 } | |
| 148 | |
| 149 | |
| 563 | 150 void test_O2_sensor_values_outOfBounds(int8_t * outOfBouds1, int8_t * outOfBouds2, int8_t * outOfBouds3) |
| 38 | 151 { |
| 152 uint8_t sensorNotActiveBinary; | |
| 153 uint8_t sensorActive[3]; | |
| 634 | 154 sensorTrustState_t sensorState[3]; |
| 155 uint8_t index; | |
| 156 | |
| 38 | 157 |
| 158 // test1: user deactivation | |
| 159 sensorNotActiveBinary = stateUsed->diveSettings.ppo2sensors_deactivated; | |
| 160 | |
| 161 for(int i=0;i<3;i++) | |
| 162 sensorActive[i] = 1; | |
| 163 | |
| 164 if(sensorNotActiveBinary) | |
| 165 { | |
| 166 if(sensorNotActiveBinary & 1) | |
| 167 sensorActive[0] = 0; | |
| 168 | |
| 169 if(sensorNotActiveBinary & 2) | |
| 170 sensorActive[1] = 0; | |
| 171 | |
| 172 if(sensorNotActiveBinary & 4) | |
| 173 sensorActive[2] = 0; | |
| 174 } | |
| 175 | |
| 176 // test2: mV of remaining sensors | |
| 744 | 177 for(index=0; index<3; index++) |
| 38 | 178 { |
| 744 | 179 sensorState[index] = sensorOK; |
| 634 | 180 |
| 744 | 181 if(sensorActive[index]) |
| 38 | 182 { |
| 797 | 183 if(((stateUsed->lifeData.extIf_sensor_map[index] == SENSOR_DIGO2M) && (((SSensorDataDiveO2*)(stateUsed->lifeData.extIf_sensor_data[index]))->status & DVO2_FATAL_ERROR)) |
| 184 || ((stateUsed->lifeData.extIf_sensor_map[index] != SENSOR_DIGO2M) | |
|
757
39ff186b6f98
Dev Bugfix: ignore analog out of bounds limits for DiveO2 sensor:
Ideenmodellierer
parents:
744
diff
changeset
|
185 && (((stateUsed->lifeData.sensorVoltage_mV[index] < MIN_SENSOR_VOLTAGE_MV) || (stateUsed->lifeData.sensorVoltage_mV[index] > MAX_SENSOR_VOLTAGE_MV))))) |
| 744 | 186 { |
| 187 sensorActive[index] = 0; | |
| 188 switch(index) | |
| 189 { | |
| 190 case 0: | |
| 191 sensorNotActiveBinary |= 1; | |
| 192 break; | |
| 193 case 1: | |
| 194 sensorNotActiveBinary |= 2; | |
| 195 break; | |
| 196 case 2: | |
| 197 sensorNotActiveBinary |= 4; | |
| 198 break; | |
| 199 } | |
| 200 } | |
| 38 | 201 } |
| 202 } | |
| 203 | |
| 204 *outOfBouds1 = 0; | |
| 205 *outOfBouds2 = 0; | |
| 206 *outOfBouds3 = 0; | |
| 207 | |
| 208 /* with two, one or no sensor, there is nothing to compare anymore | |
| 209 */ | |
| 210 if(sensorNotActiveBinary) | |
| 211 { | |
| 212 // set outOfBounds for both tests | |
| 213 if(!sensorActive[0]) | |
| 214 *outOfBouds1 = 1; | |
| 215 | |
| 216 if(!sensorActive[1]) | |
| 217 *outOfBouds2 = 1; | |
| 218 | |
| 219 if(!sensorActive[2]) | |
| 220 *outOfBouds3 = 1; | |
| 221 } | |
| 222 else | |
| 223 { | |
| 634 | 224 /* Check two or more of Three */ |
| 225 /* 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 */ | |
| 226 if(fabsf(stateUsed->lifeData.ppO2Sensor_bar[0] - stateUsed->lifeData.ppO2Sensor_bar[1]) > MAX_SENSOR_COMPARE_DEVIATION) | |
| 38 | 227 { |
| 634 | 228 sensorState[0]++; |
| 229 sensorState[1]++; | |
| 38 | 230 } |
| 634 | 231 if(fabsf(stateUsed->lifeData.ppO2Sensor_bar[0] - stateUsed->lifeData.ppO2Sensor_bar[2]) > MAX_SENSOR_COMPARE_DEVIATION) |
| 38 | 232 { |
| 634 | 233 sensorState[0]++; |
| 234 sensorState[2]++; | |
| 235 } | |
| 236 if(fabsf(stateUsed->lifeData.ppO2Sensor_bar[1] - stateUsed->lifeData.ppO2Sensor_bar[2]) > MAX_SENSOR_COMPARE_DEVIATION) | |
| 237 { | |
| 238 sensorState[1]++; | |
| 239 sensorState[2]++; | |
| 38 | 240 } |
| 634 | 241 for(index = 0; index < 3; index++) |
| 38 | 242 { |
| 634 | 243 if(sensorState[index] == SensorOutOfBounds) |
| 244 { | |
| 245 switch(index) | |
| 246 { | |
| 247 case 0: | |
| 248 *outOfBouds1 = 1; | |
| 249 break; | |
| 250 case 1: | |
| 251 *outOfBouds2 = 1; | |
| 252 break; | |
| 253 case 2: | |
| 254 *outOfBouds3 = 1; | |
| 255 break; | |
| 256 default: | |
| 257 break; | |
| 258 } | |
| 259 } | |
| 38 | 260 } |
| 261 } | |
| 262 } | |
| 263 | |
| 635 | 264 /* this function is called out of the 100ms callback => to be considered for debouncing */ |
| 38 | 265 uint8_t get_ppO2SensorWeightedResult_cbar(void) |
| 266 { | |
| 634 | 267 static uint8_t lastValidValue = 0; |
| 38 | 268 int8_t sensorOutOfBound[3]; |
| 269 uint16_t result = 0; | |
| 270 uint8_t count = 0; | |
|
582
64bf41faab83
Show Fallback if no valid sensor value is available:
Ideenmodellierer
parents:
563
diff
changeset
|
271 uint8_t retVal = 0; |
| 38 | 272 |
| 563 | 273 test_O2_sensor_values_outOfBounds(&sensorOutOfBound[0], &sensorOutOfBound[1], &sensorOutOfBound[2]); |
| 38 | 274 |
| 275 for(int i=0;i<3;i++) | |
| 276 { | |
| 277 if(!sensorOutOfBound[i]) | |
| 278 { | |
| 563 | 279 result += stateUsed->lifeData.ppO2Sensor_bar[i] * 100.0; /* convert centibar used by HUB */ |
| 38 | 280 count++; |
| 281 } | |
| 282 } | |
| 634 | 283 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
|
284 { |
| 635 | 285 if(debounce_warning_fallback(100)) |
| 286 { | |
| 287 set_warning_fallback(); | |
| 288 retVal = tCCR_fallbackToFixedSetpoint(); /* this function only changes setpoint if option is enabled */ | |
| 289 } | |
| 290 if(retVal == 0) | |
| 291 { | |
| 292 retVal = lastValidValue; | |
| 293 } | |
|
582
64bf41faab83
Show Fallback if no valid sensor value is available:
Ideenmodellierer
parents:
563
diff
changeset
|
294 } |
| 38 | 295 else |
|
582
64bf41faab83
Show Fallback if no valid sensor value is available:
Ideenmodellierer
parents:
563
diff
changeset
|
296 { |
| 635 | 297 reset_debounce_warning_fallback(); |
| 298 retVal = (uint8_t)(result / count); | |
| 299 lastValidValue = retVal; | |
|
582
64bf41faab83
Show Fallback if no valid sensor value is available:
Ideenmodellierer
parents:
563
diff
changeset
|
300 } |
|
64bf41faab83
Show Fallback if no valid sensor value is available:
Ideenmodellierer
parents:
563
diff
changeset
|
301 return retVal; |
| 38 | 302 } |
| 303 | |
| 304 | |
| 305 void tCCR_init(void) | |
| 306 { | |
|
449
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
307 uint8_t loop; |
|
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
308 |
| 38 | 309 StartListeningToUART_HUD = 1; |
|
449
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
310 |
|
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
311 SDiveState* pDiveData = stateRealGetPointerWrite(); |
|
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
312 for(loop=0;loop<(2*NUM_GASES+1);loop++) |
|
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
313 { |
|
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
314 pDiveData->lifeData.bottle_bar_age_MilliSeconds[loop] = BOTTLE_SENSOR_TIMEOUT; |
|
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
315 } |
| 38 | 316 } |
| 317 | |
| 318 | |
| 319 /* after 3 seconds without update from HUD | |
| 320 * data is considered old | |
| 321 */ | |
| 322 void tCCR_tick(void) | |
| 323 { | |
| 655 | 324 SSettings* pSettings = settingsGetPointer(); |
| 998 | 325 uint8_t timerId = 0; |
| 655 | 326 |
| 327 if(pSettings->ppo2sensors_source == O2_SENSOR_SOURCE_OPTIC) | |
| 563 | 328 { |
| 329 if(HUDTimeoutCount < 3 * 10) | |
| 330 HUDTimeoutCount++; | |
| 331 else | |
| 332 { | |
| 333 data_old__lost_connection_to_HUD = 1; | |
| 334 if(HUDTimeoutCount < 20 * 10) | |
| 335 HUDTimeoutCount++; | |
| 336 else | |
| 337 tCCR_fallbackToFixedSetpoint(); | |
| 338 } | |
| 339 } | |
| 655 | 340 |
|
980
7149f372b0ba
Fix a couple of bugs in the scrubber timer:
heinrichsweikamp
parents:
924
diff
changeset
|
341 // If we are in the simulator the counter is updated in `simulator.c` |
|
7149f372b0ba
Fix a couple of bugs in the scrubber timer:
heinrichsweikamp
parents:
924
diff
changeset
|
342 if (!is_stateUsedSetToSim()) { |
|
7149f372b0ba
Fix a couple of bugs in the scrubber timer:
heinrichsweikamp
parents:
924
diff
changeset
|
343 /* decrease scrubber timer only if we are not bailed out */ |
|
7149f372b0ba
Fix a couple of bugs in the scrubber timer:
heinrichsweikamp
parents:
924
diff
changeset
|
344 if((pSettings->scrubTimerMode != SCRUB_TIMER_OFF) && (isLoopMode(pSettings->dive_mode)) && (stateUsed->mode == MODE_DIVE) && isLoopMode(stateUsed->diveSettings.diveMode)) |
|
7149f372b0ba
Fix a couple of bugs in the scrubber timer:
heinrichsweikamp
parents:
924
diff
changeset
|
345 { |
|
7149f372b0ba
Fix a couple of bugs in the scrubber timer:
heinrichsweikamp
parents:
924
diff
changeset
|
346 ScrubberTimeoutCount++; |
|
7149f372b0ba
Fix a couple of bugs in the scrubber timer:
heinrichsweikamp
parents:
924
diff
changeset
|
347 if(ScrubberTimeoutCount >= 600) /* resolution is minutes */ |
|
7149f372b0ba
Fix a couple of bugs in the scrubber timer:
heinrichsweikamp
parents:
924
diff
changeset
|
348 { |
|
7149f372b0ba
Fix a couple of bugs in the scrubber timer:
heinrichsweikamp
parents:
924
diff
changeset
|
349 ScrubberTimeoutCount = 0; |
| 998 | 350 for(timerId = 0; timerId < 2; timerId++) |
|
980
7149f372b0ba
Fix a couple of bugs in the scrubber timer:
heinrichsweikamp
parents:
924
diff
changeset
|
351 { |
| 998 | 352 if(pSettings->scubberActiveId & (1 << timerId)) |
| 353 { | |
| 354 if(stateUsed->scrubberDataDive[timerId].TimerCur > MIN_SCRUBBER_TIME) | |
| 355 { | |
| 356 stateUsedWrite->scrubberDataDive[timerId].TimerCur--; | |
| 357 } | |
| 358 translateDate(stateUsed->lifeData.dateBinaryFormat, &stateUsedWrite->scrubberDataDive[timerId].lastDive); | |
| 359 } | |
|
980
7149f372b0ba
Fix a couple of bugs in the scrubber timer:
heinrichsweikamp
parents:
924
diff
changeset
|
360 } |
|
7149f372b0ba
Fix a couple of bugs in the scrubber timer:
heinrichsweikamp
parents:
924
diff
changeset
|
361 } |
|
7149f372b0ba
Fix a couple of bugs in the scrubber timer:
heinrichsweikamp
parents:
924
diff
changeset
|
362 } |
| 655 | 363 } |
| 38 | 364 } |
| 365 | |
|
322
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
366 void tCCR_SetRXIndication(void) |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
367 { |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
368 static uint8_t floatingRXCount = 0; |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
369 |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
370 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
|
371 { |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
372 UartReadyHUD = SET; |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
373 LastReceivedTick_HUD = HAL_GetTick(); |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
374 floatingRXCount = 0; |
|
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 else /* follow up of error handling */ |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
377 { |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
378 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
|
379 { |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
380 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
|
381 } |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
382 else |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
383 { |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
384 if(floatingRXCount++ < HUD_BABBLING_IDIOT) |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
385 { |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
386 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
|
387 } |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
388 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
|
389 { /* by not reactivation HUD RX, no recovery fromthis state */ |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
390 stateUsedWrite->diveSettings.ppo2sensors_deactivated = 0x07; /* Display deactivation */ |
|
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 } |
|
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 |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
395 } |
| 38 | 396 |
| 397 void tCCR_restart(void) | |
| 398 { | |
|
322
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
399 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
|
400 StartListeningToUART_HUD = 1; |
| 38 | 401 } |
| 402 | |
| 403 | |
| 404 void tCCR_control(void) | |
| 405 { | |
|
446
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
406 uint16_t checksum = 0; |
| 457 | 407 #ifdef ENABLE_BOTTLE_SENSOR |
|
446
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
408 SDiveState *pLivedata = stateRealGetPointerWrite(); |
| 457 | 409 #endif |
|
322
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
410 |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
411 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
|
412 { |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
413 StartListeningToUART_HUD = 0; |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
414 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
|
415 } |
| 38 | 416 |
| 417 if(UartReadyHUD == SET) | |
| 418 { | |
| 419 UartReadyHUD = RESET; | |
|
322
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
420 StartListeningToUART_HUD = 1; |
| 38 | 421 |
|
446
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
422 /* check if received package is valid */ |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
423 for(int i=0;i<13;i++) |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
424 { |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
425 checksum += receiveHUDraw[i]; |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
426 } |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
427 receiveHUD[!boolHUDdata].checksum = receiveHUDraw[13] + (256 * receiveHUDraw[14]); |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
428 if(checksum == receiveHUD[!boolHUDdata].checksum) |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
429 { |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
430 #ifdef ENABLE_BOTTLE_SENSOR |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
431 if(receiveHUDraw[0] == 0xA5) /* code for pressure sensor */ |
|
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 pLivedata->lifeData.bottle_bar[pLivedata->lifeData.actualGas.GasIdInSettings] = receiveHUDraw[10]; |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
434 pLivedata->lifeData.bottle_bar_age_MilliSeconds[pLivedata->lifeData.actualGas.GasIdInSettings] = 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 else |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
437 #endif |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
438 /* handle O2 sensor data */ |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
439 { |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
440 memcpy(&receiveHUD[!boolHUDdata], receiveHUDraw, 11); |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
441 receiveHUD[!boolHUDdata].battery_voltage_mV = receiveHUDraw[11] + (256 * receiveHUDraw[12]); |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
442 } |
| 38 | 443 |
|
446
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
444 boolHUDdata = !boolHUDdata; |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
445 HUDTimeoutCount = 0; |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
446 data_old__lost_connection_to_HUD = 0; |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
447 } |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
448 else |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
449 { |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
450 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
|
451 { |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
452 HAL_UART_Receive_IT(&UartIR_HUD_Handle, receiveHUDraw, 1); |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
453 StartListeningToUART_HUD = 0; |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
454 } |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
455 } |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
456 memset(receiveHUDraw,0,sizeof(receiveHUDraw)); |
| 38 | 457 } |
| 458 } | |
| 459 | |
| 460 #endif | |
| 461 /* Private functions ---------------------------------------------------------*/ | |
| 462 | |
| 635 | 463 static uint8_t tCCR_fallbackToFixedSetpoint(void) |
| 38 | 464 { |
| 635 | 465 uint8_t retVal = 0; |
| 662 | 466 uint8_t setpointCbar, actualGasID; |
| 38 | 467 |
| 662 | 468 if((stateUsed->mode == MODE_DIVE) && (stateUsed->diveSettings.CCR_Mode == CCRMODE_Sensors) && (stateUsed->diveSettings.fallbackOption)) |
| 469 { | |
| 470 if(stateUsed->diveSettings.diveMode == DIVEMODE_CCR) | |
| 471 { | |
| 472 setpointCbar = stateUsed->diveSettings.setpoint[1].setpoint_cbar; | |
| 473 stateUsedWrite->diveSettings.CCR_Mode = CCRMODE_FixedSetpoint; | |
| 474 } | |
| 475 else | |
| 476 { | |
| 477 setpointCbar = stateUsed->lifeData.ppo2Simulated_bar * 100; | |
| 478 stateUsedWrite->diveSettings.CCR_Mode = CCRMODE_Simulation; | |
| 479 } | |
| 480 actualGasID = stateUsed->lifeData.actualGas.GasIdInSettings; | |
| 481 setActualGas_DM(&stateUsedWrite->lifeData,actualGasID,setpointCbar); | |
| 38 | 482 |
| 662 | 483 set_warning_fallback(); |
| 484 retVal = setpointCbar; | |
| 38 | 485 } |
| 635 | 486 return retVal; |
| 38 | 487 } |
