annotate Small_CPU/Src/pressure.c @ 479:4b9427ae0a65 Improve_Button_Sleep

Bugfix unintended else condition: Most likely copy past error in preparation of last commit...
author ideenmodellierer
date Wed, 13 May 2020 21:27:30 +0200
parents 4be72d55b09a
children 3fe9cc747c5c
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 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3 * @file pressure.c
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
4 * @author heinrichs weikamp gmbh
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
5 * @date 2014
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
6 * @version V0.0.2
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
7 * @since 20-Oct-2016
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
8 * @brief
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
9 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
10 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
11 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
12 ##### How to use #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
13 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
14 V0.0.2 18-Oct-2016 pressure_calculation_AN520_004_mod_MS5803_30BA__09_2015
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
15
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
16 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
17 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
18 * @attention
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
19 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
20 * <h2><center>&copy; COPYRIGHT(c) 2016 heinrichs weikamp</center></h2>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
21 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
22 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
23 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
24
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
25
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
26
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
27 /* surface time
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
28 the last 30 minutes will be saved once per minute in a endless loop
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
29 at the beginning of a dive the oldest value will be used
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
30 */
331
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
31 #include "math.h"
241
2b9775f71e30 cleanup: factor out I2C1_Status() and cleanup type
Jan Mulder <jlmulder@xs4all.nl>
parents: 186
diff changeset
32 #include "scheduler.h"
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
33 #include "pressure.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
34 #include "i2c.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
35 #include "rtc.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
36
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
37 #define CMD_RESET 0x1E // ADC reset command
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
38 #define CMD_ADC_READ 0x00 // ADC read command
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
39 #define CMD_ADC_CONV 0x40 // ADC conversion command
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
40 #define CMD_ADC_D1 0x00 // ADC D1 conversion
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
41 #define CMD_ADC_D2 0x10 // ADC D2 conversion
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
42 #define CMD_ADC_256 0x00 // ADC OSR=256
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
43 #define CMD_ADC_512 0x02 // ADC OSR=512
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
44 #define CMD_ADC_1024 0x04 // ADC OSR=1024
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
45 #define CMD_ADC_2048 0x06 // ADC OSR=2056
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
46 #define CMD_ADC_4096 0x08 // ADC OSR=4096
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
47 #define CMD_PROM_RD 0xA0 // Prom read command
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
48
352
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
49 /* remove comment to use a predefined profile for pressure changes instead of real world data */
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
50 /* #define SIMULATE_PRESSURE */
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
51
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
52 #define PRESSURE_SURFACE_MAX_MBAR (1030.0f) /* It is unlikely that pressure at surface is greater than this value => clip to it */
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
53 #define PRESSURE_HISTORY_SIZE (8u)
331
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
54
352
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
55 #define PRESSURE_SURFACE_QUE (30u) /* history buffer [minutes] for past pressure measurements */
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
56 #define PRESSURE_SURFACE_EVA_WINDOW (15u) /* Number of entries evaluated during instability test. Used to avoid detection while dive enters water */
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
57 #define PRESSURE_SURFACE_STABLE_LIMIT (10u) /* Define pressure as stable if delta (mBar) is below this value */
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
58 #define PRESSURE_SURFACE_DETECT_STABLE_CNT (5u) /* Event count to detect stable condition */
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
59 #define PRESSURE_SURFACE_UNSTABLE_LIMIT (50u) /* Define pressure as not stable if delta (mBar) is larger than this value */
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
60 #define PRESSURE_SURFACE_DETECT_UNSTABLE_CNT (3u) /* Event count to detect unstable condition */
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
61
335
c11ce8c885d3 Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents: 331
diff changeset
62
356
cb3870f79e9d Add Support for new end-2019 hardware:
heinrichsweikamp
parents: 352
diff changeset
63 static uint8_t PRESSURE_ADDRESS = DEVICE_PRESSURE_MS5803; /* Default Address */
cb3870f79e9d Add Support for new end-2019 hardware:
heinrichsweikamp
parents: 352
diff changeset
64
186
f11f0bf6ef2d cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
65 static uint16_t get_ci_by_coef_num(uint8_t coef_num);
f11f0bf6ef2d cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
66 //void pressure_calculation_new(void);
f11f0bf6ef2d cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
67 //void pressure_calculation_old(void);
f11f0bf6ef2d cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
68 static void pressure_calculation_AN520_004_mod_MS5803_30BA__09_2015(void);
356
cb3870f79e9d Add Support for new end-2019 hardware:
heinrichsweikamp
parents: 352
diff changeset
69 //static uint8_t crc4(uint16_t n_prom[]);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
70
186
f11f0bf6ef2d cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
71 static HAL_StatusTypeDef pressure_sensor_get_data(void);
f11f0bf6ef2d cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
72 static uint32_t get_adc(void);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
73 uint8_t pressureSensorInitSuccess = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
74
186
f11f0bf6ef2d cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
75 static uint16_t C[8] = { 1 };
f11f0bf6ef2d cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
76 static uint32_t D1 = 1;
f11f0bf6ef2d cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
77 static uint32_t D2 = 1;
356
cb3870f79e9d Add Support for new end-2019 hardware:
heinrichsweikamp
parents: 352
diff changeset
78 //static uint8_t n_crc;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
79
186
f11f0bf6ef2d cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
80 static int64_t C5_x_2p8 = 1;
f11f0bf6ef2d cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
81 static int64_t C2_x_2p16 = 1;
f11f0bf6ef2d cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
82 static int64_t C1_x_2p15 = 1;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
83
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
84 /*
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
85 short C2plus10000 = -1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
86 short C3plus200 = -1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
87 short C4minus250 = -1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
88 short UT1 = -1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
89 short C6plus100 = -1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
90 */
339
37f45300bc2e Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents: 335
diff changeset
91 static float pressure_offset = 0.0; /* Offset value which may be specified by the user via PC Software */
37f45300bc2e Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents: 335
diff changeset
92 static float temperature_offset = 0.0; /* Offset value which may be specified by the user via PC Software */
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
93
186
f11f0bf6ef2d cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
94 static float ambient_temperature = 0;
331
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
95 static float ambient_pressure_mbar = 1000.0;
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
96 static float surface_pressure_mbar = 1000.0;
335
c11ce8c885d3 Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents: 331
diff changeset
97 static float surface_ring_mbar[PRESSURE_SURFACE_QUE] = { 0 };
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
98
352
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
99 static uint8_t surface_pressure_writeIndex = 0;
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
100 static float surface_pressure_stable_value = 0;
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
101 static uint8_t surface_pressure_stable = 0;
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
102
331
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
103 static float pressure_history_mbar[PRESSURE_HISTORY_SIZE];
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
104
339
37f45300bc2e Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents: 335
diff changeset
105 static uint8_t secondCounterSurfaceRing = 0;
37f45300bc2e Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents: 335
diff changeset
106 static uint8_t avgCount = 0;
37f45300bc2e Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents: 335
diff changeset
107 static float runningAvg = 0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
108
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
109 float get_temperature(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
110 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
111 return ambient_temperature;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
112 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
113
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
114 float get_pressure_mbar(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
115 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
116 return ambient_pressure_mbar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
117 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
118
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
119 float get_surface_mbar(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
120 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
121 return surface_pressure_mbar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
122 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
123
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
124
339
37f45300bc2e Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents: 335
diff changeset
125 void init_surface_ring(uint8_t force)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
126 {
339
37f45300bc2e Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents: 335
diff changeset
127 if((surface_ring_mbar[0] == 0) || (force)) /* only initialize once. Keep value in place in case of an i2c recovery */
335
c11ce8c885d3 Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents: 331
diff changeset
128 {
339
37f45300bc2e Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents: 335
diff changeset
129 secondCounterSurfaceRing = 0; /* restart calculation */
37f45300bc2e Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents: 335
diff changeset
130 avgCount = 0;
37f45300bc2e Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents: 335
diff changeset
131 runningAvg = 0;
37f45300bc2e Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents: 335
diff changeset
132
335
c11ce8c885d3 Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents: 331
diff changeset
133 for(int i=0; i<PRESSURE_SURFACE_QUE; i++)
c11ce8c885d3 Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents: 331
diff changeset
134 surface_ring_mbar[i] = ambient_pressure_mbar;
c11ce8c885d3 Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents: 331
diff changeset
135 surface_pressure_mbar = ambient_pressure_mbar;
352
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
136 surface_pressure_writeIndex = 0; /* index of the oldest value in the ring buffer */
335
c11ce8c885d3 Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents: 331
diff changeset
137 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
138 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
139
331
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
140 void init_pressure_history(void)
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
141 {
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
142 for(int i=0; i<PRESSURE_HISTORY_SIZE; i++)
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
143 {
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
144 pressure_history_mbar[i] = 1000.0;
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
145 }
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
146 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
147
352
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
148 uint8_t is_surface_pressure_stable(void)
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
149 {
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
150 return surface_pressure_stable;
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
151 }
335
c11ce8c885d3 Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents: 331
diff changeset
152
352
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
153 float set_last_surface_pressure_stable(void)
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
154 {
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
155 surface_pressure_mbar = surface_pressure_stable_value;
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
156 return surface_pressure_stable_value;
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
157 }
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
158
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
159 /* iterate backward through the history memory and evaluate the changes pressure changes during the last 30 minutes */
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
160 void evaluate_surface_pressure()
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
161 {
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
162 uint8_t index;
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
163 float lastvalue;
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
164 uint8_t stablecnt = 0;
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
165 uint8_t unstablecnt = 0;
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
166 uint8_t EvaluationWindow = PRESSURE_SURFACE_QUE - PRESSURE_SURFACE_EVA_WINDOW; /* do not use the latest 15 values to avoid unstable condition due to something like fin handling */
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
167 uint8_t EvaluatedValues = 0;
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
168
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
169 lastvalue = surface_ring_mbar[surface_pressure_writeIndex];
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
170 surface_pressure_stable_value = surface_ring_mbar[surface_pressure_writeIndex]; /* default: if no stable value is found return the oldest value */
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
171 index = surface_pressure_writeIndex;
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
172 surface_pressure_stable = 1;
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
173
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
174 if(index == 0)
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
175 {
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
176 index = PRESSURE_SURFACE_QUE - 1;
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
177 }
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
178 else
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
179 {
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
180 index = index - 1;
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
181 }
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
182 do
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
183 {
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
184 if((EvaluatedValues < EvaluationWindow) &&
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
185 (fabs(surface_pressure_stable_value - surface_ring_mbar[index]) > PRESSURE_SURFACE_UNSTABLE_LIMIT)) /* unusual change during last 30 minutes */
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
186 {
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
187 unstablecnt++;
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
188 if(unstablecnt > PRESSURE_SURFACE_DETECT_UNSTABLE_CNT)
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
189 {
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
190 surface_pressure_stable = 0;
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
191 }
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
192 }
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
193 /* search for a value which does not change for several iterations */
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
194 if (fabs(lastvalue - surface_ring_mbar[index]) < PRESSURE_SURFACE_STABLE_LIMIT)
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
195 {
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
196 stablecnt++;
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
197 }
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
198 else
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
199 {
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
200 stablecnt = 0;
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
201 }
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
202 if ((stablecnt >= PRESSURE_SURFACE_DETECT_STABLE_CNT) && (surface_pressure_stable == 0)&&(surface_pressure_stable_value == surface_ring_mbar[surface_pressure_writeIndex])) /* pressure is unstable => search for new stable value */
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
203 {
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
204 surface_pressure_stable_value = surface_ring_mbar[index];
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
205 unstablecnt = 0;
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
206 }
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
207
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
208 lastvalue = surface_ring_mbar[index];
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
209
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
210 if(index == 0)
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
211 {
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
212 index = PRESSURE_SURFACE_QUE - 1;
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
213 }
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
214 else
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
215 {
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
216 index = index - 1;
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
217 }
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
218 EvaluatedValues++;
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
219 } while (index != surface_pressure_writeIndex);
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
220 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
221 void update_surface_pressure(uint8_t call_rhythm_seconds)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
222 {
331
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
223 if(is_init_pressure_done())
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
224 {
335
c11ce8c885d3 Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents: 331
diff changeset
225 runningAvg = (runningAvg * avgCount + ambient_pressure_mbar) / (avgCount +1);
c11ce8c885d3 Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents: 331
diff changeset
226 avgCount++;
c11ce8c885d3 Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents: 331
diff changeset
227 secondCounterSurfaceRing += call_rhythm_seconds;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
228
335
c11ce8c885d3 Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents: 331
diff changeset
229 if(secondCounterSurfaceRing >= 60)
c11ce8c885d3 Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents: 331
diff changeset
230 {
339
37f45300bc2e Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents: 335
diff changeset
231 if(runningAvg < PRESSURE_SURFACE_MAX_MBAR)
37f45300bc2e Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents: 335
diff changeset
232 {
352
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
233 surface_ring_mbar[surface_pressure_writeIndex] = runningAvg;
339
37f45300bc2e Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents: 335
diff changeset
234 }
37f45300bc2e Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents: 335
diff changeset
235 else
37f45300bc2e Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents: 335
diff changeset
236 {
352
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
237 surface_ring_mbar[surface_pressure_writeIndex] = PRESSURE_SURFACE_MAX_MBAR;
339
37f45300bc2e Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents: 335
diff changeset
238 }
352
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
239 surface_pressure_writeIndex++; /* the write index is now pointing to the oldest value in the buffer which will be overwritten next time */
331
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
240
352
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
241 if(surface_pressure_writeIndex == PRESSURE_SURFACE_QUE)
335
c11ce8c885d3 Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents: 331
diff changeset
242 {
352
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
243 surface_pressure_writeIndex = 0;
335
c11ce8c885d3 Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents: 331
diff changeset
244 }
c11ce8c885d3 Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents: 331
diff changeset
245
352
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
246 surface_pressure_mbar = surface_ring_mbar[surface_pressure_writeIndex]; /* 30 minutes old measurement */
335
c11ce8c885d3 Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents: 331
diff changeset
247
c11ce8c885d3 Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents: 331
diff changeset
248 secondCounterSurfaceRing = 0;
c11ce8c885d3 Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents: 331
diff changeset
249 avgCount = 1; /* use the current value as starting point but restart the weight decrement of the measurements */
c11ce8c885d3 Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents: 331
diff changeset
250 }
352
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
251 evaluate_surface_pressure();
331
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
252 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
253 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
254
186
f11f0bf6ef2d cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
255 #ifdef DEMOMODE
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
256 float demo_modify_temperature_helper(float bottom_mbar_diff_to_surface)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
257 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
258 const float temperature_surface = 31.0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
259 const float temperature_bottom = 14.0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
260
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
261 const float temperature_difference = temperature_bottom - temperature_surface;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
262
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
263 // range 0.0 - 1.0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
264 float position_now = (ambient_pressure_mbar - surface_pressure_mbar) / bottom_mbar_diff_to_surface;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
265
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
266 if(position_now <= 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
267 return temperature_surface;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
268
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
269 if(position_now >= 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
270 return temperature_bottom;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
271
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
272 return temperature_surface + (temperature_difference * position_now);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
273 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
274
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
275
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
276 uint32_t demo_modify_temperature_and_pressure(int32_t divetime_in_seconds, uint8_t subseconds, float ceiling_mbar)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
277 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
278
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
279 const float descent_rate = 4000/60;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
280 const float ascent_rate = 1000/60;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
281 const uint32_t seconds_descend = (1 * 60) + 30;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
282 const uint32_t turbo_seconds_at_bottom_start = (0 * 60) + 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
283 const uint32_t seconds_descend_and_bottomtime = seconds_descend + turbo_seconds_at_bottom_start + (2 * 60) + 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
284 uint32_t time_elapsed_in_seconds;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
285 static float ambient_pressure_mbar_memory = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
286 static uint32_t time_last_call = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
287
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
288 if(divetime_in_seconds <= seconds_descend)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
289 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
290 ambient_pressure_mbar = (divetime_in_seconds * descent_rate) + ((float)(subseconds) * descent_rate) + surface_pressure_mbar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
291 ambient_temperature = demo_modify_temperature_helper(descent_rate * seconds_descend);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
292
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
293 time_last_call = divetime_in_seconds;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
294 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
295 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
296 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
297 if(divetime_in_seconds <= seconds_descend + turbo_seconds_at_bottom_start)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
298 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
299 ambient_pressure_mbar = (seconds_descend * descent_rate) + surface_pressure_mbar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
300 ambient_temperature = demo_modify_temperature_helper(descent_rate * seconds_descend);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
301 ambient_pressure_mbar_memory = ambient_pressure_mbar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
302 time_last_call = divetime_in_seconds;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
303 return turbo_seconds_at_bottom_start;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
304 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
305 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
306 if(divetime_in_seconds <= seconds_descend_and_bottomtime)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
307 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
308 ambient_pressure_mbar = (seconds_descend * descent_rate) + surface_pressure_mbar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
309 ambient_temperature = demo_modify_temperature_helper(descent_rate * seconds_descend);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
310 ambient_pressure_mbar_memory = ambient_pressure_mbar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
311 time_last_call = divetime_in_seconds;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
312 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
313 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
314 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
315 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
316 time_elapsed_in_seconds = divetime_in_seconds - time_last_call;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
317 ambient_pressure_mbar = ambient_pressure_mbar_memory - time_elapsed_in_seconds * ascent_rate;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
318
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
319 if(ambient_pressure_mbar < surface_pressure_mbar)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
320 ambient_pressure_mbar = surface_pressure_mbar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
321 else if(ambient_pressure_mbar < ceiling_mbar)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
322 ambient_pressure_mbar = ceiling_mbar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
323
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
324 ambient_temperature = demo_modify_temperature_helper(descent_rate * seconds_descend);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
325 ambient_pressure_mbar_memory = ambient_pressure_mbar;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
326 time_last_call = divetime_in_seconds;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
327 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
328 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
329 }
186
f11f0bf6ef2d cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
330 #endif
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
331
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
332 uint8_t is_init_pressure_done(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
333 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
334 return pressureSensorInitSuccess;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
335 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
336
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
337 uint8_t init_pressure(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
338 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
339 uint8_t buffer[1];
356
cb3870f79e9d Add Support for new end-2019 hardware:
heinrichsweikamp
parents: 352
diff changeset
340 buffer[0] = 0x1E; // Reset Command
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
341 uint8_t retValue = 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
342
331
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
343 pressureSensorInitSuccess = false;
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
344 init_pressure_history();
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
345
356
cb3870f79e9d Add Support for new end-2019 hardware:
heinrichsweikamp
parents: 352
diff changeset
346 /* Probe new sensor first */
cb3870f79e9d Add Support for new end-2019 hardware:
heinrichsweikamp
parents: 352
diff changeset
347 retValue = I2C_Master_Transmit( DEVICE_PRESSURE_MS5837, buffer, 1);
cb3870f79e9d Add Support for new end-2019 hardware:
heinrichsweikamp
parents: 352
diff changeset
348 if(retValue != HAL_OK)
cb3870f79e9d Add Support for new end-2019 hardware:
heinrichsweikamp
parents: 352
diff changeset
349 {
cb3870f79e9d Add Support for new end-2019 hardware:
heinrichsweikamp
parents: 352
diff changeset
350 PRESSURE_ADDRESS = DEVICE_PRESSURE_MS5803; // use old sensor
cb3870f79e9d Add Support for new end-2019 hardware:
heinrichsweikamp
parents: 352
diff changeset
351 HAL_Delay(100);
cb3870f79e9d Add Support for new end-2019 hardware:
heinrichsweikamp
parents: 352
diff changeset
352 MX_I2C1_Init();
cb3870f79e9d Add Support for new end-2019 hardware:
heinrichsweikamp
parents: 352
diff changeset
353 if (global.I2C_SystemStatus != HAL_OK)
cb3870f79e9d Add Support for new end-2019 hardware:
heinrichsweikamp
parents: 352
diff changeset
354 {
cb3870f79e9d Add Support for new end-2019 hardware:
heinrichsweikamp
parents: 352
diff changeset
355 if (MX_I2C1_TestAndClear() == GPIO_PIN_RESET) {
cb3870f79e9d Add Support for new end-2019 hardware:
heinrichsweikamp
parents: 352
diff changeset
356 MX_I2C1_TestAndClear(); // do it a second time
cb3870f79e9d Add Support for new end-2019 hardware:
heinrichsweikamp
parents: 352
diff changeset
357 }
cb3870f79e9d Add Support for new end-2019 hardware:
heinrichsweikamp
parents: 352
diff changeset
358 MX_I2C1_Init();
cb3870f79e9d Add Support for new end-2019 hardware:
heinrichsweikamp
parents: 352
diff changeset
359 }
cb3870f79e9d Add Support for new end-2019 hardware:
heinrichsweikamp
parents: 352
diff changeset
360 }
cb3870f79e9d Add Support for new end-2019 hardware:
heinrichsweikamp
parents: 352
diff changeset
361 else
cb3870f79e9d Add Support for new end-2019 hardware:
heinrichsweikamp
parents: 352
diff changeset
362 {
cb3870f79e9d Add Support for new end-2019 hardware:
heinrichsweikamp
parents: 352
diff changeset
363 PRESSURE_ADDRESS = DEVICE_PRESSURE_MS5837; // Success, use new sensor
cb3870f79e9d Add Support for new end-2019 hardware:
heinrichsweikamp
parents: 352
diff changeset
364 }
cb3870f79e9d Add Support for new end-2019 hardware:
heinrichsweikamp
parents: 352
diff changeset
365 HAL_Delay(3); //2.8ms according to datasheet
cb3870f79e9d Add Support for new end-2019 hardware:
heinrichsweikamp
parents: 352
diff changeset
366
cb3870f79e9d Add Support for new end-2019 hardware:
heinrichsweikamp
parents: 352
diff changeset
367 buffer[0] = 0x1E; // Reset Command
cb3870f79e9d Add Support for new end-2019 hardware:
heinrichsweikamp
parents: 352
diff changeset
368 retValue = 0xFF;
cb3870f79e9d Add Support for new end-2019 hardware:
heinrichsweikamp
parents: 352
diff changeset
369
331
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
370 /* Send reset request to pressure sensor */
356
cb3870f79e9d Add Support for new end-2019 hardware:
heinrichsweikamp
parents: 352
diff changeset
371 retValue = I2C_Master_Transmit( PRESSURE_ADDRESS, buffer, 1);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
372 if(retValue != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
373 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
374 return (HAL_StatusTypeDef)retValue;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
375 }
356
cb3870f79e9d Add Support for new end-2019 hardware:
heinrichsweikamp
parents: 352
diff changeset
376 HAL_Delay(3); //2.8ms according to datasheet
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
377
356
cb3870f79e9d Add Support for new end-2019 hardware:
heinrichsweikamp
parents: 352
diff changeset
378 for(uint8_t i=0;i<7;i++)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
379 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
380 C[i] = get_ci_by_coef_num(i);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
381 }
356
cb3870f79e9d Add Support for new end-2019 hardware:
heinrichsweikamp
parents: 352
diff changeset
382 // n_crc = crc4(C); // no evaluation at the moment hw 151026
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
383
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
384 C5_x_2p8 = C[5] * 256;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
385 C2_x_2p16 = C[2] * 65536;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
386 C1_x_2p15 = C[1] * 32768;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
387
241
2b9775f71e30 cleanup: factor out I2C1_Status() and cleanup type
Jan Mulder <jlmulder@xs4all.nl>
parents: 186
diff changeset
388 if(global.I2C_SystemStatus == HAL_OK)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
389 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
390 pressureSensorInitSuccess = 1;
331
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
391 retValue = pressure_update();
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
392 }
331
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
393 return retValue;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
394 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
395
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
396
186
f11f0bf6ef2d cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
397 static uint32_t get_adc(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
398 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
399 uint8_t buffer[1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
400 uint8_t resivebuf[4];
474
4be72d55b09a Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents: 403
diff changeset
401 uint32_t answer = 0xFFFFFFFF;
186
f11f0bf6ef2d cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
402
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
403 buffer[0] = 0x00; // Get ADC
474
4be72d55b09a Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents: 403
diff changeset
404 if(I2C_Master_Transmit( PRESSURE_ADDRESS, buffer, 1) == HAL_OK)
4be72d55b09a Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents: 403
diff changeset
405 {
4be72d55b09a Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents: 403
diff changeset
406 if(I2C_Master_Receive( PRESSURE_ADDRESS, resivebuf, 4) == HAL_OK)
4be72d55b09a Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents: 403
diff changeset
407 {
4be72d55b09a Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents: 403
diff changeset
408 resivebuf[3] = 0;
4be72d55b09a Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents: 403
diff changeset
409 answer = 256*256 *(uint32_t)resivebuf[0] + 256 * (uint32_t)resivebuf[1] + (uint32_t)resivebuf[2];
4be72d55b09a Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents: 403
diff changeset
410 }
4be72d55b09a Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents: 403
diff changeset
411 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
412 return answer;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
413 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
414
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
415
186
f11f0bf6ef2d cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
416 static uint16_t get_ci_by_coef_num(uint8_t coef_num)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
417 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
418 uint8_t resivebuf[2];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
419
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
420 uint8_t cmd = CMD_PROM_RD+coef_num*2;
356
cb3870f79e9d Add Support for new end-2019 hardware:
heinrichsweikamp
parents: 352
diff changeset
421 I2C_Master_Transmit( PRESSURE_ADDRESS, &cmd, 1);
cb3870f79e9d Add Support for new end-2019 hardware:
heinrichsweikamp
parents: 352
diff changeset
422 I2C_Master_Receive( PRESSURE_ADDRESS, resivebuf, 2);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
423 return (256*(uint16_t)resivebuf[0]) + (uint16_t)resivebuf[1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
424 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
425
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
426
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
427
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
428 uint8_t pressure_update(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
429 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
430 HAL_StatusTypeDef statusReturn = HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
431
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
432 statusReturn = pressure_sensor_get_data();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
433 pressure_calculation();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
434 return (uint8_t)statusReturn;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
435 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
436
276
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
437 /* Switch between pressure and temperature measurement with every successful read operation */
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
438 void pressure_update_alternating(void)
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
439 {
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
440 static uint8_t getTemperature= 0;
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
441
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
442 if(getTemperature)
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
443 {
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
444 if(pressure_sensor_get_temperature_raw() == HAL_OK)
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
445 {
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
446 getTemperature = 0;
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
447 }
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
448 }
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
449 else
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
450 {
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
451 if(pressure_sensor_get_pressure_raw() == HAL_OK)
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
452 {
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
453 getTemperature = 1;
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
454 }
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
455 }
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
456 pressure_calculation();
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
457 return;
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
458 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
459
186
f11f0bf6ef2d cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
460 static uint32_t pressure_sensor_get_one_value(uint8_t cmd, HAL_StatusTypeDef *statusReturn)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
461 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
462 uint8_t command = CMD_ADC_CONV + cmd;
474
4be72d55b09a Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents: 403
diff changeset
463 uint32_t adcValue = 0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
464 HAL_StatusTypeDef statusReturnTemp = HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
465
356
cb3870f79e9d Add Support for new end-2019 hardware:
heinrichsweikamp
parents: 352
diff changeset
466 statusReturnTemp = I2C_Master_Transmit( PRESSURE_ADDRESS, &command, 1);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
467
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
468 if(statusReturn)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
469 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
470 *statusReturn = statusReturnTemp;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
471 }
479
4b9427ae0a65 Bugfix unintended else condition:
ideenmodellierer
parents: 474
diff changeset
472
4b9427ae0a65 Bugfix unintended else condition:
ideenmodellierer
parents: 474
diff changeset
473 switch (cmd & 0x0f) // wait necessary conversion time
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
474 {
479
4b9427ae0a65 Bugfix unintended else condition:
ideenmodellierer
parents: 474
diff changeset
475 case CMD_ADC_256 : HAL_Delay(1); break;
4b9427ae0a65 Bugfix unintended else condition:
ideenmodellierer
parents: 474
diff changeset
476 case CMD_ADC_512 : HAL_Delay(3); break;
4b9427ae0a65 Bugfix unintended else condition:
ideenmodellierer
parents: 474
diff changeset
477 case CMD_ADC_1024: HAL_Delay(4); break;
4b9427ae0a65 Bugfix unintended else condition:
ideenmodellierer
parents: 474
diff changeset
478 case CMD_ADC_2048: HAL_Delay(6); break;
4b9427ae0a65 Bugfix unintended else condition:
ideenmodellierer
parents: 474
diff changeset
479 case CMD_ADC_4096: HAL_Delay(10); break;
4b9427ae0a65 Bugfix unintended else condition:
ideenmodellierer
parents: 474
diff changeset
480 default:
4b9427ae0a65 Bugfix unintended else condition:
ideenmodellierer
parents: 474
diff changeset
481 break;
4b9427ae0a65 Bugfix unintended else condition:
ideenmodellierer
parents: 474
diff changeset
482 }
4b9427ae0a65 Bugfix unintended else condition:
ideenmodellierer
parents: 474
diff changeset
483 adcValue = get_adc();
4b9427ae0a65 Bugfix unintended else condition:
ideenmodellierer
parents: 474
diff changeset
484 if(adcValue == 0xFFFFFFFF)
4b9427ae0a65 Bugfix unintended else condition:
ideenmodellierer
parents: 474
diff changeset
485 {
4b9427ae0a65 Bugfix unintended else condition:
ideenmodellierer
parents: 474
diff changeset
486 if(statusReturn)
474
4be72d55b09a Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents: 403
diff changeset
487 {
4be72d55b09a Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents: 403
diff changeset
488 *statusReturn = HAL_ERROR;
4be72d55b09a Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents: 403
diff changeset
489 }
4be72d55b09a Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents: 403
diff changeset
490 }
4be72d55b09a Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents: 403
diff changeset
491 return adcValue;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
492 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
493
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
494
186
f11f0bf6ef2d cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
495 static HAL_StatusTypeDef pressure_sensor_get_data(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
496 {
276
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
497 uint32_t requestedValue = 0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
498 HAL_StatusTypeDef statusReturn1 = HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
499 HAL_StatusTypeDef statusReturn2 = HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
500
276
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
501
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
502
276
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
503 requestedValue = pressure_sensor_get_one_value(CMD_ADC_D2 + CMD_ADC_1024, &statusReturn2);
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
504 if (statusReturn2 == HAL_OK)
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
505 {
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
506 D2 = requestedValue;
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
507 }
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
508
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
509 requestedValue = pressure_sensor_get_one_value(CMD_ADC_D1 + CMD_ADC_1024, &statusReturn1);
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
510 if (statusReturn1 == HAL_OK)
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
511 {
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
512 D1 = requestedValue;
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
513 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
514 if(statusReturn2 > statusReturn1) // if anything is not HAL_OK (0x00) or worse
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
515 return statusReturn2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
516 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
517 return statusReturn1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
518 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
519
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
520
276
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
521 HAL_StatusTypeDef pressure_sensor_get_pressure_raw(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
522 {
276
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
523 uint32_t requestedValue = 0;
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
524 HAL_StatusTypeDef statusReturn = HAL_TIMEOUT;
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
525
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
526 requestedValue = pressure_sensor_get_one_value(CMD_ADC_D1 + CMD_ADC_1024, &statusReturn);
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
527 if (statusReturn == HAL_OK)
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
528 {
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
529 D1 = requestedValue;
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
530 }
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
531
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
532 return statusReturn;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
533 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
534
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
535
276
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
536 HAL_StatusTypeDef pressure_sensor_get_temperature_raw(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
537 {
276
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
538 uint32_t requestedValue = 0;
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
539 HAL_StatusTypeDef statusReturn = HAL_TIMEOUT;
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
540
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
541 requestedValue = pressure_sensor_get_one_value(CMD_ADC_D2 + CMD_ADC_1024, &statusReturn);
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
542 if (statusReturn == HAL_OK)
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
543 {
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
544 D2 = requestedValue;
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
545 }
8e9c502c0b06 Rework pressure/ temperature data aquisition
ideenmodellierer
parents: 241
diff changeset
546 return statusReturn;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
547 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
548
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
549
352
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
550 #ifdef SIMULATE_PRESSURE
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
551 void pressure_simulation()
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
552 {
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
553 static uint32_t tickstart = 0;
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
554 static float pressure_sim_mbar = 0;
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
555 static uint32_t passedSecond = 0;
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
556 static uint32_t secondtick = 0;
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
557
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
558 uint32_t lasttick = 0;
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
559
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
560
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
561
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
562 if( tickstart == 0)
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
563 {
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
564 tickstart = HAL_GetTick(); /* init time stamp */
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
565 secondtick = tickstart;
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
566 pressure_sim_mbar = 1000;
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
567 }
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
568
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
569 lasttick = HAL_GetTick();
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
570 if(time_elapsed_ms(secondtick,lasttick) > 1000) /* one second passed since last tick */
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
571 {
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
572 secondtick = lasttick;
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
573 passedSecond++;
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
574
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
575 #ifdef DIVE_AFTER_LANDING
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
576 if(passedSecond < 10) pressure_sim_mbar = 1000.0; /* stay stable for 10 seconds */
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
577 else if(passedSecond < 300) pressure_sim_mbar -= 1.0; /* decrease pressure in 5 minutes target 770mbar => delta 330 */
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
578 else if(passedSecond < 900) pressure_sim_mbar += 0.0; /*stay stable 10 minutes*/
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
579 else if(passedSecond < 1500) pressure_sim_mbar += 0.5; /* return to 1 bar in 10 Minutes*/
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
580 else if(passedSecond < 1800) pressure_sim_mbar += 0.0; /* 5 minutes break */
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
581 else if(passedSecond < 2000) pressure_sim_mbar += 10.0; /* start dive */
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
582 else if(passedSecond < 2300) pressure_sim_mbar += 0.0; /* stay on depth */
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
583 else if(passedSecond < 2500) pressure_sim_mbar -= 10.0; /* return to surface */
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
584 else pressure_sim_mbar = 1000.0; /* final state */
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
585 #else /* short dive */
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
586 if(passedSecond < 10) pressure_sim_mbar = 1000.0; /* stay stable for 10 seconds */
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
587 else if(passedSecond < 180) pressure_sim_mbar += 10.0; /* Start dive */
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
588 else if(passedSecond < 300) pressure_sim_mbar += 0.0; /*stay on depth*/
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
589 else if(passedSecond < 460) pressure_sim_mbar -= 10.0; /* return to surface */
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
590 else if(passedSecond < 600) pressure_sim_mbar += 0.0; /* stay */
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
591 else if(passedSecond < 610) pressure_sim_mbar = 1000.0; /* get ready for second dive */
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
592 else if(passedSecond < 780) pressure_sim_mbar += 10.0; /* Start dive */
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
593 else if(passedSecond < 900) pressure_sim_mbar += 0.0; /*stay on depth*/
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
594 else if(passedSecond < 1060) pressure_sim_mbar -= 10.0; /* return to surface */
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
595 else if(passedSecond < 1200) pressure_sim_mbar += 0.0; /* stay */
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
596 else pressure_sim_mbar = 1000.0; /* final state */
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
597 #endif
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
598 }
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
599
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
600
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
601 ambient_pressure_mbar = pressure_sim_mbar;
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
602 ambient_temperature = 25.0;
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
603 return;
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
604 }
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
605
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
606 #endif
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
607
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
608 void pressure_calculation(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
609 {
241
2b9775f71e30 cleanup: factor out I2C1_Status() and cleanup type
Jan Mulder <jlmulder@xs4all.nl>
parents: 186
diff changeset
610 if(global.I2C_SystemStatus != HAL_OK)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
611 return;
352
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
612
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
613 #ifdef SIMULATE_PRESSURE
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
614 pressure_simulation();
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
615 #else
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
616 pressure_calculation_AN520_004_mod_MS5803_30BA__09_2015();
352
1f24022345d1 Fix merge problem
Jan Mulder <jlmulder@xs4all.nl>
parents: 351
diff changeset
617 #endif
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
618 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
619
331
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
620 static uint8_t pressure_plausible(float pressurevalue)
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
621 {
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
622 static uint8_t pressurewriteindex = 0;
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
623 uint8_t retval = 0;
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
624 uint8_t index;
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
625 float pressure_average = 0;
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
626
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
627 for(index = 0; index < PRESSURE_HISTORY_SIZE; index++)
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
628 {
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
629 pressure_average += pressure_history_mbar[index];
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
630 }
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
631 pressure_average /= PRESSURE_HISTORY_SIZE;
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
632 if(pressure_average == 1000.0) /* first pressure calculation */
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
633 {
339
37f45300bc2e Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents: 335
diff changeset
634 if(fabs(pressurevalue - pressure_average) < 11000.0) /* just in case a reset occur during dive assume value equal < 100m as valid */
331
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
635 {
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
636 for(index = 0; index < PRESSURE_HISTORY_SIZE; index++)
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
637 {
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
638 pressure_history_mbar[index] = pressurevalue; /* set history to current value */
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
639 retval = 1;
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
640 }
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
641 }
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
642 }
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
643 else
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
644 {
339
37f45300bc2e Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents: 335
diff changeset
645 pressure_history_mbar[pressurewriteindex++] = pressurevalue;
37f45300bc2e Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents: 335
diff changeset
646 pressurewriteindex &= 0x7; /* wrap around if necessary */
37f45300bc2e Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents: 335
diff changeset
647 retval = 1;
331
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
648 }
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
649
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
650 return retval;
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
651 }
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
652
186
f11f0bf6ef2d cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
653 static void pressure_calculation_AN520_004_mod_MS5803_30BA__09_2015(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
654 {
335
c11ce8c885d3 Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents: 331
diff changeset
655 static float runningAvg = 0;
c11ce8c885d3 Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents: 331
diff changeset
656 static uint8_t avgCnt = 0;
c11ce8c885d3 Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents: 331
diff changeset
657
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
658 uint32_t local_D1; // ADC value of the pressure conversion
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
659 uint32_t local_D2; // ADC value of the temperature conversion
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
660 int32_t local_Px10; // compensated pressure value
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
661 int32_t local_Tx100; // compensated temperature value
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
662 int64_t local_dT; // int32_t, difference between actual and measured temperature
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
663 int64_t local_OFF; // offset at actual temperature
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
664 int64_t local_SENS; // sensitivity at actual temperature
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
665
331
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
666 float calc_pressure;
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
667
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
668 int64_t T2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
669 int64_t OFF2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
670 int64_t SENS2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
671
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
672 local_D1 = D1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
673 local_D2 = D2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
674
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
675 local_dT = ((int64_t)local_D2) - ((int64_t)C[5]) * 256; //pow(2,8);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
676 local_OFF = ((int64_t)C[2]) * 65536 + local_dT * ((int64_t)C[4]) / 128; // pow(2,16), pow(2,7)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
677 local_SENS = ((int64_t)C[1]) * 32768 + local_dT * ((int64_t)C[3]) / 256; // pow(2,15), pow(2,8)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
678
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
679 local_Tx100 = (int32_t)(2000 + (local_dT * ((int64_t)C[6])) / 8388608);// pow(2,23)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
680
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
681
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
682 if(local_Tx100 < 2000) // low temperature
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
683 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
684 T2 = 3 * local_dT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
685 T2 *= local_dT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
686 T2 /= 8589934592;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
687
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
688 OFF2 = ((int64_t)local_Tx100) - 2000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
689 OFF2 *= OFF2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
690 OFF2 *= 3;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
691 OFF2 /= 2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
692
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
693 SENS2 = ((int64_t)local_Tx100) - 2000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
694 SENS2 *= SENS2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
695 SENS2 *= 5;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
696 SENS2 /= 8;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
697
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
698 local_Tx100 -= (int32_t)T2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
699 local_OFF -= OFF2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
700 local_SENS -= SENS2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
701 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
702 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
703 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
704 T2 = 7 * local_dT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
705 T2 *= local_dT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
706 T2 /= 137438953472;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
707
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
708 OFF2 = ((int64_t)local_Tx100) - 2000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
709 OFF2 *= OFF2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
710 OFF2 /= 16;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
711
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
712 local_Tx100 -= (int32_t)T2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
713 local_OFF -= OFF2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
714 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
715
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
716 local_Px10 = (int32_t)(
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
717 (((int64_t)((local_D1 * local_SENS) / 2097152)) - local_OFF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
718 / 8192 );// )) / 10; // pow(2,21), pow(2,13)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
719
339
37f45300bc2e Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents: 335
diff changeset
720 ambient_temperature = ((float)local_Tx100) / 100;
37f45300bc2e Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents: 335
diff changeset
721 ambient_temperature += temperature_offset;
331
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
722
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
723 calc_pressure = ((float)local_Px10) / 10;
339
37f45300bc2e Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents: 335
diff changeset
724 calc_pressure += pressure_offset;
37f45300bc2e Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents: 335
diff changeset
725
331
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
726 if(pressure_plausible(calc_pressure))
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
727 {
335
c11ce8c885d3 Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents: 331
diff changeset
728 runningAvg = (avgCnt * runningAvg + calc_pressure) / (avgCnt + 1);
339
37f45300bc2e Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents: 335
diff changeset
729 if (avgCnt < 10) /* build an average considering the last measurements to have a weight "1 of 10" */
335
c11ce8c885d3 Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents: 331
diff changeset
730 { /* Main reason for this is the jitter of up to +-10 HPa in surface mode which is caused */
c11ce8c885d3 Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents: 331
diff changeset
731 avgCnt++; /* by the measurement range of the sensor which is focused on under water pressure measurement */
c11ce8c885d3 Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents: 331
diff changeset
732 }
c11ce8c885d3 Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents: 331
diff changeset
733 ambient_pressure_mbar = runningAvg;
331
b4c578caaafb Added plausibility check for pressure values
ideenmodellierer
parents: 276
diff changeset
734 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
735 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
736
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
737
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
738 /* taken from AN520 by meas-spec.com dated 9. Aug. 2011
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
739 * short and int are both 16bit according to AVR/GCC google results
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
740 */
356
cb3870f79e9d Add Support for new end-2019 hardware:
heinrichsweikamp
parents: 352
diff changeset
741 /*static uint8_t crc4(uint16_t n_prom[])
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
742 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
743 uint16_t cnt; // simple counter
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
744 uint16_t n_rem; // crc reminder
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
745 uint16_t crc_read; // original value of the crc
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
746 uint8_t n_bit;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
747 n_rem = 0x00;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
748 crc_read=n_prom[7]; //save read CRC
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
749 n_prom[7]=(0xFF00 & (n_prom[7])); //CRC byte is replaced by 0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
750 for (cnt = 0; cnt < 16; cnt++) // operation is performed on bytes
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
751 { // choose LSB or MSB
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
752 if (cnt%2==1) n_rem ^= (uint16_t) ((n_prom[cnt>>1]) & 0x00FF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
753 else n_rem ^= (uint16_t) (n_prom[cnt>>1]>>8);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
754 for (n_bit = 8; n_bit > 0; n_bit--)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
755 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
756 if (n_rem & (0x8000))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
757 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
758 n_rem = (n_rem << 1) ^ 0x3000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
759 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
760 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
761 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
762 n_rem = (n_rem << 1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
763 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
764 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
765 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
766 n_rem= (0x000F & (n_rem >> 12)); // // final 4-bit reminder is CRC code
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
767 n_prom[7]=crc_read; // restore the crc_read to its original place
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
768 return (n_rem ^ 0x00);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
769 }
356
cb3870f79e9d Add Support for new end-2019 hardware:
heinrichsweikamp
parents: 352
diff changeset
770
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
771 void test_calculation(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
772 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
773 C1 = 29112;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
774 C2 = 26814;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
775 C3 = 19125;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
776 C4 = 17865;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
777 C5 = 32057;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
778 C6 = 31305;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
779
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
780 C2_x_2p16 = C2 * 65536;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
781 C1_x_2p15 = C1 * 32768;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
782
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
783 D1 = 4944364;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
784 D2 = 8198974;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
785 pressure_calculation() ;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
786 };
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
787 */
339
37f45300bc2e Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents: 335
diff changeset
788 void pressure_set_offset (float pressureOffset, float temperatureOffset)
37f45300bc2e Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents: 335
diff changeset
789 {
37f45300bc2e Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents: 335
diff changeset
790 if(pressure_offset != pressureOffset) /* we received a new value => reinit surface que */
37f45300bc2e Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents: 335
diff changeset
791 {
37f45300bc2e Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents: 335
diff changeset
792 ambient_pressure_mbar -= pressure_offset; /* revert old value */
37f45300bc2e Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents: 335
diff changeset
793 ambient_pressure_mbar += pressureOffset; /* apply new offset */
37f45300bc2e Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents: 335
diff changeset
794 init_surface_ring(1);
37f45300bc2e Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents: 335
diff changeset
795 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
796
339
37f45300bc2e Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents: 335
diff changeset
797 pressure_offset = pressureOffset;
37f45300bc2e Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents: 335
diff changeset
798 temperature_offset = temperatureOffset;
37f45300bc2e Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents: 335
diff changeset
799 }
37f45300bc2e Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents: 335
diff changeset
800
37f45300bc2e Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents: 335
diff changeset
801