comparison code_part1/OSTC_code_c_part2/p2_deco.c @ 353:b5b030c1ae7e

Avoid spurious switch-depth stops with 3 or more gas.
author JeanDo
date Tue, 07 Jun 2011 01:16:55 +0200
parents ecbbbd423e86
children de3b267e1fd9
comparison
equal deleted inserted replaced
349:ed137d66ac65 353:b5b030c1ae7e
970 970
971 971
972 ////////////////////////////////////////////////////////////////////////////// 972 //////////////////////////////////////////////////////////////////////////////
973 // Find current gas in the list (if any). 973 // Find current gas in the list (if any).
974 // 974 //
975 // Input: char_I_deco_N2_ratio[] and He, to detect breathed gas. 975 // Input: char_I_current_gas.
976 // 976 //
977 // Output: sim_gas_depth_used 977 // Output: sim_gas_last_depth, temp_depth_limit.
978 // 978 //
979 static void gas_switch_find_current(void) 979 static void gas_switch_find_current(void)
980 { 980 {
981 overlay unsigned char j; 981 assert( 0 <= char_I_current_gas && char_I_current_gas <= (NUM_GAS+1) );
982 overlay unsigned char N2 = (unsigned char)(N2_ratio * 100 + 0.5); 982
983 overlay unsigned char He = (unsigned char)(He_ratio * 100 + 0.5); 983 if( (char_I_current_gas <= NUM_GAS) // Gas6 == manual set.
984 984 && char_I_deco_gas_change[char_I_current_gas-1]
985 for(j=0; j<NUM_GAS; ++j) 985 )
986 { 986 {
987 // Make sure to detect if we are already breathing some gas in 987 sim_gas_last_used = char_I_current_gas-1;
988 // the current list (happends when first gas do have a depth). 988 sim_gas_last_depth = char_I_deco_gas_change[sim_gas_last_used];
989 if( N2 == char_I_deco_N2_ratio[j] 989 // temp_depth_limit = ???
990 && He == char_I_deco_He_ratio[j]
991 )
992 {
993 if( char_I_deco_gas_change[j] )
994 temp_depth_limit = sim_gas_last_depth = char_I_deco_gas_change[j];
995 sim_gas_last_used = j+1;
996 break;
997 }
998 }
999
1000 // If there is no gas-switch-delay running ?
1001 if( sim_gas_delay <= sim_dive_mins)
1002 {
1003 // Compute current depth:
1004 overlay unsigned char depth = (unsigned char)(0.5 + (pres_respiration - pres_surface) * BAR_TO_METER);
1005 assert( depth < 130 );
1006
1007 // And if I'm above the last decostop (with the 3m margin) ?
1008 if( (sim_gas_last_depth-3) > depth )
1009 {
1010 for(j=0; j<NUM_GAS; ++j)
1011 {
1012 // And If I am in the range of a valide stop ?
1013 // (again, with the same 3m margin)
1014 if( char_I_deco_gas_change[j]
1015 && depth <= char_I_deco_gas_change[j]
1016 && depth >= (char_I_deco_gas_change[j] - 3)
1017 )
1018 {
1019 // Then start gas-switch timer there,
1020 sim_gas_delay = sim_dive_mins
1021 + read_custom_function(55);
1022
1023 // And make sure decostop will be recorded at the right depth.
1024 temp_depth_limit = char_I_deco_gas_change[j];
1025 break;
1026 }
1027 }
1028 }
1029 else
1030 // Make clear there is no deay anymore.
1031 sim_gas_delay = 0;
1032 } 990 }
1033 } 991 }
1034 992
1035 ////////////////////////////////////////////////////////////////////////////// 993 //////////////////////////////////////////////////////////////////////////////
1036 // Find deepest available gas. 994 // Find deepest available gas.
1061 { 1019 {
1062 // Gas not (yet) allowed ? Skip ! 1020 // Gas not (yet) allowed ? Skip !
1063 if( temp_depth_limit > deco_gas_change[j] ) 1021 if( temp_depth_limit > deco_gas_change[j] )
1064 continue; 1022 continue;
1065 1023
1066 // Gas deeper than the current/previous one ? Skip ! 1024 // Gas deeper (or equal) than the current one ? Skip !
1067 if( sim_gas_last_depth && deco_gas_change[j] >= sim_gas_last_depth ) 1025 if( sim_gas_last_depth && deco_gas_change[j] >= sim_gas_last_depth )
1068 continue; 1026 continue;
1069 1027
1070 // First, or deeper ? 1028 // First, or deeper ?
1071 if( switch_deco < deco_gas_change[j] ) 1029 if( switch_deco < deco_gas_change[j] )