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