Mercurial > public > hwos_code
comparison src/p2_deco.c @ 288:08986d479b94
FIX gas_volume shall read gas switches from char_O_deco_gas
author | jdg@air |
---|---|
date | Fri, 29 May 2015 02:40:43 +0200 |
parents | f342853afcd9 |
children | 30edd177016a |
comparison
equal
deleted
inserted
replaced
287:f342853afcd9 | 288:08986d479b94 |
---|---|
2163 { | 2163 { |
2164 overlay float volumes[NUM_GAS]; | 2164 overlay float volumes[NUM_GAS]; |
2165 overlay float bottom_usage, deco_usage; | 2165 overlay float bottom_usage, deco_usage; |
2166 overlay unsigned char i; | 2166 overlay unsigned char i; |
2167 overlay unsigned char gas, depth; | 2167 overlay unsigned char gas, depth; |
2168 overlay unsigned char lastGasStop = 255; | |
2169 RESET_C_STACK | 2168 RESET_C_STACK |
2170 | 2169 |
2171 //---- initialize with bottom consumption -------------------------------- | 2170 //---- initialize with bottom consumption -------------------------------- |
2172 for(i=0; i<NUM_GAS; ++i) // Nothing yet... | 2171 for(i=0; i<NUM_GAS; ++i) // Nothing yet... |
2173 volumes[i] = 0.0; | 2172 volumes[i] = 0.0; |
2187 | 2186 |
2188 depth = char_I_bottom_depth; | 2187 depth = char_I_bottom_depth; |
2189 | 2188 |
2190 for(i=0; i<NUM_STOPS; ++i) | 2189 for(i=0; i<NUM_STOPS; ++i) |
2191 { | 2190 { |
2192 overlay unsigned char newDepth, time; | 2191 overlay unsigned char newDepth, time, newGas; |
2193 | 2192 |
2194 time = char_O_deco_time[i]; | 2193 time = char_O_deco_time[i]; |
2195 if( time == 0 ) continue; // not yet: still search table. | 2194 if( time == 0 ) break; // End of stops. |
2195 | |
2196 newDepth = char_O_deco_depth[i]; | 2196 newDepth = char_O_deco_depth[i]; |
2197 | 2197 newGas = char_O_deco_gas [i]-1; |
2198 //---- Gas switch during or before this stop -------------------------- | 2198 |
2199 for(;;) | 2199 assert(0 < newDepth && newDepth <= depth); |
2200 { | 2200 assert(0 <= newGas && newGas < NUM_GAS); |
2201 overlay unsigned char newGas = 0; | 2201 |
2202 overlay unsigned char newStop = 0; // NO CHANGE yet | 2202 //---- usage BEFORE gas switch (if any), at 10m/min ------------------ |
2203 overlay unsigned char j; | 2203 volumes[gas] += ((depth+newDepth)*0.05 + 1.0) // average depth --> bar. |
2204 | 2204 * (depth-newDepth)*0.1 // metre --> min |
2205 for(j=0; j<NUM_GAS; ++j) | 2205 * deco_usage; |
2206 { | 2206 |
2207 // Skip gas without changing depth: | 2207 //---- Do gas switch, at new depth |
2208 if( ! char_I_deco_gas_change[j] ) | 2208 gas = newGas; |
2209 continue; | |
2210 // Select gas changed between [newDepth .. lastGasStop[ | |
2211 // Note that <= means changing gas at BEGINNING of this stop. | |
2212 // Note that < means we cant use the same gas twice | |
2213 if( newDepth <= char_I_deco_gas_change[j] | |
2214 && char_I_deco_gas_change[j] < lastGasStop ) | |
2215 { | |
2216 // Keep the DEEPEST gas in that range: | |
2217 if( char_I_deco_gas_change[j] >= newStop ) | |
2218 { | |
2219 newGas = j; | |
2220 newStop = char_I_deco_gas_change[j]; | |
2221 } | |
2222 } | |
2223 } | |
2224 | |
2225 // Did we find something ? | |
2226 if( !newStop ) | |
2227 break; | |
2228 | |
2229 //---- usage BEFORE gas switch (if any), at 10m/min : | |
2230 if( deco_usage > 0.0 && depth > newStop ) | |
2231 // Plus usage during ascent to the next stop, at 10m/min. | |
2232 volumes[gas] += ((depth+newStop)*0.05 + 1.0) // average depth --> bar. | |
2233 * (depth-newStop)*0.1 // metre --> min | |
2234 * deco_usage; | |
2235 | |
2236 //---- Do gas switch: | |
2237 gas = newGas; | |
2238 | |
2239 lastGasStop = newStop; // Mark last used gas | |
2240 if( newStop < depth ) // ascent to gas switch, | |
2241 depth = newStop; | |
2242 } | |
2243 | |
2244 //---- usage AFTER gas switch (if any), at 10m/min : | |
2245 if( depth > newDepth ) | |
2246 volumes[gas] += ((depth+newDepth)*0.05 + 1.0) // average depth --> bar. | |
2247 * (depth-newDepth)*0.1 // metre --> min | |
2248 * deco_usage; | |
2249 | |
2250 //---- Do stop: | |
2251 depth = newDepth; | 2209 depth = newDepth; |
2252 | 2210 |
2253 // Usage at stop: | 2211 // Usage at stop: |
2254 if( deco_usage > 0.0 ) | 2212 if( deco_usage > 0.0 ) |
2255 volumes[gas] += (depth*0.1 + 1.0) // depth --> bar. | 2213 volumes[gas] += (depth*0.1 + 1.0) // depth --> bar. |