Mercurial > public > hwos_code
annotate src/divemode.asm @ 656:8af5aefbcdaf default tip
Update to 3.31 beta
| author | heinrichsweikamp |
|---|---|
| date | Thu, 27 Nov 2025 18:32:58 +0100 |
| parents | 75e90cd0c2c3 |
| children |
| rev | line source |
|---|---|
| 0 | 1 ;============================================================================= |
| 2 ; | |
| 640 | 3 ; File divemode.asm * combined next generation V3.12.3 |
| 0 | 4 ; |
| 623 | 5 ; Dive Mode |
| 0 | 6 ; |
| 654 | 7 ; Copyright (c) 2011, JD Gascuel, heinrichs weikamp gmbh, all right reserved. |
| 0 | 8 ;============================================================================= |
| 9 ; HISTORY | |
| 10 ; 2011-08-15 : [mH] moving from OSTC code | |
| 11 | |
| 604 | 12 #include "hwos.inc" ; mandatory header |
| 13 #include "shared_definitions.h" ; mailbox from/to p2_deco.c | |
| 582 | 14 #include "tft_outputs.inc" |
| 15 #include "strings.inc" | |
| 16 #include "tft.inc" | |
| 17 #include "eeprom_rs232.inc" | |
| 18 #include "math.inc" | |
| 19 #include "wait.inc" | |
| 20 #include "customview.inc" | |
| 21 #include "start.inc" | |
| 22 #include "adc_lightsensor.inc" | |
| 23 #include "ghostwriter.inc" | |
| 24 #include "i2c.inc" | |
| 25 #include "calibrate.inc" | |
| 26 #include "convert.inc" | |
| 623 | 27 #include "surfmode.inc" |
| 604 | 28 #include "rx_ops.inc" |
| 623 | 29 |
| 30 | |
| 582 | 31 extern do_line_menu |
| 32 extern do_main_divemenu | |
| 623 | 33 extern menu_draw_lines_divemode |
| 634 | 34 extern menu_draw_cursor_dive |
| 582 | 35 extern init_recording_params |
| 631 | 36 extern option_check_and_store_all |
| 582 | 37 |
| 623 | 38 IFDEF _compass |
| 39 extern TFT_dive_compass_heading | |
| 40 ENDIF | |
| 41 | |
| 631 | 42 IFDEF _cave_mode |
| 43 extern do_main_cavemenu | |
| 44 ENDIF | |
| 623 | 45 |
| 634 | 46 |
| 623 | 47 ;---- Private local Variables ------------------------------------------------- |
| 582 | 48 |
| 49 CBLOCK local1 ; max size is 16 Byte !!! | |
| 50 sensor_setpoint ; sensor ppo2 in 0.01bar for deco routine | |
| 604 | 51 check_gas_num ; used in search for best gas/dil: current gas/dil number (1-5) |
| 52 check_gas_depth ; used in search for best gas/dil: current gas/dil change depth | |
| 53 check_gas_type ; used in search for best gas/dil: current gas/dil type | |
| 54 check_gas_O2_ratio ; used in search for best gas/dil: current gas/dil O2 ratio | |
| 55 best_gas_num ; used in search for best gas/dil: best gas/dil number (1-5) CAUTION: there is also a variable named best_gas_number ! | |
| 56 best_gas_depth ; used in search for best gas/dil: best gas/dil change depth | |
| 623 | 57 last_pressure_velocity:2 ; cached last absolute pressure for velocity calculation |
| 58 TFT_output_flags_1 ; TFT update flags for output phase 1 | |
| 59 TFT_output_flags_2 ; TFT update flags for output phase 2 | |
| 60 TFT_output_flags_3 ; TFT update flags for output phase 3 | |
| 61 TFT_output_flags_4 ; TFT update flags for output phase 4 | |
| 62 DM_flags_local ; various dive mode flags | |
| 63 ENDC ; used: 14 byte, remaining: 2 byte | |
| 604 | 64 |
| 65 CBLOCK local2 ; max size is 16 Byte !!! | |
| 623 | 66 pressure_rel_accu_trip:4 ; pressure accumulator for calculating the resettable average depth |
| 67 pressure_rel_accu_total:4 ; pressure accumulator for calculating the total dive average depth | |
| 68 ppO2_min:2 ; used in search for best gas/dil: minimum ppO2 required | |
| 69 ppO2_max_default:2 ; used in search for best gas/dil: default maximum ppO2 | |
| 70 ppO2_max_deco:2 ; used in search for best gas/dil: deco maximum ppO2 | |
| 634 | 71 ENDC ; used: 14 byte, remaining: 2 byte |
| 623 | 72 |
| 73 | |
| 74 ;---- Private local Flags ---------------------------------------------------- | |
| 75 | |
| 76 ; TFT_output_flags_1 - phase 1: every second - before deco calculations, all modes | |
| 77 #DEFINE FLAG_TFT_depth_current TFT_output_flags_1,0 ; =1: show current depth | |
| 78 #DEFINE FLAG_TFT_depth_maximum TFT_output_flags_1,1 ; =1: show maximum depth | |
| 79 #DEFINE FLAG_TFT_active_gas_divemode TFT_output_flags_1,2 ; =1: show active gas and dive mode | |
| 80 #DEFINE FLAG_TFT_apnoe_surface_time TFT_output_flags_1,3 ; =1: show apnoe mode surface time | |
| 81 #DEFINE FLAG_TFT_depth_maximum_apnoe TFT_output_flags_1,4 ; =1: show maximum depth of last apnoe dive | |
| 82 #DEFINE FLAG_TFT_clear_apnoe_surface TFT_output_flags_1,5 ; =1: clear apnoe mode surface data from screen | |
| 83 #DEFINE FLAG_TFT_apnoe_divetime TFT_output_flags_1,6 ; =1: show apnoe mode dive times | |
| 656 | 84 #DEFINE FLAG_TFT_temperature TFT_output_flags_1,7 ; =1: show/redraw temperature |
| 623 | 85 |
| 86 ; TFT_output_flags_2 - phase 2: every second - before deco calculations, deco modes only | |
| 87 #DEFINE FLAG_TFT_divemode_mask TFT_output_flags_2,0 ; =1: show dive mode mask | |
| 88 #DEFINE FLAG_TFT_divetime TFT_output_flags_2,1 ; =1: show dive time | |
| 89 #DEFINE FLAG_TFT_safety_stop_show TFT_output_flags_2,2 ; =1: show safety stop | |
| 90 #DEFINE FLAG_TFT_safety_stop_clear TFT_output_flags_2,3 ; =1: clear safety stop | |
| 631 | 91 ; TFT_output_flags_2,4 ; --- unused |
| 623 | 92 ; TFT_output_flags_2,5 ; --- unused |
| 93 ; TFT_output_flags_2,6 ; --- unused | |
| 94 ; TFT_output_flags_2,7 ; --- unused | |
| 95 | |
| 96 ; TFT_output_flags_3 - phase 3: every second - after deco calculations, deco modes only | |
| 97 #DEFINE FLAG_TFT_clear_deco_data TFT_output_flags_3,0 ; =1: clear deco data (NDL or stop & TTS) | |
| 98 #DEFINE FLAG_TFT_display_ndl_mask TFT_output_flags_3,1 ; =1: show NDL mask | |
| 99 #DEFINE FLAG_TFT_display_deco_mask TFT_output_flags_3,2 ; =1: show deco mask | |
| 100 #DEFINE FLAG_TFT_display_ndl TFT_output_flags_3,3 ; =1: show NDL data | |
| 101 #DEFINE FLAG_TFT_display_deco TFT_output_flags_3,4 ; =1: show deco stop data | |
| 102 #DEFINE FLAG_TFT_display_tts TFT_output_flags_3,5 ; =1: show deco TTS data | |
| 103 ; TFT_output_flags_3,6 ; --- unused | |
| 104 ; TFT_output_flags_3,7 ; --- unused | |
| 105 | |
| 106 ; TFT_output_flags_4 - phase 4: every second - after deco calculations, all modes | |
| 631 | 107 #DEFINE FLAG_TFT_customview_callup TFT_output_flags_4,0 ; =1: show the custom view mask |
| 623 | 108 #DEFINE FLAG_TFT_sign_show TFT_output_flags_4,1 ; =1: show the advice / attention / warning sign |
| 109 #DEFINE FLAG_TFT_sign_clear TFT_output_flags_4,2 ; =1: clear the advice / attention / warning sign | |
| 110 #DEFINE FLAG_TFT_message_clear_both TFT_output_flags_4,3 ; =1: clear messages, both rows | |
| 111 #DEFINE FLAG_TFT_message_clear_2nd TFT_output_flags_4,4 ; =1: clear messages, 2nd row only | |
| 112 #DEFINE FLAG_TFT_velocity_show TFT_output_flags_4,5 ; =1: show vertical velocity | |
| 113 #DEFINE FLAG_TFT_velocity_clear TFT_output_flags_4,6 ; =1: clear vertical velocity | |
| 114 ; TFT_output_flags_4,7 ; --- unused | |
| 115 | |
| 116 | |
| 117 ; various Flags | |
| 631 | 118 #DEFINE new_deco_data_avail DM_flags_local,0 ; =1: new NDL or deco data available |
| 634 | 119 #DEFINE update_menu DM_flags_local,1 ; =1: redraw the dive menu |
| 120 #DEFINE FLAG_SP2_used DM_flags_local,2 ; =1: setpoint 2 has been auto-selected already | |
| 121 #DEFINE FLAG_SP3_used DM_flags_local,3 ; =1: setpoint 3 has been auto-selected already | |
| 122 #DEFINE FLAG_SP4_used DM_flags_local,4 ; =1: setpoint 4 has been auto-selected already | |
| 123 #DEFINE FLAG_SP5_used DM_flags_local,5 ; =1: setpoint 5 has been auto-selected already | |
| 124 ; DM_flags_local,6 ; --- unused | |
| 631 | 125 ; DM_flags_local,7 ; --- unused |
| 623 | 126 |
| 127 | |
| 582 | 128 ;============================================================================= |
| 634 | 129 dmode1 CODE |
| 130 ;============================================================================= | |
| 131 | |
| 132 | |
| 133 ;----------------------------------------------------------------------------- | |
| 134 ; Entry Point for Dive Mode | |
| 135 ; | |
| 0 | 136 global diveloop |
| 137 diveloop: | |
| 623 | 138 clrf STKPTR ; clear return addresses stack |
| 139 | |
| 140 ; start with a clean time base | |
| 141 bsf reset_timebase ; request ISR to reset the main timebase, | |
| 142 ; as we are in dive mode the dive timers will be reset as well | |
| 143 | |
| 144 ; reset global flags | |
| 145 clrf DM_flags_state ; clear all flags for dive mode status | |
| 146 clrf DM_flags_event ; clear all flags for data recording events | |
| 631 | 147 clrf DM_flags_request ; clear all flags for user requests / general |
| 148 IFDEF _cave_mode | |
| 149 clrf DM_flags_cavereq ; clear all flags for user requests / cave mode | |
| 150 ENDIF | |
| 623 | 151 clrf DM_flags_layout1 ; clear all flags for display control / layout (1) |
| 152 clrf DM_flags_layout2 ; clear all flags for display control / layout (2) | |
| 631 | 153 clrf DM_flags_layout3 ; clear all flags for display control / layout (3) |
| 623 | 154 clrf DM_flags_message ; clear all flags for display control / messages |
| 631 | 155 clrf DM_flags_gas_dil ; clear all flags for display control / gases, diluents, depth |
| 623 | 156 |
| 634 | 157 clrf DM_flags_advc_det ; clear all flags for advices detection |
| 158 clrf DM_flags_advc_ack ; clear all flags for advices acknowledged | |
| 159 | |
| 160 clrf DM_flags_att1_det ; clear all flags for attentions detection | |
| 161 clrf DM_flags_att2_det ; ... | |
| 162 clrf DM_flags_att3_det ; ... | |
| 163 | |
| 164 clrf DM_flags_att1_ack ; clear all flags for attentions acknowledged | |
| 165 clrf DM_flags_att2_ack ; ... | |
| 166 clrf DM_flags_att3_ack ; ... | |
| 167 | |
| 168 clrf DM_flags_war1_det ; clear all flags for warnings detection | |
| 169 clrf DM_flags_war2_det ; ... | |
| 170 | |
| 171 clrf DM_flags_war1_ack ; clear all flags for warnings acknowledged | |
| 172 clrf DM_flags_war2_ack ; ... | |
| 173 | |
| 174 clrf DM_flags_shown1 ; arm auto show-up of custom views | |
| 175 clrf DM_flags_shown2 ; ... | |
| 176 clrf DM_flags_shown3 ; ... | |
| 177 | |
| 178 bcf dive_main_menu ; clear dive main menu flag | |
| 179 bcf dive_pre_menu ; clear dive pre-menu flag | |
| 623 | 180 |
| 181 ; reset local flags | |
| 182 clrf TFT_output_flags_1 ; clear all flags for TFT output phase 1 | |
| 183 clrf TFT_output_flags_2 ; clear all flags for TFT output phase 2 | |
| 184 clrf TFT_output_flags_3 ; clear all flags for TFT output phase 3 | |
| 185 clrf TFT_output_flags_4 ; clear all flags for TFT output phase 4 | |
| 186 clrf DM_flags_local ; clear all the various other flags, too | |
| 187 | |
| 188 ; boot tasks for all modes | |
| 634 | 189 call diveloop_boot ; initialize dive mode |
| 604 | 190 |
| 191 ; startup tasks for all modes | |
| 192 call TFT_boot ; initialize TFT (includes clear screen) | |
| 634 | 193 call TFT_load_dive_color_pallet ; load dive color pallet |
| 623 | 194 call TFT_show_divemode_mask ; display static dive mode mask |
| 195 call TFT_Display_FadeIn ; dim up the display | |
| 196 | |
| 634 | 197 ; arm dive start timer |
| 623 | 198 bcf divetime_longer_1min ; the dive has just begun |
| 199 btfsc FLAG_apnoe_mode ; in apnea mode? | |
| 200 bsf divetime_longer_1min ; YES - force dive to have lasted for longer than 1 minute already | |
| 201 btfsc sensor_override_active ; in simulator mode? | |
| 202 bsf divetime_longer_1min ; YES - force dive to have lasted for longer than 1 minute already | |
| 203 | |
| 634 | 204 ; initiate initial display outputs |
| 623 | 205 bsf trigger_pres_cur_changed ; flag that the pressures have changed to have all data... |
| 206 bsf trigger_pres_max_changed ; ... written to the display on the first output round | |
| 207 bsf trigger_temp_changed ; flag that the temperature has changed to have the temperature ... | |
| 208 ; ... written to the display on the first output round | |
| 209 bsf new_deco_data_avail ; flag that new deco engine results are available to have the initial data ... | |
| 210 ; ... written to the display on the first output round | |
| 211 | |
| 634 | 212 ; initialize the resettable average depth |
| 213 call resettable_average_depth_init | |
| 214 | |
| 215 ; reload and redraw last custom view | |
| 216 movff customview_divemode,active_customview | |
| 217 bsf FLAG_TFT_customview_callup | |
| 623 | 218 |
| 219 btfsc FLAG_apnoe_mode ; in apnoe mode? | |
| 220 bra diveloop_1 ; YES - done with initialization | |
| 221 btfsc FLAG_gauge_mode ; NO - in gauge mode? | |
| 222 bra diveloop_1 ; YES - done with initialization | |
| 634 | 223 bsf FLAG_TFT_display_ndl_mask ; NO - request initial display of NDL mask |
| 623 | 224 bsf FLAG_TFT_active_gas_divemode; - request initial display of gas and setpoint |
| 225 | |
| 226 diveloop_1: | |
| 227 btfsc reset_timebase ; has the ISR confirmed reset of the timebase meanwhile? | |
| 634 | 228 bra $-2 ; NO - not yet, loop waiting for confirmation before entering the dive loop |
| 229 ;bra diveloop_loop ; YES - enter the dive loop | |
| 230 | |
| 231 | |
| 232 ;----------------------------------------------------------------------------- | |
| 233 ; Dive Mode Mail Loop | |
| 234 ; | |
| 623 | 235 diveloop_loop: |
| 643 | 236 btfss trigger_quarter_second ; new 1/4 second? |
| 237 bra diveloop_loop_0 ; No - continue | |
| 238 | |
| 239 ;---- tasks any new 1/4 second ----- | |
| 240 bcf trigger_quarter_second ; YES - clear flag | |
| 241 | |
| 242 movlw .4 ; 62,5ms * 4 = 1/4 second | |
| 243 movff WREG,isr_tmr7_helper ; to make sure at least 1/4 will pass before trigger_quarter_second is re-set | |
| 244 | |
| 656 | 245 IFDEF _compass |
| 246 movlw index_compass_dm ; index of compass view | |
| 247 cpfseq active_customview ; in compass view? | |
| 248 bra diveloop_loop_quarter_1 ; NO - continue with tasks 1/4 second | |
| 249 call TFT_dive_compass_heading ; YES - update compass heading value | |
| 250 btfsc compass_bearing_set ; is a bearing set? | |
| 251 call TFT_dive_compass_extras ; YES, Update Stopwatch display in compass mode | |
| 252 ENDIF | |
| 253 | |
| 254 diveloop_loop_quarter_1: | |
| 643 | 255 btfss press_sensor_type ; New sensor found? |
| 256 bra diveloop_loop_0 ; No - continue | |
| 257 | |
| 258 ; Handle new pressure sensor every 1/4 second | |
| 259 btfsc ms5837_state ; =0: result of temperature is in the ADC | |
| 260 bra diveloop_loop_quarter_2 | |
| 261 call I2C_get_temp_val_MS5837 ; (Will set ms5837_state) | |
| 262 bra diveloop_loop_0 ; Done. | |
| 263 diveloop_loop_quarter_2: | |
| 264 call I2C_get_press_val_MS5837 ; (Will clear ms5837_state) | |
| 265 ;---- tasks any new 1/4 second done ----- | |
| 266 | |
| 267 diveloop_loop_0: | |
| 268 btfsc trigger_full_second ; new 1/1 second? | |
| 623 | 269 bra diveloop_loop_2 ; YES - continue with tasks every 1/1 second |
| 270 btfsc trigger_half_second ; NO - new 1/2 second? | |
| 271 bra diveloop_loop_1 ; YES - continue with tasks every 1/2 second | |
| 656 | 272 |
| 623 | 273 ; tasks every round except every 1/1 or 1/2 second |
| 656 | 274 |
| 623 | 275 bra diveloop_loop_11 ; - continue tasks every round |
| 276 | |
| 277 diveloop_loop_1: | |
| 278 ; tasks every 1/2 second | |
| 279 bcf trigger_half_second ; clear flag | |
| 280 btfsc FLAG_gauge_mode ; in gauge mode? | |
| 281 bra diveloop_loop_11 ; YES - done with 1/2 second tasks | |
| 282 btfsc FLAG_apnoe_mode ; NO - in apnoe mode? | |
| 283 bra diveloop_loop_11 ; YES - done with 1/2 second tasks | |
| 284 | |
| 285 ; tasks every 1/2 second in deco modes | |
| 631 | 286 call callup_deco_engine ; ##### manage and invoke the deco calculation engine ##### |
| 623 | 287 bra diveloop_loop_11 ; done with 1/2 second tasks |
| 288 | |
| 289 diveloop_loop_2: | |
| 290 ; tasks every 1/1 second (code includes tasks every 1/2 second that fall onto the full second) | |
| 291 bcf trigger_full_second ; clear flag for new 1/1 second | |
| 292 bcf trigger_half_second ; clear flag for new 1/2 second as well | |
| 293 | |
| 294 btfss trigger_temp_changed ; has the temperature changed? | |
| 295 bra diveloop_loop_3 ; NO - continue with tasks every 1/1 second | |
| 296 | |
| 297 bsf FLAG_TFT_temperature ; YES - display temperature | |
| 298 bcf trigger_temp_changed ; - clear flag | |
| 299 | |
| 300 ; "future hardware will need min temperature checked every second..." (?) | |
| 301 | |
| 302 MOVII temperature_min,sub_a ; - copy last temperature_min to sub_a | |
| 303 SMOVII temperature_cur,sub_b ; - ISR-safe 2 byte copy of current temperature to sub_b | |
| 304 call sub16 ; - sub_c = sub_a - sub_b = temperature_min - temperature | |
| 305 btfsc neg_flag ; - temperature > temperature_min ? | |
| 306 bra diveloop_loop_3 ; YES - done | |
| 307 MOVII sub_b,temperature_min ; NO - store new minimum temperature | |
| 308 | |
| 309 diveloop_loop_3: | |
| 310 ; tasks every 1/1 second | |
| 311 btfss trigger_pres_cur_changed ; has the pressure changed? | |
| 312 bra diveloop_loop_4 ; NO - continue with tasks every 1/1 second | |
| 313 | |
| 314 ; set flags | |
| 315 bcf trigger_pres_cur_changed ; clear flag for pressure change | |
| 316 bsf FLAG_TFT_depth_current ; set flag to display updated depth | |
| 317 | |
| 318 ; cache new absolute and relative pressure, ISR-safe 2 byte copies | |
| 319 SMOVII pressure_abs, pressure_abs_cached | |
| 320 SMOVII pressure_rel_cur,pressure_rel_cur_cached | |
| 321 | |
| 322 ; transfer absolute pressure to deco engine | |
| 323 MOVII pressure_abs_cached,int_I_pres_respiration | |
| 324 | |
| 325 ; compute absolute pressure / 10, will be used later on a couple of times | |
| 326 MOVII pressure_abs_cached,xA | |
| 327 MOVLI .10,xB | |
| 328 call div16x16 ; xC = xA / xB = absolute pressure / 10 | |
| 329 MOVII xC,pressure_abs_10 ; store result for later use | |
| 604 | 330 |
| 331 ; compute current depth in meters | |
| 631 | 332 MOVII pressure_rel_cur_cached,mpr ; copy current relative pressure in [mbar] to MPR |
| 333 call convert_pres_to_depth ; convert pressure in [mbar] to depth in [cm] | |
| 334 ADDLI .50,mpr ; add 50 cm for rounding up/down around 0.5 meters | |
| 335 MOVII mpr, xA ; copy depth in [cm] into xA | |
| 336 MOVLI .100,xB ; load factor 100 cm/m into xB | |
| 623 | 337 call div16x16 ; xC = xA / xB = depth in full meters |
| 631 | 338 movff xC+0,depth_meter ; store result as depth in [m], only low byte needed |
| 623 | 339 |
| 340 ; check for new max pressure | |
| 341 btfss trigger_pres_max_changed ; has the max pressure changed? | |
| 342 bra diveloop_loop_4 ; NO - continue with tasks every 1/1 second | |
| 343 bcf trigger_pres_max_changed ; YES - clear flag for new max pressure | |
| 344 bsf FLAG_TFT_depth_maximum ; - set flag for displaying new max depth | |
| 345 SMOVII pressure_rel_max,pressure_rel_max_cached ; - cache new max depth | |
| 346 | |
| 347 diveloop_loop_4: | |
| 348 ; continue tasks every 1/1 second | |
| 349 | |
| 640 | 350 IFDEF _ccr_pscr |
| 351 ; adjust auto-setpoint | |
| 352 btfsc FLAG_ccr_mode ; in CCR mode? | |
| 353 call check_dive_autosp ; YES - check for Auto-SP | |
| 354 ENDIF | |
| 355 | |
| 656 | 356 IFDEF _external_sensor_eccr |
| 623 | 357 btfsc FLAG_ccr_mode ; in CCR mode? |
| 634 | 358 rcall calc_deko_divemode_sensor ; YES - process sensor readings |
| 623 | 359 btfsc FLAG_pscr_mode ; in pSCR mode? |
| 634 | 360 rcall calc_deko_divemode_sensor ; YES - process sensor readings |
| 623 | 361 ENDIF |
| 362 | |
| 631 | 363 IFDEF _cave_mode |
| 364 btfss cave_mode ; cave mode switched on? | |
| 365 bra diveloop_loop_4a ; NO - no backtracking depth recording | |
| 366 btfsc dive_turned ; dive turned? | |
| 367 bra diveloop_loop_4a ; YES - no backtracking depth recording | |
| 368 btfsc backtrack_entire_full ; backtracking storage entirely used up? | |
| 369 bra diveloop_loop_4a ; YES - no backtracking depth recording | |
| 370 | |
| 371 incf backtrack_deltatime,F ; increment time elapsed since last depth recording | |
| 372 movlw .59 ; load WREG with coding of last second of a minute | |
| 373 cpfsgt backtrack_deltatime ; time elapsed since last depth recording > 59 seconds? | |
| 374 bra diveloop_loop_4a ; NO - no backtracking depth recording now | |
| 375 rcall write_backtrack_1min_depth ; - store a backtracking depth data set | |
| 376 ENDIF | |
| 377 | |
| 378 diveloop_loop_4a: | |
| 379 ; continue tasks every 1/1 second | |
| 380 | |
| 623 | 381 btfsc FLAG_apnoe_mode ; in apnoe mode? |
| 382 rcall divemode_apnoe_tasks ; YES - do 1 sec. apnoe tasks | |
| 383 | |
| 384 ; display all animated (blinking) values at the beginning of each full second to have a stable timebase | |
| 385 rcall TFT_output_1 ; do display updates | |
| 386 | |
| 387 btfss FLAG_apnoe_mode ; in apnoe mode? | |
| 388 bra diveloop_loop_5 ; NO - continue with deco mode tasks every 1/1 second | |
| 389 | |
| 390 ; apnoe mode tasks every 1/1 second | |
| 391 call dive_customview_second ; do every second tasks for the custom view area | |
| 392 bra diveloop_loop_10 ; continue with common tasks every 1/1 second | |
| 393 | |
| 394 diveloop_loop_5: | |
| 395 ; deco mode tasks every 1/1 second | |
| 396 bsf FLAG_TFT_divetime ; display (new) dive time | |
| 397 | |
| 398 rcall safety_stop_show ; serve safety stop | |
| 399 | |
| 400 rcall TFT_output_2 ; do display updates | |
| 401 | |
| 402 call divemode_check_warnings ; check for warnings | |
| 604 | 403 |
| 404 IFDEF _rx_functions | |
| 623 | 405 btfss tr_functions_activated ; TR functions activated? |
| 406 bra diveloop_loop_6 ; NO - continue with deco mode tasks every 1/2 second | |
| 604 | 407 call get_pressure_readings ; YES - get pressure readings |
| 408 call configure_sac_calculation ; - set up SAC calculation | |
| 409 ENDIF | |
| 582 | 410 |
| 623 | 411 diveloop_loop_6: |
| 412 ; deco mode tasks every 1/1 second | |
| 656 | 413 INCI divesecs_compass_trip ; increment the compass stopwatch |
| 623 | 414 INCI divesecs_avg_trip ; increment the resettable dive time |
| 628 | 415 INCI divesecs_avg_total ; increment the total dive time |
| 623 | 416 |
| 417 btfsc FLAG_gauge_mode ; in gauge mode? | |
| 418 bra diveloop_loop_7 ; YES - skip deco calculations | |
| 419 | |
| 631 | 420 call callup_deco_engine ; ##### manage and invoke the deco calculation engine ##### |
| 623 | 421 |
| 422 btfsc new_deco_data_avail ; new NDL or deco data available? | |
| 634 | 423 call show_new_deco_data ; YES - set-up display update requests |
| 623 | 424 |
| 425 btfsc decostop_active ; in deco mode? | |
| 426 bsf FLAG_TFT_display_deco ; YES - update deco stop depth & time every second because of depth-dependent color-coding | |
| 427 | |
| 428 bsf FLAG_TFT_depth_current ; set flag to display depth (in next round, needed in deco modes irrespectively of a pressure change for color-coding and blinking effects) | |
| 429 | |
| 430 diveloop_loop_7: | |
| 431 ; deco mode tasks alternating every 2 seconds on timebase | |
| 432 btfss timebase_1sec ; on even second of timebase? | |
| 433 rcall calc_velocity ; YES - calculate velocity and display if > threshold | |
| 434 btfsc timebase_1sec ; on odd second of timebase? | |
| 435 call check_gas_best ; YES - check if a better gas cue can be given | |
| 436 | |
| 437 diveloop_loop_8: | |
| 438 ; deco mode tasks alternating every 2 seconds on resettable dive time | |
| 439 btfss divesecs_avg_trip+0,0 ; on even second of resettable dive time? | |
| 631 | 440 call calc_average_depth ; YES - calculate average depth |
| 623 | 441 btfsc divesecs_avg_trip+0,0 ; on odd second of resettable dive time? |
| 442 rcall safety_stop_control ; YES - exercise safety stop control | |
| 443 | |
| 444 diveloop_loop_9: | |
| 445 ; deco mode tasks every 1/1 second | |
| 628 | 446 rcall check_deco_states ; check and lock if in deco and in the deco stops region |
| 623 | 447 rcall TFT_output_3 ; do display updates |
| 448 | |
| 449 diveloop_loop_10: | |
| 450 ; common tasks every 1/1 second | |
| 634 | 451 rcall timeout_divemode ; check for timeout conditions |
| 452 call check_dive_modes_dive ; test if depth still deeper than threshold | |
| 623 | 453 |
| 454 btfsc trigger_full_minute ; has next minute begun? | |
| 455 rcall update_divemode60 ; YES - update clock, etc. | |
| 456 | |
| 457 btfss FLAG_oc_mode ; are we in OC mode? | |
| 458 bsf FLAG_TFT_active_gas_divemode; NO - have the gas and setpoint redrawn on every second to update setpoint display, animate the blinking, etc. | |
| 459 | |
| 460 btfsc dive_main_menu ; dive mode menu shown? | |
| 461 bsf update_menu ; YES - request update | |
| 462 | |
| 463 rcall TFT_output_4 ; do display updates | |
| 464 | |
| 465 ; tasks every round, every mode | |
| 466 diveloop_loop_11: | |
| 634 | 467 call test_switches_divemode ; check switches, in case branch into menu processor |
| 468 bra diveloop_loop_12 ; continue the dive loop | |
| 469 | |
| 470 | |
| 471 ; **** jump-in when returning from menu processor **** | |
| 472 ; | |
| 473 global divemode_option_divemenu_return | |
| 474 divemode_option_divemenu_return: | |
| 475 clrf STKPTR ; reset the stack | |
| 476 call menu_draw_cursor_dive ; show the cursor | |
| 477 bsf dive_main_menu ; set main menu is shown now | |
| 478 clrf active_premenu ; set pre-menu is not shown any more | |
| 479 bcf safety_stop_active ; set safety stop is not shown any more | |
| 480 movlw divemode_timeout_mainmenu ; get timeout for main menu | |
| 481 call restart_timeout_time ; restart the timeout | |
| 482 bra diveloop_loop_12 ; continue the dive loop | |
| 483 | |
| 484 | |
| 485 ; **** jump-in when returning from dive mode menu **** | |
| 486 ; | |
| 623 | 487 global diveloop_menu_exit |
| 634 | 488 diveloop_menu_exit: |
| 489 clrf STKPTR ; reset the stack | |
| 490 call divemenu_cleanup ; clean up menu area and restore dive data | |
| 491 ;bra diveloop_loop_12 ; continue the dive loop | |
| 492 | |
| 623 | 493 |
| 494 diveloop_loop_12: | |
| 643 | 495 bsf FLAG_TFT_active_gas_divemode; redraw gas and setpoint (eventually needed to restore the "Bailout" text) |
| 623 | 496 |
| 497 btfsc request_next_custview ; shall show next custom view? | |
| 634 | 498 call dive_customview_toggle ; YES - show next custom view |
| 623 | 499 |
| 631 | 500 btfsc request_gas_change ; shall change gas? |
| 501 call gas_switch_common ; YES | |
| 502 | |
| 503 btfsc request_gas_update ; shall update the gases? | |
| 504 call gas_update_common ; YES | |
| 0 | 505 |
| 623 | 506 btfsc request_toggle_GF ; shall toggle GF/aGF? |
| 634 | 507 call divemodemode_togglegf ; YES |
| 0 | 508 |
| 604 | 509 IFDEF _cave_mode |
| 631 | 510 btfsc request_cave_off_turned ; shall switch cave mode off and set the dive as turned? |
| 511 rcall cavemode_switch_off_turned ; YES | |
| 512 | |
| 513 btfsc request_cave_toggle ; shall toggle cave mode off/on? | |
| 514 rcall cavemode_toggle_onoff ; YES | |
| 515 | |
| 516 btfsc request_turn_turn ; shall turn the dive? | |
| 517 rcall cavemode_turndive_turn ; YES | |
| 518 | |
| 519 btfsc request_turn_toggle ; shall toggle the turn dive state? | |
| 520 rcall cavemode_turndive_toggle ; YES | |
| 521 | |
| 522 btfsc request_waypoint_set ; shall set a waypoint? | |
| 523 rcall cavemode_waypoint_set ; YES | |
| 524 | |
| 525 btfsc request_waypoint_out ; shall step one waypoint out of the cave? | |
| 526 rcall cavemode_waypoint_out ; YES | |
| 527 | |
| 528 btfsc request_waypoint_in ; shall step one waypoint into the cave? | |
| 529 rcall cavemode_waypoint_in ; YES | |
| 604 | 530 ENDIF |
| 531 | |
| 623 | 532 btfsc request_set_marker ; shall set a marker? |
| 582 | 533 call set_logbook_marker ; YES |
| 534 | |
| 623 | 535 btfsc trigger_sample_divedata ; shall store new sample of dive data? |
| 604 | 536 call store_dive_data ; YES - store profile data |
| 537 | |
| 538 btfss divemode ; dive finished? | |
| 623 | 539 goto ghostwriter_end_dive ; YES - dive finished |
| 604 | 540 |
| 541 IFDEF _screendump | |
| 623 | 542 btfsc screen_dump_avail ; screen dump function enabled? |
| 604 | 543 call TFT_dump_screen_check ; YES - check if requested and do it |
| 544 ENDIF | |
| 545 | |
| 634 | 546 bra diveloop_loop ; do next loop in dive mode |
| 547 | |
| 548 | |
| 549 ;----------------------------------------------------------------------------- | |
| 550 ; Dive Mode Tasks every 1/1 Minute | |
| 551 ; | |
| 552 update_divemode60: | |
| 553 bcf trigger_full_minute ; clear flag | |
| 554 | |
| 555 call get_battery_voltage ; get battery voltage | |
| 556 btfss battery_low_condition ; battery low condition detected? | |
| 557 bra update_divemode60_1 ; NO - skip next | |
| 558 movlw d'7' ; YES - set type of alarm = battery low | |
| 559 movwf alarm_type ; - copy to alarm register | |
| 560 bsf event_occured ; - set event flag | |
| 561 movlw .0 ; - coding of brightness level ECO | |
| 645 | 562 movff WREG,opt_brightness_divemode ; - set brightness to ECO |
| 634 | 563 |
| 564 update_divemode60_1: | |
| 565 ; max allowed runtime in simulator is 254 minutes in | |
| 566 ; order for the tissue calculation catch-up to work! | |
| 567 | |
| 568 btfss sensor_override_active ; in simulator mode? | |
| 569 return ; NO - done | |
| 570 movlw simulator_timeout_normal ; YES - set simulation timeout | |
| 571 IFDEF _cave_mode | |
| 572 TSTOSC opt_cave_mode ; - cave mode switched on? | |
| 573 movlw simulator_timeout_cave ; YES - replace with cave mode simulation timeout | |
| 574 ENDIF | |
| 575 cpfsgt counted_divetime_mins+0 ; - timeout? | |
| 576 return ; NO - done | |
| 577 IFDEF _DEBUG | |
| 578 return ; YES - but we do not care in debug mode... | |
| 579 ELSE | |
| 580 goto divemode_option_sim_quit ; YES - set depth to 0 m and return | |
| 581 ENDIF | |
| 582 | |
| 583 | |
| 584 ;----------------------------------------------------------------------------- | |
| 585 ; Helper Function - set-up Display Update Requests | |
| 586 ; | |
| 587 show_new_deco_data: | |
| 588 bcf new_deco_data_avail ; reset flag for new NDL or deco data available | |
| 589 movff char_O_deco_info,WREG ; get the deco info vector | |
| 590 btfsc WREG,deco_stops_norm ; deco stops found? | |
| 591 bra show_new_deco_data_deco ; YES - in deco | |
| 592 ;bra show_new_deco_data_ndl ; NO - within NDL | |
| 593 | |
| 594 show_new_deco_data_ndl: ; within NDL | |
| 595 btfsc decostop_active ; been in deco mode before? | |
| 596 bsf FLAG_TFT_clear_deco_data ; YES - clear old deco data | |
| 597 btfsc decostop_active ; been in deco mode before? | |
| 598 bsf FLAG_TFT_display_ndl_mask ; YES - display NDL data mask | |
| 599 bcf decostop_active ; clear flag for been in deco mode before | |
| 600 bsf FLAG_TFT_display_ndl ; display NDL time | |
| 601 return ; done | |
| 602 | |
| 603 show_new_deco_data_deco: ; in deco | |
| 604 btfss decostop_active ; been in deco mode before? | |
| 605 bsf FLAG_TFT_clear_deco_data ; NO - clear old NDL data | |
| 606 btfss decostop_active ; been in deco mode before? | |
| 607 bsf FLAG_TFT_display_deco_mask ; NO - display deco data mask | |
| 608 bsf decostop_active ; set flag for being in deco mode | |
| 609 bsf FLAG_TFT_display_tts ; display TTS time (display of stop data is managed separately) | |
| 610 return ; done | |
| 611 | |
| 612 | |
| 613 ;----------------------------------------------------------------------------- | |
| 614 ; Helper Function - do all Phase 1 Display Outputs | |
| 615 ; | |
| 623 | 616 TFT_output_1: ; every second - before deco calculations, all mode |
| 617 btfsc FLAG_TFT_clear_apnoe_surface ; shall clear apnoe mode surface data from screen? | |
| 618 call TFT_clear_apnoe_surface ; YES - clear apnoe mode surface data from screen | |
| 619 | |
| 620 btfsc FLAG_TFT_depth_current ; shall show depth? | |
| 621 call TFT_show_depth ; YES - display depth | |
| 622 btfsc FLAG_TFT_depth_maximum ; shall show max depth? | |
| 623 call TFT_show_max_depth ; YES - display max depth | |
| 624 btfsc FLAG_TFT_active_gas_divemode ; shall show active gas and dive mode? | |
| 625 call TFT_show_active_gas_divemode ; YES - display gas, setpoint and mode | |
| 631 | 626 btfsc FLAG_TFT_temperature ; shall show temperature? |
| 656 | 627 call TFT_show_temp_divemode ; YES - display temperature |
| 623 | 628 |
| 629 btfsc FLAG_TFT_apnoe_surface_time ; shall show apnoe mode surface time? | |
| 630 call TFT_show_apnoe_surface ; YES - show apnoe mode surface time | |
| 631 btfsc FLAG_TFT_depth_maximum_apnoe ; shall show max. depth of last dive? | |
| 632 call TFT_show_apnoe_max_depth ; YES - show max. depth of last dive | |
| 633 btfsc FLAG_TFT_apnoe_divetime ; shall show apnoe dive time? | |
| 634 call TFT_show_apnoe_times ; YES - show apnoe dive time? | |
| 654 | 635 btfsc FLAG_TFT_depth_maximum_apnoe ; shall show max. depth of last dive? (Flag re-used here for #dive) |
| 636 call TFT_apnoe_divecounter ; YES - show apnoe #dive counter? | |
| 623 | 637 |
| 638 clrf TFT_output_flags_1 ; mark all TFT updates done | |
| 639 return ; done | |
| 640 | |
| 634 | 641 |
| 642 ;----------------------------------------------------------------------------- | |
| 643 ; Helper Function - do all Phase 2 Display Outputs | |
| 644 ; | |
| 623 | 645 TFT_output_2: ; every second - before deco calculations, deco modes only |
| 646 btfsc FLAG_TFT_divemode_mask ; shall re-draw mask? | |
| 647 call TFT_show_divemode_mask ; YES - re-draw mask | |
| 648 btfsc FLAG_TFT_divetime ; shall show dive time? | |
| 649 call TFT_show_divetime ; YES - show dive time | |
| 650 btfsc FLAG_TFT_safety_stop_show ; shall show safety stop? | |
| 651 call TFT_safety_stop_show ; YES - show safety stop | |
| 652 btfsc FLAG_TFT_safety_stop_clear ; shall clear safety stop? | |
| 653 call TFT_safety_stop_clear ; YES - clear safety stop | |
| 654 | 654 |
| 623 | 655 clrf TFT_output_flags_2 ; mark all TFT updates done |
| 656 goto dive_customview_second ; do every-second tasks for the custom view area (in sync with the dive time) and return | |
| 657 | |
| 634 | 658 |
| 659 ;----------------------------------------------------------------------------- | |
| 660 ; Helper Function - do all Phase 3 Display Outputs | |
| 661 ; | |
| 623 | 662 TFT_output_3: ; every second - after deco calculations, deco modes only |
| 663 btfsc FLAG_TFT_clear_deco_data ; shall clear deco data (NDL or stop & TTS)? | |
| 664 call TFT_clear_deco_data ; YES - clear deco data (NDL or stop & TTS) | |
| 665 btfsc FLAG_TFT_display_ndl_mask ; shall show NDL mask? | |
| 666 call TFT_show_ndl_mask ; YES - show NDL mask | |
| 667 btfsc FLAG_TFT_display_ndl ; shall show NDL data? | |
| 668 call TFT_show_ndl ; YES - show NDL data | |
| 669 btfsc FLAG_TFT_display_deco_mask ; shall show deco mask? | |
| 670 call TFT_show_deco_mask ; YES - show deco mask | |
| 671 btfsc FLAG_TFT_display_deco ; shall show deco stop? | |
| 672 call TFT_show_deco ; YES - show deco stop | |
| 673 btfsc FLAG_TFT_display_tts ; shall show deco TTS? | |
| 674 call TFT_show_tts ; YES - show deco TTS | |
| 675 clrf TFT_output_flags_3 ; mark all TFT updates done | |
| 676 return ; done | |
| 677 | |
| 634 | 678 |
| 679 ;----------------------------------------------------------------------------- | |
| 680 ; Helper Function - do all Phase 4 Display Outputs | |
| 681 ; | |
| 623 | 682 TFT_output_4: ; every second - after deco calculations, all modes |
| 631 | 683 btfsc FLAG_TFT_customview_callup ; shall show a custom view? |
| 684 call dive_customview_callup ; YES - show a custom view | |
| 623 | 685 btfsc FLAG_TFT_velocity_show ; shall show vertical velocity? |
| 631 | 686 call TFT_velocity_show ; YES - show vertical velocity |
| 623 | 687 btfsc FLAG_TFT_velocity_clear ; shall clear vertical velocity? |
| 631 | 688 call TFT_velocity_clear ; YES - clear vertical velocity |
| 623 | 689 btfsc FLAG_TFT_sign_show ; shall show the advice / attention / warning sign? |
| 690 call TFT_divemode_sign_show ; YES - show sign | |
| 691 btfsc FLAG_TFT_sign_clear ; shall clear the advice / attention / warning sign? | |
| 692 call TFT_divemode_sign_clear ; YES - clear sign | |
| 693 btfsc FLAG_TFT_message_clear_both ; shall clear all messages? | |
| 694 call TFT_clear_message_window ; YES - clear complete message area | |
| 695 btfsc FLAG_TFT_message_clear_2nd ; shall clear 2nd row of message area? | |
| 696 call TFT_clear_message_window_row2 ; YES - clear 2nd row of message area | |
| 697 clrf TFT_output_flags_4 ; mark all TFT updates done | |
| 698 return ; done | |
| 582 | 699 |
| 634 | 700 |
| 701 ;----------------------------------------------------------------------------- | |
| 702 ; Apnoe Mode Tasks | |
| 703 ; | |
| 628 | 704 divemode_apnoe_tasks: ; 1 sec. apnoe tasks |
| 705 bsf FLAG_TFT_apnoe_divetime ; show apnoe dive times (current/last dive and total) | |
| 706 btfsc apnoe_at_surface ; at the surface? | |
| 707 bra divemode_apnoe_tasks_surf ; YES - at the surface | |
| 708 ;bra divemode_apnoe_tasks_dive ; NO - in dive phase | |
| 709 | |
| 710 divemode_apnoe_tasks_dive: ; apnoe mode, submerged | |
| 711 btfss apnoe_new_dive ; new dive begun? | |
| 712 return ; NO - done | |
| 713 bcf apnoe_new_dive ; YES - clear flag | |
| 714 bsf FLAG_TFT_clear_apnoe_surface ; - clear apnoe mode surface data from screen | |
| 654 | 715 incf apnoe_dive_counter,F ; Increase #dive counter |
| 628 | 716 return ; - done |
| 717 | |
| 718 divemode_apnoe_tasks_surf: ; apnoe mode, at the surface | |
| 719 bsf FLAG_TFT_apnoe_surface_time ; show apnoe mode surface time | |
| 623 | 720 ; TODO: these outputs would need to be done only once after surfacing... |
| 628 | 721 bsf FLAG_TFT_depth_maximum_apnoe ; show max. depth of last dive |
| 722 bsf FLAG_TFT_depth_maximum ; show max. depth of all dives | |
| 723 ;bra apnoe_calc_maxdepth ; calculate overall max. depth and return | |
| 623 | 724 |
| 0 | 725 |
| 634 | 726 ;----------------------------------------------------------------------------- |
| 727 ; Helper Function - calculate Apnoe Mode overall maximum Depth | |
| 728 ; | |
| 0 | 729 global apnoe_calc_maxdepth |
| 730 apnoe_calc_maxdepth: | |
| 623 | 731 MOVII apnoe_max_pressure, sub_a ; get max depth from all dives to far |
| 732 MOVII pressure_rel_max_cached,sub_b ; get max depth of last dive | |
| 733 call cmpU16 ; sub_a - sub_b = apnoe_max_pressure - pressure_rel_max_cached | |
| 734 btfss neg_flag ; last dive deeper than all the others before? | |
| 735 return ; NO - done | |
| 736 MOVII pressure_rel_max_cached,apnoe_max_pressure ; YES - store new overall max depth | |
| 737 return ; - done | |
| 0 | 738 |
| 634 | 739 |
| 740 ;----------------------------------------------------------------------------- | |
| 741 ; Manage and invoke the Deco Calculation Engine | |
| 742 ; | |
| 743 callup_deco_engine: | |
| 744 | |
| 631 | 745 ; Any reconfiguration done here only affects the deco calculation (prediction), not the |
| 746 ; settings for the calculations done on the real tissues. The later ones are only altered | |
| 747 ; in case of a gas change, in case of a real bailout, or in case a switchback to setpoint | |
| 748 ; or sensor is done. | |
| 749 ; On event of a gas change, a diluent change, a real bailout, or a switchback, the settings | |
| 750 ; for the deco calculation are also automatically changed to match with the settings for the | |
| 751 ; real tissues. This is all done in the function 'gas_switch_common' which is triggered by | |
| 752 ; the flag 'request_gas_change'. | |
| 753 | |
| 754 ; Deco Engine Calculation Schedules: | |
| 755 ; | |
| 634 | 756 ; Schedule Dive Mode Bailout fTTS Gas Needs Plan Deco Mode calculated Functions |
| 757 ; ----------------------------------------------------------------------------------------------------- | |
| 631 | 758 ; |
| 634 | 759 ; 1a) OC no no (yes) norm OC TTS, CNS, deco plan, (gas needs) |
| 760 ; no alt plan | |
| 560 | 761 ; |
| 634 | 762 ; 1b) OC no YES (yes) norm OC TTS, CNS, deco plan |
| 763 ; alt OC fTTS, fCNS, (gas needs) | |
| 631 | 764 ; |
| 634 | 765 ; 2a) Loop no no no norm Loop TTS, CNS, deco plan |
| 766 ; no alt plan | |
| 631 | 767 ; |
| 634 | 768 ; 2b) Loop no yes no norm Loop TTS, CNS, deco plan |
| 769 ; alt Loop fTTS, fCNS | |
| 631 | 770 ; |
| 634 | 771 ; 2c) Loop no (yes) YES norm Loop TTS, CNS, deco plan |
| 772 ; alt OC fTTS*, fCNS*, gas needs <- "what if" BAILOUT | |
| 631 | 773 ; |
| 634 | 774 ; 3) Loop YES n/a (yes) norm OC TTS, deco plan, (gas needs) <- real BAILOUT |
| 775 ; no alt plan | |
| 776 ; _____________________________________________________________________________________________________ | |
| 777 ; norm: normal plan, alt: alternative plan, (): optional, n/a: not applicable | |
| 778 ; * the fTTS time is set to zero when in cave mode and the dive is in turned state | |
| 779 | |
| 604 | 780 |
| 781 ; get working copies of char_O_main_status and char_O_deco_status | |
| 782 movff char_O_main_status,hi ; get char_O_main_status into hi | |
| 783 movff char_O_deco_status,lo ; get char_O_deco_status into lo | |
| 784 | |
| 785 ; check state of deco calculations | |
| 631 | 786 btfsc request_restart_engine ; restart of the deco engine requested? |
| 787 bra calc_deco_engine_restart ; YES - start a new normal plan | |
| 788 btfsc lo,DECO_COMPLETED_NORM ; NO - finished calculations for normal plan? | |
| 789 bra calc_deco_engine_alt ; YES - eventually do an alternative plan next | |
| 790 btfsc lo,DECO_COMPLETED_ALT ; NO - finished calculations for alternative plan? | |
| 791 bra calc_deco_engine_norm ; YES - do a normal plan next | |
| 792 bra calc_deco_engine_exec ; NO - continue executing current calculation | |
| 793 | |
| 794 calc_deco_engine_restart: | |
| 795 bcf request_restart_engine ; clear request flag | |
| 796 bcf lo,DECO_COMPLETED_NORM ; clear completion flag from normal plan if applicable | |
| 797 ;bra calc_deco_engine_norm ; continue with calculating a normal plan | |
| 798 | |
| 634 | 799 |
| 631 | 800 ; ---- normal plans ---- |
| 634 | 801 ; |
| 623 | 802 calc_deco_engine_norm: |
| 631 | 803 bcf lo,DECO_COMPLETED_ALT ; clear completion flag from alternative plan |
| 804 IFDEF _ccr_pscr | |
| 805 btfsc bailout_mode ; in real bailout? | |
| 806 bra calc_deco_engine_norm_3 ; YES - configure real bailout schedule | |
| 807 btfss FLAG_oc_mode ; in OC dive mode? | |
| 808 bra calc_deco_engine_norm_2 ; NO - configure loop schedules | |
| 809 ;bra calc_deco_engine_norm_1 ; YES - configure OC schedules | |
| 604 | 810 ENDIF |
| 811 | |
| 631 | 812 calc_deco_engine_norm_1: |
| 813 ; normal OC schedules | |
| 814 TSTOSC char_I_extra_time ; delay mode activated? | |
| 815 bra calc_deco_engine_norm_1b ; YES - schedule 1b in normal plan | |
| 816 ;bra calc_deco_engine_norm_1a ; NO - schedule 1a in normal plan | |
| 817 | |
| 818 calc_deco_engine_norm_1a: | |
| 819 ; normal schedule 1a: OC with optional gas needs | |
| 820 ; bcf lo,DECO_BAILOUT_FLAG ; switch off bailout mode (will never be activated in this plan) | |
| 821 ; bcf lo,DECO_DELAY_FLAG ; switch off delay mode (will never be activated in this plan) | |
| 822 ; bcf hi,DECO_VOLUME_FLAG ; switch off gas needs calculation by default (if on, will always be on) | |
| 823 TSTOSC opt_calc_gasvolume ; shall calculate gas needs? | |
| 824 bsf hi,DECO_VOLUME_FLAG ; YES - switch on gas needs calculation | |
| 825 bra calc_deco_engine_norm_start ; start deco engine in normal plan | |
| 826 | |
| 827 calc_deco_engine_norm_1b: | |
| 828 ; normal schedule 1b: OC without delay and gas needs | |
| 829 ; bcf lo,DECO_BAILOUT_FLAG ; switch off bailout mode (will never be activated in this plan) | |
| 830 bcf lo,DECO_DELAY_FLAG ; switch off delay mode | |
| 831 bcf hi,DECO_VOLUME_FLAG ; switch off gas needs calculation | |
| 832 bra calc_deco_engine_norm_start ; start deco engine in normal plan | |
| 833 | |
| 623 | 834 IFDEF _ccr_pscr |
| 631 | 835 calc_deco_engine_norm_2: |
| 836 ; normal loop schedules | |
| 837 TSTOSC opt_calc_gasvolume ; gas needs calculation activated? | |
| 838 bra calc_deco_engine_norm_2c ; YES - schedule 2c in normal plan | |
| 839 ;bra calc_deco_engine_norm_2ab ; NO - schedules 2a and 2b in normal plan are identical | |
| 840 | |
| 841 calc_deco_engine_norm_2ab: | |
| 842 ; normal schedule 2a & 2b: loop without anything | |
| 843 bcf lo,DECO_BAILOUT_FLAG ; switch off bailout mode (may return from real bailout) | |
| 844 ; bcf hi,DECO_VOLUME_FLAG ; switch off gas needs calculation (will never be activated in this plans) | |
| 845 bcf lo,DECO_DELAY_FLAG ; switch off delay mode (may have been set in alt. plan 2b) | |
| 846 bra calc_deco_engine_norm_start ; start deco engine in normal plan | |
| 847 | |
| 848 calc_deco_engine_norm_2c: | |
| 849 ; normal schedule 2c: loop with switch-back from simulated bailout | |
| 850 ; switch to CCR/pSCR | |
| 851 movf active_dil,W ; get current diluent | |
| 852 call deco_setup_cc_diluents_pre ; set up deco calculation in CCR/pSCR mode with diluents | |
| 853 calc_deco_engine_norm_2c_XX: | |
| 854 bcf lo,DECO_BAILOUT_FLAG ; switch off bailout mode (may return from real bailout) | |
| 855 bcf hi,DECO_VOLUME_FLAG ; switch off gas needs calculation | |
| 856 bcf lo,DECO_DELAY_FLAG ; switch off delay mode | |
| 857 bra calc_deco_engine_norm_start ; start deco engine in normal plan | |
| 858 | |
| 859 calc_deco_engine_norm_3: | |
| 860 ; real bailout schedule | |
| 861 bcf lo,DECO_DELAY_FLAG ; switch off delay mode | |
| 862 bcf hi,DECO_VOLUME_FLAG ; switch off gas needs calculation by default | |
| 863 TSTOSC opt_calc_gasvolume ; shall calculate gas needs? | |
| 864 bsf hi,DECO_VOLUME_FLAG ; YES - switch on gas needs calculation | |
| 865 bsf lo,DECO_BAILOUT_FLAG ; switch on bailout mode | |
| 866 ;bra calc_deco_engine_norm_start ; start deco engine in normal plan | |
| 867 ENDIF ; _ccr_pscr | |
| 868 | |
| 869 calc_deco_engine_norm_start: | |
| 870 bsf lo,DECO_START_NORM ; calculate a normal plan | |
| 623 | 871 bra calc_deco_engine_start ; start deco engine |
| 872 | |
| 634 | 873 |
| 631 | 874 ; ---- alternative plans ---- |
| 634 | 875 ; |
| 623 | 876 calc_deco_engine_alt: |
| 631 | 877 bcf lo,DECO_COMPLETED_NORM ; clear completion flag from normal plan |
| 878 IFDEF _ccr_pscr | |
| 879 btfsc bailout_mode ; in real bailout? | |
| 880 bra calc_deco_engine_norm_3 ; YES - schedule 3 has no alternative plan | |
| 881 btfss FLAG_oc_mode ; in OC dive mode? | |
| 882 bra calc_deco_engine_alt_2 ; NO - loop schedules | |
| 883 ;bra calc_deco_engine_alt_1 ; YES - OC schedules | |
| 884 ENDIF ; _ccr_pscr | |
| 623 | 885 |
| 886 calc_deco_engine_alt_1: | |
| 631 | 887 ; alternative OC schedules |
| 888 TSTOSS char_I_extra_time ; delay mode activated? | |
| 889 bra calc_deco_engine_norm_1a ; NO - schedule 1a has no alternative plan | |
| 604 | 890 IFDEF _cave_mode |
| 631 | 891 btfsc dive_turned ; YES - in cave mode and dive turned? |
| 892 bra calc_deco_engine_norm_1a ; YES - suppress delay mode -> do schedule 1a in normal plan | |
| 604 | 893 ENDIF |
| 631 | 894 ;bra calc_deco_engine_alt_1b ; NO - do schedule 1b in alternative plan |
| 895 | |
| 896 calc_deco_engine_alt_1b: | |
| 897 ; alternative schedule 1b: OC with delay and optional gas needs | |
| 898 ; bcf lo,DECO_BAILOUT_FLAG ; switch off bailout mode (will never be activated in this plan) | |
| 899 ; bcf hi,DECO_VOLUME_FLAG ; switch off gas needs calculation by default (comes in switched off state) | |
| 900 TSTOSC opt_calc_gasvolume ; shall calculate gas needs? | |
| 901 bsf hi,DECO_VOLUME_FLAG ; YES - switch on gas needs calculation | |
| 902 bsf lo,DECO_DELAY_FLAG ; switch on delay mode | |
| 903 bra calc_deco_engine_alt_start ; start deco engine in alternative plan | |
| 904 | |
| 905 IFDEF _ccr_pscr | |
| 623 | 906 calc_deco_engine_alt_2: |
| 631 | 907 ; alternative loop schedules |
| 908 TSTOSC opt_calc_gasvolume ; gas needs calculation activated? | |
| 909 bra calc_deco_engine_alt_2c ; YES - 2c in alternative plan | |
| 910 TSTOSS char_I_extra_time ; NO - delay mode activated? | |
| 911 bra calc_deco_engine_norm_2ab ; NO - schedule 2a has no alternative plan | |
| 912 ;bra calc_deco_engine_alt_2b ; YES - schedule 2b in alternative plan | |
| 913 | |
| 914 calc_deco_engine_alt_2b: | |
| 915 ; alternative schedule 2b: loop with delay | |
| 916 ; bcf lo,DECO_BAILOUT_FLAG ; switch off bailout mode (will be deactivated in normal plan) | |
| 917 ; bcf hi,DECO_VOLUME_FLAG ; switch off gas needs calculation (will never be activated in this plan) | |
| 918 bsf lo,DECO_DELAY_FLAG ; switch on delay mode | |
| 919 bra calc_deco_engine_alt_start ; start deco engine in normal plan | |
| 920 | |
| 921 calc_deco_engine_alt_2c: | |
| 922 ; alternative schedule 2c: simulated bailout (if possible) | |
| 923 decf best_gas_number,W ; get best gas number -1 into WREG. If not available, WREG will be 255 now. If not computed yet, WREG will be 254 now. | |
| 924 btfsc WREG,7 ; WREG < 128 (a bailout gas is available)? | |
| 925 bra calc_deco_engine_alt_2c_XX ; NO - no bailout plan possible because no bailout gas available to switch to | |
| 926 movf best_gas_number,W ; YES - get number of best gas into WREG | |
| 927 call deco_setup_oc_gases_pre ; - set up deco calculation in OC mode with OC gases | |
| 928 ; bcf lo,DECO_DELAY_FLAG ; - switch off delay mode by default (comes in switched off state) | |
| 929 TSTOSC char_I_extra_time ; - delay mode activated? | |
| 930 bsf lo,DECO_DELAY_FLAG ; YES - switch on delay mode | |
| 604 | 931 IFDEF _cave_mode |
| 631 | 932 btfsc dive_turned ; in cave mode and dive turned? |
| 933 bcf lo,DECO_DELAY_FLAG ; YES - suppress delay mode | |
| 604 | 934 ENDIF |
| 631 | 935 bsf lo,DECO_BAILOUT_FLAG ; - switch on bailout mode |
| 936 bsf hi,DECO_VOLUME_FLAG ; - switch on gas needs calculation | |
| 937 bra calc_deco_engine_alt_start ; - start deco engine in alternative plan | |
| 938 calc_deco_engine_alt_2c_XX: | |
| 604 | 939 call inval_alternative_plan_data ; invalidate all alternative (bailout) plan data because they are not applicable any more |
| 631 | 940 bra calc_deco_engine_norm_start ; continue calculating as normal plan |
| 941 ENDIF ; _ccr_pscr | |
| 942 | |
| 943 calc_deco_engine_alt_start: | |
| 944 bsf lo,DECO_START_ALT ; calculate an alternative plan | |
| 945 ;bra calc_deco_engine_start ; start deco engine | |
| 946 | |
| 634 | 947 |
| 631 | 948 ; ---- start deco engine ---- |
| 634 | 949 ; |
| 623 | 950 calc_deco_engine_start: |
| 631 | 951 IFDEF _cave_mode |
| 952 bcf hi,DECO_CAVE_MODE ; deactivate cave mode by default | |
| 953 btfss cave_mode ; cave mode switched on? | |
| 954 bra calc_deco_engine_start_1 ; NO - keep deactivated, no backtracking depth recording | |
| 955 bsf hi,DECO_CAVE_MODE ; YES - activate cave mode | |
| 956 btfss dive_turned ; - dive turned? | |
| 957 call write_backtrack_deltatime ; NO - update current delta time | |
| 958 ENDIF | |
| 959 calc_deco_engine_start_1: | |
| 604 | 960 movff hi,char_O_main_status ; write-back char_O_main_status to deco engine interface |
| 560 | 961 movff lo,char_O_deco_status ; write-back char_O_deco_status to deco engine interface |
| 0 | 962 |
| 631 | 963 calc_deco_engine_exec: |
| 623 | 964 ; +++++++++++++++++++++++++++++++++++++ |
| 634 | 965 bsf tmr5_preemtion_allowed ; grant preemption allowance for timer 5 (deco engine) |
| 623 | 966 call deco_calc_hauptroutine ; invoke the deco engine (C-code) |
| 967 banksel common ; back to bank common | |
| 634 | 968 bcf tmr5_preemtion_allowed ; revoke preemption allowance |
| 623 | 969 ; +++++++++++++++++++++++++++++++++++++ |
| 970 | |
| 631 | 971 ifdef _debug_output |
| 623 | 972 call TFT_debug_output ; debug output of scheduling performance data |
| 631 | 973 endif |
| 604 | 974 |
| 975 ; check if new calculation results for normal plan mode are available | |
| 623 | 976 movff char_O_deco_status,WREG ; get deco status of deco engine |
| 977 btfsc WREG,DECO_COMPLETED_NORM ; new calculation results for normal plan available? | |
| 978 bsf new_deco_data_avail ; YES - set flag for new NDL or deco data available | |
| 631 | 979 |
| 634 | 980 return ; done |
| 981 | |
| 623 | 982 |
| 631 | 983 IFDEF _ccr_pscr |
| 656 | 984 IFDEF _external_sensor_eccr |
| 0 | 985 |
| 634 | 986 ;----------------------------------------------------------------------------- |
| 987 ; Process Sensor Readings | |
| 988 ; | |
| 560 | 989 global calc_deko_divemode_sensor |
| 990 calc_deko_divemode_sensor: | |
| 634 | 991 btfsc ext_input_optical ; do we have an optical interface? |
| 992 bra calc_deko_divemode_sensor_opt ; YES - process received data | |
| 656 | 993 btfsc ext_s8_full_digital ; are we in external S8 full digital mode? |
| 994 bra calc_deko_divemode_sensor_opt ; YES - process received data | |
| 634 | 995 btfss ext_input_s8_ana ; NO - do we have a S8/analog interface? |
| 996 return ; NO - nothing to do, done | |
| 997 TSTOSS opt_s8_mode ; YES - shall use S8 interface? | |
| 998 bra calc_deko_divemode_sensor_ana ; - NO - use analog interface | |
| 999 ;bra calc_deko_divemode_sensor_s8 ; YES - use S8 interface | |
| 1000 | |
| 1001 calc_deko_divemode_sensor_s8: | |
| 1002 btfss trigger_S8_data_update ; new data frame available? | |
| 1003 bra calc_deko_divemode_sensor_common; NO - use old values | |
| 1004 bcf trigger_S8_data_update ; YES - clear update flag | |
| 1005 call compute_mvolts_from_rawdata ; - compute mV values from digital data | |
| 1006 bra calc_deko_divemode_sensor_common; - continue with common part | |
| 1007 | |
| 583 | 1008 calc_deko_divemode_sensor_opt: |
| 634 | 1009 ; sensor1_ppO2, sensor2_ppO2 and sensor3_ppO2 are already filled in ISR |
| 1010 btfss sensor1_active ; check HUD status data and eventually clear use_O2_sensorX | |
| 1011 bcf use_O2_sensor1 ; ... | |
| 1012 btfss sensor2_active ; ... | |
| 1013 bcf use_O2_sensor2 ; ... | |
| 1014 btfss sensor3_active ; ... | |
| 1015 bcf use_O2_sensor3 ; ... | |
| 1016 bra check_sensor_avg ; continue with calculating sensor average | |
| 1017 | |
| 1018 calc_deko_divemode_sensor_ana: | |
| 1019 call get_analog_inputs ; get the analog voltages and continue with the common part | |
| 1020 ;bra calc_deko_divemode_sensor_common; continue with common part | |
| 560 | 1021 |
| 1022 calc_deko_divemode_sensor_common: | |
| 634 | 1023 |
| 604 | 1024 ; Check each sensor if it is calibrated and if its mV value is within min_mv and max_mv limits. |
| 1025 ; If ok: compute o2_ppo2_sensorX = o2_mv_sensorX * opt_x_sX / 1000 | |
| 582 | 1026 ; If not ok: reset o2_ppo2_sensorX, reset use_O2_sensorX and show the customview 1 in case the sensor was ok before |
| 0 | 1027 |
| 604 | 1028 ; check sensor 1 |
| 582 | 1029 btfss sensor1_calibrated_ok ; check if sensor is usable at all |
| 1030 bra check_sensor_1_fail ; NO - handle it as failed | |
| 634 | 1031 SMOVII sensor1_mv,sub_a ; YES - load sensor mV value |
| 1032 | |
| 604 | 1033 ; check min threshold |
| 634 | 1034 rcall check_min_threshold ; check if sensor mV is outside minimum |
| 582 | 1035 btfsc neg_flag ; check if result is negative, i.e. sensor_mv < min_mv |
| 1036 bra check_sensor_1_fail ; YES - declare sensor as failed | |
| 634 | 1037 |
| 604 | 1038 ; check max_threshold |
| 634 | 1039 rcall check_max_threshold ; check if sensor mV is outside maximum |
| 582 | 1040 btfss neg_flag ; check if result is negative, i.e. sensor_mv < max_mv |
| 1041 bra check_sensor_1_fail ; NO - declare sensor as failed | |
| 634 | 1042 |
| 604 | 1043 ; check HUD data, if available |
| 582 | 1044 btfss hud_connection_ok ; check if there is a HUD connected |
| 1045 bra check_sensor_1_ok ; NO - all checks done then and positive | |
| 604 | 1046 btfss sensor1_active ; YES - HUD status ok? |
| 1047 bra check_sensor_1_fail ; NO - HUD reports a fail | |
| 634 | 1048 |
| 560 | 1049 check_sensor_1_ok: |
| 623 | 1050 ; sensor1_ppO2 = sensor1_mv:2 * opt_x_s1:2 / 1000 |
| 634 | 1051 SMOVII sensor1_mv,xA ; get sensor mV into xA |
| 1052 MOVII opt_x_s1, xB ; get calibration factor into xB | |
| 1053 rcall compute_ppo2_helper ; compute ppO2 | |
| 623 | 1054 movff xC+0,sensor1_ppO2 ; result in 0.01 bar |
| 634 | 1055 bcf attn_det_sensor1_lost ; clear attention |
| 1056 bcf shown_sensor1_fail ; re-arm custom-view show-up | |
| 582 | 1057 bra check_sensor_2 ; continue with next sensor |
| 634 | 1058 |
| 560 | 1059 check_sensor_1_fail: |
| 634 | 1060 clrf WREG ; set ppO2 reading to zero |
| 1061 movff WREG,sensor1_ppO2 ; ... | |
| 1062 btfsc use_O2_sensor1 ; check if sensor is in use | |
| 1063 bsf attn_det_sensor1_lost ; YES - set an attention | |
| 582 | 1064 bcf use_O2_sensor1 ; revoke sensor from usage |
| 604 | 1065 |
| 634 | 1066 check_sensor_2: |
| 1067 ; check sensor 2 | |
| 582 | 1068 btfss sensor2_calibrated_ok ; check if sensor is usable at all |
| 1069 bra check_sensor_2_fail ; NO - handle it as failed | |
| 634 | 1070 SMOVII sensor2_mv,sub_a ; YES - load sensor mV value |
| 1071 | |
| 604 | 1072 ; check min threshold |
| 634 | 1073 rcall check_min_threshold ; check if sensor mV is outside minimum |
| 582 | 1074 btfsc neg_flag ; check if result is negative, i.e. sensor_mv < min_mv |
| 1075 bra check_sensor_2_fail ; YES - declare sensor as failed | |
| 634 | 1076 |
| 604 | 1077 ; check max_threshold |
| 634 | 1078 rcall check_max_threshold ; check if sensor mV is outside maximum |
| 582 | 1079 btfss neg_flag ; check if result is nagative, i.e. sensor_mv < max_mv |
| 1080 bra check_sensor_2_fail ; NO - declare sensor as failed | |
| 634 | 1081 |
| 604 | 1082 ; check HUD data, if available |
| 582 | 1083 btfss hud_connection_ok ; check if there is a HUD connected |
| 1084 bra check_sensor_2_ok ; NO - all checks done then and positive | |
| 604 | 1085 btfss sensor2_active ; YES - HUD status ok? |
| 1086 bra check_sensor_2_fail ; NO - HUD reports a fail | |
| 634 | 1087 |
| 560 | 1088 check_sensor_2_ok: |
| 623 | 1089 ; sensor2_ppO2 = sensor2_mv:2 * opt_x_s2:2 / 1000 |
| 634 | 1090 SMOVII sensor2_mv,xA ; get sensor mV into xA |
| 1091 MOVII opt_x_s2, xB ; get calibration factor into xB | |
| 1092 rcall compute_ppo2_helper ; compute ppO2 | |
| 623 | 1093 movff xC+0,sensor2_ppO2 ; result in 0.01 bar |
| 634 | 1094 bcf attn_det_sensor2_lost ; clear attention |
| 1095 bcf shown_sensor2_fail ; re-arm custom-view show-up | |
| 582 | 1096 bra check_sensor_3 ; continue with next sensor |
| 634 | 1097 |
| 560 | 1098 check_sensor_2_fail: |
| 634 | 1099 clrf WREG ; set ppO2 reading to zero |
| 1100 movff WREG,sensor2_ppO2 ; ... | |
| 1101 btfsc use_O2_sensor2 ; check if sensor is in use | |
| 1102 bsf attn_det_sensor2_lost ; YES - set an attention | |
| 582 | 1103 bcf use_O2_sensor2 ; revoke sensor from usage |
| 604 | 1104 |
| 634 | 1105 check_sensor_3: |
| 1106 ; check sensor 3 | |
| 582 | 1107 btfss sensor3_calibrated_ok ; check if sensor is usable at all |
| 1108 bra check_sensor_3_fail ; NO - handle it as failed | |
| 634 | 1109 SMOVII sensor3_mv,sub_a ; YES - load sensor mV value |
| 1110 | |
| 604 | 1111 ; check min threshold |
| 634 | 1112 rcall check_min_threshold ; check if sensor mV is outside minimum |
| 582 | 1113 btfsc neg_flag ; check if result is negative, i.e. sensor_mv < min_mv |
| 1114 bra check_sensor_3_fail ; YES - declare sensor as failed | |
| 634 | 1115 |
| 604 | 1116 ; check max threshold |
| 634 | 1117 rcall check_max_threshold ; check if sensor mV is outside maximum |
| 582 | 1118 btfss neg_flag ; check if result is negative, i.e. sensor_mv < max_mv |
| 1119 bra check_sensor_3_fail ; NO - declare sensor as failed | |
| 634 | 1120 |
| 604 | 1121 ; check HUD data, if available |
| 582 | 1122 btfss hud_connection_ok ; check if there is a HUD connected |
| 1123 bra check_sensor_3_ok ; NO - all checks done then and positive | |
| 604 | 1124 btfss sensor3_active ; YES - HUD status ok? |
| 1125 bra check_sensor_3_fail ; NO - HUD reports a fail | |
| 634 | 1126 |
| 560 | 1127 check_sensor_3_ok: |
| 623 | 1128 ; sensor3_ppO2 = sensor3_mv:2 * opt_x_s1:2 / 1000 |
| 634 | 1129 SMOVII sensor3_mv,xA ; get sensor mV into xA |
| 1130 MOVII opt_x_s3, xB ; get calibration factor into xB | |
| 1131 rcall compute_ppo2_helper ; compute ppO2 | |
| 623 | 1132 movff xC+0,sensor3_ppO2 ; result in 0.01 bar |
| 634 | 1133 bcf attn_det_sensor3_lost ; clear attention |
| 1134 bcf shown_sensor3_fail ; re-arm custom-view show-up | |
| 1135 bra check_sensor_avg ; continue with calculating sensor average | |
| 1136 | |
| 560 | 1137 check_sensor_3_fail: |
| 634 | 1138 clrf WREG ; set ppO2 reading to zero |
| 1139 movff WREG,sensor3_ppO2 ; ... | |
| 1140 btfsc use_O2_sensor3 ; check if sensor is in use | |
| 1141 bsf attn_det_sensor3_lost ; YES - set an attention | |
| 582 | 1142 bcf use_O2_sensor3 ; revoke sensor from usage |
| 604 | 1143 |
| 634 | 1144 check_sensor_avg: |
| 1145 ; calculate sensor average | |
| 623 | 1146 btfss divemode ; in dive mode? |
| 1147 return ; NO - done here if not in dive mode | |
| 560 | 1148 |
| 634 | 1149 ; compute sensor_setpoint = average of all o2_ppo2_sensorX of |
| 1150 ; those sensors that have use_O2_sensorX == true | |
| 1151 | |
| 1152 CLRI xA ; clear sum of sensor values | |
| 1153 CLRI xB ; clear number of active sensors found | |
| 1154 | |
| 1155 check_sensor_avg_1: | |
| 1156 btfss use_O2_sensor1 ; sensor 1 active? | |
| 1157 bra check_sensor_avg_2 ; NO | |
| 1158 movff sensor1_ppO2,WREG ; YES - get ppO2 | |
| 1159 addwf xA+0,F ; - add into xA:2 | |
| 1160 movlw .0 ; - ... | |
| 1161 addwfc xA+1,F ; - ... | |
| 1162 incf xB+0,F ; - add a sensor | |
| 1163 | |
| 1164 check_sensor_avg_2: | |
| 1165 btfss use_O2_sensor2 ; sensor 2 active? | |
| 1166 bra check_sensor_avg_3 ; NO | |
| 1167 movff sensor2_ppO2,WREG ; YES - get ppO2 | |
| 1168 addwf xA+0,F ; - add into xA:2 | |
| 1169 movlw .0 ; - ... | |
| 1170 addwfc xA+1,F ; - ... | |
| 1171 incf xB+0,F ; - add a sensor | |
| 1172 | |
| 1173 check_sensor_avg_3: | |
| 1174 btfss use_O2_sensor3 ; sensor 3 active? | |
| 1175 bra check_sensor_avg_compute ; NO | |
| 1176 movff sensor3_ppO2,WREG ; YES - get ppO2 | |
| 1177 addwf xA+0,F ; - add into xA:2 | |
| 1178 movlw .0 ; - ... | |
| 1179 addwfc xA+1,F ; - ... | |
| 1180 incf xB+0,F ; add a sensor | |
| 1181 | |
| 1182 check_sensor_avg_compute: | |
| 604 | 1183 ; divide sum of sensor values by number of active sensors found |
| 634 | 1184 clrf xC+0 ; set zero as default result |
| 1185 tstfsz xB+0 ; pending div/0 ? | |
| 1186 call div16x16 ; NO - execute xC = xA / xB = summed ppO2 / number of sensors | |
| 1187 movff xC+0,sensor_setpoint ; copy result (or its default) | |
| 604 | 1188 |
| 1189 ; set default value for pSCR mode: 0 => let p2_deco.c compute the ppO2 based on current dil gas and depth | |
| 560 | 1190 ; will be overwritten later in case we are in sensor mode and have at least one usable sensor |
| 634 | 1191 clrf WREG ; pre-load a zero |
| 1192 btfsc FLAG_pscr_mode ; check if we are in pSCR mode | |
| 1193 movff WREG,char_I_const_ppO2 ; YES - write 0 to char_I_const_ppo2, | |
| 1194 ; it will be overwritten if we have a usable sensor reading | |
| 1195 btfsc bailout_mode ; check if we are in bailout | |
| 1196 bra check_sensor_vote ; YES - no sensor data transfer to char_I_const_ppO2 in this case | |
| 640 | 1197 movf dive_ccr_mode,W ; NO - get mode (0: Fixed SP, 1: Sensor, 2: Auto SP) |
| 634 | 1198 sublw .1 ; - in sensor mode? |
| 1199 bnz check_sensor_vote ; NO - not in sensor mode - no transfer of sensor data to char_I_const_ppO2 | |
| 1200 tstfsz xB+0 ; YES - check if we have found at least one usable sensor | |
| 1201 bra check_sensor_avg_use ; YES - we have at least one usable sensor | |
| 1202 bsf warn_det_sensors_lost ; NO - we have NO usable sensors | |
| 1203 btfsc FLAG_ccr_mode ; - check if we are in CCR mode | |
| 1204 movff opt_setpoint_cbar+0,char_I_const_ppO2 ; YES - select fixed setpoint no. 1 for fallback | |
| 1205 bra check_sensor_vote ; - continue with voting logic flags | |
| 1206 | |
| 1207 check_sensor_avg_use: | |
| 604 | 1208 ; we have at least one usable sensor with a ppO2 value > 0 |
| 634 | 1209 bcf warn_det_sensors_lost ; clear warning |
| 1210 bcf shown_sensors_lost ; re-arm custom view show-up | |
| 560 | 1211 movff sensor_setpoint,char_I_const_ppO2 ; transfer average sensor value to p2_deco.c code |
| 634 | 1212 |
| 1213 check_sensor_vote: | |
| 1214 ; check if individual sensors agree with their average | |
| 1215 bsf voting_logic_sensor1 ; default sensor to be within voting | |
| 1216 movff sensor1_ppO2,WREG ; get sensor's ppO2 | |
| 1217 rcall check_sensor_voting_helper ; check if sensor is within +/- range around setpoint | |
| 604 | 1218 tstfsz WREG ; sensor within range (WREG = 0)? |
| 1219 bcf voting_logic_sensor1 ; NO - vote out this sensor | |
| 560 | 1220 |
| 634 | 1221 bsf voting_logic_sensor2 ; default sensor to be within voting |
| 1222 movff sensor2_ppO2,WREG ; get sensor's ppO2 | |
| 1223 rcall check_sensor_voting_helper ; check if sensor is within +/- range around setpoint | |
| 604 | 1224 tstfsz WREG ; sensor within range (WREG = 0)? |
| 1225 bcf voting_logic_sensor2 ; NO - vote out this sensor | |
| 560 | 1226 |
| 634 | 1227 bsf voting_logic_sensor3 ; default sensor to be within voting |
| 1228 movff sensor3_ppO2,WREG ; get sensor's ppO2 | |
| 1229 rcall check_sensor_voting_helper ; check if sensor is within +/- range around setpoint | |
| 604 | 1230 tstfsz WREG ; sensor within range (WREG = 0)? |
| 1231 bcf voting_logic_sensor3 ; NO - vote out this sensor | |
| 582 | 1232 |
| 560 | 1233 ; check if a warning shall be issued on sensor disagreement |
| 582 | 1234 btfsc FLAG_ccr_mode ; check if we are in CCR mode |
| 604 | 1235 bra check_warn_sensor_0 ; YES - continue with further checks |
| 582 | 1236 btfsc FLAG_pscr_mode ; check if we are in pSCR mode |
| 604 | 1237 bra check_warn_sensor_0 ; YES - continue with further checks |
| 1238 bra check_warn_sensor_done ; not in CCR and not in pSCR, so no warning | |
| 634 | 1239 |
| 604 | 1240 check_warn_sensor_0: ; we are in CCR or pSCR mode |
| 623 | 1241 btfsc bailout_mode ; check if we are in bailout |
| 604 | 1242 bra check_warn_sensor_done ; YES - no warning in this case |
| 640 | 1243 movf dive_ccr_mode,W ; get mode (0: Fixed SP, 1: Sensor, 2: Auto SP) |
| 604 | 1244 sublw .1 ; in sensor mode? |
| 1245 bnz check_warn_sensor_done ; NO - not in sensor mode - no warning in this case | |
| 634 | 1246 |
| 604 | 1247 check_warn_sensor_1: |
| 582 | 1248 btfss sensor1_calibrated_ok ; check if sensor has a valid calibration |
| 1249 bra check_warn_sensor_2 ; NO - sensor can not cause a warning then | |
| 1250 btfss use_O2_sensor1 ; YES - check if sensor is in use | |
| 604 | 1251 bra check_warn_sensor_2 ; NO - sensor can not cause a warning then |
| 1252 btfsc voting_logic_sensor1 ; YES - check if sensor value is within agreement range | |
| 1253 bra check_warn_sensor_2 ; YES - continue with next sensor | |
| 634 | 1254 bsf warn_det_sensors_div ; NO - sensors divergence |
| 1255 return ; - done | |
| 1256 | |
| 604 | 1257 check_warn_sensor_2: |
| 582 | 1258 btfss sensor2_calibrated_ok ; check if sensor has a valid calibration |
| 1259 bra check_warn_sensor_3 ; NO - sensor can not cause a warning then | |
| 1260 btfss use_O2_sensor2 ; YES - check if sensor is in use | |
| 604 | 1261 bra check_warn_sensor_3 ; NO - sensor can not cause a warning then |
| 1262 btfsc voting_logic_sensor2 ; YES - check if sensor value is within agreement range | |
| 1263 bra check_warn_sensor_3 ; YES - continue with next sensor | |
| 634 | 1264 bsf warn_det_sensors_div ; NO - sensors divergence |
| 1265 return ; - done | |
| 1266 | |
| 604 | 1267 check_warn_sensor_3: |
| 582 | 1268 btfss sensor3_calibrated_ok ; check if sensor has a valid calibration |
| 1269 bra check_warn_sensor_agree ; NO - sensor can not cause a warning then | |
| 1270 btfss use_O2_sensor3 ; YES - check if sensor is in use | |
| 604 | 1271 bra check_warn_sensor_agree ; NO - sensor can not cause a warning then |
| 1272 btfsc voting_logic_sensor3 ; YES - check if sensor value is within agreement range | |
| 1273 bra check_warn_sensor_agree ; YES - continue with next sensor | |
| 634 | 1274 bsf warn_det_sensors_div ; NO - set warning |
| 1275 return ; - done | |
| 1276 | |
| 604 | 1277 check_warn_sensor_done: |
| 560 | 1278 check_warn_sensor_agree: |
| 634 | 1279 bcf warn_det_sensors_div ; clear warning |
| 1280 bcf shown_sensors_diverg ; re-arm custom view show-up | |
| 1281 return ; done | |
| 1282 | |
| 1283 | |
| 1284 ;----------------------------------------------------------------------------- | |
| 1285 ; Helper Function - check if sensor mV is outside minimum | |
| 1286 ; | |
| 604 | 1287 check_min_threshold: |
| 623 | 1288 MOVLI min_mv,sub_b ; load minimum mV value |
| 604 | 1289 goto sub16 ; sub_c = sensor_mv - min_mv (and return) |
| 1290 | |
| 634 | 1291 |
| 1292 ;----------------------------------------------------------------------------- | |
| 1293 ; Helper Function - check if sensor mV is outside maximum | |
| 1294 ; | |
| 604 | 1295 check_max_threshold: |
| 623 | 1296 MOVLI max_mv,sub_b ; load maximum mV value |
| 604 | 1297 goto sub16 ; sub_c = sensor_mv - max_mv (and return) |
| 1298 | |
| 634 | 1299 |
| 1300 ;----------------------------------------------------------------------------- | |
| 1301 ; Helper Function - compute ppO2 from sensor mV and calibration factor | |
| 1302 ; | |
| 560 | 1303 compute_ppo2_helper: |
| 623 | 1304 call mult16x16 ; xC:4 = xA:2 * xB:2 |
| 634 | 1305 MOVLI .1000,xB ; load scaling factor |
| 623 | 1306 call div32x16 ; xC:4 = xC:4 / xB:2 with xA as remainder |
| 1307 tstfsz xC+1 ; is the ppO2 higher than 2.55 bar? | |
| 1308 setf xC+0 ; YES - set result to 255 aka 2.55 bar | |
| 634 | 1309 return ; done |
| 1310 | |
| 1311 | |
| 1312 ;----------------------------------------------------------------------------- | |
| 1313 ; Helper Function - check if sensor is within +/- range around setpoint | |
| 1314 ; | |
| 560 | 1315 check_sensor_voting_helper: |
| 634 | 1316 subwf sensor_setpoint,W ; deviation = setpoint - sensor ppO2 |
| 1317 btfsc STATUS,N ; result negative? | |
| 1318 negf WREG,W ; YES - negate deviation | |
| 1319 sublw sensor_voting_logic_threshold ; WREG = threshold - deviation | |
| 1320 btfss STATUS,N ; result negative? | |
| 1321 retlw .0 ; NO - within range | |
| 1322 retlw .1 ; YES - out of range | |
| 1323 | |
| 1324 ; cpfsgt sensor_setpoint ; sensor ppO2 > setpoint? | |
| 1325 ; bra check_sensor_voting_helper_2 ; NO | |
| 1326 ; ;bra check_sensor_voting_helper_1 ; YES | |
| 1327 ; | |
| 1328 ;check_sensor_voting_helper_1: | |
| 1329 ; subwf sensor_setpoint,W ; WREG = setpoint - sensor ppO2 | |
| 1330 ; bra check_sensor_voting_helper_com ; continue with common part | |
| 1331 ; | |
| 1332 ;check_sensor_voting_helper_2: | |
| 1333 ; movwf lo ; copy sensor ppO2 to lo | |
| 1334 ; movf sensor_setpoint,W ; copy setpoint to WREG | |
| 1335 ; subwf lo,W ; WREG = sensor ppO2 - setpoint | |
| 1336 ; ;bra check_sensor_voting_helper_com ; continue with common part | |
| 1337 ; | |
| 1338 ;check_sensor_voting_helper_com: | |
| 1339 ; movwf lo ; copy deviation to lo | |
| 1340 ; movlw sensor_voting_logic_threshold ; load threshold in 0.01 bar | |
| 1341 ; cpfsgt lo ; deviation > threshold ? | |
| 1342 ; retlw .0 ; NO - within range | |
| 1343 ; retlw .1 ; YES - out of range | |
| 582 | 1344 |
| 656 | 1345 ENDIF ; _external_sensor_eccr |
| 631 | 1346 ENDIF ; _ccr_pscr |
| 623 | 1347 |
| 560 | 1348 |
| 604 | 1349 IFDEF _cave_mode |
| 623 | 1350 |
| 634 | 1351 ;----------------------------------------------------------------------------- |
| 1352 ; Cave Mode - on/off Switching | |
| 1353 ; | |
| 631 | 1354 cavemode_toggle_onoff: |
| 1355 bcf request_cave_toggle ; clear request flag | |
| 1356 btg cave_mode ; toggle the on/off state | |
| 1357 return ; done | |
| 1358 | |
| 634 | 1359 |
| 1360 ;----------------------------------------------------------------------------- | |
| 1361 ; Cave Mode - switch off and set Dive as turned | |
| 1362 ; | |
| 631 | 1363 cavemode_switch_off_turned: |
| 1364 bcf request_cave_off_turned ; clear request flag | |
| 1365 bcf cave_mode ; switch cave mode off | |
| 1366 bra cavemode_turndive_turn_exec ; set dive as turned (and return) | |
| 1367 | |
| 1368 | |
| 634 | 1369 ;----------------------------------------------------------------------------- |
| 1370 ; Cave Mode - check if 'turn dive' is allowed | |
| 1371 ; | |
| 631 | 1372 global cavemode_turndive_check |
| 1373 cavemode_turndive_check: | |
| 1374 btfss cave_mode ; cave mode switched on? | |
| 1375 retlw 1 ; NO - signal not allowed | |
| 1376 btfss dive_turned ; YES - is the dive currently turned? | |
| 1377 retlw 0 ; NO - command is allowed | |
| 1378 movf backtrack_waypoint_turn,W ; YES - copy turn point number to WREG | |
| 1379 cpfslt backtrack_waypoint_num ; - current waypoint number < turn point number ? | |
| 1380 retlw 1 ; NO - signal not allowed | |
| 1381 retlw 0 ; YES - command is allowed | |
| 1382 | |
| 634 | 1383 |
| 1384 ;----------------------------------------------------------------------------- | |
| 1385 ; Cave Mode - execute 'turn dive' toggle | |
| 1386 ; | |
| 631 | 1387 cavemode_turndive_toggle: |
| 1388 bcf request_turn_toggle ; clear request flag | |
| 1389 rcall cavemode_turndive_check ; check if command is allowed | |
| 1390 tstfsz WREG ; command allowed? | |
| 1391 return ; NO - abort | |
| 1392 btfss dive_turned ; YES - is the dive currently turned? | |
| 1393 bra cavemode_turndive_turn_exec ; NO - turn the dive | |
| 634 | 1394 bcf dive_turned ; YES - set dive as not turned any more |
| 1395 bcf backtrack_shutdown ; - set backtracking as not shut down any more | |
| 1396 call set_logbook_marker ; - set a logbook marker | |
| 1397 goto resume_backtrack_recording ; - append further logging after current waypoint and return | |
| 1398 | |
| 1399 | |
| 1400 ;----------------------------------------------------------------------------- | |
| 1401 ; Cave Mode - set the dive as turned | |
| 1402 ; | |
| 631 | 1403 cavemode_turndive_turn: |
| 1404 bcf request_turn_turn ; clear request flag | |
| 1405 btfss cave_mode ; cave mode switched on? | |
| 1406 return ; NO - abort | |
| 1407 btfsc dive_turned ; YES - is the dive already turned? | |
| 1408 return ; YES - nothing to do any more | |
| 1409 cavemode_turndive_turn_exec: | |
| 634 | 1410 bsf dive_turned ; NO - set dive as turned |
| 1411 call set_logbook_marker ; - set a logbook marker | |
| 1412 goto write_backtrack_turnpoint ; - write a turn-point waypoint and return | |
| 1413 | |
| 1414 | |
| 1415 ;----------------------------------------------------------------------------- | |
| 1416 ; Cave Mode - check if setting a Waypoint is allowed | |
| 1417 ; | |
| 631 | 1418 global cavemode_waypoint_set_check |
| 1419 cavemode_waypoint_set_check: | |
| 1420 btfss cave_mode ; cave mode switched on? | |
| 1421 retlw 1 ; NO - command not allowed | |
| 1422 btfsc dive_turned ; YES - is the dive turned? | |
| 1423 retlw 1 ; YES - no setting of waypoints on way out, command not allowed | |
| 1424 btfsc backtrack_entire_full ; NO - storage entirely used up? | |
| 1425 retlw 1 ; YES - out of storage capacity, command not allowed | |
| 1426 movlw backtrack_waypoint_max ; NO - get highest allowed waypoint number | |
| 1427 cpfslt backtrack_waypoint_num ; - current waypoint number < max allowed number? | |
| 1428 retlw 1 ; NO - command not allowed | |
| 1429 retlw 0 ; YES - command is allowed | |
| 1430 | |
| 634 | 1431 |
| 1432 ;----------------------------------------------------------------------------- | |
| 1433 ; Cave Mode - set a Waypoint | |
| 1434 ; | |
| 631 | 1435 cavemode_waypoint_set: |
| 1436 bcf request_waypoint_set ; clear request flag | |
| 1437 rcall cavemode_waypoint_set_check ; check if command is allowed to execute | |
| 1438 tstfsz WREG ; command allowed? | |
| 1439 return ; NO - no waypoint setting possible, abort | |
| 1440 call set_logbook_marker ; YES - set a logbook marker | |
| 1441 goto write_backtrack_waypoint ; - execute command (and return) | |
| 1442 | |
| 1443 | |
| 634 | 1444 ;----------------------------------------------------------------------------- |
| 1445 ; Cave Mode - check if stepping one Waypoint outwards is allowed | |
| 1446 ; | |
| 631 | 1447 global cavemode_waypoint_out_check |
| 1448 cavemode_waypoint_out_check: | |
| 1449 btfss cave_mode ; cave mode switched on? | |
| 1450 retlw 1 ; NO - command not allowed | |
| 1451 btfss dive_turned ; YES - is the dive turned? | |
| 1452 retlw 1 ; NO - no stepping back on way in, command not allowed | |
| 1453 btfsc waypoint_reached_first ; YES - already at first waypoint? | |
| 1454 retlw 1 ; YES - command not allowed | |
| 1455 retlw 0 ; NO - command is allowed | |
| 1456 | |
| 634 | 1457 |
| 1458 ;----------------------------------------------------------------------------- | |
| 1459 ; Cave Mode - step one Waypoint outwards | |
| 1460 ; | |
| 631 | 1461 cavemode_waypoint_out: |
| 1462 bcf request_waypoint_out ; clear request flag | |
| 1463 rcall cavemode_waypoint_out_check ; check if command is allowed to execute | |
| 1464 tstfsz WREG ; command allowed? | |
| 1465 return ; NO - no further out possible, abort | |
| 1466 goto backtrack_waypoint_go_out ; YES - execute the command (and return) | |
| 1467 | |
| 1468 | |
| 634 | 1469 ;----------------------------------------------------------------------------- |
| 1470 ; Cave Mode - check if stepping one Waypoint inwards is allowed | |
| 1471 ; | |
| 631 | 1472 global cavemode_waypoint_in_check |
| 1473 cavemode_waypoint_in_check: | |
| 1474 btfss cave_mode ; cave mode switched on? | |
| 1475 retlw 1 ; NO - command not allowed | |
| 1476 btfss dive_turned ; YES - is the dive turned? | |
| 1477 retlw 1 ; NO - no stepping forward on way in, command not allowed | |
| 1478 btfsc waypoint_reached_last ; YES - already at last waypoint? | |
| 1479 retlw 1 ; YES - command not allowed | |
| 1480 retlw 0 ; NO - command is allowed | |
| 1481 | |
| 634 | 1482 |
| 1483 ;----------------------------------------------------------------------------- | |
| 1484 ; Cave Mode - step one Waypoint inwards | |
| 1485 ; | |
| 631 | 1486 cavemode_waypoint_in: |
| 1487 bcf request_waypoint_in ; clear request flag | |
| 1488 rcall cavemode_waypoint_in_check ; check if command is allowed to execute | |
| 1489 tstfsz WREG ; command allowed? | |
| 1490 return ; NO - no further in possible, abort | |
| 1491 goto backtrack_waypoint_go_in ; YES - execute command (and return) | |
| 623 | 1492 |
| 634 | 1493 |
| 1494 ;----------------------------------------------------------------------------- | |
| 1495 ; Cave Mode - store current Delta Time | |
| 1496 ; | |
| 1497 write_backtrack_deltatime: | |
| 1498 rcall setup_backtrack_index ; setup writing position | |
| 1499 bra write_backtrack_datum_deltatime ; store the current delta time (and return) | |
| 1500 | |
| 1501 | |
| 1502 ;----------------------------------------------------------------------------- | |
| 1503 ; Cave Mode - store a Backtracking Depth Data Set | |
| 1504 ; | |
| 1505 write_backtrack_1min_depth: | |
| 1506 rcall setup_backtrack_index ; setup writing position | |
| 1507 rcall write_backtrack_datum_depth ; store depth | |
| 1508 rcall write_backtrack_datum_zerotime ; reset the time elapsed since last depth recording and store it | |
| 1509 bra write_backtrack_datum_check ; store new writing position, check remaining storage capacity ()and return) | |
| 1510 | |
| 1511 | |
| 1512 ;----------------------------------------------------------------------------- | |
| 1513 ; Cave Mode - store a Waypoint | |
| 1514 ; | |
| 1515 write_backtrack_waypoint: | |
| 1516 rcall setup_backtrack_index ; setup writing position | |
| 1517 rcall write_backtrack_datum_deltatime ; store the time elapsed since last depth recording | |
| 1518 movf POSTINC1,W ; dummy read to increment the writing position index | |
| 1519 rcall write_backtrack_datum_depth ; store depth | |
| 1520 rcall write_backtrack_datum_gas ; store gas availability vector | |
| 1521 rcall write_backtrack_datum_waypoint ; store waypoint number | |
| 1522 rcall write_backtrack_datum_zerotime ; reset the time elapsed since last depth recording and store it | |
| 1523 bra write_backtrack_datum_check ; store new writing position, check remaining storage capacity (and return) | |
| 1524 | |
| 1525 | |
| 1526 ;----------------------------------------------------------------------------- | |
| 1527 ; Cave Mode - store a Turn Point | |
| 1528 write_backtrack_turnpoint: | |
| 1529 rcall write_backtrack_waypoint ; write a waypoint (see above) | |
| 1530 movf POSTDEC1,W ; dummy read to decrement the position index to the waypoint number datum | |
| 1531 movff FSR1L,char_I_backtrack_index ; store updated writing position | |
| 1532 movff backtrack_waypoint_num,backtrack_waypoint_turn; memorize this waypoint as turn point | |
| 1533 return ; done | |
| 1534 | |
| 1535 | |
| 1536 ;----------------------------------------------------------------------------- | |
| 1537 ; Cave Mode - append further Logging after current Waypoint | |
| 1538 ; | |
| 1539 resume_backtrack_recording: | |
| 1540 clrf backtrack_waypoint_turn ; clear turn point reference | |
| 1541 bsf waypoint_reached_last ; declare to be at last waypoint now | |
| 1542 rcall setup_backtrack_index ; setup index position | |
| 1543 movf POSTINC1,W ; dummy read to increment the position index to the delta time datum | |
| 1544 rcall write_backtrack_datum_zerotime ; reset the time elapsed since last depth recording and store it | |
| 1545 bra write_backtrack_datum_check ; store new writing position, check remaining storage capacity (and return) | |
| 1546 | |
| 1547 | |
| 1548 ;----------------------------------------------------------------------------- | |
| 1549 ; Cave Mode - execute stepping one Waypoint outwards | |
| 1550 ; | |
| 1551 backtrack_waypoint_go_out: | |
| 1552 bcf waypoint_reached_last ; not at last waypoint (or turn point) any more | |
| 1553 rcall setup_backtrack_index ; setup index position | |
| 1554 movlw b'11100000'-.1 ; a waypoint datum has bits 5-7 set, -1 because of cpfsgt | |
| 1555 backtrack_waypoint_go_out_loop: | |
| 1556 movff POSTDEC1,lo ; dummy read current datum and go to previous datum (there is no PREDEC) | |
| 1557 cpfsgt INDF1 ; read datum, is it a waypoint datum? | |
| 1558 bra backtrack_waypoint_go_out_loop ; NO - try next datum | |
| 1559 movff FSR1L,char_I_backtrack_index ; store new index position | |
| 1560 movf INDF1,W ; copy waypoint datum to WREG | |
| 1561 andlw b'00011111' ; remove waypoint tag | |
| 1562 movwf backtrack_waypoint_num ; store new waypoint number | |
| 1563 movlw .1 ; number of first waypoint | |
| 1564 cpfsgt backtrack_waypoint_num ; current waypoint number > number of first waypoint ? | |
| 1565 bsf waypoint_reached_first ; NO - reached first waypoint | |
| 1566 goto restart_deco_engine_wo_norm ; invalidate all alternative plan data and restart deco engine | |
| 1567 | |
| 1568 | |
| 1569 ;----------------------------------------------------------------------------- | |
| 1570 ; Cave Mode - execute stepping one Waypoint inwards | |
| 1571 ; | |
| 1572 backtrack_waypoint_go_in: | |
| 1573 bcf waypoint_reached_first ; not at first waypoint any more | |
| 1574 rcall setup_backtrack_index ; setup index position | |
| 1575 movlw b'11100000'-.1 ; a waypoint datum has bits 5-7 set, -1 because of cpfsgt | |
| 1576 backtrack_waypoint_go_in_loop: | |
| 1577 cpfsgt PREINC1 ; go to next datum, read it, is it a waypoint datum? | |
| 1578 bra backtrack_waypoint_go_in_loop ; NO - try next datum | |
| 1579 movff FSR1L,char_I_backtrack_index ; store new index position | |
| 1580 movf INDF1,W ; copy waypoint datum to WREG | |
| 1581 andlw b'00011111' ; remove waypoint tag | |
| 1582 movwf backtrack_waypoint_num ; store new waypoint number | |
| 1583 movf backtrack_waypoint_turn,W ; load WREG with waypoint number of turn point | |
| 1584 cpfslt backtrack_waypoint_num ; new waypoint number < number of turn point ? | |
| 1585 bsf waypoint_reached_last ; NO - reached last waypoint | |
| 1586 goto restart_deco_engine_wo_norm ; invalidate all alternative plan data and restart deco engine | |
| 1587 | |
| 1588 | |
| 1589 ;----------------------------------------------------------------------------- | |
| 1590 ; Cave Mode Helper Function - set up Index Position | |
| 1591 ; | |
| 1592 setup_backtrack_index: | |
| 1593 lfsr FSR1,char_I_backtrack_storage ; load FSR1 with base address of the backtracking storage | |
| 1594 movff char_I_backtrack_index,FSR1L ; adjust FSR1 to the current index position | |
| 1595 return | |
| 1596 | |
| 1597 | |
| 1598 ;----------------------------------------------------------------------------- | |
| 1599 ; Cave Mode Helper Function - reset Time since last Depth Recording and store it | |
| 1600 ; | |
| 1601 write_backtrack_datum_zerotime: | |
| 1602 clrf backtrack_deltatime ; reset the time elapsed since last depth recording | |
| 1603 ;bra write_backtrack_datum_deltatime ; store the time | |
| 1604 | |
| 1605 | |
| 1606 ;----------------------------------------------------------------------------- | |
| 1607 ; Cave Mode Helper Function - store Time elapsed since last Depth Recording | |
| 1608 ; | |
| 1609 write_backtrack_datum_deltatime: | |
| 1610 movf backtrack_deltatime,W ; get the time elapsed since last depth recording | |
| 1611 bsf WREG,7 ; add the time marker (bit 7 set) to the time stored in WREG | |
| 1612 movwf INDF1 ; write the time and keep the writing position index pointing on it | |
| 1613 return ; done | |
| 1614 | |
| 1615 | |
| 1616 ;----------------------------------------------------------------------------- | |
| 1617 ; Cave Mode Helper Function - store Depth | |
| 1618 ; | |
| 1619 write_backtrack_datum_depth: | |
| 1620 movf depth_meter,W ; get current depth in meters into WREG | |
| 1621 btfsc WREG,7 ; current depth < 128 m ? | |
| 1622 movlw .127 ; NO - clip depth to 127 meters (protect time marker bit) | |
| 1623 movwf POSTINC1 ; write the depth entry and increment the writing position index | |
| 1624 return ; done | |
| 1625 | |
| 1626 | |
| 1627 ;----------------------------------------------------------------------------- | |
| 1628 ; Cave Mode Helper Function - store Gas Availability Vector | |
| 1629 ; | |
| 1630 write_backtrack_datum_gas: | |
| 1631 ; Cave mode is currently only available with gas needs calculation enabled, | |
| 1632 ; so deco mode is either OC anyhow or CCR/pSCR in bailout mode. Hence it is | |
| 1633 ; always the OC (bailout) gases whose staging status needs to be stored. | |
| 1634 lfsr FSR2,opt_gas_type ; load base address of the OC/bailout gas types | |
| 1635 movlw NUM_GAS ; load number of gases | |
| 1636 movwf lo ; initialize loop counter | |
| 1637 movlw b'00000001' ; load gas bit pattern for the first gas | |
| 1638 movwf hi ; store gas bit pattern in hi | |
| 1639 movlw b'11000000' ; initialize WREG with the gas staging status tag | |
| 1640 write_backtrack_datum_gas_loop: | |
| 1641 movff POSTINC2,up ; get gas type and increment index | |
| 1642 btfsc up,gas_staged ; gas staged? | |
| 1643 iorwf hi,W ; YES - set respective gas bit | |
| 1644 rlncf hi,F ; rotate gas bit pattern to match the next gas | |
| 1645 decfsz lo,F ; decrement loop counter, did it became zero? | |
| 1646 bra write_backtrack_datum_gas_loop ; NO - loop | |
| 1647 movwf POSTINC1 ; YES - write the gas staging status entry and increment the writing position index | |
| 1648 return ; - done | |
| 1649 | |
| 1650 | |
| 1651 ;----------------------------------------------------------------------------- | |
| 1652 ; Cave Mode Helper Function - store a Waypoint Number | |
| 1653 ; | |
| 1654 write_backtrack_datum_waypoint: | |
| 1655 incf backtrack_waypoint_num,F ; increment the waypoint number | |
| 1656 movf backtrack_waypoint_num,W ; copy waypoint number to WREG | |
| 1657 iorlw b'11100000' ; add the waypoint marker (bit 7-5 set) to the number stored in WREG | |
| 1658 movwf POSTINC1 ; write the waypoint datum and increment the writing position index | |
| 1659 movlw .2 ; load a 2 into WREG | |
| 1660 cpfslt backtrack_waypoint_num ; new waypoint number >= 2 ? | |
| 1661 bcf waypoint_reached_first ; YES - not at first waypoint any more | |
| 1662 return ; done | |
| 1663 | |
| 1664 | |
| 1665 ;----------------------------------------------------------------------------- | |
| 1666 ; Cave Mode Helper Function - store new writing position and check remaining storage capacity | |
| 1667 ; | |
| 1668 write_backtrack_datum_check: | |
| 1669 movff FSR1L,char_I_backtrack_index ; store new index position | |
| 1670 movlw backtrack_almost_full_threshold ; load threshold for backtracking storage almost full | |
| 1671 bcf backtrack_almost_full ; clear almost full state | |
| 1672 cpfslt FSR1L ; index < threshold ? | |
| 1673 bsf backtrack_almost_full ; NO - flag backtracking storage is almost full | |
| 1674 movlw backtrack_entire_full_threshold ; load threshold for backtracking storage entirely full | |
| 1675 bcf backtrack_entire_full ; clear entirely full state | |
| 1676 cpfslt FSR1L ; index < threshold ? | |
| 1677 bsf backtrack_entire_full ; NO - flag backtracking storage is entirely full | |
| 1678 return ; done | |
| 1679 | |
| 1680 ENDIF ; _cave_mode | |
| 1681 | |
| 1682 | |
| 1683 ;----------------------------------------------------------------------------- | |
| 1684 ; Calculate vertical Velocity | |
| 1685 ; | |
| 623 | 1686 calc_velocity: ; called every two seconds |
| 1687 btfsc velocity_active_num ; was velocity shown in last cycle? | |
| 1688 bra calc_velocity_1 ; YES - always update if shown before | |
| 1689 btfss count_divetime ; NO - is the dive time counted, i.e. deeper than dive threshold? | |
| 1690 return ; NO - display velocity only if deeper than 1m, | |
| 1691 ; i.e. not at the surface after the dive | |
| 1692 calc_velocity_1: | |
| 1693 ; calculate pressure difference | |
| 1694 MOVII pressure_abs_cached, sub_a; current pressure | |
| 1695 MOVII last_pressure_velocity,sub_b; last pressure | |
| 1696 call subU16 ; do an unsigned subtraction | |
| 1697 | |
| 1698 ; decide if ascending or descending | |
| 1699 bcf neg_flag_velocity ; set to ascending by default | |
| 1700 btfsc neg_flag ; pressure differential negative? | |
| 1701 bsf neg_flag_velocity ; YES - descending | |
| 1702 | |
| 1703 ; store current pressure as last pressure for next round | |
| 1704 MOVII pressure_abs_cached,last_pressure_velocity | |
| 1705 | |
| 1706 ; calculate velocity in m/min | |
| 1707 MOVII sub_c,xA ; copy pressure differential to xA | |
| 1708 MOVLI .39,xB ; put scale coefficient into xB (use 77 when called every second) | |
| 628 | 1709 call mult16x16 ; compute differential pressure in mbar * scale coefficient |
| 623 | 1710 MOVII xC,divA ; copy result to divA |
| 631 | 1711 ADDLI .64,divA ; add some round-up |
| 623 | 1712 movlw .7 ; divide by 2^7 |
| 1713 call div16 ; divA = divA / 2^WREG, yields velocity in m/min | |
| 1714 | |
| 1715 movlw .99 ; load a 99 | |
| 1716 cpfslt divA+0 ; velocity < 99 m/min ? | |
| 1717 movwf divA+0 ; NO - limit to 99 m/min | |
| 1718 | |
| 1719 bcf STATUS,C ; clear carry flag | |
| 1720 movlw velocity_display_threshold ; get threshold for displaying vertical velocity | |
| 1721 subwf divA+0,W ; subtract threshold from velocity | |
| 1722 btfss STATUS,C ; above threshold? | |
| 1723 bsf FLAG_TFT_velocity_clear ; NO - don't show / request to clear | |
| 1724 btfsc STATUS,C ; above threshold? | |
| 1725 bsf FLAG_TFT_velocity_show ; YES - request to show | |
| 1726 return ; done | |
| 0 | 1727 |
| 1728 | |
| 634 | 1729 ;----------------------------------------------------------------------------- |
| 1730 ; Check and Memorize if Dive went into Deco & Deco Region | |
| 1731 ; | |
| 628 | 1732 check_deco_states: |
| 1733 btfsc deco_region ; been within the deco stops region before? | |
| 1734 return ; YES - been in deco then before too, done | |
| 1735 movff char_O_deco_info,WREG ; NO - get deco info vector | |
| 631 | 1736 btfss WREG,deco_stops_norm ; do we have a deco obligation right now? |
| 628 | 1737 return ; NO - done |
| 654 | 1738 ; bsf deco_locked ; YES - memorize dive was in deco |
| 628 | 1739 movff char_O_deco_depth+0,WREG ; - get depth of first stop in meters into WREG |
| 1740 addlw deco_region_distance+.1 ; - add deco region start distance + 1 meter for the negative test to work | |
| 631 | 1741 subwf depth_meter,W ; - compute current depth - (first stop depth + deco region distance) |
| 628 | 1742 btfss STATUS,C ; - result negative? |
| 1743 bsf deco_region ; YES - memorize to have entered the deco stops region | |
| 1744 return ; - done | |
| 1745 | |
| 634 | 1746 |
| 1747 ;----------------------------------------------------------------------------- | |
| 1748 ; Exercise Safety Stop Control | |
| 1749 ; | |
| 623 | 1750 safety_stop_control: |
| 631 | 1751 TSTOSS opt_safetystop ; safety stop enabled? (=1: show safety stop) |
| 623 | 1752 return ; NO - done |
| 1753 | |
| 1754 btfsc FLAG_gauge_mode ; in gauge mode? | |
| 1755 return ; YES - omit (well, else fix collision of safety stop output with avg depth label) | |
| 1756 | |
| 1757 ; setup | |
| 1758 bcf safety_stop_enabled ; disable safety stop by default | |
| 1759 | |
| 1760 ; check for deco | |
| 1761 btfsc decostop_active ; in deco mode? | |
| 1762 bra safety_stop_finish ; YES - shut down safety stop | |
| 1763 | |
| 1764 ; below "opt_safety_stop_reset"? | |
| 631 | 1765 MOVII pressure_rel_cur_cached,mpr ; get current pressure into MPR |
| 1766 call convert_pres_to_depth ; convert pressure in [mbar] to depth in [cm] | |
| 1767 MOVII mpr,sub_a ; move depth in [cm] to sub_a | |
| 1768 movff opt_safety_stop_reset,WREG ; load safety stop reset threshold [dm] | |
| 1769 mullw .10 ; convert threshold from [dm] to [cm] | |
| 1770 MOVII PROD,sub_b ; move threshold in [cm] to sub_b | |
| 623 | 1771 call cmpU16 ; sub_a - sub_b |
| 634 | 1772 btfsc neg_flag ; below threshold depth? |
| 1773 bra safety_stop_control_chk ; NO - check if above end threshold | |
| 1774 ;bra safety_stop_reset ; YES - reset safety stop | |
| 1775 | |
| 1776 safety_stop_reset: | |
| 1777 movff opt_safety_stop_length,safety_stop_countdown ; rearm safety stop (load timer) | |
| 1778 incf safety_stop_countdown,F ; +1 because safety_stop_show decrements first | |
| 1779 bsf FLAG_TFT_safety_stop_clear ; request to clear safety stop | |
| 1780 return ; done | |
| 1781 | |
| 1782 safety_stop_control_chk: | |
| 623 | 1783 ; above "opt_safety_stop_end"? |
| 631 | 1784 movff opt_safety_stop_end,WREG ; load safety stop end threshold [dm] |
| 1785 mullw .10 ; convert threshold from [dm] to [cm] | |
| 1786 MOVII PROD,sub_b ; move threshold in [cm] to sub_b | |
| 623 | 1787 call cmpU16 ; sub_a - sub_b |
| 1788 btfsc neg_flag ; above or at threshold depth? | |
| 634 | 1789 bra safety_stop_finish ; YES - finish with safety stop and return |
| 1790 | |
| 623 | 1791 ; above "opt_safety_stop_start"? |
| 631 | 1792 movff opt_safety_stop_start,WREG ; load safety stop start threshold [dm] |
| 1793 mullw .10 ; convert threshold from [dm] to [cm] | |
| 1794 MOVII PROD,sub_b ; move threshold in [cm] to sub_b | |
| 623 | 1795 call cmpU16 ; sub_a - sub_b |
| 1796 btfss neg_flag ; above or at threshold depth? | |
| 1797 return ; NO - pause safety stop | |
| 1798 tstfsz safety_stop_countdown ; YES - safety stop armed? | |
| 1799 bsf safety_stop_enabled ; YES - enable safety stop | |
| 634 | 1800 return ; - done |
| 1801 | |
| 1802 | |
| 1803 ;----------------------------------------------------------------------------- | |
| 1804 ; Show Safety Stop | |
| 1805 ; | |
| 623 | 1806 safety_stop_show: |
| 1807 btfss safety_stop_enabled ; safety stop enabled? | |
| 1808 return ; NO - done | |
| 1809 dcfsnz safety_stop_countdown,F ; YES - decrement remaining stop time, reached zero? | |
| 634 | 1810 bra safety_stop_finish ; YES - finished with safety stop and return |
| 623 | 1811 bsf FLAG_TFT_safety_stop_show ; NO - request to show safety stop |
| 1812 return ; - done | |
| 1813 | |
| 634 | 1814 |
| 1815 ;----------------------------------------------------------------------------- | |
| 1816 ; Finish Safety Stop | |
| 1817 ; | |
| 623 | 1818 safety_stop_finish: |
| 634 | 1819 clrf safety_stop_countdown ; disarm safety stop |
| 1820 bcf safety_stop_enabled ; disable safety stop | |
| 1821 bsf FLAG_TFT_safety_stop_clear ; request to clear safety stop | |
| 1822 return ; done | |
| 1823 | |
| 1824 | |
| 1825 ;----------------------------------------------------------------------------- | |
| 1826 ; Check for Timeouts (called by tasks every 1/1 second) | |
| 1827 ; | |
| 1828 timeout_divemode: | |
| 1829 btfss dive_main_menu ; main dive menu shown? | |
| 1830 bra timeout_divemode_1 ; NO - skip | |
| 1831 btfsc trigger_timeout ; YES - timeout occurred? | |
| 1832 rcall divemenu_cleanup ; YES - clean up main menu and restore dive data | |
| 1833 | |
| 1834 timeout_divemode_1: | |
| 1835 btfss dive_pre_menu ; pre-menu shown? | |
| 1836 bra timeout_divemode_2 ; NO - skip | |
| 1837 btfsc trigger_timeout ; YES - timeout occurred? | |
| 1838 call menuview_toggle_reset ; YES - terminate the pre-menu | |
| 1839 | |
| 1840 timeout_divemode_2: | |
| 640 | 1841 INCI dive_timeout_timer ; increment timeout timer |
| 1842 | |
| 634 | 1843 btfss divetime_longer_1min ; does the dive already last for longer than one minute? |
| 640 | 1844 bra timeout_divemode_sub_1min ; NO - use a short timeout to achieve some extra hysteris when starting the dive |
| 634 | 1845 |
| 1846 btfsc FLAG_apnoe_mode ; in apnoe mode? | |
| 1847 bra timeout_divemode_apnoe ; YES - use apnoe timeout | |
| 1848 | |
| 1849 IFNDEF _DEBUG | |
| 1850 btfsc sensor_override_active ; in simulator mode? | |
| 1851 bra timeout_divemode_sim ; YES - use simulator timeout | |
| 1852 ENDIF | |
| 1853 | |
| 1854 movff opt_diveTimeout,WREG ; get dive timeout in minutes into WREG | |
| 1855 bra timeout_divemode_com_min ; continue with common part for minutes | |
| 1856 | |
| 1857 timeout_divemode_apnoe: | |
| 1858 movlw apnoe_timeout ; get apnoe timeout in minutes into WREG | |
| 1859 bra timeout_divemode_com_min ; continue with common part for minutes | |
| 1860 | |
| 1861 timeout_divemode_sim: | |
| 1862 MOVLI simulator_timeout,sub_a ; get simulator timeout in seconds directly into sub_a | |
| 1863 bra timeout_divemode_com_sec ; continue with common part for seconds | |
| 1864 | |
| 640 | 1865 timeout_divemode_sub_1min: |
| 1866 MOVLI divetime_less_1min_timeout,sub_a ; use a short timeout as an extra hysteresis during the descent | |
| 1867 bra timeout_divemode_com_sec ; continue with common part for seconds | |
| 1868 | |
| 634 | 1869 timeout_divemode_com_min: |
| 1870 mullw .60 ; multiply with 60 to convert minutes in WREG to seconds | |
| 1871 MOVII PRODL,sub_a ; copy resulting seconds to sub_a | |
| 1872 | |
| 1873 timeout_divemode_com_sec: | |
| 1874 MOVII dive_timeout_timer,sub_b ; copy current timeout timer value to sub_b | |
| 1875 call cmpU16 ; check sub_a - sub_b | |
| 1876 btfsc neg_flag ; result negative, i.e. timeout? | |
| 1877 bcf divemode ; YES - terminate dive mode | |
| 1878 return ; done | |
| 1879 | |
| 1880 | |
| 1881 ;----------------------------------------------------------------------------- | |
| 1882 ; Clean up Dive Menu Area and restore Dive Data | |
| 1883 ; | |
| 1884 divemenu_cleanup: | |
| 631 | 1885 bcf dive_main_menu ; clear flag for dive mode menu shown |
| 1886 call TFT_clear_divemode_menu ; clear menu area | |
| 1887 | |
| 1888 btfss custom_view_locked ; was the custom view locked by the menu system? | |
| 634 | 1889 bra divemenu_cleanup_1 ; NO - continue with redrawing the lower display |
| 1890 bcf custom_view_locked ; YES - release locked | |
| 631 | 1891 movf backup_customview,W ; - get previous custom view into WREG |
| 1892 cpfseq active_customview ; - compare with current custom view, equal? | |
| 1893 call dive_customview_recall ; NO - redraw previous custom view | |
| 1894 | |
| 634 | 1895 divemenu_cleanup_1: |
| 1896 bsf FLAG_TFT_active_gas_divemode; request redraw of gas/setpoint/diluent | |
| 656 | 1897 bsf FLAG_TFT_temperature ; request redraw of temperature |
| 631 | 1898 bcf better_gas_blinking ; stop better gas cue |
| 1899 bcf better_dil_blinking ; stop better dil cue | |
| 634 | 1900 ;bra request_redraw_NDL_deco_data; request redraw of NDL/deco data and return |
| 1901 | |
| 1902 | |
| 1903 ;----------------------------------------------------------------------------- | |
| 1904 ; Request redraw of NDL/Deco Data | |
| 1905 ; | |
| 623 | 1906 request_redraw_NDL_deco_data: |
| 1907 btfsc FLAG_gauge_mode ; in gauge mode? | |
| 1908 return ; YES - done | |
| 1909 btfss decostop_active ; NO - in deco mode? | |
| 1910 bra timeout_divemode_menu_ndl ; NO - show NDL again | |
| 1911 ;bra timeout_divemode_menu_deco ; YES - show deco again | |
| 1912 | |
| 1913 timeout_divemode_menu_deco: | |
| 1914 bsf FLAG_TFT_display_deco_mask ; show deco mask | |
| 1915 bsf FLAG_TFT_display_deco ; show deco stop | |
| 1916 bsf FLAG_TFT_display_tts ; show TTS time | |
| 1917 return ; done | |
| 582 | 1918 |
| 1919 timeout_divemode_menu_ndl: | |
| 623 | 1920 bsf FLAG_TFT_display_ndl_mask ; show NDL mask |
| 1921 bsf FLAG_TFT_display_ndl ; show NDL time | |
| 1922 return ; done | |
| 0 | 1923 |
| 634 | 1924 |
| 1925 ;----------------------------------------------------------------------------- | |
| 1926 ; Check if Dive Mode needs to be started (called from Surface Mode) | |
| 1927 ; | |
| 1928 global check_dive_modes_surf | |
| 1929 check_dive_modes_surf: | |
| 1930 SMOVII pressure_rel_cur,sub_a ; ISR-safe 2 byte copy of current relative pressure to sub_a | |
| 650 | 1931 bcf divetime_longer_1min ; not diving when in surface mode |
| 1932 btfsc cc_active ; charging constant current? | |
| 1933 bra check_dive_modes_shallow ; YES - abort (And reset debounce counter) | |
| 1934 btfsc cv_active ; NO - charging constant voltage? | |
| 1935 bra check_dive_modes_shallow ; YES - abort (And reset debounce counter) | |
| 1936 bra check_dive_modes ; continue with common part | |
| 634 | 1937 |
| 1938 | |
| 1939 ;----------------------------------------------------------------------------- | |
| 1940 ; Check if Dive Mode needs to be finished (called from Dive Loop) | |
| 1941 ; | |
| 1942 check_dive_modes_dive: | |
| 1943 MOVII pressure_rel_cur_cached,sub_a ; copy cached relative pressure to sub_a | |
| 1944 ;bra check_dive_modes ; continue with common part | |
| 1945 | |
| 1946 | |
| 1947 ;----------------------------------------------------------------------------- | |
| 1948 ; Check for Dive Mode Start/Finish - common Part | |
| 1949 ; | |
| 1950 check_dive_modes: | |
| 1951 btfss high_altitude_mode ; in high altitude mode? | |
| 1952 bra check_dive_modes_norm ; NO - use normal start-dive threshold | |
| 1953 btfsc divetime_longer_1min ; YES - diving since > one minute? | |
| 1954 bra check_dive_modes_norm ; YES - this is a real dive -> use normal start-dive threshold | |
| 1955 ;bra check_dive_modes_high ; NO - use hight-altitude start-dive threshold | |
| 1956 | |
| 1957 check_dive_modes_high: | |
| 1958 ; high altitude start/end dive thresholds | |
| 1959 btfss count_divetime ; dive time counting, i.e. already in the dive? | |
| 1960 bra check_dive_modes_high_start ; NO - select start threshold | |
| 1961 ;bra check_dive_modes_high_end ; YES - select end threshold | |
| 1962 | |
| 1963 check_dive_modes_high_end: | |
| 1964 MOVLI dive_threshold_high_alt_end,sub_b ; load high altitude end threshold | |
| 1965 bra check_dive_modes_comm ; continue with common part | |
| 1966 | |
| 1967 check_dive_modes_high_start: | |
| 1968 MOVLI dive_threshold_high_alt_start,sub_b ; load high altitude start threshold | |
| 1969 bra check_dive_modes_comm ; continue with common part | |
| 1970 | |
| 1971 check_dive_modes_norm: | |
| 1972 ; normal altitude start/end dive thresholds | |
| 1973 btfss count_divetime ; dive time counting, i.e. already in the dive? | |
| 1974 bra check_dive_modes_norm_start ; NO - select start threshold | |
| 1975 ;bra check_dive_modes_norm_end ; YES - select end threshold | |
| 1976 | |
| 1977 check_dive_modes_norm_end: | |
| 1978 MOVLI dive_threshold_norm_alt_end,sub_b ; load normal altitude end threshold | |
| 1979 bra check_dive_modes_comm ; continue with common part | |
| 1980 | |
| 650 | 1981 check_dive_modes_norm_start: |
| 634 | 1982 MOVLI dive_threshold_norm_alt_start,sub_b ; load normal altitude start threshold |
| 1983 ;bra check_dive_modes_comm ; continue with common part | |
| 1984 | |
| 1985 check_dive_modes_comm: | |
| 1986 call cmpU16 ; sub_a - sub_b = pressure_rel_cur - start-dive threshold | |
| 1987 btfsc neg_flag ; pressure_rel_cur > dive_threshold, i.e. deeper than threshold? | |
| 1988 bra check_dive_modes_shallow ; NO - shallower than threshold | |
| 1989 btfsc divetime_longer_1min ; YES - diving > one minute? | |
| 1990 CLRI dive_timeout_timer ; YES - reset timeout counter | |
| 645 | 1991 decfsz dive_threshold_debounce,F ; debounce counter |
| 1992 return | |
| 1993 incf dive_threshold_debounce,F | |
| 634 | 1994 bsf divemode ; - set dive mode flag |
| 1995 bsf count_divetime ; - count dive time | |
| 1996 return ; - done | |
| 1997 | |
| 1998 check_dive_modes_shallow: | |
| 645 | 1999 movlw .5 ; load debounce counter |
| 2000 movwf dive_threshold_debounce | |
| 634 | 2001 bcf count_divetime ; stop counting dive time |
| 640 | 2002 ; btfss divetime_longer_1min ; diving > one minute? |
| 2003 ; bcf divemode ; NO - quit dive mode as this was no real dive | |
| 2004 return ; done mH | |
| 631 | 2005 |
| 634 | 2006 |
| 2007 ;----------------------------------------------------------------------------- | |
| 2008 ; Initialize the resettable Depth and Timer | |
| 2009 ; | |
| 2010 resettable_average_depth_init: | |
| 2011 CLRI pressure_rel_avg_trip ; prime the resettable average depth with 0 | |
| 2012 bra resettable_average_depth_common ; clear pressure accumulator and timer | |
| 2013 | |
| 2014 | |
| 2015 ;----------------------------------------------------------------------------- | |
| 2016 ; Reset the resettable Depth and Timer | |
| 2017 ; | |
| 2018 resettable_average_depth_reset: | |
| 2019 bcf request_reset_avg ; clear request | |
| 2020 MOVII pressure_rel_cur_cached,pressure_rel_avg_trip ; prime the resettable average depth | |
| 2021 ; with the current relative pressure (depth) | |
| 2022 ;bra resettable_average_depth_common ; clear pressure accumulator and timer | |
| 2023 | |
| 2024 | |
| 2025 ;----------------------------------------------------------------------------- | |
| 2026 ; Helper Function - common Part for resettable Depth and Timer init/reset | |
| 2027 ; | |
| 2028 resettable_average_depth_common: | |
| 2029 clrf pressure_rel_accu_trip+0 ; clear the resettable depth accumulator | |
| 2030 clrf pressure_rel_accu_trip+1 ; .... | |
| 2031 clrf pressure_rel_accu_trip+2 ; .... | |
| 2032 clrf pressure_rel_accu_trip+3 ; .... | |
| 2033 CLRI divesecs_avg_trip ; clear the resettable time accumulator | |
| 2034 return ; done | |
| 2035 | |
| 2036 | |
| 2037 ;----------------------------------------------------------------------------- | |
| 2038 ; Calculate Average Depth | |
| 2039 ; | |
| 0 | 2040 calc_average_depth: |
| 623 | 2041 ; 1. compute pressure_rel_cur_cached x 2, because this routine is called every 2nd second only |
| 634 | 2042 MOVII pressure_rel_cur_cached,xB ; copy current rel pressure to xB |
| 2043 bcf STATUS,C ; multiply rel pressure x 2 (via shift left) | |
| 2044 rlcf xB+0,F ; ... | |
| 2045 rlcf xB+1,F ; ... | |
| 623 | 2046 |
| 2047 ; 2a add (pressure_rel_cur_cached x 2) to the resettable depth accumulator | |
| 2048 ; will work up to 9999 mbar * 60 * 60 * 24 = 863913600 mbar (24h @ 90 m depth) | |
| 634 | 2049 movf xB+0,W ; pressure_rel_accu_trip += xB |
| 2050 addwf pressure_rel_accu_trip+0,F ; ... | |
| 2051 movf xB+1,W ; ... | |
| 2052 addwfc pressure_rel_accu_trip+1,F ; ... | |
| 2053 movlw .0 ; ... | |
| 2054 addwfc pressure_rel_accu_trip+2,F ; ... | |
| 2055 addwfc pressure_rel_accu_trip+3,F ; ... | |
| 623 | 2056 |
| 2057 ; 2b add (pressure_rel_cur_cached x 2) to the total depth accumulator | |
| 2058 ; will work up to 9999 mbar * 60 * 60 * 24 = 863913600 mbar (24h @ 90 m depth) | |
| 634 | 2059 movf xB+0,W ; pressure_rel_accu_total += xB |
| 2060 addwf pressure_rel_accu_total+0,F ; ... | |
| 2061 movf xB+1,W ; ... | |
| 2062 addwfc pressure_rel_accu_total+1,F ; ... | |
| 2063 movlw .0 ; ... | |
| 2064 addwfc pressure_rel_accu_total+2,F ; ... | |
| 2065 addwfc pressure_rel_accu_total+3,F ; ... | |
| 623 | 2066 |
| 2067 ; 3a compute the resettable average depth | |
| 634 | 2068 movff pressure_rel_accu_trip+0,xC+0 ; get the accumulated depth |
| 2069 movff pressure_rel_accu_trip+1,xC+1 ; ... | |
| 2070 movff pressure_rel_accu_trip+2,xC+2 ; ... | |
| 2071 movff pressure_rel_accu_trip+3,xC+3 ; ... | |
| 2072 MOVII divesecs_avg_trip,xB ; get the accumulated time | |
| 623 | 2073 |
| 2074 ; divide accumulated depth by accumulated time | |
| 604 | 2075 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder |
| 623 | 2076 |
| 2077 ; store result | |
| 2078 MOVII xC,pressure_rel_avg_trip ; resettable average depth | |
| 2079 btfss count_divetime ; is dive time counted? | |
| 604 | 2080 return ; NO (e.g. too shallow) |
| 2081 | |
| 623 | 2082 ; 3b compute the dive total average depth |
| 634 | 2083 movff pressure_rel_accu_total+0,xC+0 ; get accumulated depth |
| 2084 movff pressure_rel_accu_total+1,xC+1 ; ... | |
| 2085 movff pressure_rel_accu_total+2,xC+2 ; ... | |
| 2086 movff pressure_rel_accu_total+3,xC+3 ; ... | |
| 2087 MOVII divesecs_avg_total,xB ; get accumulated time | |
| 623 | 2088 |
| 2089 ; divide accumulated depth by accumulated time | |
| 2090 call div32x16 ; xC:4 = xC:4 / xB:2 with xA as remainder | |
| 2091 | |
| 2092 ; store result | |
| 2093 MOVII xC,pressure_rel_avg_total ; total dive average depth | |
| 2094 | |
| 2095 btfsc request_reset_avg ; shall reset the resettable average depth? | |
| 634 | 2096 rcall resettable_average_depth_reset ; YES - reset the resettable average depth |
| 623 | 2097 |
| 2098 TSTOSC opt_2ndDepthDisp ; drawing average depth instead of max depth? | |
| 2099 bsf FLAG_TFT_depth_maximum ; YES - flag to update display | |
| 2100 | |
| 2101 btfsc FLAG_gauge_mode ; in gauge mode? | |
| 2102 bsf FLAG_TFT_depth_maximum ; YES - flag to update display (needed for alternative layout) | |
| 2103 | |
| 2104 return ; done | |
| 2105 | |
| 2106 | |
| 634 | 2107 ;----------------------------------------------------------------------------- |
| 2108 ; Check Switches, execute Pre-Menu Items (called every second) | |
| 2109 ; | |
| 2110 test_switches_divemode: | |
| 623 | 2111 btfsc dive_main_menu ; dive mode menu shown? |
| 604 | 2112 bra test_switches_divemode_menu ; YES - use menu processor |
| 2113 btfsc switch_left ; NO - left button pressed? | |
| 634 | 2114 goto menuview_toggle ; YES - step through pre-menu |
| 604 | 2115 btfss switch_right ; NO - right button pressed? |
| 2116 return ; NO - done | |
| 623 | 2117 bcf switch_right ; YES - clear button event |
| 2118 tstfsz active_premenu ; - any pre-menu task selected? | |
| 634 | 2119 bra test_switches_divemode1 ; YES - execute a pre-menu item |
| 623 | 2120 bsf request_next_custview ; NO - request next custom view |
| 604 | 2121 return ; - done |
| 0 | 2122 |
| 2123 test_switches_divemode_menu: | |
| 623 | 2124 btfsc switch_left ; left button pressed? |
| 2125 bra test_switches_divemode_menu2 ; YES - move cursor | |
| 2126 btfsc switch_right ; NO - right button pressed? | |
| 634 | 2127 bra test_switches_divemode_menu3 ; YES - do a menu operation |
| 623 | 2128 btfss update_menu ; NO - shall update the menu? |
| 2129 return ; NO - done | |
| 2130 bcf update_menu ; YES - clear request | |
| 2131 goto menu_draw_lines_divemode ; - redraw the menu (to update color coding) and return | |
| 0 | 2132 |
| 2133 test_switches_divemode_menu1: | |
| 634 | 2134 clrf menu_pos_cur ; reset menu item number to zero |
| 0 | 2135 test_switches_divemode_menu2: |
| 634 | 2136 bcf switch_left ; clear left button event |
| 2137 incf menu_pos_cur,F ; increment menu item number | |
| 2138 incf menu_pos_max,W ; get number of items + 1 into WREG | |
| 2139 cpfslt menu_pos_cur ; incremented item number > number of items ? | |
| 2140 bra test_switches_divemode_menu1 ; YES - restart from first item | |
| 2141 call menu_draw_cursor_dive ; draw cursor at new position | |
| 623 | 2142 movlw divemode_timeout_mainmenu ; get timeout for main menu |
| 634 | 2143 call restart_timeout_time ; restart the timeout |
| 2144 return ; done | |
| 2145 | |
| 2146 test_switches_divemode_menu3: | |
| 2147 bcf switch_right ; clear right button event | |
| 2148 goto do_line_menu ; Warning! trashes STKPTR and returns to | |
| 2149 ; divemode_option_divemenu_return | |
| 0 | 2150 |
| 2151 test_switches_divemode1: | |
| 634 | 2152 movlw divemode_timeout_premenu ; get timeout for pre-menu |
| 2153 call restart_timeout_time ; restart the timeout | |
| 2154 movf active_premenu,W ; get active pre-menu item | |
| 0 | 2155 dcfsnz WREG,F |
| 634 | 2156 bra divemode_option_gaschange ; 1: switch to the the "better gas" / "better diluent" |
| 137 | 2157 dcfsnz WREG,F |
| 634 | 2158 bra divemode_option_ackn ; 2: acknowledge current advice, attention, or warning |
| 2159 dcfsnz WREG,F | |
| 2160 bra divemode_option_divemenu ; 3: enter dive mode menu | |
| 0 | 2161 dcfsnz WREG,F |
| 631 | 2162 IFDEF _cave_mode |
| 634 | 2163 bra divemode_option_cavemenu ; 4: enter cave mode menu |
| 631 | 2164 ELSE |
| 634 | 2165 return ; 4: (no cave mode compiled in) |
| 2166 ENDIF | |
| 2167 dcfsnz WREG,F | |
| 2168 bra divemode_option_sim_quit ; 5: quit simulator mode | |
| 2169 dcfsnz WREG,F | |
| 2170 bra divemode_option_sim_down ; 6: simulator mode - descent | |
| 2171 dcfsnz WREG,F | |
| 2172 bra divemode_option_sim_up ; 7: simulator mode - ascend | |
| 2173 dcfsnz WREG,F | |
| 2174 bra divemode_option_sim_time ; 8: simulator mode - +5 min | |
| 2175 dcfsnz WREG,F | |
| 2176 bra divemode_option_apnoe_quit ; 9: quit apnoe dive | |
| 2177 dcfsnz WREG,F | |
| 2178 bra divemode_option_gauge_reset ; 10: reset stopwatch and avg depth (gauge mode) | |
| 2179 dcfsnz WREG,F | |
| 2180 IFDEF _compass | |
| 2181 bra divemode_option_course ; 11: set bearing | |
| 2182 ELSE | |
| 2183 return ; 11: (no compass compiled in) | |
| 631 | 2184 ENDIF |
| 0 | 2185 dcfsnz WREG,F |
| 634 | 2186 bra divemode_option_layout ; 12: switch layout |
| 2187 return ; catch illegal item number | |
| 2188 | |
| 2189 | |
| 2190 ; item 1: switch to the the "better gas" / "better diluent" | |
| 2191 ; | |
| 2192 divemode_option_gaschange: | |
| 2193 IFDEF _ccr_pscr | |
| 2194 btfsc FLAG_oc_mode ; in OC mode? | |
| 2195 bra divemode_option_gaschange_oc ; YES | |
| 2196 btfsc bailout_mode ; in bailout? | |
| 2197 bra divemode_option_gaschange_oc ; YES | |
| 2198 | |
| 2199 ; in CCR/pSCR mode and not in bailout | |
| 2200 movff best_dil_number,menu_pos_cur ; select best diluent | |
| 2201 bcf better_dil_available ; clear flag immediately | |
| 2202 bra divemode_option_gaschange3 ; continue with common part | |
| 2203 ENDIF | |
| 2204 divemode_option_gaschange_oc: | |
| 2205 movff best_gas_number,menu_pos_cur ; select best gas | |
| 2206 bcf better_gas_available ; clear better gas cue | |
| 2207 | |
| 2208 divemode_option_gaschange3 | |
| 2209 bsf request_gas_change ; request a gas/diluent change | |
| 2210 goto menuview_toggle_reset ; terminate the pre-menu (and return) | |
| 2211 | |
| 2212 | |
| 2213 ; item 2: acknowledge current advice, attention, or warning | |
| 2214 ; | |
| 2215 divemode_option_ackn: | |
| 2216 btfss sign_warning ; any warning active? | |
| 2217 bra divemode_option_ackn_attn ; NO - check for active attentions | |
| 2218 movff DM_flags_war1_det,DM_flags_war1_ack ; YES - memorize active warnings as acknowledged | |
| 2219 movff DM_flags_war2_det,DM_flags_war2_ack ; - ... | |
| 2220 bra divemode_option_ackn_common ; - update screen | |
| 2221 | |
| 2222 divemode_option_ackn_attn: | |
| 2223 btfss sign_attention ; any attention active? | |
| 2224 bra divemode_option_ackn_advc ; NO - must be active advice then | |
| 2225 movff DM_flags_att1_det,DM_flags_att1_ack ; YES - memorize active attentions as acknowledged | |
| 2226 movff DM_flags_att2_det,DM_flags_att2_ack ; - ... | |
| 2227 movff DM_flags_att3_det,DM_flags_att3_ack ; - ... | |
| 2228 bra divemode_option_ackn_common ; - update screen | |
| 2229 | |
| 2230 divemode_option_ackn_advc: | |
| 2231 movff DM_flags_advc_det,DM_flags_advc_ack ; memorize active advices as acknowledged | |
| 2232 ;bra divemode_option_ackn_common ; update screen | |
| 2233 | |
| 2234 divemode_option_ackn_common: | |
| 2235 call menuview_toggle_reset ; terminate pre-menu | |
| 2236 call divemode_check_sign ; compute if the advice / attention / warning sign shall be shown | |
| 2237 btfsc FLAG_TFT_sign_show ; shall show the advice / attention / warning sign? | |
| 2238 goto TFT_divemode_sign_show ; YES - show sign and return | |
| 2239 goto TFT_divemode_sign_clear ; NO - clear sign and return | |
| 2240 | |
| 2241 | |
| 2242 ; item 3: enter dive mode menu | |
| 2243 ; | |
| 2244 divemode_option_divemenu: | |
| 2245 btfss divemode ; in dive mode? | |
| 2246 goto menuview_toggle_reset ; NO - block menu, terminate the pre-menu | |
| 2247 call TFT_clear_divemode_menu ; YES - clear menu area | |
| 2248 bcf dive_pre_menu ; - set pre-menu as not shown anymore | |
| 2249 goto do_main_divemenu ; - hand over to menu processor | |
| 2250 | |
| 2251 | |
| 2252 ; item 4: enter cave mode menu | |
| 2253 ; | |
| 2254 IFDEF _cave_mode | |
| 2255 divemode_option_cavemenu: | |
| 2256 btfss divemode ; in dive mode? | |
| 2257 goto menuview_toggle_reset ; NO - block menu, terminate the pre-menu | |
| 2258 call TFT_clear_divemode_menu ; YES - clear menu area | |
| 2259 bcf dive_pre_menu ; - set pre-menu as not shown anymore | |
| 2260 goto do_main_cavemenu ; - hand over to menu processor | |
| 2261 ENDIF | |
| 2262 | |
| 2263 | |
| 2264 ; item 5: quit simulator mode | |
| 2265 ; | |
| 2266 divemode_option_sim_quit: | |
| 2267 clrf simulatormode_depth ; set target depth to zero | |
| 2268 bsf quit_simulatormode ; request ISR to end simulator mode | |
| 2269 call menuview_toggle_reset ; terminate the pre-menu | |
| 2270 btfsc FLAG_apnoe_mode ; in apnoe mode? | |
| 2271 bcf divemode ; YES - force end of dive mode | |
| 2272 return ; done | |
| 2273 | |
| 2274 | |
| 2275 ; item 6: simulator mode - descent 1 meter | |
| 2276 ; | |
| 2277 divemode_option_sim_down: | |
| 2278 movlw ostc_depth_max-1 ; load depth limit into WREG | |
| 2279 cpfsgt simulatormode_depth ; simulated depth < limit ? | |
| 2280 incf simulatormode_depth,F ; YES - increment simulated depth | |
| 2281 return ; done | |
| 2282 | |
| 2283 | |
| 2284 ; item 7: simulator mode - ascent 1 meter | |
| 2285 ; | |
| 2286 divemode_option_sim_up: | |
| 2287 tstfsz simulatormode_depth ; simulated depth > 0 ? | |
| 2288 decf simulatormode_depth,F ; YES - decrement simulated depth | |
| 2289 return ; done | |
| 2290 | |
| 2291 | |
| 2292 ; item 8: simulator mode - +5 min | |
| 2293 ; | |
| 2294 divemode_option_sim_time: | |
| 2295 movff char_I_sim_advance_time,WREG ; get mailbox content | |
| 2296 tstfsz WREG ; mailbox clear (=0) ? | |
| 2297 return ; NO - still having a pending +5' request, refuse new request | |
| 2298 bra advance_time ; YES - advance time and return | |
| 2299 | |
| 2300 | |
| 2301 ; item 9: quit apnoe dive | |
| 2302 ; | |
| 2303 divemode_option_apnoe_quit: | |
| 2304 btfsc sensor_override_active ; in simulator mode? | |
| 2305 bra divemode_option_sim_quit ; YES - use simulator quit procedure | |
| 2306 bcf divemode ; NO - force end of dive mode | |
| 2307 return ; - done | |
| 2308 | |
| 2309 | |
| 2310 ; item 10: reset stopwatch and avg depth (gauge mode only) | |
| 2311 ; | |
| 2312 divemode_option_gauge_reset: | |
| 2313 bsf request_reset_avg ; request reset of average depth | |
| 2314 goto menuview_toggle_reset ; terminate pre-menu and return | |
| 2315 | |
| 2316 | |
| 2317 ; item 11: set bearing | |
| 2318 ; | |
| 623 | 2319 IFDEF _compass |
| 634 | 2320 divemode_option_course: |
| 2321 MOVII compass_heading_shown,compass_bearing | |
| 656 | 2322 CLRI divesecs_compass_trip |
| 634 | 2323 bsf compass_bearing_set ; set flag to show heading |
| 2324 goto menuview_toggle_reset ; terminate the pre-menu and return | |
| 623 | 2325 ENDIF |
| 634 | 2326 |
| 2327 | |
| 2328 ; item 12: switch layout | |
| 2329 ; | |
| 2330 divemode_option_layout: | |
| 2331 call menuview_toggle_reset ; terminate the pre-menu | |
| 2332 call TFT_ClearScreen ; clear the whole screen | |
| 2333 btg alt_layout_active ; toggle layout | |
| 2334 | |
| 2335 bcf depth_color_last ; set warning or attention on the depth not shown | |
| 2336 bcf depth_inverse_last ; set depth displayed in inverse as not shown | |
| 2337 bcf sign_shown ; set warning/attention/advice sign not shown | |
| 2338 bcf velocity_active_num ; set numerical vertical velocity display not shown | |
| 2339 bcf velocity_active_vsi ; set vertical vertical velocity display not shown | |
| 2340 bcf safety_stop_active ; set safety stop not shown | |
| 2341 | |
| 2342 bsf FLAG_TFT_divemode_mask ; request redraw of dive screen mask | |
| 2343 bsf FLAG_TFT_divetime ; request redraw of dive time | |
| 2344 bsf FLAG_TFT_depth_current ; request redraw of current depth | |
| 2345 bsf FLAG_TFT_depth_maximum ; request redraw of maximum depth | |
| 2346 bsf FLAG_TFT_active_gas_divemode; request redraw of gas and setpoint | |
| 2347 bsf FLAG_TFT_temperature ; request redraw of temperature | |
| 2348 bsf FLAG_TFT_customview_callup ; request redraw of custom view | |
| 2349 | |
| 2350 goto request_redraw_NDL_deco_data; request redraw of NDL/deco data and return | |
| 2351 | |
| 2352 | |
| 2353 ;----------------------------------------------------------------------------- | |
| 2354 ; Helper Function - advance Time by 5 Minutes (Simulator Mode) | |
| 2355 ; | |
| 2356 advance_time: | |
| 2357 ; advance tissues pressures and deco obligation by 5 minutes | |
| 2358 movlw .5 ; + 5 minutes | |
| 2359 movff WREG,char_I_sim_advance_time ; copy to mailbox | |
| 2360 call restart_deco_engine ; condition deco engine to execute the +5 minutes | |
| 2361 | |
| 2362 bcf count_divetime ; stop dive time incrementing in ISR | |
| 2363 ADDLI .5,counted_divetime_mins ; add 5 minutes to counted_divetime_mins | |
| 2364 ADDLI .300,total_divetime_secs ; add 5 minutes (300 seconds) to total_divetime_secs | |
| 2365 bsf count_divetime ; continue dive time incrementing in ISR | |
| 2366 | |
| 2367 ADDLI .300,divesecs_avg_trip ; add 5 minutes (300 seconds) to resettable time accumulator | |
| 2368 ADDLI .300,divesecs_avg_total ; add 5 minutes (300 seconds) to total time accumulator | |
| 656 | 2369 ADDLI .300,divesecs_compass_trip ; add 5 minutes (300 seconds) to compass stopwatch accumulator |
| 634 | 2370 |
| 2371 MOVII pressure_rel_cur_cached,xB ; calculate 300 x depth in mbar (300 = 5 min * 60 sec/min) | |
| 2372 MOVLI .300,xA ; ... | |
| 2373 call mult16x16 ; xC = xA * xB | |
| 2374 | |
| 2375 movf xC+0,W ; add to the resettable depth accumulator | |
| 2376 addwf pressure_rel_accu_trip+0,F ; ... | |
| 2377 movf xC+1,W ; ... | |
| 2378 addwfc pressure_rel_accu_trip+1,F ; ... | |
| 2379 movf xC+2,W ; ... | |
| 2380 addwfc pressure_rel_accu_trip+2,F ; ... | |
| 2381 movf xC+3,W ; ... | |
| 2382 addwfc pressure_rel_accu_trip+3,F ; ... | |
| 2383 | |
| 2384 movf xC+0,W ; add to the total depth accumulator | |
| 2385 addwf pressure_rel_accu_total+0,F ; ... | |
| 2386 movf xC+1,W ; ... | |
| 2387 addwfc pressure_rel_accu_total+1,F ; ... | |
| 2388 movf xC+2,W ; ... | |
| 2389 addwfc pressure_rel_accu_total+2,F ; ... | |
| 2390 movf xC+3,W ; ... | |
| 2391 addwfc pressure_rel_accu_total+3,F ; ... | |
| 2392 | |
| 2393 IFDEF _cave_mode | |
| 2394 ; update backtracking data | |
| 2395 btfss cave_mode ; cave mode switched on? | |
| 2396 bra divemode_option_sim_time_exit ; NO - skip backtracking depth recording | |
| 2397 btfsc dive_turned ; YES - dive turned? | |
| 2398 bra divemode_option_sim_time_exit ; YES - skip backtracking depth recording | |
| 2399 ;bra divemode_option_sim_time_exec ; NO - update backtracking depth recording | |
| 2400 | |
| 2401 divemode_option_sim_time_exec: | |
| 2402 movff backtrack_deltatime,hi ; backup time elapsed since last depth recording | |
| 2403 movlw .5 ; configure 5 minutes | |
| 2404 movwf lo ; use lo as loop counter | |
| 2405 | |
| 2406 divemode_option_sim_time_loop: | |
| 2407 call write_backtrack_1min_depth ; store a backtracking depth data set | |
| 2408 btfsc backtrack_entire_full ; backtracking storage entirely used up? | |
| 2409 bra divemode_option_sim_time_exit ; YES - abort backtracking depth recording | |
| 2410 decfsz lo,F ; NO - decrement loop counter, did it became zero? | |
| 2411 bra divemode_option_sim_time_loop ; NO - loop | |
| 2412 ;bra divemode_option_sim_time_done ; YES - done | |
| 2413 | |
| 2414 divemode_option_sim_time_done: | |
| 2415 movff hi,backtrack_deltatime ; restore time elapsed since last depth recording | |
| 2416 ENDIF ; _cave_mode | |
| 2417 | |
| 2418 divemode_option_sim_time_exit: | |
| 2419 return ; done (leaving option avail for repeated selection) | |
| 2420 | |
| 2421 | |
| 2422 ;----------------------------------------------------------------------------- | |
| 2423 ; Change Gas / Diluent | |
| 2424 ; | |
| 631 | 2425 gas_switch_common: |
| 634 | 2426 bcf request_gas_change ; clear request flag |
| 623 | 2427 IFDEF _ccr_pscr |
| 634 | 2428 btfss request_back_to_loop ; is a switchback from OC bailout to loop requested? |
| 2429 bra gas_switched_common0 ; NO - continue with checking if selected gas is valid | |
| 2430 bcf request_back_to_loop ; YES - clear flag | |
| 2431 movff active_dil,menu_pos_cur ; - reload last diluent | |
| 2432 bra gas_switched_common1 ; - continue with common part | |
| 623 | 2433 ENDIF |
| 582 | 2434 gas_switched_common0: |
| 634 | 2435 tstfsz menu_pos_cur ; menu_pos_cur = 0 ? |
| 2436 bra gas_switched_common1 ; NO - valid gas | |
| 2437 return ; YES - something went wrong, invalid gas, abort | |
| 560 | 2438 gas_switched_common1: |
| 634 | 2439 movf menu_pos_cur,W ; get selected gas into WREG (1-5) |
| 623 | 2440 IFDEF _ccr_pscr |
| 634 | 2441 btfsc FLAG_oc_mode ; in OC mode? |
| 2442 bra gas_switched_common_OC ; YES | |
| 2443 btfsc bailout_mode ; in bailout? | |
| 2444 bra gas_switched_common_OC ; YES | |
| 2445 gas_switched_common_loop: ; NO to both - must be loop mode then | |
| 2446 call setup_dil_registers ; set up real tissues with WREG = diluent 1-6 | |
| 2447 call deco_setup_cc_diluents ; set up deco planning with WREG = diluent 1-6 | |
| 2448 bra gas_switched_common3 ; continue with common part | |
| 631 | 2449 ENDIF ; _ccr_pscr |
| 634 | 2450 |
| 604 | 2451 gas_switched_common_OC: |
| 634 | 2452 call setup_gas_registers ; set up real tissues with WREG = gas 1-6 |
| 2453 call deco_setup_oc_gases ; set up deco planning with WREG = gas 1-6 | |
| 2454 ;bra gas_switched_common3 ; continue with common part | |
| 2455 | |
| 560 | 2456 gas_switched_common3: |
| 605 | 2457 banksel int_O_breathed_ppO2 |
| 2458 bcf int_O_breathed_ppO2+1,int_low_flag ; | clear all flags that control color-coding | |
| 2459 bcf int_O_breathed_ppO2+1,int_high_flag ; | to have the new gas initially displayed in | |
| 2460 bcf int_O_breathed_ppO2+1,int_attention_flag ; | memo color instead of a warning or attention | |
| 2461 bcf int_O_breathed_ppO2+1,int_warning_flag ; | color that belonged to the previous gas | |
| 2462 banksel common | |
| 631 | 2463 bsf FLAG_TFT_active_gas_divemode ; redraw gas/setpoint/diluent |
| 2464 bsf FLAG_TFT_temperature ; redraw temperature | |
| 2465 bsf event_occured ; set global event flag | |
| 623 | 2466 IFDEF _ccr_pscr |
| 631 | 2467 btfsc bailout_mode ; in bailout mode? |
| 2468 bsf event_bailout ; YES - set bailout event | |
| 2469 btfss bailout_mode ; in bailout mode? | |
| 623 | 2470 ENDIF |
| 631 | 2471 bsf event_gas_change ; (NO) - set gas change event (normal change) |
| 2472 goto restart_deco_engine_wo_ceiling ; abort running deco calculations and restart (and return) | |
| 2473 | |
| 2474 | |
| 634 | 2475 ;----------------------------------------------------------------------------- |
| 2476 ; Reload the current Gas / Diluent | |
| 2477 ; | |
| 631 | 2478 gas_update_common: |
| 2479 bcf request_gas_update ; reset the request flag | |
| 2480 movf active_gas,W ; load WREG with currently used gas | |
| 2481 IFDEF _ccr_pscr | |
| 2482 btfsc FLAG_oc_mode ; in OC mode? | |
| 2483 bra gas_switched_common_OC ; YES - reload OC gases | |
| 2484 btfsc bailout_mode ; NO - in bailout? | |
| 2485 bra gas_switched_common_OC ; YES - reload OC gases | |
| 2486 movf active_dil,W ; NO - load WREG with currently used diluent | |
| 2487 bra gas_switched_common_loop ; - set up diluent gases | |
| 2488 ELSE | |
| 2489 bra gas_switched_common_OC ; reload OC gases | |
| 2490 ENDIF | |
| 560 | 2491 |
| 634 | 2492 |
| 2493 ;----------------------------------------------------------------------------- | |
| 2494 ; Toggle GF/aGF (finalization) | |
| 2495 ; | |
| 2496 divemodemode_togglegf: | |
| 2497 bcf request_toggle_GF ; clear request flag | |
| 2498 goto restart_deco_engine ; restart the deco engine and return | |
| 2499 | |
| 2500 | |
| 2501 ;----------------------------------------------------------------------------- | |
| 2502 ; Set a Marker in the Dive Profile | |
| 2503 ; | |
| 2504 set_logbook_marker: | |
| 2505 bcf request_set_marker ; clear request flag | |
| 2506 movlw d'6' ; set type of alarm: manual marker | |
| 2507 movwf alarm_type ; copy to alarm register | |
| 2508 bsf event_occured ; set event flag | |
| 631 | 2509 return ; done |
| 0 | 2510 |
| 634 | 2511 |
| 2512 ;----------------------------------------------------------------------------- | |
| 604 | 2513 ; Find the best gas and diluent for the current depth |
| 2514 ; and check if a gas/diluent change is to be advised. | |
| 2515 ; | |
| 2516 ; Output: best_gas_number : number of best gas, 0= none avail, 255= not computed | |
| 2517 ; best_dil_number : number of best dil, 0= none avail, 255= not computed | |
| 2518 ; better_gas_available : flag indicating if a change is advised | |
| 2519 ; better_dil_available : flag indicating if a change is advised | |
| 2520 ; | |
| 2521 ; | |
| 2522 ; in CCR and pSCR mode: - checks both, gases and diluents for respective best gas / best diluent | |
| 2523 ; - if not in bailout, sets better_dil_available on diluents | |
| 2524 ; - if in bailout, sets better_gas_available on OC gases | |
| 2525 ; | |
| 2526 ; in OC mode : - checks only gases for best gas | |
| 2527 ; - sets better_gas_available on OC gases | |
| 0 | 2528 ; |
| 628 | 2529 global check_gas_best |
| 604 | 2530 check_gas_best: |
| 623 | 2531 btfsc FLAG_gauge_mode ; in gauge mode? |
| 2532 return ; YES - done | |
| 2533 | |
| 2534 MOVII pressure_abs_10,xA ; copy absolute pressure / 10 into xA:2, will be used by ppO2 min/max checks later | |
| 2535 | |
| 2536 ; compute max. allowed deco ppO2 | |
| 2537 movff char_I_ppO2_max_deco,WREG ; max ppO2 [cbar] for deco phase | |
| 2538 mullw .100 ; compute max ppO2 * 100, result is in 0.1 mbar | |
| 2539 ADDLI ppO2_margin_on_max,PROD ; add ppO2 margin on max value to compensate for surface pressures > 1000 hPa | |
| 2540 MOVII PROD,ppO2_max_deco ; store as deco ppO2 max | |
| 2541 | |
| 2542 ; compute max. allowed default ppO2 | |
| 604 | 2543 movff char_O_deco_info,lo ; bank-safe copy of deco info vector |
| 628 | 2544 btfss lo,deco_mode ; is the ppO2 deco limit enabled? |
| 623 | 2545 bra check_gas_best_1 ; NO - compute default ppO2 max |
| 2546 MOVII ppO2_max_deco,ppO2_max_default ; YES - copy default ppO2 max from deco max. | |
| 2547 bra check_gas_best_2 ; - continue with common part | |
| 2548 | |
| 2549 check_gas_best_1: | |
| 2550 movff char_I_ppO2_max_work,WREG ; max ppO2 [cbar] for working phase | |
| 2551 mullw .100 ; compute max ppO2 * 100, result is in 0.1 mbar | |
| 2552 ADDLI ppO2_margin_on_max,PROD ; add ppO2 margin on max value to compensate for surface pressures > 1000 hPa | |
| 2553 MOVII PROD,ppO2_max_default ; store as default ppO2 max | |
| 2554 | |
| 2555 check_gas_best_2: | |
| 2556 | |
| 2557 IFDEF _ccr_pscr | |
| 604 | 2558 ; check dive mode |
| 2559 btfsc FLAG_oc_mode ; in OC mode? | |
| 2560 bra check_gas_best_gas ; YES - skip diluents, check for best gas only | |
| 2561 | |
| 2562 check_gas_best_dil: | |
| 2563 ; set minimum ppO2 required | |
| 2564 movff char_I_ppO2_min,WREG ; min ppO2 for pure diluent in CCR mode (default) | |
| 2565 btfsc FLAG_pscr_mode ; in pSCR mode? | |
| 623 | 2566 movff char_I_ppO2_min_loop,WREG ; YES - replace by min ppO2 for pure diluent in pSCR mode |
| 2567 mullw .100 ; min ppO2 * 100, result in 0.1 mbar | |
| 2568 MOVII PROD,ppO2_min ; store in ppO2_min | |
| 631 | 2569 ; check diluents |
| 604 | 2570 lfsr FSR1,opt_dil_O2_ratio ; set base address for diluent arrays |
| 631 | 2571 movff active_dil,lo ; set number of currently used diluent |
| 2572 ; preset result to nothing found | |
| 2573 clrf best_gas_num ; initialize best diluent to 0 = none found yet | |
| 2574 setf best_gas_depth ; initialize change depth to 255 = any one will be better | |
| 2575 ; check if current diluent is usable | |
| 2576 movff lo,check_gas_num ; check if the current diluent is usable | |
| 2577 rcall check_gas_best_common ; if yes, the current diluent will become the best diluent found so far | |
| 2578 rcall check_gas_best_all ; check if any other diluent is better | |
| 604 | 2579 ; store result |
| 2580 movff best_gas_num,best_dil_number ; store new best diluent found (1-5 or 0 of no usable diluent available) | |
| 2581 ; check if change advices shall be given in general | |
| 623 | 2582 btfsc bailout_mode ; in bailout? |
| 604 | 2583 bra check_gas_best_gas ; YES - no better diluent advice when in bailout |
| 2584 check_gas_best_dil1: | |
| 2585 ; check if a change advice shall be given right now | |
| 631 | 2586 bcf better_dil_available ; default to no better diluent found |
| 604 | 2587 movf best_dil_number,W ; load number of best diluent into WREG (1-5) |
| 2588 bz check_gas_best_dil3 ; has a best diluent been found at all? NO - nothing to signal for | |
| 2589 cpfseq active_dil ; is this the currently used diluent? | |
| 631 | 2590 bra check_gas_best_dil2 ; NO - a better diluent has been found |
| 604 | 2591 bra check_gas_best_dil3 ; YES - no need to signal a better diluent if this diluent is already in use |
| 2592 check_gas_best_dil2: | |
| 634 | 2593 btfsc warn_det_sensors_lost ; all sensors lost? |
| 604 | 2594 bra check_gas_best_dil3 ; YES - suppress better diluent prompt in this case |
| 2595 ; not using the best gas - show better diluent hint whenever a better diluent is available | |
| 2596 bsf better_dil_available ; signal that a better diluent is available | |
| 2597 bsf FLAG_TFT_active_gas_divemode ; redraw gas/setpoint/diluent | |
| 2598 check_gas_best_dil3: | |
| 2599 btfss better_dil_available ; shall a better diluent be signaled for? | |
| 623 | 2600 bcf better_dil_blinking ; NO - clear blinking flag |
| 631 | 2601 ;bra check_gas_best_gas ; ; continue with checking for best bailout gas |
| 623 | 2602 ENDIF ; _ccr_pscr |
| 2603 | |
| 631 | 2604 |
| 604 | 2605 check_gas_best_gas: |
| 2606 ; set minimum ppO2 required | |
| 628 | 2607 movff char_I_ppO2_min,WREG ; min ppO2 for OC and bailout |
| 623 | 2608 mullw .100 ; min ppO2 * 100, result in 0.1 mbar |
| 2609 MOVII PROD,ppO2_min ; store in ppO2_min | |
| 631 | 2610 ; check gases |
| 604 | 2611 lfsr FSR1,opt_gas_O2_ratio ; set base address for gas arrays |
| 631 | 2612 movff active_gas,lo ; set number of currently used gas |
| 2613 ; preset result to nothing found | |
| 2614 clrf best_gas_num ; initialize best gas to 0 = none found yet | |
| 2615 setf best_gas_depth ; initialize change depth to 255 = any one will be better | |
| 2616 ; check if current gas is usable | |
| 2617 movff lo,check_gas_num ; check if the current gas is usable | |
| 2618 rcall check_gas_best_common ; if yes, the current gas will become the best gas found so far | |
| 2619 rcall check_gas_best_all ; check if any other gas is better | |
| 604 | 2620 ; store result |
| 2621 movff best_gas_num,best_gas_number ; store new best gas found (1-5 or 0 of no usable gas available) | |
| 631 | 2622 IFDEF _ccr_pscr |
| 604 | 2623 ; check if change advices shall be given in general |
| 2624 btfsc FLAG_oc_mode ; in OC mode? | |
| 631 | 2625 bra check_gas_best_gas1 ; YES - give advice |
| 2626 btfsc bailout_mode ; NO - in bailout? | |
| 2627 bra check_gas_best_gas1 ; YES - give advice | |
| 2628 return ; NO - no better (OC) gas advice when not in OC or bailout mode | |
| 2629 ENDIF ; _ccr_pscr | |
| 604 | 2630 check_gas_best_gas1: ; check if we are already on the best gas |
| 2631 ; check if a change advice shall be given right now | |
| 631 | 2632 bcf better_gas_available ; default to no better gas found |
| 604 | 2633 movf best_gas_number,W ; load number of best gas into WREG (1-5) |
| 2634 bz check_gas_best_gas3 ; has a best gas been found at all? NO - nothing to signal for | |
| 2635 cpfseq active_gas ; is this the currently used gas? | |
| 631 | 2636 bra check_gas_best_gas2 ; NO - a better gas has been found |
| 604 | 2637 bra check_gas_best_gas3 ; YES - no need to signal a better gas if this gas is already in use |
| 2638 check_gas_best_gas2: | |
| 2639 ; not using the best gas - show better gas hint whenever a better gas is available | |
| 2640 bsf better_gas_available ; YES - signal that a better gas is available | |
| 2641 bsf FLAG_TFT_active_gas_divemode ; YES - redraw gas/setpoint/diluent | |
| 2642 check_gas_best_gas3: | |
| 2643 btfss better_gas_available ; shall a better gas be signaled for? | |
| 623 | 2644 bcf better_gas_blinking ; NO - clear blinking flag |
| 582 | 2645 return |
| 0 | 2646 |
| 631 | 2647 |
| 2648 check_gas_best_all: | |
| 2649 clrf check_gas_num ; increment comes first, so initialize with zero | |
| 2650 check_gas_best_loop: | |
| 2651 incf check_gas_num,F ; increment number of gas to check | |
| 2652 movf lo,W ; copy number of currently used gas to WREG | |
| 2653 cpfseq check_gas_num ; gas to be checked = currently used gas ? | |
| 2654 rcall check_gas_best_common ; NO - check the gas | |
| 2655 movlw NUM_GAS ; get total number of gases | |
| 2656 cpfseq check_gas_num ; reached last gas? | |
| 2657 bra check_gas_best_loop ; NO - loop | |
| 2658 return ; YES - done | |
| 2659 | |
| 2660 | |
| 604 | 2661 check_gas_best_common: ; with gas to be checked in check_gas_num (1-5) |
| 634 | 2662 ; and current gas in lo (1-5) |
| 604 | 2663 ; |
| 2664 ; Memory Map: | |
| 2665 ; --------------------------------------------------------------------------------------- | |
| 2666 ; opt_gas_O2_ratio res 5 ; base address for gases | |
| 2667 ; opt_dil_O2_ratio res 5 ; base address for diluents | |
| 2668 ; opt_gas_He_ratio res 5 ; (not needed here) | |
| 2669 ; opt_dil_He_ratio res 5 ; (not needed here) | |
| 2670 ; opt_gas_type res 5 ; has offset of 20 bytes from base address for gases | |
| 2671 ; opt_dil_type res 5 ; has offset of 20 bytes from base address for diluents | |
| 2672 ; opt_gas_change res 5 ; has offset of 10 bytes from opt_gas_type | |
| 2673 ; opt_dil_change res 5 ; has offset of 10 bytes from opt_dil_type | |
| 2674 | |
| 2675 ; get gas data | |
| 2676 decf check_gas_num,W ; (1-5) -> (0-4) into WREG to be used as index | |
| 623 | 2677 movff PLUSW1,check_gas_O2_ratio ; copy O2 ratio (%) of current gas/dil to check_gas_O2_ratio |
| 604 | 2678 addlw .20 ; add offset of 20 bytes to index type in opt_gas_type/opt_dil_type |
| 623 | 2679 movff PLUSW1,check_gas_type ; copy type of current gas/dil to check_gas_type (0=disabled, 1=first, 2=travel/normal, 3=deco/-) |
| 604 | 2680 addlw .10 ; add offset of 10 bytes to index change depth in opt_gas_change/opt_dil_change |
| 623 | 2681 movff PLUSW1,check_gas_depth ; copy change depth of current gas/dil to check_gas_depth |
| 2682 MOVII ppO2_max_default,sub_b ; select default ppO2 max for first / travel / normal gas | |
| 628 | 2683 ; check if the gas is the current gas |
| 2684 movf check_gas_num,W ; get the number of the gas to be checked (1-5) | |
| 2685 cpfseq lo ; is this the currently used gas? | |
| 2686 bra check_gas_best_common0 ; NO - do the disabled & deco gas checks | |
| 2687 bra check_gas_best_common3 ; YES - a gas in use overrides disabled and deco status | |
| 2688 check_gas_best_common0: | |
| 623 | 2689 ; check if gas is available (i.e. not disabled) |
| 631 | 2690 btfsc check_gas_type,gas_lost ; gas/dil lost? |
| 2691 return ; YES - skip as not available any more | |
| 2692 btfsc check_gas_type,gas_staged ; gas/dil staged? | |
| 2693 return ; YES - skip as currently not available | |
| 623 | 2694 tstfsz check_gas_type ; type = disabled (0) ? |
| 2695 bra check_gas_best_common1 ; NO - continue checks | |
| 631 | 2696 return ; YES - skip as not available at all |
| 623 | 2697 check_gas_best_common1: |
| 2698 ; skip deco gases (type=3) if there are no stops, but include them when in bailout mode | |
| 2699 movlw .3 ; coding for deco gas | |
| 2700 cpfseq check_gas_type ; type = deco (3) ? | |
| 2701 bra check_gas_best_common3 ; NO - first or travel/normal then, ok to use | |
| 631 | 2702 IFDEF _ccr_pscr |
| 623 | 2703 btfsc bailout_mode ; YES - in bailout? |
| 2704 bra check_gas_best_common2 ; YES - ok to use (using deco gases is always allowed when in bailout) | |
| 631 | 2705 ENDIF |
| 2706 TSTOSS opt_ext_stops ; NO - extended stops enabled? | |
| 2707 bra check_gas_best_common1b ; NO - only ok if in deco region | |
| 2708 ;bra check_gas_best_common1a ; YES - only ok if in deco mode | |
| 623 | 2709 check_gas_best_common1a: |
| 628 | 2710 movff char_O_deco_info,WREG ; get deco info vector |
| 2711 btfss WREG,deco_mode ; are we in deco mode? | |
| 2712 return ; NO - skip deco gas while not in deco mode | |
| 2713 bra check_gas_best_common2 ; YES - deco gases allowed | |
| 2714 check_gas_best_common1b: | |
| 2715 btfss deco_region ; are we in the deco region? | |
| 2716 return ; NO - skip deco gas while not in the deco region | |
| 2717 ;bra check_gas_best_common2 ; YES - deco gases allowed | |
| 623 | 2718 check_gas_best_common2: |
| 2719 MOVII ppO2_max_deco,sub_b ; replace by ppO2 max for a deco gas | |
| 2720 check_gas_best_common3: | |
| 604 | 2721 ; check if gas is usable, i.e. its change depth is below or equal to the current depth |
| 623 | 2722 movf depth_meter,W ; load current depth (in m) into WREG |
| 604 | 2723 cpfslt check_gas_depth ; change depth of checked gas < (shallower than) current depth? |
| 623 | 2724 bra check_gas_best_common4 ; NO - gas is usable |
| 604 | 2725 return ; YES - gas is not usable |
| 623 | 2726 check_gas_best_common4: |
| 604 | 2727 ; check if this gas is the first best gas candidate |
| 2728 movf best_gas_num,W ; get best gas found so far (1-5) or 0 if none found yet | |
| 2729 tstfsz WREG ; has a best gas candidate been found yet? | |
| 623 | 2730 bra check_gas_best_common5 ; YES - check if the new one is better than the one we have so far |
| 2731 bra check_gas_best_common6 ; NO - no need to do the above mentioned check | |
| 2732 check_gas_best_common5: | |
| 631 | 2733 ; check if the change depth of the checked gas is < (shallower) than the change depth of the best gas found so far |
| 604 | 2734 movf best_gas_depth,W ; load change depth of best gas so far into WREG |
| 631 | 2735 cpfslt check_gas_depth ; change depth of checked gas < (shallower than) change depth of best gas so far? |
| 2736 return ; NO - this gas is not better than the best already found | |
| 2737 ;bra check_gas_best_common6 ; YES - this gas is better, continue | |
| 623 | 2738 check_gas_best_common6: |
| 604 | 2739 ; check if the gas fits into the ppO2 limits |
| 623 | 2740 movff check_gas_O2_ratio,xB+0 ; xB = O2 ratio, xA is still loaded with (absolute pressure / 10) |
| 69 | 2741 clrf xB+1 |
| 623 | 2742 call mult16x16 ; xC = O2 ratio * (absolute pressure / 10), result in 0.1 mbar |
| 604 | 2743 ; check for very high ppO2 |
| 623 | 2744 tstfsz xC+2 ; O2_ratio * absolute pressure / 10 > 65536, i.e. ppO2 > 6.55 bar ? |
| 604 | 2745 return ; YES - gas is not usable |
| 623 | 2746 btfsc xC+1,7 ; ppO2 > 3.30 bar ? |
| 604 | 2747 return ; YES - gas is not usable |
| 623 | 2748 MOVII xC,sub_a ; NO - gas may be usable |
| 2749 ; check for high ppO2 | |
| 2750 call cmpU16 ; sub_a - sub_b | |
| 2751 btfss neg_flag ; within limit? | |
| 2752 return ; NO - too high, gas is not usable | |
| 604 | 2753 ; check for low ppO2 |
| 623 | 2754 MOVII ppO2_min,sub_b ; copy minimum ppO2 to sub_b |
| 2755 call cmpU16 ; sub_a - sub_b | |
| 604 | 2756 btfsc neg_flag ; within limit? |
| 2757 return ; NO - too low, gas is not usable | |
| 2758 ; we have a (new) best gas | |
| 631 | 2759 movff check_gas_num, best_gas_num ; YES - set checked gas (1-5) as best gas |
| 2760 movff check_gas_depth,best_gas_depth ; - memorize its change depth | |
| 2761 return ; - done | |
| 0 | 2762 |
| 634 | 2763 IFDEF _ccr_pscr |
| 2764 | |
| 2765 | |
| 2766 ;----------------------------------------------------------------------------- | |
|
338
2811932b4e99
NEW: Mode Auto SP: Automatically switches the SP during descent (CC Mode)
heinrichsweikamp
parents:
337
diff
changeset
|
2767 ; Check for Auto-SP |
|
2811932b4e99
NEW: Mode Auto SP: Automatically switches the SP during descent (CC Mode)
heinrichsweikamp
parents:
337
diff
changeset
|
2768 ; |
| 634 | 2769 check_dive_autosp: |
| 640 | 2770 movf dive_ccr_mode,W ; =0: Fixed SP, =1: Sensor, =2: Auto SP |
| 2771 sublw .2 ; dive_ccr_mode = 2 (Auto SP)? | |
| 604 | 2772 bz check_dive_autosp2 ; YES - check |
| 2773 return ; NO - return for sensor or fixed mode | |
| 634 | 2774 |
|
338
2811932b4e99
NEW: Mode Auto SP: Automatically switches the SP during descent (CC Mode)
heinrichsweikamp
parents:
337
diff
changeset
|
2775 check_dive_autosp2: |
| 640 | 2776 ; check for restart request |
| 2777 btfss restart_auto_sp ; shall restart from 1st SP? | |
| 2778 bra check_dive_autosp2a ; NO - skip next | |
| 2779 bcf restart_auto_sp ; YES - clear request flag | |
| 2780 bcf FLAG_SP2_used ; - flag SP 2, ... | |
| 2781 bcf FLAG_SP3_used ; - flag SP 3, ... | |
| 2782 bcf FLAG_SP4_used ; - flag SP 4, ... | |
| 2783 bcf FLAG_SP5_used ; - flag SP 5 as unused so far | |
| 2784 | |
| 2785 check_dive_autosp2a: | |
| 631 | 2786 ; check SP2 |
| 623 | 2787 btfsc FLAG_SP2_used ; SP 2 used so far? |
| 604 | 2788 bra check_dive_autosp3 ; YES - continue with SP 3 |
| 623 | 2789 movff opt_setpoint_change+1,lo ; NO - get depth in m |
| 604 | 2790 tstfsz lo ; - SP change depth = 0 ? |
| 640 | 2791 bra check_dive_autosp2b ; NO - continue |
| 604 | 2792 bra check_dive_autosp3 ; YES - continue with SP 3 |
| 640 | 2793 check_dive_autosp2b: |
| 604 | 2794 decf lo,W ; SP change depth -1 -> WREG |
| 623 | 2795 cpfsgt depth_meter ; current depth > change depth - 1 ? |
| 604 | 2796 bra check_dive_autosp3 ; NO - continue with SP 3 |
| 582 | 2797 ; auto switch to SP2 |
| 623 | 2798 movff opt_setpoint_cbar+1,char_I_const_ppO2 ; YES - use SP |
| 604 | 2799 rcall xmit_sp_set_flag ; - send SP to external devices |
| 623 | 2800 bsf FLAG_SP2_used ; - set SP 2 used flag |
| 634 | 2801 |
|
338
2811932b4e99
NEW: Mode Auto SP: Automatically switches the SP during descent (CC Mode)
heinrichsweikamp
parents:
337
diff
changeset
|
2802 check_dive_autosp3: |
| 631 | 2803 ; check SP3 |
| 623 | 2804 btfsc FLAG_SP3_used ; SP 3 used so far? |
| 604 | 2805 bra check_dive_autosp4 ; YES - continue with SP 4 |
| 623 | 2806 movff opt_setpoint_change+2,lo ; NO - get depth in m |
| 604 | 2807 tstfsz lo ; - SP change depth = 0 ? |
| 2808 bra check_dive_autosp3a ; NO - continue | |
| 2809 bra check_dive_autosp4 ; YES - continue with SP 4 | |
| 560 | 2810 check_dive_autosp3a: |
| 604 | 2811 decf lo,W ; SP change depth -1 -> WREG |
| 623 | 2812 cpfsgt depth_meter ; current depth > change depth - 1 ? |
| 604 | 2813 bra check_dive_autosp4 ; NO - continue with SP 4 |
| 582 | 2814 ; auto switch to SP3 |
| 623 | 2815 movff opt_setpoint_cbar+2,char_I_const_ppO2 ; YES - use SP |
| 604 | 2816 rcall xmit_sp_set_flag ; - send SP to external devices |
| 623 | 2817 bsf FLAG_SP3_used ; - set SP 3 used flag |
| 634 | 2818 |
|
338
2811932b4e99
NEW: Mode Auto SP: Automatically switches the SP during descent (CC Mode)
heinrichsweikamp
parents:
337
diff
changeset
|
2819 check_dive_autosp4: |
| 631 | 2820 ; check SP4 |
| 623 | 2821 btfsc FLAG_SP4_used ; SP 4 used so far? |
| 604 | 2822 bra check_dive_autosp5 ; YES - continue with SP 5 |
| 623 | 2823 movff opt_setpoint_change+3,lo ; NO - get depth in m |
| 604 | 2824 tstfsz lo ; - SP change depth = 0 ? |
| 2825 bra check_dive_autosp4a ; NO - continue | |
| 623 | 2826 bra check_dive_autosp5 ; YES - continue with SP 5 |
| 560 | 2827 check_dive_autosp4a: |
| 604 | 2828 decf lo,W ; SP change depth -1 -> WREG |
| 623 | 2829 cpfsgt depth_meter ; current depth > change depth - 1 ? |
| 604 | 2830 bra check_dive_autosp5 ; NO - continue with SP 5 |
| 582 | 2831 ; auto switch to SP4 |
| 623 | 2832 movff opt_setpoint_cbar+3,char_I_const_ppO2 ; YES - use SP |
| 604 | 2833 rcall xmit_sp_set_flag ; - send SP to external devices |
| 623 | 2834 bsf FLAG_SP4_used ; - set SP 4 used flag |
| 634 | 2835 |
|
338
2811932b4e99
NEW: Mode Auto SP: Automatically switches the SP during descent (CC Mode)
heinrichsweikamp
parents:
337
diff
changeset
|
2836 check_dive_autosp5: |
| 631 | 2837 ; check SP5 |
| 623 | 2838 btfsc FLAG_SP5_used ; SP 5 used so far? |
| 604 | 2839 bra check_dive_autosp6 ; YES - done |
| 623 | 2840 movff opt_setpoint_change+4,lo ; NO - get depth in m |
| 604 | 2841 tstfsz lo ; - SP change depth = 0 ? |
| 2842 bra check_dive_autosp5a ; NO - continue | |
| 2843 bra check_dive_autosp6 ; YES - done | |
| 560 | 2844 check_dive_autosp5a: |
| 604 | 2845 decf lo,W ; SP change depth -1 -> WREG |
| 623 | 2846 cpfsgt depth_meter ; current depth > change depth - 1 ? |
| 604 | 2847 bra check_dive_autosp6 ; NO - done |
| 582 | 2848 ; auto switch to SP5 |
| 623 | 2849 movff opt_setpoint_cbar+4,char_I_const_ppO2 ; YES - use SP |
| 604 | 2850 rcall xmit_sp_set_flag ; - send SP to external devices |
| 623 | 2851 bsf FLAG_SP5_used ; - set SP 5 used flag |
| 634 | 2852 |
|
352
5c6da9fa5cb0
add setpoint change to first sample in CCR mode
heinrichsweikamp
parents:
339
diff
changeset
|
2853 check_dive_autosp6: |
| 634 | 2854 return ; done |
| 2855 | |
| 2856 | |
| 2857 ;----------------------------------------------------------------------------- | |
| 2858 ; Helper Function - transmit new Setpoint to external Electronics and flag Change | |
| 2859 ; | |
|
352
5c6da9fa5cb0
add setpoint change to first sample in CCR mode
heinrichsweikamp
parents:
339
diff
changeset
|
2860 xmit_sp_set_flag: |
| 656 | 2861 IFDEF _external_sensor_eccr |
| 604 | 2862 call transmit_setpoint ; transmit current setpoint from WREG (in cbar) to external electronics |
| 623 | 2863 ENDIF |
| 2864 bsf event_occured ; set global event flag | |
| 2865 bsf event_SP_change ; set setpoint event flag | |
| 582 | 2866 return |
| 2867 | |
| 623 | 2868 ENDIF ; _ccr_pscr |
| 2869 | |
|
338
2811932b4e99
NEW: Mode Auto SP: Automatically switches the SP during descent (CC Mode)
heinrichsweikamp
parents:
337
diff
changeset
|
2870 |
| 0 | 2871 ;============================================================================= |
| 634 | 2872 dmode2 CODE |
| 2873 ;============================================================================= | |
| 2874 | |
| 2875 | |
| 2876 ;----------------------------------------------------------------------------- | |
| 2877 ; Setup everything to enter OC Dive Mode | |
| 0 | 2878 ; |
| 604 | 2879 global dive_boot_oc |
| 0 | 2880 dive_boot_oc: |
| 631 | 2881 rcall get_first_gas_to_WREG ; get first gas (1-5) into WREG |
| 2882 rcall setup_gas_registers ; set-up of gas parameters of currently breathed gas (with WREG = gas 1-5) | |
| 2883 rcall deco_setup_oc_gases ; set-up of gas list for deco calculations (with WREG = gas 1-5) | |
| 634 | 2884 return ; done |
| 2885 | |
| 2886 | |
| 2887 ;----------------------------------------------------------------------------- | |
| 2888 ; Helper Function - get first Gas (1-5) into WREG | |
| 2889 ; | |
| 2890 global get_first_gas_to_WREG | |
| 2891 get_first_gas_to_WREG: | |
| 2892 lfsr FSR1,opt_gas_type ; load base address of the gas types | |
| 2893 clrf lo ; start with gas 0 | |
| 2894 get_first_gas_to_WREG2: | |
| 2895 movf lo,W ; set index | |
| 2896 movf PLUSW1,W ; get type of gas (0=Disabled, 1=First, 2=Travel, 3=Deco) | |
| 2897 sublw .1 ; is it of type First? | |
| 2898 bz get_first_gas_to_WREG3 ; YES - found the First gas | |
| 2899 incf lo,F ; NO - increment index | |
| 2900 movlw NUM_GAS+1 ; - get highest index+1 | |
| 2901 cpfseq lo ; - all gases checked? | |
| 2902 bra get_first_gas_to_WREG2 ; NO - not yet | |
| 2903 movlw .1 ; YES - default to gas 1 | |
| 2904 movff WREG,opt_gas_type+0 ; - force it to be of type First | |
| 2905 return ; - done | |
| 2906 get_first_gas_to_WREG3: | |
| 2907 movf lo,W ; copy index of gas found to be the First to WREG | |
| 2908 incf WREG,W ; turn index into gas number (0-4 -> 1-5) | |
| 2909 return ; done | |
| 2910 | |
| 2911 | |
| 2912 ;----------------------------------------------------------------------------- | |
| 2913 ; Helper Function - load currently breathed Gas into Deco Engine | |
| 2914 ; | |
| 2915 global setup_gas_registers | |
| 2916 setup_gas_registers: | |
| 2917 movwf active_gas ; set as current gas | |
| 2918 movlw .6 ; gas = gas6 ? | |
| 2919 cpfseq active_gas ; ... | |
| 2920 bra setup_gas_registers_15 ; NO - load gas 1-5 | |
| 2921 | |
| 2922 ; load gas 6 | |
| 2923 movff opt_gas6_O2_ratio,char_I_O2_ratio ; copy gas6 O2 ratio to deco engine | |
| 2924 IFDEF _helium | |
| 2925 movff opt_gas6_He_ratio,char_I_He_ratio ; copy gas6 H2 ratio to deco engine | |
| 2926 ENDIF | |
| 2927 movlw .3 ; declare gas6 as a deco gas | |
| 2928 movff WREG,char_I_current_gas_type ; copy gas type to deco engine | |
| 2929 movff depth_meter,char_I_gas6_depth ;set current depth as change depth | |
| 2930 bra setup_gas_registers_com ; continue with common part | |
| 2931 | |
| 2932 setup_gas_registers_15: | |
| 2933 lfsr FSR1,opt_gas_O2_ratio ; load base address of gas data | |
| 2934 decf active_gas,W ; set index to O2 ratio of current gas (1-5 -> 0-4) | |
| 2935 movff PLUSW1,char_I_O2_ratio ; copy O2 ratio to deco engine | |
| 2936 addlw .10 ; advance index from O2 ratio to He ratio | |
| 2937 IFDEF _helium | |
| 2938 movff PLUSW1,char_I_He_ratio ; copy He ratio to deco engine | |
| 2939 ENDIF | |
| 2940 addlw .10 ; advance index from He ratio to gas type | |
| 2941 movff PLUSW1,char_I_current_gas_type ; copy gas type (0=Disabled, 1=First, 2=Travel, 3=Deco) | |
| 2942 setup_gas_registers_com: | |
| 2943 movff char_O_main_status,lo ; working copy of char_O_main_status in bank common | |
| 2944 bcf lo,DECO_MODE_PSCR_FLAG ; clear the pSCR-mode flag (if applicable) | |
| 2945 bcf lo,DECO_MODE_LOOP_FLAG ; clear the loop/CCR-mode flag | |
| 2946 movff lo,char_O_main_status ; bank safe write-back of char_O_main_status | |
| 2947 movf active_gas,W ; reload WREG with gas 1-5 or 6 (important!) | |
| 2948 return ; done | |
| 2949 | |
| 2950 | |
| 2951 ;----------------------------------------------------------------------------- | |
| 2952 ; Helper Function - load OC Gases into Deco Engine (currently breathed gas in WREG) | |
| 2953 ; | |
| 2954 global deco_setup_oc_gases | |
| 2955 deco_setup_oc_gases: | |
| 2956 movff char_O_deco_status,lo ; get working copy of char_O_deco_status in bank common | |
| 2957 deco_setup_oc_gases_pre: ; entry point with lo preloaded | |
| 2958 movff WREG,char_I_current_gas_num ; set gas to start with when doing the deco calculations | |
| 2959 ; | |
| 2960 ; Memory Map: | |
| 2961 ; --------------------------------------------------------------------------------- | |
| 2962 ; opt_gas_O2_ratio res NUM_GAS | char_I_deco_O2_ratio res NUM_GAS | |
| 2963 ; opt_dil_O2_ratio res NUM_GAS | | |
| 2964 ; opt_gas_He_ratio res NUM_GAS | char_I_deco_He_ratio res NUM_GAS | |
| 2965 ; opt_dil_He_ratio res NUM_GAS | | |
| 2966 ; opt_gas_type res NUM_GAS | char_I_deco_gas_type res NUM_GAS | |
| 2967 ; opt_dil_type res NUM_GAS | | |
| 2968 ; opt_gas_change res NUM_GAS | char_I_deco_gas_change res NUM_GAS | |
| 2969 ; opt_dil_change res NUM_GAS | | |
| 2970 ; | |
| 2971 lfsr FSR2,char_I_deco_O2_ratio ; load FSR2 with base address of char_I_deco_O2_ratio | |
| 2972 ; FSR2 will step through all char_I_deco_... vars | |
| 2973 lfsr FSR1,opt_gas_O2_ratio ; load FSR1 with base address of opt_gas_O2_ratio | |
| 2974 rcall deco_setup_copy ; copy all OC O2 ratios | |
| 2975 lfsr FSR1,opt_gas_He_ratio ; load FSR1 with base address of opt_gas_He_ratio | |
| 2976 rcall deco_setup_copy ; copy all OC He ratios | |
| 2977 lfsr FSR1,opt_gas_type ; load FSR1 with base address of opt_gas_type | |
| 2978 rcall deco_setup_copy ; copy all gas types | |
| 2979 lfsr FSR1,opt_gas_change ; load FSR1 with base address of opt_gas_change | |
| 2980 rcall deco_setup_copy ; copy all gas change depths | |
| 2981 | |
| 2982 ; switch deco engine to oc mode | |
| 2983 bcf lo,DECO_MODE_PSCR_FLAG ; clear the pSCR-mode flag (may not be set, but never mind) | |
| 2984 bcf lo,DECO_MODE_LOOP_FLAG ; clear the loop/CCR-mode flag | |
| 2985 movff lo,char_O_deco_status ; bank safe write-back of char_O_deco_status | |
| 2986 return ; done | |
| 2987 | |
| 2988 | |
| 2989 ;----------------------------------------------------------------------------- | |
| 2990 ; Helper Function - dedicated Memory Copy | |
| 2991 deco_setup_copy: | |
| 2992 movlw NUM_GAS ; load loop counter with number of gases (5) | |
| 2993 deco_setup_copy_loop: | |
| 2994 movff POSTINC1,POSTINC2 ; copy from (FSR1) to (FSR2) | |
| 2995 decfsz WREG ; decrement loop counter and check if it became 0 | |
| 2996 bra deco_setup_copy_loop ; NO - not yet, loop | |
| 2997 return ; YES - done | |
| 2998 | |
| 0 | 2999 |
| 623 | 3000 |
| 3001 IFDEF _ccr_pscr | |
| 3002 | |
| 634 | 3003 ;----------------------------------------------------------------------------- |
| 3004 ; Setup everything to enter CCR/pSCR Dive Mode - Part 1 | |
| 3005 ; | |
| 604 | 3006 global dive_boot_cc |
| 0 | 3007 dive_boot_cc: |
| 631 | 3008 rcall get_first_dil_to_WREG ; get first diluent (1-5) into WREG |
| 3009 rcall setup_dil_registers ; set-up of diluent parameters for currently breathed diluent (with WREG = current diluent 1-5) | |
| 3010 rcall deco_setup_cc_diluents ; set-up of diluent list for deco calculations (with WREG = current diluent 1-5) | |
| 634 | 3011 return ; done |
| 3012 | |
| 3013 | |
| 3014 ;----------------------------------------------------------------------------- | |
| 3015 ; Helper Function - get first Diluent (1-5) into WREG | |
| 3016 ; | |
| 3017 global get_first_dil_to_WREG | |
| 3018 get_first_dil_to_WREG: ; gets first dil (1-5) into WREG | |
| 3019 lfsr FSR1,opt_dil_type ; load base address of the dil types | |
| 3020 clrf lo ; start with dil 0 | |
| 3021 get_first_dil_to_WREG2: | |
| 3022 movf lo,W ; set index | |
| 3023 movf PLUSW1,W ; get type of Dil (0=Disabled, 1=First, 2=Normal) | |
| 3024 sublw .1 ; is it of type First? | |
| 3025 bz get_first_dil_to_WREG3 ; YES - found the First dil | |
| 3026 incf lo,F ; NO - increment index | |
| 3027 movlw NUM_GAS+1 ; - get highest index+1 | |
| 3028 cpfseq lo ; - dils checked? | |
| 3029 bra get_first_dil_to_WREG2 ; NO - not yet | |
| 3030 movlw .1 ; YES - default to dil 1 | |
| 3031 movff WREG,opt_dil_type+0 ; - force it to be of type First | |
| 3032 return ; - done | |
| 3033 get_first_dil_to_WREG3: | |
| 3034 movf lo,W ; copy index of dil found to be the First to WREG | |
| 3035 incf WREG,W ; turn index into dil number (0-4 -> 1-5) | |
| 3036 return ; done | |
| 3037 | |
| 3038 | |
| 3039 ;----------------------------------------------------------------------------- | |
| 3040 ; Helper Function - load currently breathed Diluent into Deco Engine | |
| 3041 ; | |
| 3042 global setup_dil_registers | |
| 3043 setup_dil_registers: | |
| 3044 btfsc bailout_mode ; check if in bailout condition | --------------- FOR SAFETY ONLY -------------- | |
| 3045 bra setup_gas_registers ; revert to setting up OC gases in bailout condition | This branch should never happen to be taken... | |
| 3046 movwf active_dil ; set as current diluent | |
| 3047 movlw .6 ; diluent = gas6 ? | |
| 3048 cpfseq active_dil ; ... | |
| 3049 bra setup_dil_registers_15 ; NO - load diluent 1-5 | |
| 3050 | |
| 3051 ; load gas 6 | |
| 3052 movff opt_gas6_O2_ratio,char_I_O2_ratio ; copy gas6 O2 ratio to deco engine | |
| 3053 IFDEF _helium | |
| 3054 movff opt_gas6_He_ratio,char_I_He_ratio ; copy gas6 He ratio to deco engine | |
| 3055 ENDIF | |
| 3056 movlw .2 ; declare gas6 as a normal diluent | |
| 3057 movff WREG,char_I_current_gas_type ; copy gas type to deco engine | |
| 3058 movff depth_meter,char_I_gas6_depth ;set current depth as change depth | |
| 3059 bra setup_dil_registers_com ; continue with common part | |
| 3060 | |
| 3061 setup_dil_registers_15: | |
| 3062 lfsr FSR1,opt_dil_O2_ratio ; load base address of diluent data | |
| 3063 decf active_dil,W ; set index to O2 ratio of current diluent (1-5 -> 0-4) | |
| 3064 movff PLUSW1,char_I_O2_ratio ; copy O2 ratio to deco engine | |
| 3065 addlw .10 ; advance index from O2 ratio to He ratio | |
| 3066 IFDEF _helium | |
| 3067 movff PLUSW1,char_I_He_ratio ; copy He ratio to deco engine | |
| 3068 ENDIF | |
| 3069 addlw .10 ; advance index from He ratio to diluent type | |
| 3070 movff PLUSW1,char_I_current_gas_type ; copy diluent type (0=Disabled, 1=First, 2=Normal) | |
| 3071 setup_dil_registers_com: | |
| 3072 movff char_O_main_status,lo ; working copy of char_O_main_status in bank common | |
| 3073 bsf lo,DECO_MODE_LOOP_FLAG ; loop flag is set in both, CCR and pSCR mode | |
| 3074 bcf lo,DECO_MODE_PSCR_FLAG ; clear pSCR mode flag by default | |
| 3075 btfsc FLAG_pscr_mode ; check if we are in pSCR mode | |
| 3076 bsf lo,DECO_MODE_PSCR_FLAG ; YES - set additional flag for pSCR mode | |
| 3077 movff lo,char_O_main_status ; bank safe write-back of char_O_main_status | |
| 3078 movf active_dil,W ; reload WREG with diluent 1-5 or 6 (important!) | |
| 3079 return ; done | |
| 3080 | |
| 3081 | |
| 3082 ;----------------------------------------------------------------------------- | |
| 3083 ; Helper Function - load Diluents into Deco Engine (currently breathed dil in WREG) | |
| 3084 ; | |
| 3085 global deco_setup_cc_diluents | |
| 3086 deco_setup_cc_diluents: | |
| 3087 movff char_O_deco_status,lo ; working copy of char_O_deco_status in bank common | |
| 3088 deco_setup_cc_diluents_pre: ; entry point with lo preloaded | |
| 3089 btfsc bailout_mode ; check if in bailout condition | --------------- FOR SAFETY ONLY -------------- | |
| 3090 bra deco_setup_oc_gases_pre ; YES - revert to setting up OC gases | This branch should never happen to be taken... | |
| 3091 movff WREG,char_I_current_gas_num ; NO - set diluent to start with when doing the deco calculations | |
| 3092 ; | |
| 3093 ; Memory Map: | |
| 3094 ; --------------------------------------------------------------------------------- | |
| 3095 ; opt_gas_O2_ratio res NUM_GAS | | |
| 3096 ; opt_dil_O2_ratio res NUM_GAS | char_I_deco_O2_ratio res NUM_GAS | |
| 3097 ; opt_gas_He_ratio res NUM_GAS | | |
| 3098 ; opt_dil_He_ratio res NUM_GAS | char_I_deco_He_ratio res NUM_GAS | |
| 3099 ; opt_gas_type res NUM_GAS | | |
| 3100 ; opt_dil_type res NUM_GAS | char_I_deco_gas_type res NUM_GAS | |
| 3101 ; opt_gas_change res NUM_GAS | | |
| 3102 ; opt_dil_change res NUM_GAS | char_I_deco_gas_change res NUM_GAS | |
| 3103 ; | |
| 3104 lfsr FSR2,char_I_deco_O2_ratio ; load FSR2 with base address of char_I_deco_O2_ratio. | |
| 3105 ; FSR2 will step through all char_I_deco_... vars. | |
| 3106 lfsr FSR1,opt_dil_O2_ratio ; load FSR1 with base address of opt_dil_O2_ratio | |
| 3107 rcall deco_setup_copy ; copy all dil O2 ratios | |
| 3108 lfsr FSR1,opt_dil_He_ratio ; load FSR1 with base address of opt_dil_He_ratio | |
| 3109 rcall deco_setup_copy ; copy all dil He ratios | |
| 3110 lfsr FSR1,opt_dil_type ; load FSR1 with base address of opt_dil_type | |
| 3111 rcall deco_setup_copy ; copy all dil types | |
| 3112 lfsr FSR1,opt_dil_change ; load FSR1 with base address of opt_dil_change | |
| 3113 rcall deco_setup_copy ; copy all dil change depths | |
| 3114 ; switch to CCR / pSCR mode: | |
| 3115 bsf lo,DECO_MODE_LOOP_FLAG ; - loop flag is set in both, CCR and pSCR mode | |
| 3116 bcf lo,DECO_MODE_PSCR_FLAG ; - clear pSCR mode flag by default | |
| 3117 btfsc FLAG_pscr_mode ; - check if we are in pSCR mode | |
| 3118 bsf lo,DECO_MODE_PSCR_FLAG ; YES - set additional flag for pSCR mode | |
| 3119 movff lo,char_O_deco_status ; - bank safe write-back of char_O_deco_status | |
| 3120 return ; done | |
| 3121 | |
| 3122 | |
| 3123 ;----------------------------------------------------------------------------- | |
| 3124 ; Setup everything to enter CCR / pSCR Dive Mode - Part 2 | |
| 3125 ; | |
| 604 | 3126 dive_boot_cc_part2: |
| 560 | 3127 ; revoke sensors from usage if they do not have a valid calibration |
| 3128 bsf use_O2_sensor1 | |
| 3129 btfss sensor1_calibrated_ok | |
| 3130 bcf use_O2_sensor1 | |
| 634 | 3131 |
| 3132 bsf use_O2_sensor2 | |
| 560 | 3133 btfss sensor2_calibrated_ok |
| 3134 bcf use_O2_sensor2 | |
| 634 | 3135 |
| 3136 bsf use_O2_sensor3 | |
| 560 | 3137 btfss sensor3_calibrated_ok |
| 3138 bcf use_O2_sensor3 | |
| 623 | 3139 |
| 656 | 3140 IFDEF _external_sensor_eccr |
| 604 | 3141 ; check for external HUD/ppO2 Monitor |
| 634 | 3142 btfss ext_input_optical ; do we have an optical input? |
| 604 | 3143 bra dive_boot_cc_part2_1 ; NO |
| 656 | 3144 btfss ext_s8_full_digital ; are we in external S8 full digital mode? |
| 3145 bra dive_boot_cc_part2_1 ; NO | |
| 634 | 3146 btfsc sensor1_active ; YES - process flags from HUD/ppO2 Monitor |
| 623 | 3147 bsf use_O2_sensor1 ; - ... |
| 3148 btfsc sensor2_active ; - ... | |
| 3149 bsf use_O2_sensor2 ; - ... | |
| 3150 btfsc sensor3_active ; - ... | |
| 3151 bsf use_O2_sensor3 ; - ... | |
| 3152 ENDIF | |
| 3153 | |
| 604 | 3154 dive_boot_cc_part2_1: |
| 560 | 3155 ; In pSCR mode, only settings 0 (calculated ppO2) and 1 (ppO2 from sensors) are defined. |
| 604 | 3156 ; In case we still have 3 (auto SP) selected out of previous CCR mode, we reset to 0. |
| 634 | 3157 btfss FLAG_pscr_mode ; in pSCR mode? |
| 3158 bra dive_boot_cc_part2_2 ; NO | |
| 640 | 3159 movf dive_ccr_mode,W ; YES - get mode (=0: Fixed SP (CCR) / calculated SP (pSCR), =1: Sensor, =2: Auto SP) |
| 3160 sublw .2 ; dive_ccr_mode = 1 (Auto SP)? | |
| 634 | 3161 bnz dive_boot_cc_part2_2 ; NO - ok |
| 640 | 3162 clrf dive_ccr_mode ; YES - revert to calculated SP |
| 634 | 3163 |
| 604 | 3164 dive_boot_cc_part2_2: |
| 623 | 3165 bsf event_SP_change ; set setpoint event flag |
| 3166 | |
| 560 | 3167 ; Start with SP1 (CCR) or 0 (pSCR) as default. |
| 3168 ; If in sensor mode, this value will be overwritten by calc_deko_divemode_sensor | |
| 623 | 3169 clrf WREG ; pre-load WREG with setpoint value 0 for pSCR calculated |
| 3170 btfsc FLAG_ccr_mode ; in CCR mode? | |
| 3171 movff opt_setpoint_cbar+0,WREG ; YES - get value of setpoint 1 into WREG | |
| 582 | 3172 movff WREG,char_I_const_ppO2 ; write setpoint to deco engine |
| 634 | 3173 |
| 656 | 3174 IFDEF _external_sensor_eccr |
| 582 | 3175 call transmit_setpoint ; transmit current setpoint from WREG (in cbar) to external electronics |
| 634 | 3176 goto calc_deko_divemode_sensor ; process sensor readings and return |
| 623 | 3177 ELSE |
| 3178 return ; done | |
| 3179 ENDIF | |
| 3180 | |
| 3181 ENDIF ; _ccr_pscr | |
| 3182 | |
| 634 | 3183 |
| 623 | 3184 ;============================================================================= |
| 634 | 3185 dmode3 CODE |
| 3186 ;============================================================================= | |
| 3187 | |
| 3188 | |
| 3189 ;----------------------------------------------------------------------------- | |
| 3190 ; Initialize Dive Mode | |
| 3191 ; | |
| 0 | 3192 diveloop_boot: |
| 604 | 3193 ; do the basic initialization |
| 634 | 3194 call restart_set_modes_and_flags ; basic settings depending on deco mode |
| 3195 | |
| 3196 ; save on energy | |
| 3197 call I2C_sleep_compass ; stop accelerometer and compass | |
| 604 | 3198 |
| 623 | 3199 ; do an early initialization of all deco engine output variables to |
| 3200 ; avoid glitches in the display outputs during deco engine start-up | |
| 3201 call deco_init_output_vars; ; (C-code) | |
| 3202 banksel common ; back to bank common | |
| 3203 | |
| 634 | 3204 ; configure screen layout |
| 3205 TSTOSC opt_layout ; alternative layout enabled? | |
| 3206 bsf alt_layout_active ; YES - start with alternative layout | |
| 3207 | |
| 3208 ; configure tissue graphics | |
|
635
9a64914a8fca
3.10 re-release addressing some minor issues and language fixes
heinrichsweikamp
parents:
634
diff
changeset
|
3209 TSTOSC opt_tissue_graphics ; shall show: 0= pres+sat, 1= N2+He |
| 634 | 3210 bsf tissue_graphic_layout ; YES - show press+sat |
| 3211 TSTOSC char_I_model ; GF factors enabled? | |
| 3212 bsf tissue_graphic_gf ; YES - show GF lines | |
| 3213 | |
| 623 | 3214 ; reset max relative pressure (max depth) |
| 3215 bsf reset_max_pressure ; request ISR to reset the max pressure | |
| 3216 | |
| 640 | 3217 ; make working copy of opt_ccr_mode |
| 3218 movff opt_ccr_mode,dive_ccr_mode ; copy option setting | |
| 3219 | |
| 3220 | |
| 623 | 3221 IFDEF _min_depth_option |
| 3222 ; reset the resettable min/max relative pressure (trip-wise min/max depth) | |
| 3223 bsf reset_trip_pressure ; request ISR to reset the resettable min/max pressure | |
| 3224 ENDIF | |
| 3225 | |
| 604 | 3226 IFDEF _cave_mode |
| 623 | 3227 ; initialize the cave mode |
| 631 | 3228 bcf cave_mode ; disable cave mode by default |
| 3229 TSTOSC opt_cave_mode ; cave mode switched on? | |
| 3230 bsf cave_mode ; YES - enable cave mode | |
| 3231 | |
| 3232 bcf dive_turned ; dive is not turned yet | |
| 3233 bcf backtrack_almost_full ; backtracking storage is not almost full yet | |
| 3234 bcf backtrack_entire_full ; backtracking storage is not entirely full yet | |
| 3235 bsf waypoint_reached_first ; current waypoint is the first recorded waypoint | |
| 3236 bsf waypoint_reached_last ; current waypoint is the last recorded waypoint | |
| 3237 | |
| 3238 clrf backtrack_waypoint_num ; initialize the waypoint number | |
| 3239 clrf backtrack_waypoint_turn ; no turn point yet | |
| 3240 | |
| 3241 movlw .0 ; initialize backtracking index to first position in storage | |
| 3242 movff WREG,char_I_backtrack_index ; ... | |
| 3243 | |
| 3244 clrf depth_meter ; store initial depth data set with depth = surface | |
| 3245 call write_backtrack_1min_depth ; ... | |
| 3246 ENDIF ; _cave_mode | |
| 3247 | |
| 3248 ; base configuration of the deco engine | |
| 623 | 3249 clrf hi ; start with everything disabled |
| 631 | 3250 TSTOSC opt_ext_stops ; shall make extended stops? |
| 623 | 3251 bsf hi,DECO_EXTENDED_STOPS ; YES - enable extended stops |
| 604 | 3252 IFDEF _rx_functions |
| 623 | 3253 btfsc tr_functions_activated ; TR functions activated? |
| 3254 bsf hi,DECO_TR_FUNCTIONS ; YES - enable TR functions | |
| 604 | 3255 ENDIF |
| 631 | 3256 IFDEF _gas_contingency |
| 3257 ; set contingency mode on/off | |
| 3258 TSTOSC opt_gas_contingency_dive ; gas contingency for dive mode switched on? | |
| 3259 bsf hi,DECO_GAS_CONTINGENCY ; YES - activate gas contingency mode | |
| 3260 ENDIF ; _gas_contingency | |
| 604 | 3261 movff hi,char_O_main_status ; bank-safe copy to deco engine |
| 3262 | |
| 631 | 3263 clrf lo ; start with everything disabled |
| 3264 bsf lo,DECO_START_NORM ; set flag for doing a normal plan | |
| 3265 bsf lo,DECO_INITIALIZE ; set flag for initializing the deco engine | |
| 604 | 3266 movff lo,char_O_deco_status ; bank-safe copy back to deco engine |
| 0 | 3267 |
| 623 | 3268 ; disable "fast forward" function |
| 634 | 3269 movlw .0 ; set fast forward to zero |
| 3270 movff WREG,char_I_sim_advance_time; ... | |
| 623 | 3271 |
| 3272 ; write last stop depth to deco engine | |
| 631 | 3273 movff opt_last_stop,char_I_last_stop_depth |
| 623 | 3274 |
| 3275 ; initialize max depth for apnoe mode | |
| 634 | 3276 CLRI apnoe_max_pressure ; reset to zero |
| 623 | 3277 |
| 3278 ; reset minimum temperature, ISR-safe 2 byte copy | |
| 3279 SMOVII temperature_cur,temperature_min | |
| 3280 | |
| 3281 ; ISR-safe copy of start-of-dive date and time for logbook (6 bytes in total) | |
| 3282 SMOVSS rtc_year,start_year | |
| 3283 | |
| 3284 MOVII int_O_CNS_current,CNS_start ; save current CNS at beginning of dive, but | |
| 3285 bcf CNS_start+1,int_warning_flag ; without warning flag | |
| 3286 bcf CNS_start+1,int_attention_flag ; without attention flag | |
| 3287 | |
| 3288 ; save supersaturation at beginning of dive (only lower byte is used for value) | |
| 3289 movff int_O_lead_supersat+0,supersat_start | |
| 3290 | |
| 631 | 3291 clrf menu_pos_cur ; reset current menu position |
| 3292 clrf active_premenu ; no pre-menu task active | |
| 623 | 3293 |
| 3294 clrf safety_stop_countdown ; clear safety stop count-down | |
| 3295 | |
| 3296 CLRI last_pressure_velocity ; initialize last pressure for velocity calculation | |
| 3297 CLRI dive_timeout_timer ; initialize timeout counter | |
| 3298 | |
| 3299 movlw .1 ; initialize the sampling timer such that the 1st sampling ... | |
| 3300 movwf sampling_timer ; ... trigger will be given as soon as possible | |
| 3301 | |
| 3302 clrf message_page ; initialize message page counter | |
| 3303 clrf alarm_type ; clear all alarms | |
| 3304 | |
| 3305 ; clear the total dive average depth | |
| 3306 CLRI pressure_rel_avg_total ; average depth | |
| 3307 CLRI divesecs_avg_total ; time accumulator | |
| 3308 clrf pressure_rel_accu_total+0 ; depth accumulator | |
| 631 | 3309 clrf pressure_rel_accu_total+1 ; ... |
| 3310 clrf pressure_rel_accu_total+2 ; ... | |
| 3311 clrf pressure_rel_accu_total+3 ; ... | |
| 656 | 3312 |
| 3313 ; IFDEF _compass | |
| 3314 ; CLRI divesecs_compass_trip ; time accumulator for the compass stopwatch (Not really needed, it's not shown until it's reset with the 1st. course set) | |
| 3315 ; ENDIF | |
| 604 | 3316 |
| 3317 IFDEF _rx_functions | |
| 623 | 3318 |
| 3319 btfss tr_functions_activated ; TR functions activated? | |
| 604 | 3320 bra diveloop_boot_0 ; NO - skip TR function initialization |
| 623 | 3321 |
| 604 | 3322 banksel int_IO_pressure_value |
| 634 | 3323 |
| 3324 clrf WREG ; set WREG to coding for integer numbers -> data not available | |
| 3325 bsf WREG,int_not_avail_flag ; ... | |
| 623 | 3326 clrf int_IO_pressure_value+0 ; clear low byte of 1st pressure reading value |
| 3327 movwf int_IO_pressure_value+1 ; copy to high byte of 1st pressure reading value | |
| 3328 clrf int_IO_pressure_value+2 ; clear low byte of 2nd pressure reading value | |
| 3329 movwf int_IO_pressure_value+3 ; copy to high byte of 2nd pressure reading value | |
| 3330 clrf int_I_pressure_drop+0 ; clear low byte of 1st pressure drop value | |
| 3331 movwf int_I_pressure_drop+1 ; copy to high byte of 1st pressure drop value | |
| 3332 clrf int_I_pressure_drop+2 ; clear low byte of 2nd pressure drop value | |
| 3333 movwf int_I_pressure_drop+3 ; copy to high byte of 1st pressure drop value | |
| 604 | 3334 clrf char_I_pressure_gas+0 ; clear gas selection of 1st pressure reading |
| 3335 clrf char_I_pressure_gas+1 ; clear gas selection of 2nd pressure reading | |
| 3336 clrf char_I_pressure_age+0 ; clear age of 1st pressure reading | |
| 3337 clrf char_I_pressure_age+1 ; clear age of 2nd pressure reading | |
| 3338 clrf char_I_pressure_stat+0 ; clear status of 1st pressure reading | |
| 3339 clrf char_I_pressure_stat+1 ; clear status of 2nd pressure reading | |
| 623 | 3340 |
| 604 | 3341 banksel gas__last_1st ; select bank with vars for pressure drop calculation |
| 3342 setf gas__last_1st ; invalidate last gas of 1st reading | |
| 623 | 3343 setf gas__last_2nd ; invalidate last gas of 2nd reading |
| 3344 | |
| 604 | 3345 banksel common ; back to bank common |
| 623 | 3346 |
| 3347 ENDIF ; _rx_functions | |
| 3348 | |
| 604 | 3349 |
| 3350 diveloop_boot_0: | |
| 3351 setf best_gas_number ; initialize best gas as not computed yet (255) | |
| 623 | 3352 IFDEF _ccr_pscr |
| 604 | 3353 setf best_dil_number ; initialize best diluent as not computed yet (255) |
| 623 | 3354 ENDIF |
| 604 | 3355 |
| 3356 btfsc FLAG_oc_mode ; in OC mode? | |
| 634 | 3357 call dive_boot_oc ; YES - add OC mode settings |
| 604 | 3358 |
| 623 | 3359 IFDEF _ccr_pscr |
| 604 | 3360 btfsc FLAG_ccr_mode ; in CCR mode? |
| 634 | 3361 call dive_boot_cc ; YES - add CC mode settings |
| 604 | 3362 btfsc FLAG_ccr_mode ; in CCR mode? |
| 634 | 3363 call dive_boot_cc_part2 ; YES - add CC sensor and SP settings |
| 604 | 3364 |
| 3365 btfsc FLAG_pscr_mode ; in pSCR mode? | |
| 634 | 3366 call dive_boot_cc ; YES - add CC mode settings |
| 604 | 3367 btfsc FLAG_pscr_mode ; in pSCR mode? |
| 634 | 3368 call dive_boot_cc_part2 ; YES - add CC sensor and SP settings |
| 623 | 3369 ENDIF |
| 604 | 3370 |
| 631 | 3371 bcf bailout_mode ; not in bailout mode |
| 3372 | |
| 604 | 3373 call ghostwriter_short_header ; write short header with dive number into profile memory |
| 623 | 3374 call init_recording_params ; set up all the divisors for dive data recording |
| 3375 | |
| 3376 ; setup gas selector flag (required to have better gas working) | |
| 3377 bsf is_diluent_menu ; default to using diluents | |
| 3378 btfsc FLAG_ccr_mode ; in CCR mode? | |
| 3379 bra diveloop_boot_3 ; YES - default was right | |
| 3380 btfsc FLAG_pscr_mode ; in pSCR mode? | |
| 3381 bra diveloop_boot_3 ; YES - default was right | |
| 3382 bcf is_diluent_menu ; NO to both - revert to using OC gases | |
| 604 | 3383 |
| 3384 diveloop_boot_3: | |
| 582 | 3385 bcf LEDg ; switch off green LED / release reset to RX circuitry |
| 604 | 3386 bcf LEDr ; switch off red LED |
| 623 | 3387 |
| 3388 btfss sensor_override_active ; in simulator mode? | |
| 604 | 3389 call disable_rs232 ; NO - disable RS232 |
| 3390 | |
| 3391 IFDEF _screendump | |
| 623 | 3392 btfsc screen_dump_avail ; screen dump function enabled? |
| 3393 call enable_rs232 ; enable interface (also sets CPU speed to normal) | |
| 604 | 3394 ENDIF |
| 3395 | |
| 623 | 3396 clrf apnoe_surface_mins ; clear apnoe surface time, minutes (8 bit) |
| 3397 clrf apnoe_surface_secs ; clear apnoe surface time, seconds (8 bit) | |
| 3398 clrf apnoe_dive_mins ; clear apnoe dive time, minutes (8 bit) | |
| 3399 clrf apnoe_dive_secs ; clear apnoe dive time, seconds (8 bit) | |
| 654 | 3400 clrf apnoe_dive_counter ; clear apnoe #dive counter (8 bit) |
| 604 | 3401 |
| 3402 return ; done with dive mode boot | |
| 3403 | |
| 3404 | |
| 3405 ;============================================================================= | |
| 634 | 3406 dmode4 CODE |
| 3407 ;============================================================================= | |
| 3408 | |
| 3409 | |
| 3410 ;----------------------------------------------------------------------------- | |
| 3411 ; Check all Sorts of Parameters and issue Warnings and Attentions if applicable | |
| 3412 ; | |
| 623 | 3413 divemode_check_warnings: |
| 604 | 3414 movlw .1 ; one message at a time in alternative layout |
| 623 | 3415 btfss alt_layout_active ; in alternative layout? |
| 3416 movlw .2 ; NO - two messages at a time in normal layout | |
| 634 | 3417 cpfsgt message_counter ; had more than 1 / 2 messages in the last round? |
| 623 | 3418 bra divemode_check_warnings1 ; NO - update messages every second |
| 3419 | |
| 3420 ; ; YES - update every 4 seconds: | |
| 631 | 3421 ; btfss timebase_1sec ; - on second 1 or 3 ? |
| 623 | 3422 ; return ; NO - no update in this cycle |
| 3423 ; btfss timebase_2sec ; YES - on second 3 ? | |
| 3424 ; return ; NO - no update in this cycle | |
| 3425 ; ;bra divemode_check_warnings1 ; YES - update messages | |
| 3426 | |
| 634 | 3427 ; YES - update every 2 seconds |
| 623 | 3428 btfsc timebase_1sec ; - on even second? |
| 3429 return ; NO - done | |
| 3430 ;bra divemode_check_warnings1 ; YES - update messages | |
| 3431 | |
| 3432 divemode_check_warnings1: | |
| 604 | 3433 clrf message_counter ; clear message counter |
| 3434 | |
| 3435 ; messages sorted by severity: highest severity warnings first, then attentions, advices and last info | |
| 3436 | |
| 3437 ; warnings for all modes | |
| 634 | 3438 call check_battery ; check battery status |
| 3439 rcall check_depth_limit ; check current depth | |
| 3440 call check_divetimeout ; check dive timeout | |
| 604 | 3441 |
| 623 | 3442 btfsc FLAG_apnoe_mode ; in apnoe mode? |
| 634 | 3443 bra divemode_check_warnings2 ; YES - skip deco mode checks |
| 623 | 3444 |
| 604 | 3445 btfsc FLAG_gauge_mode ; in gauge mode? |
| 634 | 3446 bra divemode_check_warnings2 ; YES - skip deco mode checks |
| 604 | 3447 |
| 3448 ; warnings applicable only in deco modes | |
| 631 | 3449 |
| 3450 IFDEF _cave_mode | |
| 3451 rcall check_cavemode ; check cave mode status | |
| 3452 ENDIF | |
| 3453 | |
| 634 | 3454 rcall check_display_ftts ; show fTTS time (or cave mode cTTS) |
| 3455 rcall check_ppO2 ; check ppO2 | |
| 0 | 3456 |
| 656 | 3457 IFDEF _external_sensor_eccr |
| 634 | 3458 rcall check_ext_sensors ; check external sensors |
| 623 | 3459 ENDIF |
| 582 | 3460 |
| 604 | 3461 rcall check_outside ; check of ZHL16 model violation |
| 560 | 3462 |
| 634 | 3463 IFDEF _ccr_pscr |
| 623 | 3464 btfsc FLAG_ccr_mode ; in CCR mode? |
| 3465 rcall check_OC_gas_avail ; YES - check if a breathable OC (bailout) gas is available | |
| 3466 btfsc FLAG_pscr_mode ; in pSCR mode? | |
| 3467 rcall check_OC_gas_avail ; YES - check if a breathable OC (bailout) gas is available | |
| 634 | 3468 ENDIF |
| 604 | 3469 |
| 3470 btfsc decostop_active ; in deco mode? | |
| 634 | 3471 rcall check_saturation ; YES - check tissue saturation |
| 604 | 3472 |
| 3473 rcall check_mbubbles ; check for micro bubbles | |
| 634 | 3474 rcall check_cns_violation_now ; check current CNS value |
| 3475 rcall check_cns_violation_eod ; check end-of-dive CNS value (needs to be done after check_cns_violation_now) | |
| 3476 rcall check_gas_needs ; check for gas needs | |
| 3477 rcall check_gas_change ; check for diluent or gas change advice | |
| 3478 | |
| 3479 IFDEF _ccr_pscr | |
| 3480 btfsc FLAG_ccr_mode ; in CCR mode? | |
| 3481 rcall check_gas_density ; YES - check gas density | |
| 3482 btfsc FLAG_pscr_mode ; in pSCR mode? | |
| 3483 rcall check_gas_density ; YES - check gas density | |
| 3484 ENDIF | |
| 604 | 3485 |
| 623 | 3486 btfsc use_aGF ; using alternative GF factors? |
| 634 | 3487 rcall remind_agf_in_use ; YES - show reminder |
| 582 | 3488 |
| 623 | 3489 divemode_check_warnings2: |
| 634 | 3490 |
| 604 | 3491 IFDEF _rx_functions |
| 623 | 3492 btfss tr_functions_activated ; TR functions activated? |
| 3493 bra divemode_check_warnings3 ; NO - skip | |
| 3494 call check_tr_functions ; YES - check transmitter functions | |
| 3495 call check_tr_messages ; - check SAC attention and switch advice | |
| 604 | 3496 ENDIF |
| 3497 | |
| 623 | 3498 divemode_check_warnings3: |
| 634 | 3499 |
| 3500 ; compute if an advice / attention / warning sign shall be shown | |
| 3501 rcall divemode_check_sign | |
| 3502 | |
| 3503 ; increment message page number | |
| 623 | 3504 incf message_page,F ; increment page number |
| 3505 bcf STATUS,C ; clear carry bit | |
| 3506 movf message_page,W ; get page number into WREG | |
| 3507 btfss alt_layout_active ; in alternative layout? | |
| 3508 rlcf WREG,W ; NO - each page can take two messages | |
| 3509 cpfsgt message_counter ; number of actual messages > message capacity ? | |
| 3510 clrf message_page ; NO - all messages could be shown, restart from first page next time | |
| 604 | 3511 |
| 634 | 3512 ; clear both rows of messages if there is nothing to show at all |
| 623 | 3513 tstfsz message_counter ; any message to show? |
| 3514 bra divemode_check_warnings4 ; YES - look if second row needs to be cleared | |
| 3515 bsf FLAG_TFT_message_clear_both ; NO - request clearing of left-over messages | |
| 3516 return ; - done | |
| 3517 | |
| 3518 divemode_check_warnings4: | |
| 634 | 3519 ; clear 2nd row of messages if there is nothing to show (on this page) |
| 623 | 3520 btfss message_2nd_row_used ; does the 2nd row contain a message? |
| 3521 bsf FLAG_TFT_message_clear_2nd ; NO - set flag to clear the 2nd row | |
| 3522 return ; done | |
| 3523 | |
| 634 | 3524 |
| 623 | 3525 ;----------------------------------------------------------------------------- |
| 634 | 3526 ; Helper Function - check if an Advice / Attention / Warning Sign shall be shown |
| 3527 ; | |
| 3528 divemode_check_sign: | |
| 3529 ; clear sign flags | |
| 3530 bcf sign_advice ; clear flag for showing advice sign | |
| 3531 bcf sign_attention ; clear flag for showing attention sign | |
| 3532 bcf sign_warning ; clear flag for showing warning sign | |
| 3533 | |
| 3534 ; check for new advices | |
| 3535 movf DM_flags_advc_det,W ; get current advices | |
| 3536 andwf DM_flags_advc_ack,W ; keep only those acknowledgments that have current advices | |
| 3537 movwf DM_flags_advc_ack ; store updated acknowledgments | |
| 3538 xorwf DM_flags_advc_det,W ; find advices that have not been acknowledged yet | |
| 3539 tstfsz WREG ; any new advice? | |
| 3540 bsf sign_advice ; YES - set flag for showing advice sign | |
| 3541 | |
| 3542 ; check for new attentions (1) | |
| 3543 movf DM_flags_att1_det,W ; get current attentions | |
| 3544 andwf DM_flags_att1_ack,W ; keep only those acknowledgments that have current attentions | |
| 3545 movwf DM_flags_att1_ack ; store updated acknowledgments | |
| 3546 xorwf DM_flags_att1_det,W ; find attentions that have not been acknowledged yet | |
| 3547 tstfsz WREG ; any new attention? | |
| 3548 bsf sign_attention ; YES - set flag for showing attention sign | |
| 3549 | |
| 3550 ; check for new attentions (2) | |
| 3551 movf DM_flags_att2_det,W ; get current attentions | |
| 3552 andwf DM_flags_att2_ack,W ; keep only those acknowledgments that have current attentions | |
| 3553 movwf DM_flags_att2_ack ; store updated acknowledgments | |
| 3554 xorwf DM_flags_att2_det,W ; find attentions that have not been acknowledged yet | |
| 3555 tstfsz WREG ; any new attention? | |
| 3556 bsf sign_attention ; YES - set flag for showing attention sign | |
| 3557 | |
| 3558 ; check for new attentions (3) | |
| 3559 movf DM_flags_att3_det,W ; get current attentions | |
| 3560 andwf DM_flags_att3_ack,W ; keep only those acknowledgments that have current attentions | |
| 3561 movwf DM_flags_att3_ack ; store updated acknowledgments | |
| 3562 xorwf DM_flags_att3_det,W ; find attentions that have not been acknowledged yet | |
| 3563 tstfsz WREG ; any new attention? | |
| 3564 bsf sign_attention ; YES - set flag for showing attention sign | |
| 3565 | |
| 3566 ; check for new warnings (1) | |
| 3567 movf DM_flags_war1_det,W ; get current warnings | |
| 3568 andwf DM_flags_war1_ack,W ; keep only those acknowledgments that have current warnings | |
| 3569 movwf DM_flags_war1_ack ; store updated acknowledgments | |
| 3570 xorwf DM_flags_war1_det,W ; find warnings that have not been acknowledged yet | |
| 3571 tstfsz WREG ; any new warning? | |
| 3572 bsf sign_warning ; YES - set flag for showing warning sign | |
| 3573 | |
| 3574 ; check for new warnings (2) | |
| 3575 movf DM_flags_war2_det,W ; get current warnings | |
| 3576 andwf DM_flags_war2_ack,W ; keep only those acknowledgments that have current warnings | |
| 3577 movwf DM_flags_war2_ack ; store updated acknowledgments | |
| 3578 xorwf DM_flags_war2_det,W ; find warnings that have not been acknowledged yet | |
| 3579 tstfsz WREG ; any new warning? | |
| 3580 bsf sign_warning ; YES - set flag for showing warning sign | |
| 3581 | |
| 3582 ; show or clear the advice / attention / warning sign | |
| 3583 btfsc sign_advice ; shall show advice sign? | |
| 3584 bsf FLAG_TFT_sign_show ; YES - show sign | |
| 3585 btfsc sign_attention ; shall show attention sign? | |
| 3586 bsf FLAG_TFT_sign_show ; YES - show sign | |
| 3587 btfsc sign_warning ; shall show warning sign? | |
| 3588 bsf FLAG_TFT_sign_show ; YES - show sign | |
| 3589 btfss FLAG_TFT_sign_show ; shall show any sign? | |
| 3590 bsf FLAG_TFT_sign_clear ; NO - then clear the sign | |
| 3591 | |
| 3592 return ; done | |
| 3593 | |
| 3594 | |
| 3595 ;----------------------------------------------------------------------------- | |
| 3596 ; Check Battery Power | |
| 3597 ; | |
| 3598 global check_battery | |
| 3599 check_battery: | |
| 3600 bcf warn_det_batt_low ; clear warning for battery low | |
| 623 | 3601 movlw battery_show_level+1 ; get threshold for showing battery level, incremented by 1 |
| 628 | 3602 cpfslt batt_percent ; battery percentage ok? |
| 634 | 3603 return ; YES - done |
| 3604 btfsc battery_low_condition ; NO - battery low condition detected? | |
| 3605 bsf warn_det_batt_low ; YES - set warning for battery low | |
| 3606 movf active_customview,W ; - get current custom view | |
| 3607 xorlw index_clock_batt_surfpress ; - battery shown in custom view? | |
| 3608 bnz check_battery_mesg ; NO - show message | |
| 3609 return ; YES - do not show twice, done | |
| 3610 | |
| 3611 check_battery_mesg: | |
| 3612 incf message_counter,F ; increase message counter | |
| 3613 goto TFT_message_battery_percent ; show message for battery low (battery percent) and return | |
| 3614 | |
| 3615 | |
| 3616 ;----------------------------------------------------------------------------- | |
| 3617 ; Show Dive Timeout Counter if Dive Time is not counted | |
| 3618 ; | |
| 55 | 3619 check_divetimeout: |
| 623 | 3620 btfsc count_divetime ; is dive time counted? |
| 634 | 3621 return ; YES - nothing to do, done |
| 3622 incf message_counter,F ; NO - increase message counter | |
| 3623 goto TFT_message_divetimeout ; - show timeout counter and return | |
| 3624 | |
| 3625 | |
| 3626 ;----------------------------------------------------------------------------- | |
| 3627 ; Check ppO2 of all Gases / Diluents in use | |
| 3628 ; | |
| 560 | 3629 check_ppO2: |
| 623 | 3630 IFDEF _ccr_pscr |
| 634 | 3631 ; check if breathing from the loop |
| 3632 btfsc FLAG_oc_mode ; in OC mode? | |
| 604 | 3633 bra check_ppO2_1 ; YES - continue with breathed gas |
| 623 | 3634 btfsc bailout_mode ; NO - in bailout? |
| 604 | 3635 bra check_ppO2_1 ; YES - continue with breathed gas |
| 634 | 3636 ; CCR / pSCR mode - check the pure diluent |
| 3637 bcf warn_det_ppO2_diluent ; clear warning for pure diluent ppO2 | |
| 3638 bcf attn_det_ppo2_diluent ; clear attention for pure diluent ppO2 | |
| 623 | 3639 MOVII int_O_pure_ppO2,mpr ; get value and attention/warning flags for the pure diluent |
| 634 | 3640 btfsc hi,int_warning_flag ; ppO2 of the pure diluent in warning state? |
| 3641 bra check_ppO2_dil_warn ; YES - show warning | |
| 604 | 3642 btfsc hi,int_attention_flag ; ppO2 of the pure diluent in attention state? |
| 634 | 3643 bra check_ppO2_dil_attn ; YES - show attention |
| 3644 bra check_ppO2_1 ; continue with checking breathed gas | |
| 3645 | |
| 3646 check_ppO2_dil_warn: | |
| 3647 bsf warn_det_ppO2_diluent ; set warning for pure diluent ppO2 | |
| 3648 rcall check_ppO2_show_mesg ; show ppO2 message | |
| 3649 bra check_ppO2_1 ; continue with checking breathed gas | |
| 3650 | |
| 3651 check_ppO2_dil_attn: | |
| 3652 bsf attn_det_ppo2_diluent ; set attention for pure diluent ppO2 | |
| 3653 rcall check_ppO2_show_mesg ; show ppO2 message | |
| 3654 ;bra check_ppO2_1 ; continue with checking breathed gas | |
| 3655 ENDIF ; _ccr_pscr | |
| 3656 | |
| 604 | 3657 check_ppO2_1: |
| 634 | 3658 ; all modes - check breathed gas (OC or loop) |
| 3659 bcf attn_det_ppo2_breathed ; clear attention for breathed ppO2 | |
| 3660 bcf warn_det_ppO2_breathed ; clear warning for breathed ppO2 | |
| 623 | 3661 MOVII int_O_breathed_ppO2,mpr ; get value and attention/warning flags for the breathed gas |
| 604 | 3662 btfsc hi,int_attention_flag ; breathed ppO2 in attention state (when in loop mode, no attention will be generated)? |
| 634 | 3663 bra check_ppO2_breath_attn ; YES - set attention flag and show ppO2 |
| 3664 btfsc hi,int_low_flag ; NO - breathed ppO2 too low? | |
| 3665 bra check_ppO2_breath_warn_low ; YES - record the warning and show ppO2 | |
| 3666 btfsc hi,int_high_flag ; NO - breathed ppO2 too high? | |
| 3667 bra check_ppO2_breath_warn_high ; YES - record the warning and show ppO2 | |
| 3668 bra check_ppO2_breath_ok ; NO - ppO2 is ok | |
| 3669 | |
| 3670 check_ppO2_breath_attn: | |
| 3671 bsf attn_det_ppo2_breathed ; set attention for breathed ppO2 | |
| 3672 bra check_ppO2_show ; show ppO2 message | |
| 3673 | |
| 3674 check_ppO2_breath_warn_low: | |
| 582 | 3675 movlw d'4' ; set type of alarm (ppO2 low) |
| 634 | 3676 bra check_ppO2_breath_common ; continue with common part |
| 3677 | |
| 3678 check_ppO2_breath_warn_high: | |
| 560 | 3679 movlw d'5' ; set type of alarm (ppO2 high) |
| 634 | 3680 ;bra check_ppO2_breath_common ; continue with common part |
| 3681 | |
| 3682 check_ppO2_breath_common: | |
| 623 | 3683 movwf alarm_type ; copy alarm type to alarm register |
| 634 | 3684 bsf event_occured ; set event flag |
| 3685 bsf warn_det_ppO2_breathed ; set warning for breathed ppO2 | |
| 3686 bra check_ppO2_show ; show ppO2 message | |
| 3687 | |
| 3688 check_ppO2_breath_ok: | |
| 3689 TSTOSS opt_showppo2 ; shall always show ppO2 (0 = no, 1 = yes) | |
| 3690 return ; NO - done | |
| 3691 ;bra check_ppO2_show ; YES - show ppO2 message | |
| 3692 | |
| 3693 check_ppO2_show: | |
| 631 | 3694 IFDEF _ccr_pscr |
| 634 | 3695 btfsc FLAG_oc_mode ; in OC mode? |
| 3696 bra check_ppO2_show_1 ; YES - show ppO2 message | |
| 3697 btfsc bailout_mode ; in bailout mode? | |
| 3698 bra check_ppO2_show_1 ; YES - show ppO2 message | |
| 604 | 3699 return ; NO - in loop mode, ppO2 is already shown via setpoint display |
| 634 | 3700 ENDIF |
| 3701 check_ppO2_show_1: | |
| 3702 movf active_customview,W ; get current custom view | |
| 3703 xorlw index_ppo2_ead_end_cns ; ppO2 shown already via custom view? | |
| 3704 bz check_ppO2_done ; YES - done | |
| 3705 movf active_customview,W ; get current custom view (again) | |
| 3706 xorlw index_pscr_info ; ppO2 shown already via custom view? | |
| 3707 bz check_ppO2_done ; YES - done | |
| 3708 ;bra check_ppO2_show_mesg ; NO - show ppO2 message | |
| 3709 | |
| 3710 check_ppO2_show_mesg: | |
| 3711 incf message_counter,F ; increase message counter | |
| 3712 goto TFT_message_ppo2 ; show ppO2 message and return | |
| 3713 | |
| 3714 check_ppO2_done: | |
| 3715 return ; done | |
| 3716 | |
| 3717 | |
| 3718 ;----------------------------------------------------------------------------- | |
| 3719 ; Show fTTS Message | |
| 3720 ; | |
| 604 | 3721 check_display_ftts: |
| 631 | 3722 IFDEF _ccr_pscr |
| 3723 btfsc bailout_mode ; in bailout mode? | |
| 3724 return ; YES - in bailout no fTTS is computed, done | |
| 3725 ENDIF | |
| 623 | 3726 btfss count_divetime ; is dive time counted? |
| 631 | 3727 return ; NO - omit, done |
| 623 | 3728 movff char_I_extra_time,lo ; YES - get extra time |
| 3729 tstfsz lo ; - extra time > 0 ? | |
| 634 | 3730 bra check_display_ftts_mesg ; YES - show fTTS |
| 631 | 3731 return ; NO - no fTTS computed, done |
| 634 | 3732 |
| 3733 check_display_ftts_mesg: | |
| 631 | 3734 incf message_counter,F ; increase counter |
| 634 | 3735 goto TFT_message_ftts ; show @+x time |
| 3736 | |
| 3737 | |
| 3738 ;----------------------------------------------------------------------------- | |
| 3739 ; check current CNS Value | |
| 3740 ; | |
| 3741 global check_cns_violation_now | |
| 3742 check_cns_violation_now: | |
| 3743 bcf warn_det_cns_current ; clear warning for CNS | |
| 3744 bcf attn_det_cns_current ; clear attention for CNS | |
| 623 | 3745 movff int_O_CNS_current+1,WREG ; get current CNS, high byte |
| 582 | 3746 btfsc WREG,int_warning_flag ; warning flag set? |
| 634 | 3747 bra check_cns_violation_now_warn; YES - show a warning |
| 3748 btfsc WREG,int_attention_flag ; attention flag set? | |
| 3749 bra check_cns_violation_now_attn; YES - show an attention | |
| 3750 return ; NO - done | |
| 3751 | |
| 3752 check_cns_violation_now_warn: | |
| 3753 bsf warn_det_cns_current ; set warning for CNS | |
| 3754 bra check_cns_violation_now_mesg; show message | |
| 3755 | |
| 3756 check_cns_violation_now_attn: | |
| 3757 bsf attn_det_cns_current ; set attention for CNS | |
| 3758 ;bra check_cns_violation_now_mesg; show message | |
| 3759 | |
| 3760 check_cns_violation_now_mesg: | |
| 628 | 3761 IFNDEF _helium |
| 634 | 3762 movf active_customview,W ; get current custom view |
| 3763 xorlw index_ppo2_ead_end_cns ; CNS shown? | |
| 3764 bz check_cns_violation_now_done; YES - done | |
| 628 | 3765 ENDIF |
| 634 | 3766 movf active_customview,W ; get current custom view (again) |
| 3767 xorlw index_CNS ; CNS shown? | |
| 3768 bz check_cns_violation_now_done; YES - done | |
| 3769 incf message_counter,F ; NO - increase counter | |
| 3770 goto TFT_message_cns ; - show message and return | |
| 3771 | |
| 3772 check_cns_violation_now_done: | |
| 3773 return ; done | |
| 3774 | |
| 3775 | |
| 3776 ;----------------------------------------------------------------------------- | |
| 3777 ; check end-of-Dive CNS Value | |
| 3778 ; | |
| 3779 global check_cns_violation_eod | |
| 3780 check_cns_violation_eod: | |
| 3781 bcf attn_det_cns_eod ; clear attention for end-of-dive CNS | |
| 3782 btfsc warn_det_cns_current ; current CNS value in warning state? | |
| 3783 return ; YES - inhibit end-of-dive CNS checks if current CNS is already in warning | |
| 3784 ;bra check_cns_violation_eod_norm; NO - check normal plan | |
| 3785 | |
| 3786 check_cns_violation_eod_norm: | |
| 623 | 3787 movff int_O_CNS_norm+1,WREG ; get CNS at end of dive in normal plan, high byte |
| 560 | 3788 btfsc WREG,int_invalid_flag ; flag for invalid value set? |
| 634 | 3789 bra check_cns_violation_eod_alt ; YES - continue with checking alternative plan |
| 582 | 3790 btfsc WREG,int_warning_flag ; NO - flag for warning set? |
| 634 | 3791 bra check_cns_violation_eod_warn; YES - show message |
| 3792 ;bra check_cns_violation_eod_alt ; NO - check alternative plan | |
| 3793 | |
| 3794 check_cns_violation_eod_alt: | |
| 623 | 3795 movff int_O_CNS_alt+1,WREG ; get CNS at end of dive in alternative plan, high byte |
| 560 | 3796 btfsc WREG,int_invalid_flag ; flag for invalid value set? |
| 634 | 3797 return ; YES - done |
| 560 | 3798 btfsc WREG,int_warning_flag ; NO - flag for warning set? |
| 634 | 3799 bra check_cns_violation_eod_warn; YES - show message |
| 3800 return ; NO - done | |
| 3801 | |
| 3802 check_cns_violation_eod_warn: | |
| 3803 bsf attn_det_cns_eod ; set attention(!) for end-of-dive CNS | |
| 3804 movf active_customview,W ; get current custom view | |
| 3805 xorlw index_CNS ; CNS shown? | |
| 3806 bz check_cns_violation_eod_done; YES - done | |
| 3807 incf message_counter,F ; NO - increase message counter | |
| 3808 goto TFT_message_cns_eod ; - show message for end-of-dive CNS and return | |
| 3809 | |
| 3810 check_cns_violation_eod_done: | |
| 3811 return ; done | |
| 3812 | |
| 3813 | |
| 3814 ;----------------------------------------------------------------------------- | |
| 3815 ; Check current Tissue Supersaturation | |
| 3816 ; | |
| 3817 global check_saturation | |
| 3818 check_saturation: | |
| 3819 bcf attn_det_saturation ; clear attention for saturation | |
| 3820 bcf warn_det_saturation ; clear warning for saturation | |
| 3821 bcf attn_det_ibcd ; clear attention for IBCD | |
| 3822 movff int_O_lead_supersat+1,WREG ; get upper byte of leading tissue's supersaturation | |
| 3823 btfss WREG,int_warning_flag ; warning flag set? | |
| 3824 bra check_saturation_1 ; NO - continue with checking for attention flag | |
| 3825 movlw d'2' ; YES - set type of alarm | |
| 3826 movwf alarm_type ; - copy to alarm register | |
| 3827 bsf event_occured ; - set event flag | |
| 3828 bsf warn_det_saturation ; - set warning | |
| 3829 bra check_saturation_mesg ; - show saturation message | |
| 3830 | |
| 3831 check_saturation_1: | |
| 3832 btfss WREG,int_attention_flag ; attention flag set? | |
| 3833 bra check_saturation_2 ; NO - continue with checking for IBCD | |
| 3834 bsf attn_det_saturation ; YES - set attention | |
| 3835 bra check_saturation_mesg ; - show saturation message | |
| 3836 | |
| 3837 check_saturation_2: | |
| 3838 IFDEF _helium | |
| 3839 TSTOSS opt_enable_IBCD ; IBCD warning activated? | |
| 3840 bra check_saturation_3 ; NO - continue with checking deco info | |
| 3841 movff char_O_deco_warnings,WREG ; YES - get the deco warnings vector | |
| 3842 btfss WREG,IBCD_warning ; - IBCD warning flag set? | |
| 3843 bra check_saturation_3 ; NO - continue with checking deco info | |
| 3844 bsf attn_det_ibcd ; YES - set attention | |
| 3845 bra check_saturation_mesg ; - show saturation message | |
| 3846 ENDIF | |
| 3847 | |
| 3848 check_saturation_3: | |
| 3849 btfss divemode ; in dive mode? | |
| 3850 return ; NO - done | |
| 631 | 3851 IFDEF _ccr_pscr |
| 634 | 3852 btfsc bailout_mode ; YES - in bailout mode? |
| 3853 return ; YES - done (deco zone flag is not updated when in bailout mode) | |
| 631 | 3854 ENDIF |
| 650 | 3855 TSTOSS opt_warning_level_divemode ; Warning level set to =1 "All" ? |
| 3856 return ; NO, skip warning/advise then | |
| 634 | 3857 movff char_O_deco_info,WREG ; NO - get the deco info vector |
| 3858 btfss WREG,deco_zone ; deco zone flag set? | |
| 3859 return ; NO - done | |
| 3860 btfsc use_aGF ; YES - using alternative GF factors? | |
| 3861 return ; YES - suppress deco zone info | |
| 3862 btfsc alt_layout_active ; NO - in alternative layout? | |
| 3863 return ; YES - suppress deco zone info | |
| 3864 incf message_counter,F ; NO - increase message counter | |
| 3865 goto TFT_message_deco_info ; - show deco info and return | |
| 3866 | |
| 3867 check_saturation_mesg: | |
| 3868 IFDEF _helium | |
| 3869 btfss attn_det_ibcd ; IBCD detected? | |
| 3870 bra check_saturation_mesg_1 ; NO - show saturation message | |
| 3871 incf message_counter,F ; YES - increase message counter | |
| 3872 call TFT_message_IBCD ; - show IBCD message | |
| 3873 ENDIF | |
| 3874 check_saturation_mesg_1: | |
| 3875 incf message_counter,F ; increase message counter | |
| 3876 goto TFT_message_saturation ; show saturation message and return | |
| 3877 | |
| 3878 | |
| 3879 ;----------------------------------------------------------------------------- | |
| 3880 ; Check Depth Limit | |
| 3881 ; | |
| 623 | 3882 check_depth_limit: |
| 634 | 3883 bcf warn_det_depth_limit ; clear warning by default |
| 623 | 3884 movff opt_max_depth,WREG ; get depth limit |
| 3885 cpfsgt depth_meter ; current depth > depth limit? | |
| 634 | 3886 return ; NO - done |
| 3887 bsf warn_det_depth_limit ; YES - set warning | |
| 650 | 3888 TSTOSS opt_warning_level_divemode ; Warning level set to =1 "All" ? |
| 3889 return ; NO, skip warning/advise then | |
| 634 | 3890 incf message_counter,F ; - increase message counter |
| 3891 goto TFT_message_depth_limit ; - show message | |
| 3892 | |
| 3893 | |
| 3894 ;----------------------------------------------------------------------------- | |
| 650 | 3895 ; Check Bühlmann Model Violation |
| 634 | 3896 ; |
| 604 | 3897 check_outside: |
| 634 | 3898 bcf warn_det_outside ; clear warning |
| 3899 bcf attn_det_outside ; clear attention | |
| 604 | 3900 movff char_O_deco_warnings,WREG ; bank-safe copy of deco warnings |
| 634 | 3901 btfss WREG,outside_warning ; currently outside the ZH-L16 model? |
| 3902 bra check_outside_1 ; NO | |
| 3903 bsf warn_det_outside ; YES - set warning | |
| 3904 bra check_outside_mesg ; - show message | |
| 3905 | |
| 3906 check_outside_1: | |
| 3907 btfss WREG,outside_warning_lock ; had been outside of the ZH-L16 model? | |
| 604 | 3908 return ; NO - done |
| 634 | 3909 bsf attn_det_outside ; YES - set attention |
| 3910 ;bra check_outside_mesg ; - show message | |
| 3911 | |
| 3912 check_outside_mesg: | |
| 3913 incf message_counter,F ; increase message counter | |
| 3914 goto TFT_message_outside ; show message and return | |
| 3915 | |
| 3916 | |
| 3917 ;----------------------------------------------------------------------------- | |
| 3918 ; Check raised Probability for Micro-Bubbles | |
| 3919 ; | |
| 604 | 3920 global check_mbubbles |
| 3921 check_mbubbles: | |
| 634 | 3922 bcf warn_det_microbubble ; clear warning |
| 3923 bcf attn_det_microbubble ; clear attention | |
| 604 | 3924 movff char_O_deco_warnings,WREG ; bank-safe copy for deco warnings |
| 634 | 3925 btfss WREG,mbubble_warning ; currently in micro bubbling zone? |
| 3926 bra check_mbubbles_1 ; NO | |
| 3927 bsf warn_det_microbubble ; YES - set warning | |
| 3928 bra check_mbubbles_mesg ; - show message | |
| 3929 | |
| 650 | 3930 check_mbubbles_1: |
| 634 | 3931 btfss WREG,mbubble_warning_lock ; had been in micro bubbling zone? |
| 604 | 3932 return ; NO - done |
| 634 | 3933 bsf attn_det_microbubble ; YES - set attention |
| 3934 ;bra check_mbubbles_mesg ; - show message | |
| 3935 | |
| 3936 check_mbubbles_mesg: | |
| 3937 incf message_counter,F ; increase message counter | |
| 3938 goto TFT_message_mbubbles ; show message and return | |
| 3939 | |
| 3940 | |
| 3941 IFDEF _ccr_pscr | |
| 3942 ;----------------------------------------------------------------------------- | |
| 3943 ; Check Gas Density | |
| 3944 ; | |
| 3945 check_gas_density: | |
| 3946 TSTOSS opt_gas_density_check ; shall check gas density? | |
| 3947 return ; NO - done | |
| 3948 bcf warn_det_gas_density ; YES - clear attention for gas density by default | |
| 3949 bcf attn_det_gas_density ; - clear warning for gas density by default | |
| 3950 movff int_O_gas_density+1,WREG ; - get upper byte of current gas density | |
| 3951 btfsc WREG,int_warning_flag ; - warning flag set? | |
| 3952 bra check_gas_density_warn ; YES - generate a warning | |
| 3953 btfsc WREG,int_attention_flag ; NO - attention flag set? | |
| 3954 bra check_gas_density_attn ; YES - generate an attention | |
| 3955 ;bra check_gas_density_ok ; NO - gas density ok | |
| 3956 | |
| 3957 check_gas_density_ok: | |
| 3958 bcf shown_gas_density_attn ; re-arm custom view show-up for warning | |
| 3959 bcf shown_gas_density_warn ; re-arm custom view show-up for attention | |
| 3960 return ; done | |
| 3961 | |
| 3962 check_gas_density_warn: | |
| 3963 bsf warn_det_gas_density ; set warning | |
| 3964 bcf shown_gas_density_attn ; re-arm custom view show-up for attention | |
| 3965 btfsc shown_gas_density_warn ; has the custom view been shown before on warning level? | |
| 3966 bra check_gas_density_mesg ; YES - do not show the gas needs custom view again | |
| 3967 btfsc custom_view_locked ; NO - custom view locked? | |
| 3968 bra check_gas_density_mesg ; YES - do not show it now | |
| 3969 bsf shown_gas_density_warn ; NO - set custom view as shown now | |
| 3970 bra check_gas_density_cv ; - show gas needs custom view | |
| 3971 | |
| 3972 check_gas_density_attn: | |
| 3973 bsf attn_det_gas_density ; set attention | |
| 3974 bcf shown_gas_density_warn ; re-arm custom view show-up for warning | |
| 3975 btfsc shown_gas_density_attn ; has the custom view been shown before on attention level? | |
| 3976 bra check_gas_density_mesg ; YES - do not show the gas needs custom view again | |
| 3977 btfsc custom_view_locked ; NO - custom view locked? | |
| 3978 bra check_gas_density_mesg ; YES - do not show it now | |
| 3979 bsf shown_gas_density_attn ; NO - set custom view as shown now | |
| 3980 ;bra check_gas_density_cv ; - show gas needs custom view | |
| 3981 | |
| 3982 check_gas_density_cv: | |
| 3983 movlw index_ppo2_ead_end_cns ; get custom view number of gas density | |
| 3984 call dive_customview_show ; show custom view | |
| 3985 ;bra check_gas_density_mesg ; show message | |
| 3986 | |
| 3987 check_gas_density_mesg: | |
| 3988 incf message_counter,F ; increase message counter | |
| 3989 goto TFT_message_gas_density ; show gas density message and return | |
| 3990 | |
| 3991 | |
| 3992 ;----------------------------------------------------------------------------- | |
| 3993 ; Check if an OC Bailout Gas is available | |
| 3994 ; | |
| 3995 check_OC_gas_avail: | |
| 3996 bcf warn_det_no_bo_gas ; clear warning by default | |
| 3997 tstfsz best_gas_number ; is a breathable OC (bailout) gas available? | |
| 3998 return ; YES - a breathable gas is available, done | |
| 3999 btfsc bailout_mode ; NO - in bailout? | |
| 4000 return ; YES - suppress warning, done | |
| 4001 bsf warn_det_no_bo_gas ; NO - set warning for no bailout gas | |
| 4002 incf message_counter,F ; - increase message counter | |
| 4003 goto TFT_message_no_BO_gas ; - show message and return | |
| 4004 | |
| 4005 ENDIF ; _ccr_pscr | |
| 631 | 4006 |
| 604 | 4007 |
| 4008 IFDEF _cave_mode | |
| 631 | 4009 |
| 634 | 4010 ;----------------------------------------------------------------------------- |
| 4011 ; Check Cave Profile Storage Usage | |
| 4012 ; | |
| 604 | 4013 check_cavemode: |
| 634 | 4014 bcf warn_det_cave_shut_down ; clear warning by default |
| 4015 bcf attn_det_cave_shut_down ; clear attention by default | |
| 631 | 4016 btfsc backtrack_entire_full ; is the backtracking storage entirely used up? |
| 4017 bra check_cavemode_full ; YES - turn dive, switch off cave mode and show warning message | |
| 4018 btfsc backtrack_almost_full ; NO - backtracking storage almost full? | |
| 4019 bra check_cavemode_almost_full ; YES - show attention message that cave mode will stop soon | |
| 634 | 4020 btfss cave_mode ; NO - cave mode switched on? |
| 4021 return ; NO - do not show info | |
| 4022 btfsc alt_layout_active ; YES - alternative layout active? | |
| 4023 return ; YES - suppress info message | |
| 4024 ;bra check_cavemode_mesg ; NO - show cave mode active info | |
| 4025 | |
| 4026 check_cavemode_mesg: | |
| 4027 incf message_counter,F ; increase message counter | |
| 4028 goto TFT_message_cave_mode ; show cave mode message | |
| 631 | 4029 |
| 4030 check_cavemode_full: | |
| 4031 btfss backtrack_shutdown ; backtracking shut down already? | |
| 4032 bsf request_cave_off_turned ; NO - request to switch cave mode off and to set the dive as turned | |
| 4033 bsf backtrack_shutdown ; remember shut down as been executed (anyhow) | |
| 634 | 4034 btfss cave_mode ; has the cave mode been switched on again meanwhile? |
| 4035 bsf warn_det_cave_shut_down ; NO - set warning level | |
| 631 | 4036 btfsc cave_mode ; has the cave mode been switched on again meanwhile? |
| 634 | 4037 bsf attn_det_cave_shut_down ; YES - set attention level |
| 4038 bra check_cavemode_mesg ; show message | |
| 631 | 4039 |
| 4040 check_cavemode_almost_full: | |
| 4041 btfss cave_mode ; cave mode switched on? | |
| 4042 return ; NO - suppress message | |
| 634 | 4043 bsf attn_det_cave_shut_down ; YES - set an attention |
| 4044 bra check_cavemode_mesg ; - show message | |
| 631 | 4045 |
| 4046 ENDIF ; _cave_mode | |
| 4047 | |
| 604 | 4048 |
| 634 | 4049 ;----------------------------------------------------------------------------- |
| 4050 ; Show aGF Reminder | |
| 4051 ; | |
| 4052 remind_agf_in_use: | |
| 4053 incf message_counter,F ; increase message counter | |
| 4054 goto TFT_message_agf ; show aGF reminder and return | |
| 4055 | |
| 4056 | |
| 4057 ;----------------------------------------------------------------------------- | |
| 4058 ; Check better Gas / Diluent Advice | |
| 4059 ; | |
| 4060 check_gas_change: | |
| 4061 bcf advc_det_change_gas ; clear advice by default | |
| 4062 IFDEF _ccr_pscr | |
| 4063 btfsc better_dil_available ; is a better diluent available? | |
| 4064 bra check_gas_change_mesg ; YES - show a gas change advice | |
| 4065 ENDIF | |
| 4066 btfsc better_gas_available ; is a better gas available? | |
| 4067 bra check_gas_change_mesg ; YES - show a gas change advice | |
| 4068 return ; NO - done | |
| 4069 | |
| 4070 check_gas_change_mesg: | |
| 650 | 4071 TSTOSS opt_warning_level_divemode ; Warning level set to =1 "All" ? |
| 4072 return ; NO, skip warning/advise then | |
| 634 | 4073 bsf advc_det_change_gas ; set advice |
| 4074 incf message_counter,F ; increase message counter | |
| 4075 goto TFT_message_gas_change ; show advice and return | |
| 4076 | |
| 604 | 4077 |
| 4078 IFDEF _rx_functions | |
| 4079 | |
| 634 | 4080 ;----------------------------------------------------------------------------- |
| 4081 ; Check SAC and Swap-Tank Advice | |
| 4082 ; | |
| 604 | 4083 check_tr_messages: |
| 634 | 4084 bcf attn_det_sac_rate ; clear SAC attention by default |
| 4085 bcf advc_det_switch_tank ; clear switch advice by default | |
| 623 | 4086 btfss count_divetime ; is the dive time counted, i.e. deeper than dive threshold? |
| 634 | 4087 return ; NO - suppress check |
| 623 | 4088 movff int_O_SAC_measured+1,WREG ; YES - bank-safe copy of measured SAC rate |
| 4089 btfss WREG,int_attention_flag ; - attention flag set? | |
| 634 | 4090 bra check_tr_messages_chk_swap ; NO - continue with checking for swap advice |
| 623 | 4091 btfsc WREG,int_not_avail_flag ; SAC rate available? |
| 634 | 4092 bra check_tr_messages_chk_swap ; NO - continue with checking for swap advice |
| 4093 bsf attn_det_sac_rate ; YES - set attention for SAC rate | |
| 4094 movf active_customview,W ; - get current custom view | |
| 4095 xorlw index_pressures_SAC ; - SAC rate shown? | |
| 4096 bz check_tr_messages_chk_swap ; YES - do not show twice, continue with swap advice | |
| 4097 ;bra check_tr_messages_mesg_sac ; NO - show SAC message | |
| 4098 | |
| 4099 check_tr_messages_mesg_sac: | |
| 4100 incf message_counter,F ; increase message counter | |
| 4101 call TFT_message_sac ; show message for SAC rate | |
| 4102 ;bra check_tr_messages_chk_swap ; continue with switch advice | |
| 4103 | |
| 4104 check_tr_messages_chk_swap: | |
| 604 | 4105 movff char_O_deco_info,WREG ; bank-safe copy of deco info vector |
| 4106 btfss WREG,ind_double_switch ; swap tank flag set? | |
| 634 | 4107 return ; NO - done |
| 4108 ;bra check_tr_messages_mesg_swap ; YES - show swap message | |
| 4109 | |
| 4110 check_tr_messages_mesg_swap: | |
| 4111 bsf advc_det_switch_tank ; set advice | |
| 4112 incf message_counter,F ; increase message counter | |
| 4113 goto TFT_message_switch_tanks ; show message for switching tanks and return | |
| 4114 | |
| 4115 | |
| 4116 ;----------------------------------------------------------------------------- | |
| 4117 ; Check Transmitter States | |
| 4118 ; | |
| 604 | 4119 check_tr_functions: |
| 634 | 4120 ; check transmitter 1 |
| 604 | 4121 movff char_I_pressure_stat+0,WREG ; get status of 1st pressure reading |
| 4122 rcall check_tr_functions_helper1 ; check for transmitter 1 lost | |
| 4123 rcall check_tr_functions_helper2 ; check for transmitter 1 low battery | |
| 4124 movff int_IO_pressure_value+1,WREG ; get high byte of 1st pressure reading | |
| 4125 rcall check_tr_functions_helper3 ; check for transmitter 1 pressure warning | |
| 4126 rcall check_tr_functions_helper4 ; check for transmitter 1 pressure attention | |
| 634 | 4127 ; check transmitter 2 |
| 604 | 4128 movff char_I_pressure_stat+1,WREG ; get status of 2nd pressure reading |
| 4129 rcall check_tr_functions_helper5 ; check for transmitter 2 lost | |
| 4130 rcall check_tr_functions_helper6 ; check for transmitter 2 low battery | |
| 4131 movff int_IO_pressure_value+3,WREG ; get high byte of 2nd pressure reading | |
| 4132 rcall check_tr_functions_helper7 ; check for transmitter 2 pressure warning | |
| 4133 rcall check_tr_functions_helper8 ; check for transmitter 2 pressure attention | |
| 634 | 4134 |
| 4135 ; results for transmitter | |
| 4136 btfsc attn_det_xmit1_bat ; do we have a transmitter 1 attention? | |
| 4137 bra check_tr_functions_xmitter_mesg ; YES - show transmitter message | |
| 4138 btfsc attn_det_xmit2_bat ; do we have a transmitter 2 attention? | |
| 4139 bra check_tr_functions_xmitter_mesg ; YES - show transmitter message | |
| 4140 check_tr_functions_1: | |
| 4141 btfsc warn_det_pressure1 ; do we have a pressure 1 warning? | |
| 4142 bra check_tr_functions_pres_mesg ; YES - show pressure message | |
| 4143 btfsc warn_det_pressure2 ; do we have a pressure 2 warning? | |
| 4144 bra check_tr_functions_pres_mesg ; YES - show pressure message | |
| 4145 btfsc attn_det_pressure1 ; do we have a pressure 1 attention? | |
| 4146 bra check_tr_functions_pres_mesg ; YES - show pressure message | |
| 4147 btfsc attn_det_pressure2 ; do we have a pressure 2 attention? | |
| 4148 bra check_tr_functions_pres_mesg ; YES - show pressure message | |
| 4149 return ; done | |
| 4150 | |
| 4151 check_tr_functions_xmitter_mesg: | |
| 4152 incf message_counter,F ; increase message counter | |
| 4153 call TFT_message_transmitter ; show transmitter message | |
| 4154 bra check_tr_functions_1 ; continue with pressure messages | |
| 4155 | |
| 4156 check_tr_functions_pres_mesg: | |
| 4157 incf message_counter,F ; increase message counter | |
| 4158 goto TFT_message_pressure ; show pressure message and return | |
| 604 | 4159 |
| 4160 check_tr_functions_helper1: | |
| 4161 btfsc WREG,char_transmitter_lost ; transmitter 1 lost? | |
| 4162 bra check_tr_functions_helper1a ; YES - show transmitter attention message | |
| 634 | 4163 bcf shown_xmit1_lost ; NO - clear flag for old message |
| 604 | 4164 return ; - done |
| 4165 check_tr_functions_helper1a: | |
| 634 | 4166 btfsc shown_xmit1_lost ; is it a new message? |
| 604 | 4167 return ; NO - do not show the pressure readings custom view again |
| 634 | 4168 bsf shown_xmit1_lost ; YES - memorize it's an old message now |
| 4169 rcall check_tr_functions_show_cv ; - show custom view | |
| 604 | 4170 |
| 4171 check_tr_functions_helper2: | |
| 4172 btfsc WREG,char_transmitter_low_bat ; transmitter 1 low battery? | |
| 4173 bra check_tr_functions_helper2a ; YES - show transmitter attention message | |
| 634 | 4174 bcf shown_xmit1_battery ; NO - clear flag for old message |
| 4175 bcf attn_det_xmit1_bat ; - clear transmitter 1 attention | |
| 604 | 4176 return ; - done |
| 4177 check_tr_functions_helper2a: | |
| 634 | 4178 bsf attn_det_xmit1_bat ; set transmitter 1 attention |
| 4179 btfsc shown_xmit1_battery ; is it a new message? | |
| 604 | 4180 return ; NO - do not show the pressure readings custom view again |
| 634 | 4181 bsf shown_xmit1_battery ; YES - memorize it's an old message now |
| 4182 rcall check_tr_functions_show_cv ; - show custom view | |
| 604 | 4183 |
| 4184 check_tr_functions_helper3: | |
| 4185 btfsc WREG,int_warning_flag ; transmitter 1 pressure warning? | |
| 4186 bra check_tr_functions_helper3a ; YES - show pressure reading message as warning | |
| 634 | 4187 bcf shown_xmit1_pres_warn ; NO - clear flag for old message |
| 4188 bcf warn_det_pressure1 ; - clear pressure 1 warning | |
| 604 | 4189 return ; - done |
| 4190 check_tr_functions_helper3a: | |
| 634 | 4191 bsf warn_det_pressure1 ; set pressure 1 warning |
| 4192 btfsc shown_xmit1_pres_warn ; is it a new message? | |
| 604 | 4193 return ; NO - do not show the pressure readings custom view again |
| 634 | 4194 bsf shown_xmit1_pres_warn ; YES - memorize it's an old message now |
| 604 | 4195 bra check_tr_functions_show_cv ; - show custom view |
| 4196 | |
| 4197 check_tr_functions_helper4: | |
| 4198 btfsc WREG,int_attention_flag ; transmitter 1 pressure attention? | |
| 4199 bra check_tr_functions_helper4a ; YES - show pressure reading message as attention | |
| 634 | 4200 bcf shown_xmit1_pres_attn ; NO - clear flag for old message |
| 4201 bcf attn_det_pressure1 ; - clear pressure 1 attention | |
| 604 | 4202 return ; - done |
| 4203 check_tr_functions_helper4a | |
| 634 | 4204 bsf attn_det_pressure1 ; set pressure 1 attention |
| 4205 btfsc shown_xmit1_pres_attn ; is it a new message? | |
| 604 | 4206 return ; NO - do not show the pressure readings custom view again |
| 634 | 4207 bsf shown_xmit1_pres_attn ; YES - memorize it's an old message now |
| 604 | 4208 bra check_tr_functions_show_cv ; - show custom view |
| 4209 | |
| 4210 check_tr_functions_helper5: | |
| 4211 btfsc WREG,char_transmitter_lost ; transmitter 2 lost? | |
| 4212 bra check_tr_functions_helper5a ; YES - show transmitter attention message | |
| 634 | 4213 bcf shown_xmit2_lost ; NO - clear flag for old lost message |
| 604 | 4214 return ; - done |
| 4215 check_tr_functions_helper5a: | |
| 634 | 4216 btfsc shown_xmit2_lost ; is it a new message? |
| 604 | 4217 return ; NO - do not show the pressure readings custom view again |
| 634 | 4218 bsf shown_xmit2_lost ; YES - memorize it's an old message now |
| 604 | 4219 bra check_tr_functions_show_cv ; - show custom view |
| 4220 | |
| 4221 check_tr_functions_helper6: | |
| 4222 btfsc WREG,char_transmitter_low_bat ; transmitter 2 low battery? | |
| 4223 bra check_tr_functions_helper6a ; YES - show transmitter attention message | |
| 634 | 4224 bcf shown_xmit2_battery ; NO - clear flag for old battery message |
| 4225 bcf attn_det_xmit2_bat ; - clear transmitter 2 attention | |
| 604 | 4226 return ; - done |
| 4227 check_tr_functions_helper6a: | |
| 634 | 4228 bsf attn_det_xmit2_bat ; set transmitter 2 attention |
| 4229 btfsc shown_xmit2_battery ; is it a new message? | |
| 604 | 4230 return ; NO - do not show the pressure readings custom view again |
| 634 | 4231 bsf shown_xmit2_battery ; YES - memorize it's an old message now |
| 604 | 4232 bra check_tr_functions_show_cv ; - show custom view |
| 4233 | |
| 4234 check_tr_functions_helper7: | |
| 4235 btfsc WREG,int_warning_flag ; transmitter 2 pressure warning? | |
| 4236 bra check_tr_functions_helper7a ; YES - show pressure reading message as warning | |
| 634 | 4237 bcf shown_xmit2_pres_warn ; NO - clear flag for old message |
| 4238 bcf warn_det_pressure2 ; - clear pressure 2 warning | |
| 604 | 4239 return ; - done |
| 4240 check_tr_functions_helper7a: | |
| 634 | 4241 bsf warn_det_pressure2 ; set pressure 2 warning |
| 4242 btfsc shown_xmit2_pres_warn ; is it a new message? | |
| 604 | 4243 return ; NO - do not show the pressure readings custom view again |
| 634 | 4244 bsf shown_xmit2_pres_warn ; YES - memorize it's an old message now |
| 604 | 4245 bra check_tr_functions_show_cv ; - show custom view |
| 4246 | |
| 4247 check_tr_functions_helper8: | |
| 4248 btfsc WREG,int_attention_flag ; transmitter 2 pressure attention? | |
| 4249 bra check_tr_functions_helper8a ; YES - show pressure reading message as attention | |
| 634 | 4250 bcf shown_xmit2_pres_attn ; NO - clear flag for old message |
| 4251 bcf attn_det_pressure2 ; - clear pressure 2 attention | |
| 604 | 4252 return ; - done |
| 4253 check_tr_functions_helper8a | |
| 634 | 4254 bsf attn_det_pressure2 ; set pressure 2 attention |
| 4255 btfsc shown_xmit2_pres_attn ; is it a new message? | |
| 604 | 4256 return ; NO - do not show the pressure readings custom view again |
| 634 | 4257 bsf shown_xmit2_pres_attn ; YES - memorize it's an old message now |
| 604 | 4258 ;bra check_tr_functions_show_cv ; - show custom view |
| 4259 | |
| 4260 check_tr_functions_show_cv: | |
| 634 | 4261 btfsc custom_view_locked ; NO - custom view locked? |
| 4262 return ; YES - do not show now | |
| 4263 movlw index_pressures_SAC ; NO - get custom view number of pressure readings | |
| 4264 goto dive_customview_show ; - show custom view and return | |
| 4265 | |
| 4266 ENDIF ; _rx_functions | |
| 4267 | |
| 4268 | |
| 4269 ;----------------------------------------------------------------------------- | |
| 4270 ; Check Gas Needs | |
| 4271 ; | |
| 631 | 4272 check_gas_needs: |
| 634 | 4273 bcf attn_det_gas_needs ; clear attention by default |
| 4274 bcf warn_det_gas_needs ; clear warning by default | |
| 4275 banksel int_O_gas_need_pres ; switch to bank where int_O_gas_need_pres is stored | |
| 623 | 4276 movf int_O_gas_need_pres+1,W ; get high byte from pres need of 1st tank |
| 4277 iorwf int_O_gas_need_pres+3,W ; inclusive or with high byte from pres need of 2nd tank | |
| 4278 iorwf int_O_gas_need_pres+5,W ; inclusive or with high byte from pres need of 3rd tank | |
| 4279 iorwf int_O_gas_need_pres+7,W ; inclusive or with high byte from pres need of 4th tank | |
| 4280 iorwf int_O_gas_need_pres+9,W ; inclusive or with high byte from pres need of 5th tank | |
| 634 | 4281 banksel common ; back to bank common |
| 4282 btfsc WREG,int_invalid_flag ; any invalid flag set? | |
| 4283 bra check_gas_needs_ok ; YES - no further checking required | |
| 4284 btfsc WREG,int_warning_flag ; NO - any gas with pres_need >= pres_fill ? | |
| 631 | 4285 bra check_gas_needs_warn ; YES - generate a warning |
| 634 | 4286 btfsc WREG,int_attention_flag ; NO - any gas with pres_need >= pres_fill * threshold ? |
| 4287 bra check_gas_needs_attn ; YES - generate an attention | |
| 4288 ;bra check_gas_needs_ok ; NO - gas needs ok | |
| 4289 | |
| 4290 check_gas_needs_ok: | |
| 4291 bcf shown_gas_needs_warn ; re-arm custom view show-up for warning | |
| 4292 bcf shown_gas_needs_attn ; re-arm custom view show-up for attention | |
| 4293 return ; done | |
| 623 | 4294 |
| 631 | 4295 check_gas_needs_warn: |
| 634 | 4296 bsf warn_det_gas_needs ; set warning |
| 4297 bcf shown_gas_needs_attn ; re-arm custom view show-up for attention | |
| 4298 btfsc shown_gas_needs_warn ; has the custom view been shown before on warning level? | |
| 4299 bra check_gas_needs_mesg ; YES - do not show the gas needs custom view again | |
| 4300 btfsc custom_view_locked ; NO - custom view locked? | |
| 4301 bra check_gas_needs_mesg ; YES - do not show it now | |
| 4302 bsf shown_gas_needs_warn ; NO - set custom view as shown now | |
| 4303 bra check_gas_needs_cv ; - show gas needs custom view | |
| 4304 | |
| 4305 check_gas_needs_attn: | |
| 4306 bsf attn_det_gas_needs ; set attention | |
| 4307 bcf shown_gas_needs_warn ; re-arm custom view show-up for warning | |
| 4308 btfsc shown_gas_needs_attn ; has the custom view been shown before on attention level? | |
| 4309 bra check_gas_needs_mesg ; YES - do not show the gas needs custom view again | |
| 4310 btfsc custom_view_locked ; NO - custom view locked? | |
| 4311 bra check_gas_needs_mesg ; YES - do not show it now | |
| 4312 bsf shown_gas_needs_attn ; NO - set custom view as shown now | |
| 4313 ;bra check_gas_needs_cv ; - show gas needs custom view | |
| 4314 | |
| 4315 check_gas_needs_cv: | |
| 4316 movlw index_gas_needs_ascent ; get custom view number of gas needs | |
| 4317 call dive_customview_show ; show custom view | |
| 4318 ;bra check_gas_needs_mesg ; show message | |
| 4319 | |
| 4320 check_gas_needs_mesg: | |
| 4321 incf message_counter,F ; increase message counter | |
| 4322 goto TFT_message_gas_needs ; show message for gas needs and return | |
| 4323 | |
| 623 | 4324 |
| 656 | 4325 IFDEF _external_sensor_eccr |
| 582 | 4326 |
| 634 | 4327 ;----------------------------------------------------------------------------- |
| 4328 ; Check external Sensors for Loss and Divergence | |
| 4329 ; | |
| 4330 check_ext_sensors: | |
| 4331 btfsc warn_det_sensors_lost ; all sensors lost? | |
| 4332 bra check_ext_sensors_lost_all ; YES - show a warning and return | |
| 4333 | |
| 4334 btfsc attn_det_sensor1_lost ; sensor 1 lost? | |
| 4335 rcall check_ext_sensors_lost_1 ; YES - show an attention | |
| 4336 | |
| 4337 btfsc attn_det_sensor2_lost ; sensor 2 lost? | |
| 4338 rcall check_ext_sensors_lost_2 ; YES - show an attention | |
| 4339 | |
| 4340 btfsc attn_det_sensor3_lost ; sensor 3 lost? | |
| 4341 rcall check_ext_sensors_lost_3 ; YES - show an attention | |
| 4342 | |
| 4343 btfsc warn_det_sensors_div ; sensor values divergence? | |
| 4344 bra check_ext_sensors_diverg ; YES - show a warning and return | |
| 4345 | |
| 4346 return ; done | |
| 4347 | |
| 4348 check_ext_sensors_lost_all: | |
| 4349 btfsc shown_sensors_lost ; has the custom view been shown before? | |
| 4350 bra warn_sensors_lost_mesg ; YES - do not show the sensor custom view again | |
| 4351 btfsc custom_view_locked ; NO - custom view locked? | |
| 4352 bra warn_sensors_lost_mesg ; YES - do not show it now | |
| 4353 bsf shown_sensors_lost ; NO - set it as shown now | |
| 4354 movlw index_ppo2_sensors ; - get custom view number of sensors | |
| 4355 call dive_customview_show ; - show custom view | |
| 4356 ;bra warn_sensors_lost_mesg ; - show message | |
| 4357 | |
| 4358 warn_sensors_lost_mesg: | |
| 4359 incf message_counter,F ; increase message counter | |
| 4360 goto TFT_message_fallback ; show message and return | |
| 4361 | |
| 4362 check_ext_sensors_lost_1: | |
| 4363 btfsc shown_sensor1_fail ; has the custom view been shown before for sensor 1? | |
| 4364 return ; YES - do not show the sensor custom view again | |
| 4365 btfsc custom_view_locked ; NO - custom view locked? | |
| 4366 return ; YES - do not show it now | |
| 4367 bsf shown_sensor1_fail ; NO - set it as shown now | |
| 4368 bra check_ext_sensors_show_cv ; - show sensor custom view | |
| 4369 | |
| 4370 check_ext_sensors_lost_2: | |
| 4371 btfsc shown_sensor2_fail ; has the custom view been shown before for sensor 2? | |
| 4372 return ; YES - do not show the sensor custom view again | |
| 4373 btfsc custom_view_locked ; NO - custom view locked? | |
| 4374 return ; YES - do not show it now | |
| 4375 bsf shown_sensor2_fail ; NO - set it as shown now | |
| 4376 bra check_ext_sensors_show_cv ; - show sensor custom view | |
| 4377 | |
| 4378 check_ext_sensors_lost_3: | |
| 4379 btfsc shown_sensor3_fail ; has the custom view been shown before for sensor 3? | |
| 4380 return ; YES - do not show the sensor custom view again | |
| 4381 btfsc custom_view_locked ; NO - custom view locked? | |
| 4382 return ; YES - do not show it now | |
| 4383 bsf shown_sensor3_fail ; NO - set it as shown now | |
| 4384 ;bra check_ext_sensors_show_cv ; - show sensor custom view | |
| 4385 | |
| 4386 check_ext_sensors_show_cv: | |
| 4387 movlw index_ppo2_sensors ; get custom view number of sensors | |
| 4388 goto dive_customview_show ; show custom view and return | |
| 4389 | |
| 4390 check_ext_sensors_diverg: | |
| 4391 btfsc shown_sensors_diverg ; has the custom view been shown before for divergence? | |
| 4392 bra check_ext_sensors_diverg_mesg ; YES - do not show the sensor custom view again | |
| 4393 btfsc custom_view_locked ; NO - custom view locked? | |
| 4394 bra check_ext_sensors_diverg_mesg ; YES - do not show it now | |
| 4395 bsf shown_sensors_diverg ; NO - set it as shown now | |
| 4396 movlw index_ppo2_sensors ; - get custom view number of sensors | |
| 4397 call dive_customview_show ; - show custom view | |
| 4398 ;bra check_ext_sensors_diverg_mesg ; - show message | |
| 4399 | |
| 4400 check_ext_sensors_diverg_mesg: | |
| 4401 incf message_counter,F ; increase message counter | |
| 4402 goto TFT_message_divergence ; show message and return | |
| 4403 | |
| 656 | 4404 ENDIF ; _external_sensor_eccr |
| 634 | 4405 |
| 623 | 4406 |
| 4407 ;============================================================================= | |
| 634 | 4408 dmode5 CODE |
| 623 | 4409 ;============================================================================= |
| 560 | 4410 |
| 634 | 4411 |
| 4412 ;----------------------------------------------------------------------------- | |
| 4413 ; Restart the Deco Engine | |
| 4414 ; | |
| 560 | 4415 global restart_deco_engine |
| 4416 global restart_deco_engine_wo_ceiling | |
| 4417 restart_deco_engine: | |
| 623 | 4418 banksel int_O_ceiling ; switch to bank where the shared "_O_" variables are stored |
| 4419 bsf int_O_ceiling+1,char_invalid_flag ; invalidate ceiling (int_O_ceiling has its invalid flag on a char's position!) | |
| 560 | 4420 |
| 4421 restart_deco_engine_wo_ceiling: | |
| 634 | 4422 banksel char_O_deco_gas ; switch to bank where the stops table is stored |
| 623 | 4423 bsf char_O_deco_gas+0,char_invalid_flag ; invalidate deco data (stop table data) |
| 634 | 4424 banksel int_O_NDL_norm ; switch to bank where the shared "_O_" variables are stored |
| 631 | 4425 bsf int_O_NDL_norm+1,int_invalid_flag ; invalidate NDL time (normal plan) |
| 4426 bsf int_O_TTS_norm+1,int_invalid_flag ; invalidate TTS time (normal plan) | |
| 4427 bsf int_O_TST_norm+1,int_invalid_flag ; invalidate TST time (normal plan) | |
| 623 | 4428 bsf int_O_CNS_norm+1,int_invalid_flag ; invalidate CNS at end of dive in normal plan |
| 631 | 4429 |
| 4430 restart_deco_engine_wo_norm: | |
| 4431 banksel common ; bank to bank common | |
| 4432 bsf request_restart_engine ; request restart of the deco engine | |
| 604 | 4433 |
| 4434 inval_alternative_plan_data: | |
| 634 | 4435 banksel int_O_NDL_alt ; switch to bank where the shared "_O_" variables are stored |
| 631 | 4436 bsf int_O_NDL_alt+1,int_invalid_flag ; invalidate NDL time (alternative plan) |
| 4437 bsf int_O_TTS_alt+1,int_invalid_flag ; invalidate TTS time (alternative plan) | |
| 4438 bsf int_O_TST_alt+1,int_invalid_flag ; invalidate TST time (alternative plan) | |
| 623 | 4439 bsf int_O_CNS_alt+1,int_invalid_flag ; invalidate CNS at end of dive in alternative plan |
| 4440 bsf int_O_gas_need_pres+1,int_invalid_flag ; invalidate ascent gas needs | |
| 604 | 4441 |
| 4442 IFDEF _rx_functions | |
| 623 | 4443 bsf int_O_pressure_need+1,int_not_avail_flag ; invalidate pressure needs to reading 1 (TR functions) |
| 4444 bsf int_O_pressure_need+3,int_not_avail_flag ; invalidate pressure needs to reading 2 (TR functions) | |
| 604 | 4445 ENDIF |
| 4446 | |
| 623 | 4447 banksel common ; bank to bank common |
| 4448 bsf new_deco_data_avail ; set flag for new NDL and deco data available to have the display updated | |
| 582 | 4449 |
| 634 | 4450 return ; done |
| 4451 | |
| 582 | 4452 |
| 4453 ;============================================================================= | |
| 634 | 4454 dmode6 CODE |
| 4455 ;============================================================================= | |
| 4456 | |
| 4457 | |
| 4458 ;----------------------------------------------------------------------------- | |
| 4459 ; Start-up Simulator Mode | |
| 582 | 4460 ; |
| 634 | 4461 global demo_divemode |
| 4462 demo_divemode: | |
| 631 | 4463 call TFT_ClearScreen ; blank screen |
| 4464 | |
| 4465 ; leaving menu mode, so have option values in EEPROM up-to-date | |
| 634 | 4466 btfsc option_changed ; do the options need to be stored to EEPROM ? |
| 631 | 4467 call option_check_and_store_all ; YES - check and store all option values in EEPROM |
| 604 | 4468 |
| 4469 ; +++ COMMENT OUT FOR TESTING PURPOSE ONLY !!! +++ | |
| 631 | 4470 bsf simulatormode ; restore tissue pressures and CNS value after finishing simulator use |
| 604 | 4471 ; +++ DO NOT COMMENT OUT IN OPERATIONAL USE !!! +++ |
| 560 | 4472 |
| 623 | 4473 call deco_push_tissues_to_vault ; back-up the tissue pressures (C-code) |
| 4474 banksel common ; back to bank common | |
| 4475 | |
| 4476 ; set simulated target depth | |
| 4477 movff char_I_bottom_depth,simulatormode_depth | |
| 4478 | |
| 4479 ; set initial simulated depth (needed to overcome end-of-dive detection) | |
| 4480 banksel pressure_rel_sim | |
| 4481 MOVLI simulator_startdepth,pressure_rel_sim | |
| 4482 banksel common | |
| 4483 | |
| 4484 ; switch ISR pressure calculations to simulator mode | |
| 4485 bcf quit_simulatormode ; clear flag for fast abort request | |
| 4486 bcf sensor_override_active ; make sure ISR mode switch confirmation is not older than from now on | |
| 4487 bsf sensor_override_request ; request ISR to switch to simulator mode | |
| 4488 btfss sensor_override_active ; has the ISR confirmed switch to simulator mode? | |
| 4489 bra $-2 ; NO - not yet, loop waiting for the ISR to kick in | |
| 4490 | |
| 4491 ; branch into dive mode | |
| 4492 bsf divemode ; activate dive mode (to be done after simulator mode is activated) | |
| 634 | 4493 goto diveloop ; start dive mode |
| 4494 | |
| 4495 ;----------------------------------------------------------------------------- | |
| 623 | 4496 |
| 4497 END |
