annotate Discovery/Src/tCCR.c @ 830:b7d93ff6b3b2 Evo_2_23

Added selection if an active gas shall be used for deco calculation or not: In previous version selecting a gas as deco gas automatically activated the gas for deco calculation. Some divers prever to have the deco time displayed which matches to the gas currently in use. These divers kept the gas deactivated unless they switch to it. Features like gas usability visualization or easy gas change using quick selection were not usable for these divers. With introduction of the new option the gas switching / visualization features may be used without having the gas been considered for calculation in the background. The option may be operated in the gas selection menu.
author Ideenmodellierer
date Thu, 16 Nov 2023 20:32:09 +0100
parents acf6614dc396
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1 ///////////////////////////////////////////////////////////////////////////////
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2 /// -*- coding: UTF-8 -*-
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
4 /// \file Discovery/Src/tCCR.c
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
5 /// \brief HUD data via optical port
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
6 /// \author Heinrichs Weikamp gmbh
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
7 /// \date 18-Dec-2014
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
8 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
9 /// \details
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
10 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
11 /// $Id$
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
12 ///////////////////////////////////////////////////////////////////////////////
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
13 /// \par Copyright (c) 2014-2018 Heinrichs Weikamp gmbh
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
14 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
15 /// This program is free software: you can redistribute it and/or modify
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
16 /// it under the terms of the GNU General Public License as published by
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
17 /// the Free Software Foundation, either version 3 of the License, or
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
18 /// (at your option) any later version.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
19 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
20 /// This program is distributed in the hope that it will be useful,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
21 /// but WITHOUT ANY WARRANTY; without even the implied warranty of
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
22 /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
23 /// GNU General Public License for more details.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
24 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
25 /// You should have received a copy of the GNU General Public License
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
26 /// along with this program. If not, see <http://www.gnu.org/licenses/>.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
27 //////////////////////////////////////////////////////////////////////////////
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
28
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
29 /* Includes ------------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
30 #include <string.h>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
31 #include "tCCR.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
32 #include "ostc.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
33 #include "data_central.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
34 #include "data_exchange.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
35 #include "check_warning.h"
446
f1257a32f2d4 Introduced configuration header for variant managment:
ideenmodellierer
parents: 322
diff changeset
36 #include "configuration.h"
634
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
37 #include <math.h>
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
39 /* Private types -------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
40 typedef struct
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
41 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
42 uint8_t hud_firmwareVersion;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
43 bit8_Type status_byte;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
44 uint16_t sensor_voltage_100uV[3];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
45 uint8_t sensor_ppo2_cbar[3];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
46 uint8_t temp1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
47 uint16_t battery_voltage_mV;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
48 uint16_t checksum;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
49 } SIrLink;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
50
634
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
51 typedef enum
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
52 {
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
53 sensorOK = 0,
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
54 sensorSuspect,
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
55 SensorOutOfBounds
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
56 } sensorTrustState_t;
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
57
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
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
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
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
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
67 #define MAX_SENSOR_COMPARE_DEVIATION (0.15f) /* max deviation between two sensors allowed before their results are rated as suspect */
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 655
diff changeset
68 #define MAX_SENSOR_VOLTAGE_MV (250u) /* max allowed voltage value for a sensor measurement */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 655
diff changeset
69
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 655
diff changeset
70 #ifdef ENABLE_ALTERNATIVE_SENSORTYP
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 655
diff changeset
71 #define MIN_SENSOR_VOLTAGE_MV (3u) /* min allowed voltage value for a sensor measurement (Inspiration, Submatix, Sentinel Typ) */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 655
diff changeset
72 #else
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 655
diff changeset
73 #define MIN_SENSOR_VOLTAGE_MV (8u) /* min allowed voltage value for a sensor measurement (legacy OSTC TYP) */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 655
diff changeset
74 #endif
634
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
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
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
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
980b4aa60a0e Added count down timer for scrubber time:
Ideenmodellierer
parents: 635
diff changeset
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
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
89
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
90 /* Private variables with external access via get_xxx() function -------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
91
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
92 /* Private function prototypes -----------------------------------------------*/
635
66c8a4ff9fc4 Debounce fallback warning:
Ideenmodellierer
parents: 634
diff changeset
93 static uint8_t tCCR_fallbackToFixedSetpoint(void);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
94
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
95 #ifndef USART_IR_HUD
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
96
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
97 void tCCR_init(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
98 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
99 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
100 void tCCR_control(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
101 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
102 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
103 void tCCR_test(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
104 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
105 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
106 void tCCR_restart(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
107 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
108 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
109 float get_ppO2Sensor_bar(uint8_t sensor_id)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
110 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
111 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
112 float get_sensorVoltage_mV(uint8_t sensor_id)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
113 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
114 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
115 float get_HUD_battery_voltage_V(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
116 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
117 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
118 void tCCR_tick(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
119 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
120 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
121
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
122 #else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
123 /* Exported functions --------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
124
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
125 float get_ppO2Sensor_bar(uint8_t sensor_id)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
126 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
127 if((sensor_id > 2) || data_old__lost_connection_to_HUD)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
128 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
129
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
130 return (float)(receiveHUD[boolHUDdata].sensor_ppo2_cbar[sensor_id]) / 100.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
131 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
132
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
133 float get_sensorVoltage_mV(uint8_t sensor_id)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
134 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
135 if((sensor_id > 2) || data_old__lost_connection_to_HUD)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
136 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
137
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
138 return (float)(receiveHUD[boolHUDdata].sensor_voltage_100uV[sensor_id]) / 10.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
139 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
140
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
141 float get_HUD_battery_voltage_V(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
142 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
143 if(data_old__lost_connection_to_HUD)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
144 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
145
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
146 return (float)(receiveHUD[boolHUDdata].battery_voltage_mV) / 1000.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
147 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
148
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
149
563
d97f0e395058 Refine o2 sensor diagnostic functions:
Ideenmodellierer
parents: 457
diff changeset
150 void test_O2_sensor_values_outOfBounds(int8_t * outOfBouds1, int8_t * outOfBouds2, int8_t * outOfBouds3)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
151 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
152 uint8_t sensorNotActiveBinary;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
153 uint8_t sensorActive[3];
634
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
154 sensorTrustState_t sensorState[3];
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
155 uint8_t index;
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
156
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
157
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
158 // test1: user deactivation
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
159 sensorNotActiveBinary = stateUsed->diveSettings.ppo2sensors_deactivated;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
160
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
161 for(int i=0;i<3;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
162 sensorActive[i] = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
163
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
164 if(sensorNotActiveBinary)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
165 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
166 if(sensorNotActiveBinary & 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
167 sensorActive[0] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
168
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
169 if(sensorNotActiveBinary & 2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
170 sensorActive[1] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
171
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
172 if(sensorNotActiveBinary & 4)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
173 sensorActive[2] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
174 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
175
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
176 // test2: mV of remaining sensors
744
dd5db6e2c9a4 Added DiveO2 fatal error detection:
Ideenmodellierer
parents: 710
diff changeset
177 for(index=0; index<3; index++)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
178 {
744
dd5db6e2c9a4 Added DiveO2 fatal error detection:
Ideenmodellierer
parents: 710
diff changeset
179 sensorState[index] = sensorOK;
634
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
180
744
dd5db6e2c9a4 Added DiveO2 fatal error detection:
Ideenmodellierer
parents: 710
diff changeset
181 if(sensorActive[index])
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
182 {
797
acf6614dc396 Use mirror sensortype for visualization:
Ideenmodellierer
parents: 782
diff changeset
183 if(((stateUsed->lifeData.extIf_sensor_map[index] == SENSOR_DIGO2M) && (((SSensorDataDiveO2*)(stateUsed->lifeData.extIf_sensor_data[index]))->status & DVO2_FATAL_ERROR))
acf6614dc396 Use mirror sensortype for visualization:
Ideenmodellierer
parents: 782
diff changeset
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
dd5db6e2c9a4 Added DiveO2 fatal error detection:
Ideenmodellierer
parents: 710
diff changeset
186 {
dd5db6e2c9a4 Added DiveO2 fatal error detection:
Ideenmodellierer
parents: 710
diff changeset
187 sensorActive[index] = 0;
dd5db6e2c9a4 Added DiveO2 fatal error detection:
Ideenmodellierer
parents: 710
diff changeset
188 switch(index)
dd5db6e2c9a4 Added DiveO2 fatal error detection:
Ideenmodellierer
parents: 710
diff changeset
189 {
dd5db6e2c9a4 Added DiveO2 fatal error detection:
Ideenmodellierer
parents: 710
diff changeset
190 case 0:
dd5db6e2c9a4 Added DiveO2 fatal error detection:
Ideenmodellierer
parents: 710
diff changeset
191 sensorNotActiveBinary |= 1;
dd5db6e2c9a4 Added DiveO2 fatal error detection:
Ideenmodellierer
parents: 710
diff changeset
192 break;
dd5db6e2c9a4 Added DiveO2 fatal error detection:
Ideenmodellierer
parents: 710
diff changeset
193 case 1:
dd5db6e2c9a4 Added DiveO2 fatal error detection:
Ideenmodellierer
parents: 710
diff changeset
194 sensorNotActiveBinary |= 2;
dd5db6e2c9a4 Added DiveO2 fatal error detection:
Ideenmodellierer
parents: 710
diff changeset
195 break;
dd5db6e2c9a4 Added DiveO2 fatal error detection:
Ideenmodellierer
parents: 710
diff changeset
196 case 2:
dd5db6e2c9a4 Added DiveO2 fatal error detection:
Ideenmodellierer
parents: 710
diff changeset
197 sensorNotActiveBinary |= 4;
dd5db6e2c9a4 Added DiveO2 fatal error detection:
Ideenmodellierer
parents: 710
diff changeset
198 break;
dd5db6e2c9a4 Added DiveO2 fatal error detection:
Ideenmodellierer
parents: 710
diff changeset
199 }
dd5db6e2c9a4 Added DiveO2 fatal error detection:
Ideenmodellierer
parents: 710
diff changeset
200 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
201 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
202 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
203
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
204 *outOfBouds1 = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
205 *outOfBouds2 = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
206 *outOfBouds3 = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
207
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
208 /* with two, one or no sensor, there is nothing to compare anymore
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
209 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
210 if(sensorNotActiveBinary)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
211 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
212 // set outOfBounds for both tests
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
213 if(!sensorActive[0])
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
214 *outOfBouds1 = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
215
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
216 if(!sensorActive[1])
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
217 *outOfBouds2 = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
218
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
219 if(!sensorActive[2])
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
220 *outOfBouds3 = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
221 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
222 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
223 {
634
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
224 /* Check two or more of Three */
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
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 */
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
226 if(fabsf(stateUsed->lifeData.ppO2Sensor_bar[0] - stateUsed->lifeData.ppO2Sensor_bar[1]) > MAX_SENSOR_COMPARE_DEVIATION)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
227 {
634
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
228 sensorState[0]++;
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
229 sensorState[1]++;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
230 }
634
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
231 if(fabsf(stateUsed->lifeData.ppO2Sensor_bar[0] - stateUsed->lifeData.ppO2Sensor_bar[2]) > MAX_SENSOR_COMPARE_DEVIATION)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
232 {
634
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
233 sensorState[0]++;
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
234 sensorState[2]++;
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
235 }
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
236 if(fabsf(stateUsed->lifeData.ppO2Sensor_bar[1] - stateUsed->lifeData.ppO2Sensor_bar[2]) > MAX_SENSOR_COMPARE_DEVIATION)
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
237 {
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
238 sensorState[1]++;
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
239 sensorState[2]++;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
240 }
634
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
241 for(index = 0; index < 3; index++)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
242 {
634
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
243 if(sensorState[index] == SensorOutOfBounds)
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
244 {
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
245 switch(index)
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
246 {
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
247 case 0:
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
248 *outOfBouds1 = 1;
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
249 break;
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
250 case 1:
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
251 *outOfBouds2 = 1;
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
252 break;
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
253 case 2:
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
254 *outOfBouds3 = 1;
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
255 break;
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
256 default:
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
257 break;
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
258 }
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
259 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
260 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
261 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
262 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
263
635
66c8a4ff9fc4 Debounce fallback warning:
Ideenmodellierer
parents: 634
diff changeset
264 /* this function is called out of the 100ms callback => to be considered for debouncing */
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
265 uint8_t get_ppO2SensorWeightedResult_cbar(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
266 {
634
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
267 static uint8_t lastValidValue = 0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
268 int8_t sensorOutOfBound[3];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
269 uint16_t result = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
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
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
272
563
d97f0e395058 Refine o2 sensor diagnostic functions:
Ideenmodellierer
parents: 457
diff changeset
273 test_O2_sensor_values_outOfBounds(&sensorOutOfBound[0], &sensorOutOfBound[1], &sensorOutOfBound[2]);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
274
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
275 for(int i=0;i<3;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
276 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
277 if(!sensorOutOfBound[i])
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
278 {
563
d97f0e395058 Refine o2 sensor diagnostic functions:
Ideenmodellierer
parents: 457
diff changeset
279 result += stateUsed->lifeData.ppO2Sensor_bar[i] * 100.0; /* convert centibar used by HUB */
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
280 count++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
281 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
282 }
634
7c73f066cd16 Enable sensor check for Analog PPO2 mode:
Ideenmodellierer
parents: 582
diff changeset
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
66c8a4ff9fc4 Debounce fallback warning:
Ideenmodellierer
parents: 634
diff changeset
285 if(debounce_warning_fallback(100))
66c8a4ff9fc4 Debounce fallback warning:
Ideenmodellierer
parents: 634
diff changeset
286 {
66c8a4ff9fc4 Debounce fallback warning:
Ideenmodellierer
parents: 634
diff changeset
287 set_warning_fallback();
66c8a4ff9fc4 Debounce fallback warning:
Ideenmodellierer
parents: 634
diff changeset
288 retVal = tCCR_fallbackToFixedSetpoint(); /* this function only changes setpoint if option is enabled */
66c8a4ff9fc4 Debounce fallback warning:
Ideenmodellierer
parents: 634
diff changeset
289 }
66c8a4ff9fc4 Debounce fallback warning:
Ideenmodellierer
parents: 634
diff changeset
290 if(retVal == 0)
66c8a4ff9fc4 Debounce fallback warning:
Ideenmodellierer
parents: 634
diff changeset
291 {
66c8a4ff9fc4 Debounce fallback warning:
Ideenmodellierer
parents: 634
diff changeset
292 retVal = lastValidValue;
66c8a4ff9fc4 Debounce fallback warning:
Ideenmodellierer
parents: 634
diff changeset
293 }
582
64bf41faab83 Show Fallback if no valid sensor value is available:
Ideenmodellierer
parents: 563
diff changeset
294 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
295 else
582
64bf41faab83 Show Fallback if no valid sensor value is available:
Ideenmodellierer
parents: 563
diff changeset
296 {
635
66c8a4ff9fc4 Debounce fallback warning:
Ideenmodellierer
parents: 634
diff changeset
297 reset_debounce_warning_fallback();
66c8a4ff9fc4 Debounce fallback warning:
Ideenmodellierer
parents: 634
diff changeset
298 retVal = (uint8_t)(result / count);
66c8a4ff9fc4 Debounce fallback warning:
Ideenmodellierer
parents: 634
diff changeset
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
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
302 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
303
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
304
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
305 void tCCR_init(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
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
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
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
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
316 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
317
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
318
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
319 /* after 3 seconds without update from HUD
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
320 * data is considered old
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
321 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
322 void tCCR_tick(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
323 {
655
980b4aa60a0e Added count down timer for scrubber time:
Ideenmodellierer
parents: 635
diff changeset
324 SSettings* pSettings = settingsGetPointer();
980b4aa60a0e Added count down timer for scrubber time:
Ideenmodellierer
parents: 635
diff changeset
325
980b4aa60a0e Added count down timer for scrubber time:
Ideenmodellierer
parents: 635
diff changeset
326 if(pSettings->ppo2sensors_source == O2_SENSOR_SOURCE_OPTIC)
563
d97f0e395058 Refine o2 sensor diagnostic functions:
Ideenmodellierer
parents: 457
diff changeset
327 {
d97f0e395058 Refine o2 sensor diagnostic functions:
Ideenmodellierer
parents: 457
diff changeset
328 if(HUDTimeoutCount < 3 * 10)
d97f0e395058 Refine o2 sensor diagnostic functions:
Ideenmodellierer
parents: 457
diff changeset
329 HUDTimeoutCount++;
d97f0e395058 Refine o2 sensor diagnostic functions:
Ideenmodellierer
parents: 457
diff changeset
330 else
d97f0e395058 Refine o2 sensor diagnostic functions:
Ideenmodellierer
parents: 457
diff changeset
331 {
d97f0e395058 Refine o2 sensor diagnostic functions:
Ideenmodellierer
parents: 457
diff changeset
332 data_old__lost_connection_to_HUD = 1;
d97f0e395058 Refine o2 sensor diagnostic functions:
Ideenmodellierer
parents: 457
diff changeset
333 if(HUDTimeoutCount < 20 * 10)
d97f0e395058 Refine o2 sensor diagnostic functions:
Ideenmodellierer
parents: 457
diff changeset
334 HUDTimeoutCount++;
d97f0e395058 Refine o2 sensor diagnostic functions:
Ideenmodellierer
parents: 457
diff changeset
335 else
d97f0e395058 Refine o2 sensor diagnostic functions:
Ideenmodellierer
parents: 457
diff changeset
336 tCCR_fallbackToFixedSetpoint();
d97f0e395058 Refine o2 sensor diagnostic functions:
Ideenmodellierer
parents: 457
diff changeset
337 }
d97f0e395058 Refine o2 sensor diagnostic functions:
Ideenmodellierer
parents: 457
diff changeset
338 }
655
980b4aa60a0e Added count down timer for scrubber time:
Ideenmodellierer
parents: 635
diff changeset
339
758
b6d8a6fbf4fd - Colours for scrubber display when time remaining falls below a threshold value
heinrichsweikamp
parents: 757
diff changeset
340 /* decrease scrubber timer only in real dive mode, and if we are not bailed out */
b6d8a6fbf4fd - Colours for scrubber display when time remaining falls below a threshold value
heinrichsweikamp
parents: 757
diff changeset
341 if((pSettings->scrubTimerMode != SCRUB_TIMER_OFF) && (isLoopMode(pSettings->dive_mode)) && (stateUsed->mode == MODE_DIVE) && isLoopMode(stateUsed->diveSettings.diveMode)) // && (stateUsed == stateRealGetPointer()))
655
980b4aa60a0e Added count down timer for scrubber time:
Ideenmodellierer
parents: 635
diff changeset
342 {
980b4aa60a0e Added count down timer for scrubber time:
Ideenmodellierer
parents: 635
diff changeset
343 ScrubberTimeoutCount++;
980b4aa60a0e Added count down timer for scrubber time:
Ideenmodellierer
parents: 635
diff changeset
344 if(ScrubberTimeoutCount >= 600) /* resolution is minutes */
980b4aa60a0e Added count down timer for scrubber time:
Ideenmodellierer
parents: 635
diff changeset
345 {
980b4aa60a0e Added count down timer for scrubber time:
Ideenmodellierer
parents: 635
diff changeset
346 ScrubberTimeoutCount = 0;
758
b6d8a6fbf4fd - Colours for scrubber display when time remaining falls below a threshold value
heinrichsweikamp
parents: 757
diff changeset
347 if(pSettings->scrubberData[pSettings->scubberActiveId].TimerCur > MIN_SCRUBBER_TIME)
655
980b4aa60a0e Added count down timer for scrubber time:
Ideenmodellierer
parents: 635
diff changeset
348 {
710
8adf9b8fc7fa Extension scrubber time:
Ideenmodellierer
parents: 662
diff changeset
349 pSettings->scrubberData[pSettings->scubberActiveId].TimerCur--;
655
980b4aa60a0e Added count down timer for scrubber time:
Ideenmodellierer
parents: 635
diff changeset
350 }
710
8adf9b8fc7fa Extension scrubber time:
Ideenmodellierer
parents: 662
diff changeset
351 translateDate(stateUsed->lifeData.dateBinaryFormat, &pSettings->scrubberData[pSettings->scubberActiveId].lastDive);
655
980b4aa60a0e Added count down timer for scrubber time:
Ideenmodellierer
parents: 635
diff changeset
352 }
980b4aa60a0e Added count down timer for scrubber time:
Ideenmodellierer
parents: 635
diff changeset
353 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
354 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
355
322
31e471d60797 Added start of frame detection for HUD data
ideenmodellierer
parents: 272
diff changeset
356 void tCCR_SetRXIndication(void)
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 static uint8_t floatingRXCount = 0;
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 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
361 {
31e471d60797 Added start of frame detection for HUD data
ideenmodellierer
parents: 272
diff changeset
362 UartReadyHUD = SET;
31e471d60797 Added start of frame detection for HUD data
ideenmodellierer
parents: 272
diff changeset
363 LastReceivedTick_HUD = HAL_GetTick();
31e471d60797 Added start of frame detection for HUD data
ideenmodellierer
parents: 272
diff changeset
364 floatingRXCount = 0;
31e471d60797 Added start of frame detection for HUD data
ideenmodellierer
parents: 272
diff changeset
365 }
31e471d60797 Added start of frame detection for HUD data
ideenmodellierer
parents: 272
diff changeset
366 else /* follow up of error handling */
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 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
369 {
31e471d60797 Added start of frame detection for HUD data
ideenmodellierer
parents: 272
diff changeset
370 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
371 }
31e471d60797 Added start of frame detection for HUD data
ideenmodellierer
parents: 272
diff changeset
372 else
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 if(floatingRXCount++ < HUD_BABBLING_IDIOT)
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 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
377 }
31e471d60797 Added start of frame detection for HUD data
ideenmodellierer
parents: 272
diff changeset
378 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
379 { /* by not reactivation HUD RX, no recovery fromthis state */
31e471d60797 Added start of frame detection for HUD data
ideenmodellierer
parents: 272
diff changeset
380 stateUsedWrite->diveSettings.ppo2sensors_deactivated = 0x07; /* Display deactivation */
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 }
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
31e471d60797 Added start of frame detection for HUD data
ideenmodellierer
parents: 272
diff changeset
385 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
386
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
387 void tCCR_restart(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
388 {
322
31e471d60797 Added start of frame detection for HUD data
ideenmodellierer
parents: 272
diff changeset
389 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
390 StartListeningToUART_HUD = 1;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
391 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
392
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
393
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
394 void tCCR_control(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
395 {
446
f1257a32f2d4 Introduced configuration header for variant managment:
ideenmodellierer
parents: 322
diff changeset
396 uint16_t checksum = 0;
457
4bd01f48c285 Eliminated some minor warnings
ideenmodellierer
parents: 449
diff changeset
397 #ifdef ENABLE_BOTTLE_SENSOR
446
f1257a32f2d4 Introduced configuration header for variant managment:
ideenmodellierer
parents: 322
diff changeset
398 SDiveState *pLivedata = stateRealGetPointerWrite();
457
4bd01f48c285 Eliminated some minor warnings
ideenmodellierer
parents: 449
diff changeset
399 #endif
322
31e471d60797 Added start of frame detection for HUD data
ideenmodellierer
parents: 272
diff changeset
400
31e471d60797 Added start of frame detection for HUD data
ideenmodellierer
parents: 272
diff changeset
401 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
402 {
31e471d60797 Added start of frame detection for HUD data
ideenmodellierer
parents: 272
diff changeset
403 StartListeningToUART_HUD = 0;
31e471d60797 Added start of frame detection for HUD data
ideenmodellierer
parents: 272
diff changeset
404 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
405 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
406
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
407 if(UartReadyHUD == SET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
408 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
409 UartReadyHUD = RESET;
322
31e471d60797 Added start of frame detection for HUD data
ideenmodellierer
parents: 272
diff changeset
410 StartListeningToUART_HUD = 1;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
411
446
f1257a32f2d4 Introduced configuration header for variant managment:
ideenmodellierer
parents: 322
diff changeset
412 /* check if received package is valid */
f1257a32f2d4 Introduced configuration header for variant managment:
ideenmodellierer
parents: 322
diff changeset
413 for(int i=0;i<13;i++)
f1257a32f2d4 Introduced configuration header for variant managment:
ideenmodellierer
parents: 322
diff changeset
414 {
f1257a32f2d4 Introduced configuration header for variant managment:
ideenmodellierer
parents: 322
diff changeset
415 checksum += receiveHUDraw[i];
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 receiveHUD[!boolHUDdata].checksum = receiveHUDraw[13] + (256 * receiveHUDraw[14]);
f1257a32f2d4 Introduced configuration header for variant managment:
ideenmodellierer
parents: 322
diff changeset
418 if(checksum == receiveHUD[!boolHUDdata].checksum)
f1257a32f2d4 Introduced configuration header for variant managment:
ideenmodellierer
parents: 322
diff changeset
419 {
f1257a32f2d4 Introduced configuration header for variant managment:
ideenmodellierer
parents: 322
diff changeset
420 #ifdef ENABLE_BOTTLE_SENSOR
f1257a32f2d4 Introduced configuration header for variant managment:
ideenmodellierer
parents: 322
diff changeset
421 if(receiveHUDraw[0] == 0xA5) /* code for pressure sensor */
f1257a32f2d4 Introduced configuration header for variant managment:
ideenmodellierer
parents: 322
diff changeset
422 {
f1257a32f2d4 Introduced configuration header for variant managment:
ideenmodellierer
parents: 322
diff changeset
423 pLivedata->lifeData.bottle_bar[pLivedata->lifeData.actualGas.GasIdInSettings] = receiveHUDraw[10];
f1257a32f2d4 Introduced configuration header for variant managment:
ideenmodellierer
parents: 322
diff changeset
424 pLivedata->lifeData.bottle_bar_age_MilliSeconds[pLivedata->lifeData.actualGas.GasIdInSettings] = 0;
f1257a32f2d4 Introduced configuration header for variant managment:
ideenmodellierer
parents: 322
diff changeset
425 }
f1257a32f2d4 Introduced configuration header for variant managment:
ideenmodellierer
parents: 322
diff changeset
426 else
f1257a32f2d4 Introduced configuration header for variant managment:
ideenmodellierer
parents: 322
diff changeset
427 #endif
f1257a32f2d4 Introduced configuration header for variant managment:
ideenmodellierer
parents: 322
diff changeset
428 /* handle O2 sensor data */
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 memcpy(&receiveHUD[!boolHUDdata], receiveHUDraw, 11);
f1257a32f2d4 Introduced configuration header for variant managment:
ideenmodellierer
parents: 322
diff changeset
431 receiveHUD[!boolHUDdata].battery_voltage_mV = receiveHUDraw[11] + (256 * receiveHUDraw[12]);
f1257a32f2d4 Introduced configuration header for variant managment:
ideenmodellierer
parents: 322
diff changeset
432 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
433
446
f1257a32f2d4 Introduced configuration header for variant managment:
ideenmodellierer
parents: 322
diff changeset
434 boolHUDdata = !boolHUDdata;
f1257a32f2d4 Introduced configuration header for variant managment:
ideenmodellierer
parents: 322
diff changeset
435 HUDTimeoutCount = 0;
f1257a32f2d4 Introduced configuration header for variant managment:
ideenmodellierer
parents: 322
diff changeset
436 data_old__lost_connection_to_HUD = 0;
f1257a32f2d4 Introduced configuration header for variant managment:
ideenmodellierer
parents: 322
diff changeset
437 }
f1257a32f2d4 Introduced configuration header for variant managment:
ideenmodellierer
parents: 322
diff changeset
438 else
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 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
441 {
f1257a32f2d4 Introduced configuration header for variant managment:
ideenmodellierer
parents: 322
diff changeset
442 HAL_UART_Receive_IT(&UartIR_HUD_Handle, receiveHUDraw, 1);
f1257a32f2d4 Introduced configuration header for variant managment:
ideenmodellierer
parents: 322
diff changeset
443 StartListeningToUART_HUD = 0;
f1257a32f2d4 Introduced configuration header for variant managment:
ideenmodellierer
parents: 322
diff changeset
444 }
f1257a32f2d4 Introduced configuration header for variant managment:
ideenmodellierer
parents: 322
diff changeset
445 }
f1257a32f2d4 Introduced configuration header for variant managment:
ideenmodellierer
parents: 322
diff changeset
446 memset(receiveHUDraw,0,sizeof(receiveHUDraw));
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
447 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
448 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
449
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
450 #endif
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
451 /* Private functions ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
452
635
66c8a4ff9fc4 Debounce fallback warning:
Ideenmodellierer
parents: 634
diff changeset
453 static uint8_t tCCR_fallbackToFixedSetpoint(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
454 {
635
66c8a4ff9fc4 Debounce fallback warning:
Ideenmodellierer
parents: 634
diff changeset
455 uint8_t retVal = 0;
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 655
diff changeset
456 uint8_t setpointCbar, actualGasID;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
457
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 655
diff changeset
458 if((stateUsed->mode == MODE_DIVE) && (stateUsed->diveSettings.CCR_Mode == CCRMODE_Sensors) && (stateUsed->diveSettings.fallbackOption))
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 655
diff changeset
459 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 655
diff changeset
460 if(stateUsed->diveSettings.diveMode == DIVEMODE_CCR)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 655
diff changeset
461 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 655
diff changeset
462 setpointCbar = stateUsed->diveSettings.setpoint[1].setpoint_cbar;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 655
diff changeset
463 stateUsedWrite->diveSettings.CCR_Mode = CCRMODE_FixedSetpoint;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 655
diff changeset
464 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 655
diff changeset
465 else
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 655
diff changeset
466 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 655
diff changeset
467 setpointCbar = stateUsed->lifeData.ppo2Simulated_bar * 100;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 655
diff changeset
468 stateUsedWrite->diveSettings.CCR_Mode = CCRMODE_Simulation;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 655
diff changeset
469 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 655
diff changeset
470 actualGasID = stateUsed->lifeData.actualGas.GasIdInSettings;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 655
diff changeset
471 setActualGas_DM(&stateUsedWrite->lifeData,actualGasID,setpointCbar);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
472
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 655
diff changeset
473 set_warning_fallback();
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 655
diff changeset
474 retVal = setpointCbar;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
475 }
635
66c8a4ff9fc4 Debounce fallback warning:
Ideenmodellierer
parents: 634
diff changeset
476 return retVal;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
477 }