Mercurial > public > hwos_code
annotate src/divemode.asm @ 606:8b250afb8bdd
minor
author | heinrichsweikamp |
---|---|
date | Sun, 25 Nov 2018 15:15:27 +0100 |
parents | 5ce603c29750 |
children | d866684249bd |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
604 | 3 ; File divemode.asm REFACTORED VERSION V2.99e |
0 | 4 ; |
5 ; Divemode | |
6 ; | |
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. | |
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 "isr.inc" | |
19 #include "math.inc" | |
20 #include "wait.inc" | |
21 #include "customview.inc" | |
22 #include "start.inc" | |
23 #include "adc_lightsensor.inc" | |
24 #include "ghostwriter.inc" | |
25 #include "i2c.inc" | |
26 #include "calibrate.inc" | |
27 #include "convert.inc" | |
28 | |
604 | 29 IFDEF _rx_functions |
30 #include "rx_ops.inc" | |
31 ENDIF | |
32 | |
0 | 33 |
582 | 34 extern TFT_dive_compass_heading |
35 extern do_line_menu | |
36 extern do_main_divemenu | |
37 extern option_save_all | |
38 extern init_recording_params | |
39 | |
40 | |
41 ;---- Private local variables ------------------------------------------------- | |
42 | |
43 CBLOCK local1 ; max size is 16 Byte !!! | |
44 apnoe_timeout_counter ; timeout counter for apnoe mode | |
45 sensor_setpoint ; sensor ppo2 in 0.01bar for deco routine | |
604 | 46 check_gas_num ; used in search for best gas/dil: current gas/dil number (1-5) |
47 check_gas_depth ; used in search for best gas/dil: current gas/dil change depth | |
48 check_gas_type ; used in search for best gas/dil: current gas/dil type | |
49 check_gas_O2_ratio ; used in search for best gas/dil: current gas/dil O2 ratio | |
50 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 ! | |
51 best_gas_depth ; used in search for best gas/dil: best gas/dil change depth | |
52 ppO2_min ; used in search for best gas/dil: minimum ppO2 required | |
53 ppO2_max ; used in search for best gas/dil: maximum ppO2 allowed | |
54 ENDC ; used: 10 byte, remaining: 6 byte | |
55 | |
56 CBLOCK local2 ; max size is 16 Byte !!! | |
57 average_depth_hold:4 ; used to calculate the resettable average depth | |
58 average_depth_hold_total:4 ; used to calculate the absolute average depth | |
59 ENDC ; used: 8 byte, remaining: 8 byte | |
60 | |
61 dmode CODE | |
582 | 62 |
63 ;============================================================================= | |
0 | 64 |
65 global diveloop | |
66 diveloop: | |
604 | 67 banksel common |
582 | 68 call speed_normal |
604 | 69 call diveloop_boot ; boot tasks for all modes |
70 | |
71 ; startup tasks for all modes | |
72 call TFT_boot ; initialize TFT (includes clear screen) | |
73 bsf FLAG_TFT_divemode_mask ; request display of dive mode mask | |
74 | |
75 movff customview_divemode,menupos3; reload last custom view | |
76 bsf redraw_custview_mask ; request redraw of last custom view | |
0 | 77 |
582 | 78 btfsc FLAG_apnoe_mode |
604 | 79 bsf realdive ; set realdive flag in apnoe mode |
80 | |
81 btfsc FLAG_apnoe_mode ; done for apnoe or gauge mode | |
582 | 82 bra diveloop_loop_start |
604 | 83 btfsc FLAG_gauge_mode ; done for apnoe or gauge mode |
582 | 84 bra diveloop_loop_start |
0 | 85 |
604 | 86 ; Deco modes |
87 bsf FLAG_TFT_active_gas_divemode; request display of gas and setpoint | |
88 bsf FLAG_TFT_display_ndl_mask ; request display of "NDL" | |
0 | 89 |
90 ; +@5 init | |
582 | 91 clrf WREG ; WAIT marker: display "---" |
92 movff WREG,char_I_sim_advance_time | |
93 movff WREG,int_O_alternate_ascenttime+0 | |
560 | 94 bsf WREG,int_not_yet_computed |
95 bsf WREG,int_invalid_flag | |
582 | 96 movff WREG,int_O_alternate_ascenttime+1 |
560 | 97 |
98 diveloop_loop_start: | |
604 | 99 btfsc FLAG_TFT_divemode_mask |
100 call TFT_divemode_mask | |
582 | 101 btfsc FLAG_TFT_display_ndl_mask |
102 call TFT_display_ndl_mask | |
560 | 103 |
604 | 104 diveloop_loop: ; the dive loop starts here |
582 | 105 btfss quarter_second_update |
106 bra diveloop_loop1 | |
107 | |
108 ; tasks any 1/4 second, any mode | |
109 bcf quarter_second_update ; clear flag | |
0 | 110 |
604 | 111 btfsc alternative_divelayout ; in alternative layout? |
112 bra diveloop_loop1 ; YES - no compass in alternative layout mode | |
113 movlw index_compass_dm ; NO - index of compass view | |
114 cpfseq menupos3 ; - in compass view? | |
115 bra diveloop_loop1 ; NO - done | |
116 call TFT_dive_compass_heading ; YES - update compass heading value | |
117 bsf FLAG_TFT_temp_divemode ; - redraw temperature (is slightly affected from compass heading arrow) | |
560 | 118 |
582 | 119 diveloop_loop1: |
604 | 120 btfss onesecupdate ; next second begun? |
121 bra diveloop_loop3 ; NO | |
582 | 122 |
0 | 123 ; tasks any new second... |
582 | 124 bcf onesecupdate ; one seconds update, clear flag here in case it's set again in ISR before all tasks are done. |
178 | 125 |
604 | 126 ; ###-- USE FOR DEBUG ONLY - RESETS RX CIRCUITRY --### |
127 ; bsf LEDg | |
128 ; ###----------------------------------------------### | |
129 | |
130 ; compute current depth in meters | |
131 SAFE_2BYTE_COPY rel_pressure,xA | |
132 movlw .100 | |
133 movwf xB+0 | |
134 clrf xB+1 | |
135 call div16x16 ; xC = xA / xB, xC+0 now holds depth in full meters | |
136 movff xC+0,curr_depth ; store result in curr_depth | |
137 | |
138 ; compute ambient pressure / 10, will be needed later | |
139 SAFE_2BYTE_COPY amb_pressure,xA | |
140 movlw .10 | |
141 movwf xB+0 | |
142 clrf xB+1 | |
143 call div16x16 ; xC = xA / xB = p_amb / 10 | |
144 movff xC+0,amb_press_10+0 ; store result for later use | |
145 movff xC+1,amb_press_10+1 ; ... | |
0 | 146 |
560 | 147 ; display depth based on full seconds interval (nicer blinking) |
582 | 148 btfss alternative_divelayout |
149 rcall TFT_output4_normal | |
150 btfsc alternative_divelayout | |
151 rcall TFT_output4_alternative | |
152 | |
604 | 153 btfsc FLAG_apnoe_mode ; in Apnoe mode? |
154 bra diveloop_loop1_nonedeco ; YES - do Apnoe mode every second tasks | |
582 | 155 |
560 | 156 ; tasks any new second - only for deco modes |
604 | 157 diveloop_loop1_deco: |
158 bsf FLAG_TFT_divemins ; display (new) dive time! | |
159 btfsc show_safety_stop ; show the safety stop? | |
160 bsf FLAG_TFT_show_safety_stop ; YES - show/delete if done | |
0 | 161 |
560 | 162 btfss alternative_divelayout |
163 rcall TFT_output1_normal | |
164 btfsc alternative_divelayout | |
165 rcall TFT_output1_alternative | |
0 | 166 |
604 | 167 call divemode_check_for_warnings ; check for warnings |
168 | |
169 IFDEF _rx_functions | |
170 btfss FLAG_tr_enabled ; TR functions enabled? | |
171 bra diveloop_loop1_deco1 ; NO - skip pressure readings part | |
172 call get_pressure_readings ; YES - get pressure readings | |
173 call configure_sac_calculation ; - set up SAC calculation | |
174 diveloop_loop1_deco1: | |
175 ENDIF | |
582 | 176 |
605 | 177 call calc_deco_divemode ; calculate decompression and set resulting display flags |
560 | 178 |
179 btfss alternative_divelayout | |
180 rcall TFT_output2_normal | |
181 btfsc alternative_divelayout | |
182 rcall TFT_output2_alternative | |
604 | 183 bra diveloop_loop2 ; continue with common tasks |
560 | 184 |
185 ; tasks any new second - only for apnoe mode | |
582 | 186 diveloop_loop1_nonedeco: |
604 | 187 rcall divemode_apnoe_tasks ; 1 sec. apnoe tasks |
188 call customview_second ; do every-second tasks for the custom view area | |
189 ;bra diveloop_loop2 ; common tasks | |
560 | 190 |
191 ; continue tasks any new second, any mode | |
582 | 192 diveloop_loop2: |
604 | 193 btfsc redraw_custview_mask ; shall we redraw the custom view mask? |
194 call customview_mask ; YES - redraw custom view mask | |
195 | |
196 rcall timeout_divemode ; ** menu timeout? ** - this routine sets the required flags | |
582 | 197 rcall set_dive_modes ; tests if depth > threshold |
604 | 198 rcall set_min_temp ; store min. temp if required (future hardware will need this to be checked 1/second...) |
0 | 199 |
560 | 200 btfsc oneminupdate ; one minute tasks |
604 | 201 rcall update_divemode60 ; update clock, etc. |
202 | |
606 | 203 bsf FLAG_TFT_active_gas_divemode; have the gas and setpoint redrawn on every second to update setpoint display, animate the blinking, etc. |
0 | 204 |
560 | 205 btfss alternative_divelayout |
206 rcall TFT_output3_normal | |
207 btfsc alternative_divelayout | |
208 rcall TFT_output3_alternative | |
209 | |
604 | 210 ; ###-- USE FOR DEBUG ONLY - RESETS RX CIRCUITRY --### |
211 ; bcf LEDg | |
212 ; ###----------------------------------------------### | |
0 | 213 |
560 | 214 ; tasks any round, any mode |
0 | 215 diveloop_loop3: |
604 | 216 call test_switches_divemode ; check switches in dive mode |
582 | 217 |
218 global diveloop_loop4 | |
604 | 219 diveloop_loop4: ; menu-exit returns here... |
220 btfsc toggle_customview ; next view? | |
221 call customview_toggle ; YES - show next custom view (and delete this flag) | |
222 | |
223 btfsc divemode_gaschange ; gas switch flag set? | |
582 | 224 call gas_switched_common ; YES |
0 | 225 |
604 | 226 btfsc toggle_gf ; toggle GF/aGF? |
582 | 227 rcall divemodemode_togglegf ; YES |
0 | 228 |
604 | 229 IFDEF _cave_mode |
230 btfsc toggle_turn_dive ; toggle dive turned? | |
231 rcall divemodemode_toggleturn ; YES | |
232 ENDIF | |
233 | |
234 btfsc FLAG_set_marker ; shall set a marker? | |
582 | 235 call set_logbook_marker ; YES |
236 | |
604 | 237 btfsc store_sample ; shall store new sample? |
238 call store_dive_data ; YES - store profile data | |
239 | |
240 btfss divemode ; dive finished? | |
241 goto ghostwriter_end_dive ; YES - dive finished! | |
83 | 242 |
582 | 243 btfsc pressure_refresh ; new pressure available? |
604 | 244 rcall set_max_depth ; YES - update max. depth if required |
582 | 245 btfsc pressure_refresh ; new pressure available? |
604 | 246 bsf FLAG_TFT_depth ; YES - update depth |
582 | 247 bcf pressure_refresh ; clear flag |
560 | 248 |
604 | 249 btfsc temp_changed ; temperature changed? |
250 bsf FLAG_TFT_temp_divemode ; YES - display temperature | |
251 | |
252 IFDEF _screendump | |
253 btfsc enable_screen_dumps ; screen dump function enabled? | |
254 call TFT_dump_screen_check ; YES - check if requested and do it | |
255 ENDIF | |
256 | |
257 bra diveloop_loop ; loop the dive mode | |
582 | 258 |
560 | 259 ;-------------------------------------------------------------------------------------------------------- |
582 | 260 |
604 | 261 TFT_output1_normal: ; beginning of any new second - only for deco modes |
582 | 262 btfsc FLAG_TFT_divemode_mask |
263 call TFT_divemode_mask | |
560 | 264 btfsc FLAG_TFT_divemins |
604 | 265 call TFT_divemins ; display (new) dive time! |
266 call customview_second ; do every-second tasks for the custom view area (in sync with the dive time) mH | |
560 | 267 btfsc FLAG_TFT_show_safety_stop |
604 | 268 call TFT_show_safety_stop ; show safety stop |
560 | 269 btfsc FLAG_TFT_clear_safety_stop |
604 | 270 call TFT_clear_safety_stop ; clear safety stop |
560 | 271 return |
582 | 272 |
604 | 273 TFT_output1_alternative: ; beginning of any new second - only for deco modes |
274 btfsc FLAG_TFT_divemode_mask_alt | |
275 call TFT_divemode_mask_alternative ; alternative mask | |
560 | 276 btfsc FLAG_TFT_divemins |
604 | 277 call TFT_divemins_alternative ; display (new) divetime! |
278 call customview_alternative_second ; do every-second tasks for the custom view area (in sync with the dive time) mH | |
588 | 279 btfsc FLAG_TFT_big_deco_alt |
604 | 280 call TFT_big_deco_alt ; big deco, also manages alternative safety stop thus moved to first wave of outputs [rl] |
560 | 281 return |
582 | 282 |
604 | 283 TFT_output2_normal: ; any new second - only for deco modes |
582 | 284 btfsc FLAG_TFT_display_ndl_mask |
285 call TFT_display_ndl_mask | |
286 btfsc FLAG_TFT_display_ndl | |
287 call TFT_display_ndl | |
560 | 288 btfsc FLAG_TFT_display_deko_mask |
289 call TFT_display_deko_mask | |
290 btfsc FLAG_TFT_display_deko | |
291 call TFT_display_deko | |
292 btfsc FLAG_TFT_display_tts | |
293 call TFT_display_tts | |
294 return | |
0 | 295 |
604 | 296 TFT_output2_alternative: ; any new second - only for deco modes |
560 | 297 return |
582 | 298 |
604 | 299 TFT_output3_normal: ; tasks any new second, any mode, after deco calculations |
560 | 300 btfsc FLAG_TFT_max_depth |
604 | 301 call TFT_max_depth ; use normal max. depth |
560 | 302 btfsc FLAG_TFT_divemode_warning |
303 call TFT_divemode_warning | |
304 btfsc FLAG_TFT_divemode_warning_clear | |
305 call TFT_divemode_warning_clear | |
306 btfsc FLAG_TFT_dive_warning_text_clear | |
604 | 307 call TFT_clear_warning_text ; clear complete warnings area |
582 | 308 btfsc FLAG_TFT_dive_warning_text_clr2 |
604 | 309 call TFT_clear_warning_text_2nd_row ; clear 2nd row of warnings |
560 | 310 return |
582 | 311 |
604 | 312 TFT_output3_alternative: ; tasks any new second |
313 btfsc FLAG_TFT_max_depth | |
314 call TFT_max_depth_alternative ; big max. depth | |
560 | 315 btfsc FLAG_TFT_dive_warning_text_clear |
604 | 316 call TFT_clear_warning_text ; clear complete warnings area (in alt mode only 2nd row...) |
560 | 317 return |
318 | |
604 | 319 TFT_output4_normal: ; tasks any round, any mode, before deco calculations (stable timebase) |
560 | 320 btfsc FLAG_TFT_depth |
604 | 321 call TFT_depth ; display depth |
322 btfsc FLAG_TFT_active_gas_divemode | |
323 call TFT_active_gas_divemode ; display gas/setpoint | |
582 | 324 btfsc FLAG_TFT_temp_divemode |
604 | 325 call TFT_temp_divemode ; update temperature |
560 | 326 return |
582 | 327 |
604 | 328 TFT_output4_alternative: ; tasks any round, any mode |
582 | 329 btfsc FLAG_TFT_depth |
604 | 330 call TFT_depth ; display new depth |
560 | 331 return |
582 | 332 |
333 | |
0 | 334 ;-------------------------------------------------------------------------------------------------------- |
335 | |
604 | 336 divemode_apnoe_tasks: ; 1 sec. apnoe tasks |
337 call TFT_display_apnoe_descent ; show descent timer | |
560 | 338 call TFT_max_depth ; use normal max. depth |
0 | 339 |
604 | 340 btfsc divemode2 ; time running? |
341 bra divemode_apnoe_tasks2 ; YES - new descent, reset data if flag is set | |
0 | 342 |
343 rcall apnoe_calc_maxdepth | |
344 call TFT_display_apnoe_surface | |
604 | 345 call TFT_display_apnoe_last_max ; show last max. depth |
0 | 346 incf apnoe_surface_secs,F |
347 movlw d'60' | |
348 cpfseq apnoe_surface_secs | |
349 bra divemode_apnoe_tasks1 | |
350 clrf apnoe_surface_secs | |
351 incf apnoe_surface_mins,F | |
352 | |
582 | 353 divemode_apnoe_tasks1: |
604 | 354 bcf FLAG_active_descent ; clear flag |
355 btfsc divemode2 ; time running? | |
356 return ; YES - return | |
357 bsf FLAG_active_descent ; set flag | |
0 | 358 return |
359 | |
360 divemode_apnoe_tasks2: | |
604 | 361 btfss FLAG_active_descent ; are we descending? |
362 return ; NO - we are at the surface | |
363 rcall apnoe_calc_maxdepth ; YES | |
364 call TFT_apnoe_clear_surface ; clear surface timer | |
365 clrf apnoe_timeout_counter ; delete timeout | |
0 | 366 clrf apnoe_surface_secs |
367 clrf apnoe_surface_mins | |
368 clrf apnoe_secs | |
604 | 369 clrf apnoe_mins ; reset descent time |
0 | 370 movlw .0 |
371 movff WREG,max_pressure+0 | |
604 | 372 movff WREG,max_pressure+1 ; reset max. depth |
373 bcf FLAG_active_descent ; clear flag | |
0 | 374 return |
375 | |
376 global apnoe_calc_maxdepth | |
377 apnoe_calc_maxdepth: | |
378 movff apnoe_max_pressure+0,sub_a+0 | |
379 movff apnoe_max_pressure+1,sub_a+1 | |
380 movff max_pressure+0,sub_b+0 | |
381 movff max_pressure+1,sub_b+1 | |
560 | 382 call subU16 ; sub_c = sub_a - sub_b |
604 | 383 ; apnoe_max_pressure < max_pressure -> neg_flag=1 |
384 ; max_pressure <= apnoe_max_pressure -> neg_flag=0 | |
582 | 385 btfss neg_flag |
0 | 386 return |
560 | 387 ;apnoe_max_pressure<max_pressure |
0 | 388 movff max_pressure+0,apnoe_max_pressure+0 |
389 movff max_pressure+1,apnoe_max_pressure+1 | |
390 return | |
391 | |
560 | 392 ; -------------------------------------------------------------------------------------- |
0 | 393 |
605 | 394 calc_deco_divemode: |
604 | 395 btfss FLAG_gauge_mode ; in gauge mode? |
396 rcall calc_deko_engine ; NO - do deco calculations | |
397 | |
398 ; Increment the time accumulators used for calculating the average depths. | |
399 ; This done here and not in the ISR to guarantee synchronism between time | |
400 ; and depth accumulator incrementing. | |
401 infsnz average_divesecs+0,F | |
402 incf average_divesecs+1,F | |
403 infsnz average_divesecs_total+0,F | |
404 incf average_divesecs_total+1,F | |
405 | |
406 btg onesectoggle ; toggle the one-second toggle bit | |
407 btfss onesectoggle ; toggle bit set? | |
408 bra calc_deko_divemode2 ; NO | |
409 ;bra calc_deko_divemode1 ; YES | |
410 | |
411 calc_deko_divemode1: ; every-2-seconds tasks, 1st phase | |
412 ; call TFT_debug_output ; optional debug output | |
413 btfsc FLAG_gauge_mode ; in gauge mode? | |
414 return ; YES - done | |
415 goto check_gas_best ; NO - checks if a better gas should be selected (by user) and return | |
416 | |
417 calc_deko_divemode2: ; every-2-seconds tasks, 2nd phase | |
560 | 418 call calc_average_depth ; calculate average depth |
419 call calc_velocity ; calculate vertical velocity and display if > threshold (every two seconds) | |
604 | 420 goto set_reset_safety_stop ; set/reset flags for safety stop and return |
421 | |
422 | |
423 calc_deko_engine: | |
424 btfsc FLAG_ccr_mode ; in CCR mode? | |
425 call check_dive_autosp ; YES - check for Auto-SP | |
426 | |
427 btfsc FLAG_ccr_mode ; in CCR mode? | |
428 rcall calc_deko_divemode_sensor ; YES - do sensor data acquisition if applicable by OSTC model | |
429 | |
430 btfsc FLAG_pscr_mode ; in pSCR mode? | |
431 rcall calc_deko_divemode_sensor ; YES - do sensor data acquisition if applicable by OSTC model | |
0 | 432 |
195 | 433 |
560 | 434 ; check deco engine state and switch between normal and alternative plan calculations |
435 ; | |
436 ; Remark: Any reconfigurations done here do only affect the ascent & deco calculation settings, | |
604 | 437 ; not the settings for the calculations done on the real tissues. The later ones are only |
438 ; altered in case of a gas change, or in case of a real bailout or switchback to setpoint | |
439 ; or sensor, respectively. | |
440 ; In case of a gas change or real bailout/switchback, the settings for the deco calculations | |
441 ; are also changed to match the settings for the real tissues. This is done on signal through | |
442 ; 'divemode_gaschange' and will also leave the deco engine status in state as if having done | |
443 ; the alternative plan last. | |
444 | |
445 ; get working copies of char_O_main_status and char_O_deco_status | |
446 movff char_O_main_status,hi ; get char_O_main_status into hi | |
447 movff char_O_deco_status,lo ; get char_O_deco_status into lo | |
448 | |
449 ; check state of deco calculations | |
450 btfsc hi,DECO_COMPLETED_NORM ; finished calculations for normal plan? | |
451 bra calc_deko_engine_alt ; YES - do an alternative plan next (or a normal one with more features enabled) | |
452 btfsc hi,DECO_COMPLETED_ALT ; finished calculations for alternative plan? | |
453 bra calc_deko_engine_norm ; YES - do a normal plan next | |
454 bra calc_deko_engine_cont ; NO to both - continue calculations / do first invocation in INIT mode | |
455 | |
456 calc_deko_engine_norm: | |
457 ; Last cycle did an alternative plan, or the deco engine has been restarted because of a gas change etc. | |
458 ; --> Reconfigure to normal plan for next computation cycle. | |
459 bcf lo,DECO_PLAN_FLAG ; clear flag for alternative plan to do a normal plan next | |
460 bcf lo,DECO_ASCENT_FLAG ; clear flag for delayed ascent calculation | |
461 bcf lo,DECO_VOLUME_FLAG ; clear flag for gas needs calculation | |
462 bcf lo,DECO_BAILOUT_FLAG ; clear flag for bailout mode | |
463 IFDEF _cave_mode | |
464 bcf hi,DECO_CAVE_MODE ; clear flag for cave mode | |
465 ENDIF | |
466 | |
467 btfsc FLAG_ccr_mode ; in CCR mode? | |
468 bra calc_deko_engine_norm_loop ; YES - reload diluents and reconfigure CCR mode if not in bailout | |
469 btfsc FLAG_pscr_mode ; in pSCR mode? | |
470 bra calc_deko_engine_norm_loop ; YES - reload diluents and reconfigure pSCR mode if not in bailout | |
471 ;bra calc_deko_engine_norm_OC ; neither in CCR nor pSCR mode, so reload OC gases and reconfigure OC mode | |
472 ; (first cycle omits gas needs calculation for faster first deco results) | |
473 calc_deko_engine_norm_OC: | |
474 movff active_gas,WREG ; get current OC gas | |
475 call deco_setup_oc_gases_pre ; set up deco calculations in OC mode with OC gases | |
476 bra calc_deko_engine_start ; start deco engine | |
477 | |
478 calc_deko_engine_norm_loop: ; switch to loop calculation if not in a real bailout situation | |
479 btfsc FLAG_bailout_mode ; check if a real bailout situation is present | |
480 bra calc_deko_engine_norm_OC ; YES - revert to OC mode | |
481 ; NO - switch to loop calculation: | |
482 movff active_dil,WREG ; - get current diluent | |
483 call deco_setup_cc_diluents_pre ; - set up deco calculations in CCR/pSCR mode with diluents | |
484 bra calc_deko_engine_start ; - start deco engine | |
485 | |
486 calc_deko_engine_alt: | |
487 ; A normal plan was computed in the last cycle. For the next calculation cycle the mode may be switched | |
488 ; to alternative plan, or stay in normal plan but with certain features enabled... | |
489 bcf lo,DECO_ASCENT_FLAG ; clear flag for delayed ascent calculation | |
490 bcf lo,DECO_VOLUME_FLAG ; clear flag for gas needs calculation | |
491 bcf lo,DECO_BAILOUT_FLAG ; clear flag for bailout mode | |
492 IFDEF _cave_mode | |
493 bcf hi,DECO_CAVE_MODE ; clear flag for cave mode | |
494 ENDIF | |
495 | |
496 btfsc FLAG_bailout_mode ; check if a real bailout situation is present | |
497 bra calc_deko_engine_alt_1 ; YES - stay in normal plan mode and preclude delayed ascent calculation | |
498 TSTOSS char_I_extra_time ; NO - check if a delayed ascent is enabled | |
499 bra calc_deko_engine_alt_1 ; NO - stay in normal plan mode and preclude delayed ascent calculation | |
500 bsf lo,DECO_PLAN_FLAG ; YES - set flag for alternative plan | |
501 bsf lo,DECO_ASCENT_FLAG ; - set flag for delayed ascent | |
502 | |
503 calc_deko_engine_alt_1: | |
504 TSTOSS opt_calc_asc_gasvolume ; check if gas volume calculation is enabled | |
505 bra calc_deko_engine_start ; NO - no volume calculation, no simulated bailout plan in this case | |
506 bsf lo,DECO_VOLUME_FLAG ; YES - set gas needs calculation flag | |
507 | |
508 btfsc FLAG_bailout_mode ; check if a real bailout situation is present | |
509 bra calc_deko_engine_start ; YES - normal plan already does bailout (OC) calculation "for real" | |
510 | |
511 IFDEF _cave_mode | |
512 bsf hi,DECO_CAVE_MODE ; activate cave mode by default | |
513 btfss FLAG_cave_mode ; cave mode switched on? | |
514 bcf hi,DECO_CAVE_MODE ; NO - deactivate p2deco cave mode again | |
515 btfsc FLAG_dive_turned ; dive turned? | |
516 bcf hi,DECO_CAVE_MODE ; YES - deactivate p2deco cave mode again | |
517 btfsc FLAG_cave_mode_shutdown ; cave mode function shut down? | |
518 bcf hi,DECO_CAVE_MODE ; YES - deactivate p2deco cave mode again | |
519 ENDIF | |
520 | |
521 btfss lo,DECO_MODE_LOOP_FLAG ; NO - has a loop mode calculation been done during the normal plan? | |
522 bra calc_deko_engine_start ; NO - when not in loop mode, no simulated bailout to be done | |
523 decf best_gas_number,W ; YES - get best gas number -1 into WREG. If not available, WREG will be 255 now. If not computed yet, WREG will be 254 now. | |
524 btfsc WREG,7 ; - WREG < 128 (a bailout gas is available)? | |
525 bra calc_deko_engine_alt_2 ; NO - no simulated bailout possible because no bailout gas available to switch to | |
526 bsf lo,DECO_PLAN_FLAG ; YES - set flag for alternative plan | |
527 bsf lo,DECO_BAILOUT_FLAG ; - set bailout mode flag (enables gas changes before 1st stop) | |
528 movf best_gas_number,W ; - put number of best gas into WREG | |
529 call deco_setup_oc_gases_pre ; - set up deco calculations in OC mode with OC gases | |
530 bra calc_deko_engine_start ; - start in alternative plan mode | |
531 | |
532 calc_deko_engine_alt_2: | |
560 | 533 bcf lo,DECO_PLAN_FLAG ; clear flag for alternative plan |
534 bcf lo,DECO_ASCENT_FLAG ; clear flag for delayed ascent calculation | |
535 bcf lo,DECO_VOLUME_FLAG ; clear flag for gas needs calculation | |
604 | 536 IFDEF _cave_mode |
537 bcf hi,DECO_CAVE_MODE ; clear flag for cave mode | |
538 ENDIF | |
539 call inval_alternative_plan_data ; invalidate all alternative (bailout) plan data because they are not applicable any more | |
540 | |
541 calc_deko_engine_start: | |
542 IFDEF _cave_mode | |
543 movff hi,char_O_main_status ; write-back char_O_main_status to deco engine interface | |
544 ENDIF | |
560 | 545 movff lo,char_O_deco_status ; write-back char_O_deco_status to deco engine interface |
0 | 546 |
604 | 547 calc_deko_engine_cont: |
548 SAFE_2BYTE_COPY amb_pressure,int_I_pres_respiration ; transfer ambient pressure to deco engine | |
549 clrf TMR5L ; restart timer used to preempt stops calculation | |
550 clrf TMR5H ; | |
551 call deco_calc_hauptroutine ; invoke the deco engine (p2_deco.c) | |
582 | 552 banksel common |
0 | 553 |
604 | 554 ; check if display shall be updated due to deco engine restart |
555 btfsc FLAG_TFT_display_ndl_or_deko; shall update immediately? | |
556 bra calc_deko_engine_update ; YES | |
557 | |
558 ; check if new calculation results for normal plan mode are available | |
559 movff char_O_main_status,WREG ; get deco status of deco engine | |
560 btfss WREG,DECO_COMPLETED_NORM ; new calculation results for normal plan available? | |
561 return ; NO - done | |
605 | 562 |
604 | 563 calc_deko_engine_update: |
564 bcf FLAG_TFT_display_ndl_or_deko; YES - reset flag for immediate update | |
565 movff char_O_deco_info,WREG ; - get deco info vector | |
566 btfsc WREG,deco_ceiling ; - ceiling depth > 0 ? | |
567 bra calc_deko_engine_update_deco; YES - in deco | |
568 ;bra calc_deko_engine_update_NDL ; NO - within NDL | |
569 | |
570 calc_deko_engine_update_NDL: ; within NDL | |
571 btfsc decostop_active ; been in deco mode before? | |
572 bsf FLAG_TFT_display_ndl_mask ; YES - clear deco data, display NDL time | |
582 | 573 bsf FLAG_TFT_display_ndl ; display NDL time |
604 | 574 bcf decostop_active ; clear flag for been in deco mode before |
560 | 575 return |
0 | 576 |
604 | 577 calc_deko_engine_update_deco: ; in deco |
578 btfss decostop_active ; already been in deco mode before? | |
582 | 579 bsf FLAG_TFT_display_deko_mask ; NO - clear NDL time, display deco data |
580 bsf FLAG_TFT_display_deko ; display deco data | |
581 bsf FLAG_TFT_display_tts ; display TTS | |
604 | 582 bsf decostop_active ; set flag for being in deco mode |
560 | 583 return |
584 | |
585 ; -------------------------------------------------------------------------------------- | |
0 | 586 |
560 | 587 global calc_deko_divemode_sensor |
588 calc_deko_divemode_sensor: | |
589 ; sensor acquisition code | |
582 | 590 btfss s8_digital ; check if we have a digital interface to the sensors |
591 bra calc_deko_divemode_sensor_analog ; NO - check if we have an analog interface | |
592 btfss new_s8_data_available ; YES - check if a new data frame was received | |
604 | 593 bra calc_deko_divemode_sensor_common ; NO - use old values |
582 | 594 call compute_mvolts_for_all_sensors ; YES - compute mV values from digital data |
595 bra calc_deko_divemode_sensor_common | |
604 | 596 calc_deko_divemode_sensor_analog: |
597 btfss analog_o2_input ; do we have an analog input? | |
598 bra calc_deko_divemode_sensor_opt ; NO - check if we have an optical interface | |
599 call get_analog_inputs ; YES - get the analog voltages and continue with the common part | |
600 bra calc_deko_divemode_sensor_common | |
583 | 601 calc_deko_divemode_sensor_opt: |
604 | 602 btfss optical_input ; do we have an optical input? |
603 return ; NO - return (we have no sensors at all: not analog, not S8 and not optical) | |
604 btfss sensor1_active ; YES - o2_ppo2_sensor1, o2_ppo2_sensor2 and o2_ppo2_sensor3 are already filled in ISR | |
605 bcf use_O2_sensor1 ; check HUD status data and eventually clear use_O2_sensorX | |
606 btfss sensor2_active | |
607 bcf use_O2_sensor2 | |
583 | 608 btfss sensor3_active |
604 | 609 bcf use_O2_sensor3 |
610 bra calc_deko_divemode_sensor_A ; continue with calculating sensor average | |
560 | 611 |
612 calc_deko_divemode_sensor_common: | |
604 | 613 ; Check each sensor if it is calibrated and if its mV value is within min_mv and max_mv limits. |
614 ; If ok: compute o2_ppo2_sensorX = o2_mv_sensorX * opt_x_sX / 1000 | |
582 | 615 ; If not ok: reset o2_ppo2_sensorX, reset use_O2_sensorX and show the customview 1 in case the sensor was ok before |
0 | 616 |
604 | 617 ; check sensor 1 |
582 | 618 btfss sensor1_calibrated_ok ; check if sensor is usable at all |
619 bra check_sensor_1_fail ; NO - handle it as failed | |
604 | 620 ; check min threshold |
621 movff o2_mv_sensor1+0,sub_a+0 ; load sensor mV value | |
622 movff o2_mv_sensor1+1,sub_a+1 | |
623 rcall check_min_threshold | |
582 | 624 btfsc neg_flag ; check if result is negative, i.e. sensor_mv < min_mv |
625 bra check_sensor_1_fail ; YES - declare sensor as failed | |
604 | 626 ; check max_threshold |
627 rcall check_max_threshold | |
582 | 628 btfss neg_flag ; check if result is negative, i.e. sensor_mv < max_mv |
629 bra check_sensor_1_fail ; NO - declare sensor as failed | |
604 | 630 ; check HUD data, if available |
582 | 631 btfss hud_connection_ok ; check if there is a HUD connected |
632 bra check_sensor_1_ok ; NO - all checks done then and positive | |
604 | 633 btfss sensor1_active ; YES - HUD status ok? |
634 bra check_sensor_1_fail ; NO - HUD reports a fail | |
560 | 635 check_sensor_1_ok: |
604 | 636 ; o2_ppo2_sensor1 = o2_mv_sensor1:2 * opt_x_s1:2 / 1000 |
560 | 637 movff o2_mv_sensor1+0,xA+0 |
638 movff o2_mv_sensor1+1,xA+1 | |
639 movff opt_x_s1+0,xB+0 | |
640 movff opt_x_s1+1,xB+1 | |
641 rcall compute_ppo2_helper | |
604 | 642 movff xC+0,o2_ppo2_sensor1 ; result in 0.01 bar |
582 | 643 bra check_sensor_2 ; continue with next sensor |
560 | 644 check_sensor_1_fail: |
645 clrf WREG | |
582 | 646 movff WREG,o2_ppo2_sensor1 ; set ppO2 reading to zero |
647 btfss use_O2_sensor1 ; check if sensor was in use before | |
648 bra check_sensor_1_fail_1 ; NO - no new news then | |
649 call check_sensor_custview_helper; YES - show customview 1 (sensor values) on further conditions met | |
560 | 650 check_sensor_1_fail_1: |
582 | 651 bcf use_O2_sensor1 ; revoke sensor from usage |
604 | 652 |
653 check_sensor_2: ; check min_mv of sensor 2 | |
582 | 654 btfss sensor2_calibrated_ok ; check if sensor is usable at all |
655 bra check_sensor_2_fail ; NO - handle it as failed | |
604 | 656 ; check min threshold |
657 movff o2_mv_sensor2+0,sub_a+0 ; load sensor mV value | |
658 movff o2_mv_sensor2+1,sub_a+1 | |
659 rcall check_min_threshold | |
582 | 660 btfsc neg_flag ; check if result is negative, i.e. sensor_mv < min_mv |
661 bra check_sensor_2_fail ; YES - declare sensor as failed | |
604 | 662 ; check max_threshold |
663 rcall check_max_threshold | |
582 | 664 btfss neg_flag ; check if result is nagative, i.e. sensor_mv < max_mv |
665 bra check_sensor_2_fail ; NO - declare sensor as failed | |
604 | 666 ; check HUD data, if available |
582 | 667 btfss hud_connection_ok ; check if there is a HUD connected |
668 bra check_sensor_2_ok ; NO - all checks done then and positive | |
604 | 669 btfss sensor2_active ; YES - HUD status ok? |
670 bra check_sensor_2_fail ; NO - HUD reports a fail | |
560 | 671 check_sensor_2_ok: |
604 | 672 ; o2_ppo2_sensor2 = o2_mv_sensor2:2 * opt_x_s2:2 / 1000 |
560 | 673 movff o2_mv_sensor2+0,xA+0 |
674 movff o2_mv_sensor2+1,xA+1 | |
675 movff opt_x_s2+0,xB+0 | |
676 movff opt_x_s2+1,xB+1 | |
677 rcall compute_ppo2_helper | |
604 | 678 movff xC+0,o2_ppo2_sensor2 ; result in 0.01 bar |
582 | 679 bra check_sensor_3 ; continue with next sensor |
560 | 680 check_sensor_2_fail: |
681 clrf WREG | |
582 | 682 movff WREG,o2_ppo2_sensor2 ; set ppO2 reading to zero |
683 btfss use_O2_sensor2 ; check if sensor was in use before | |
684 bra check_sensor_2_fail_1 ; NO - no new news then | |
685 call check_sensor_custview_helper; YES - show customview 1 (sensor values) on further conditions met | |
560 | 686 check_sensor_2_fail_1: |
582 | 687 bcf use_O2_sensor2 ; revoke sensor from usage |
604 | 688 |
689 check_sensor_3: ; check min_mv of sensor 2 | |
582 | 690 btfss sensor3_calibrated_ok ; check if sensor is usable at all |
691 bra check_sensor_3_fail ; NO - handle it as failed | |
604 | 692 ; check min threshold |
693 movff o2_mv_sensor3+0,sub_a+0 ; load sensor mV value | |
694 movff o2_mv_sensor3+1,sub_a+1 | |
695 rcall check_min_threshold | |
582 | 696 btfsc neg_flag ; check if result is negative, i.e. sensor_mv < min_mv |
697 bra check_sensor_3_fail ; YES - declare sensor as failed | |
604 | 698 ; check max threshold |
699 rcall check_max_threshold | |
582 | 700 btfss neg_flag ; check if result is negative, i.e. sensor_mv < max_mv |
701 bra check_sensor_3_fail ; NO - declare sensor as failed | |
604 | 702 ; check HUD data, if available |
582 | 703 btfss hud_connection_ok ; check if there is a HUD connected |
704 bra check_sensor_3_ok ; NO - all checks done then and positive | |
604 | 705 btfss sensor3_active ; YES - HUD status ok? |
706 bra check_sensor_3_fail ; NO - HUD reports a fail | |
560 | 707 check_sensor_3_ok: |
604 | 708 ; o2_ppo2_sensor3 = o2_mv_sensor3:2 * opt_x_s1:2 / 1000 |
560 | 709 movff o2_mv_sensor3+0,xA+0 |
710 movff o2_mv_sensor3+1,xA+1 | |
711 movff opt_x_s3+0,xB+0 | |
712 movff opt_x_s3+1,xB+1 | |
713 rcall compute_ppo2_helper | |
604 | 714 movff xC+0,o2_ppo2_sensor3 ; result in 0.01 bar |
715 bra calc_deko_divemode_sensor_A ; continue with calculating sensor average | |
560 | 716 check_sensor_3_fail: |
717 clrf WREG | |
582 | 718 movff WREG,o2_ppo2_sensor3 ; set ppO2 reading to zero |
719 btfss use_O2_sensor3 ; check if sensor was in use before | |
720 bra check_sensor_3_fail_1 ; NO - no new news then | |
604 | 721 call check_sensor_custview_helper; YES - show custom view 1 (sensor values) on further conditions met |
560 | 722 check_sensor_3_fail_1: |
582 | 723 bcf use_O2_sensor3 ; revoke sensor from usage |
604 | 724 |
725 calc_deko_divemode_sensor_A: ; calculate sensor average | |
726 ; exit here if not in dive mode | |
560 | 727 btfss divemode |
728 return | |
729 | |
604 | 730 ; compute sensor_setpoint = average of all o2_ppo2_sensorX of those sensors that have use_O2_sensorX == true |
582 | 731 ; sum up sensor values (in xA:2) and active sensors in (xB:2) |
732 clrf xB+0 | |
733 clrf xB+1 | |
734 clrf xA+0 | |
735 clrf xA+1 | |
604 | 736 divemode_setup_sensor_1_value: |
737 btfss use_O2_sensor1 ; sensor1 active? | |
738 bra divemode_setup_sensor_2_value ; NO | |
582 | 739 movf o2_ppo2_sensor1,W |
604 | 740 addwf xA+0,F |
582 | 741 movlw .0 |
604 | 742 addwfc xA+1,F ; add into xA:2 |
743 incf xB+0,F ; add a sensor | |
744 divemode_setup_sensor_2_value: | |
745 btfss use_O2_sensor2 ; sensor2 active? | |
746 bra divemode_setup_sensor_3_value ; NO | |
582 | 747 movf o2_ppo2_sensor2,W |
604 | 748 addwf xA+0,F |
582 | 749 movlw .0 |
604 | 750 addwfc xA+1,F ; add into xA:2 |
751 incf xB+0,F ; add a sensor | |
752 divemode_setup_sensor_3_value: | |
753 btfss use_O2_sensor3 ; sensor3 active? | |
754 bra divemode_setup_sensor_mean ; NO | |
582 | 755 movf o2_ppo2_sensor3,W |
604 | 756 addwf xA+0,F |
582 | 757 movlw .0 |
604 | 758 addwfc xA+1,F ; add into xA:2 |
759 incf xB+0,F ; add a sensor | |
760 | |
761 ; divide sum of sensor values by number of active sensors found | |
762 divemode_setup_sensor_mean: | |
763 clrf xC+0 ; set zero as default result | |
764 tstfsz xB+0 ; pending div/0 ? | |
765 call div16x16 ; NO - execute xC = xA / xB = summed ppO2 / number of sensors | |
766 movff xC+0,sensor_setpoint ; copy result (or its default) | |
767 | |
768 ; set default value for pSCR mode: 0 => let p2_deco.c compute the ppO2 based on current dil gas and depth | |
560 | 769 ; will be overwritten later in case we are in sensor mode and have at least one usable sensor |
604 | 770 clrf WREG ; preload a zero |
771 btfsc FLAG_pscr_mode ; check if we are in pSCR mode | |
772 movff WREG,char_I_const_ppO2 ; YES - write 0 to char_I_const_ppo2, | |
773 ; it will be overwritten if we have a usable sensor reading | |
774 btfsc FLAG_bailout_mode ; check if we are in bailout | |
775 bra calc_deko_divemode_sensor_V ; YES - no sensor data transfer to char_I_const_ppO2 in this case | |
776 movff opt_ccr_mode,WREG ; NO - get mode (0: Fixed SP, 1: Sensor, 2: Auto SP) | |
777 sublw .1 ; - in sensor mode? | |
778 bnz calc_deko_divemode_sensor_V ; NO - not in sensor mode - no transfer of sensor data to char_I_const_ppO2 | |
779 tstfsz xB+0 ; YES - check if we have found at least one usable sensor | |
780 bra divemode_setup_sensor_mean1 ; YES - we have at least one usable sensor | |
781 bsf setpoint_fallback ; NO - we have NO usable sensors -> initiate fallback | |
782 btfss FLAG_ccr_mode ; - check if we are in CCR mode | |
783 bra calc_deko_divemode_sensor_V ; NO - continue with voting logic flags | |
784 movff char_I_setpoint_cbar+0,char_I_const_ppO2; YES - select fixed setpoint no. 1 for fallback | |
785 bra calc_deko_divemode_sensor_V ; - continue with voting logic flags | |
786 ; we have at least one usable sensor with a ppO2 value > 0 | |
787 divemode_setup_sensor_mean1: | |
788 bcf setpoint_fallback ; clear fallback condition | |
560 | 789 movff sensor_setpoint,char_I_const_ppO2 ; transfer average sensor value to p2_deco.c code |
604 | 790 ; vote sensors |
791 calc_deko_divemode_sensor_V: | |
582 | 792 bsf voting_logic_sensor1 |
793 movff o2_ppo2_sensor1,lo | |
794 rcall check_sensor_voting_helper | |
604 | 795 tstfsz WREG ; sensor within range (WREG = 0)? |
796 bcf voting_logic_sensor1 ; NO - vote out this sensor | |
560 | 797 |
582 | 798 bsf voting_logic_sensor2 |
799 movff o2_ppo2_sensor2,lo | |
800 rcall check_sensor_voting_helper | |
604 | 801 tstfsz WREG ; sensor within range (WREG = 0)? |
802 bcf voting_logic_sensor2 ; NO - vote out this sensor | |
560 | 803 |
582 | 804 bsf voting_logic_sensor3 |
805 movff o2_ppo2_sensor3,lo | |
806 rcall check_sensor_voting_helper | |
604 | 807 tstfsz WREG ; sensor within range (WREG = 0)? |
808 bcf voting_logic_sensor3 ; NO - vote out this sensor | |
582 | 809 |
560 | 810 ; check if a warning shall be issued on sensor disagreement |
582 | 811 btfsc FLAG_ccr_mode ; check if we are in CCR mode |
604 | 812 bra check_warn_sensor_0 ; YES - continue with further checks |
582 | 813 btfsc FLAG_pscr_mode ; check if we are in pSCR mode |
604 | 814 bra check_warn_sensor_0 ; YES - continue with further checks |
815 bra check_warn_sensor_done ; not in CCR and not in pSCR, so no warning | |
816 check_warn_sensor_0: ; we are in CCR or pSCR mode | |
817 btfsc FLAG_bailout_mode ; check if we are in bailout | |
818 bra check_warn_sensor_done ; YES - no warning in this case | |
819 movff opt_ccr_mode,WREG ; get mode (0: Fixed SP, 1: Sensor, 2: Auto SP) | |
820 sublw .1 ; in sensor mode? | |
821 bnz check_warn_sensor_done ; NO - not in sensor mode - no warning in this case | |
822 ; check sensor 1 | |
823 check_warn_sensor_1: | |
582 | 824 btfss sensor1_calibrated_ok ; check if sensor has a valid calibration |
825 bra check_warn_sensor_2 ; NO - sensor can not cause a warning then | |
826 btfss use_O2_sensor1 ; YES - check if sensor is in use | |
604 | 827 bra check_warn_sensor_2 ; NO - sensor can not cause a warning then |
828 btfsc voting_logic_sensor1 ; YES - check if sensor value is within agreement range | |
829 bra check_warn_sensor_2 ; YES - continue with next sensor | |
830 bcf sensors_agree ; NO - issue a warning | |
560 | 831 return |
604 | 832 ; check sensor 2 |
833 check_warn_sensor_2: | |
582 | 834 btfss sensor2_calibrated_ok ; check if sensor has a valid calibration |
835 bra check_warn_sensor_3 ; NO - sensor can not cause a warning then | |
836 btfss use_O2_sensor2 ; YES - check if sensor is in use | |
604 | 837 bra check_warn_sensor_3 ; NO - sensor can not cause a warning then |
838 btfsc voting_logic_sensor2 ; YES - check if sensor value is within agreement range | |
839 bra check_warn_sensor_3 ; YES - continue with next sensor | |
840 bcf sensors_agree ; NO - issue a warning | |
560 | 841 return |
604 | 842 ; check sensor 3 |
843 check_warn_sensor_3: | |
582 | 844 btfss sensor3_calibrated_ok ; check if sensor has a valid calibration |
845 bra check_warn_sensor_agree ; NO - sensor can not cause a warning then | |
846 btfss use_O2_sensor3 ; YES - check if sensor is in use | |
604 | 847 bra check_warn_sensor_agree ; NO - sensor can not cause a warning then |
848 btfsc voting_logic_sensor3 ; YES - check if sensor value is within agreement range | |
849 bra check_warn_sensor_agree ; YES - continue with next sensor | |
850 bcf sensors_agree ; NO - issue a warning | |
560 | 851 return |
604 | 852 ; no need for a warning |
853 check_warn_sensor_done: | |
560 | 854 check_warn_sensor_agree: |
855 bsf sensors_agree | |
856 return | |
857 | |
604 | 858 |
859 check_min_threshold: | |
860 movlw LOW min_mv ; load minimum mV value | |
861 movwf sub_b+0 | |
862 movlw HIGH min_mv | |
863 movwf sub_b+1 | |
864 goto sub16 ; sub_c = sensor_mv - min_mv (and return) | |
865 | |
866 check_max_threshold: | |
867 movlw LOW max_mv | |
868 movwf sub_b+0 | |
869 movlw HIGH max_mv | |
870 movwf sub_b+1 | |
871 goto sub16 ; sub_c = sensor_mv - max_mv (and return) | |
872 | |
560 | 873 compute_ppo2_helper: |
582 | 874 call mult16x16 ; xA:2*xB:2=xC:4 |
875 movlw LOW .1000 | |
560 | 876 movwf xB+0 |
582 | 877 movlw HIGH .1000 |
560 | 878 movwf xB+1 |
582 | 879 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder |
560 | 880 movlw d'1' |
582 | 881 addwf xC+0,W ; we are just interested in the carry flag |
560 | 882 movlw d'0' |
582 | 883 addwfc xC+1,W ; we are still just interested in the carry flag |
884 tstfsz WREG ; ppO2 is higher than 2.55bar? | |
604 | 885 setf xC+0 ; YES |
582 | 886 return |
0 | 887 |
560 | 888 check_sensor_custview_helper: |
604 | 889 btfss divemode ; check if we are in dive mode |
582 | 890 return ; NO - not in dive mode, return |
604 | 891 movff opt_ccr_mode,WREG ; YES - =0: Fixed SP, =1: Sensor, =2: Auto SP |
892 decfsz WREG,W ; - opt_ccr_mode = 1 (sensors)? | |
893 return ; NO - not using the sensors in the moment | |
894 btfsc alternative_divelayout ; YES - in alternative layout? | |
895 call switch_layout_to_normal ; YES - switch to normal layout | |
896 movlw index_ppo2_sensors-1 ; custom view number one below ppO2 sensors | |
897 movwf menupos3 ; set custom view number | |
898 bsf toggle_customview ; initiate toggle to desired custom view -> ppO2 sensors | |
560 | 899 return |
900 | |
901 check_sensor_voting_helper: | |
582 | 902 movf lo,W |
903 cpfsgt sensor_setpoint | |
604 | 904 bra check_sensor_voting_helper2 ; lo < sensor_setpoint |
582 | 905 ; lo > sensor_setpoint |
906 movf lo,W | |
907 subwf sensor_setpoint,W | |
908 movwf lo | |
604 | 909 check_sensor_voting_helper1: |
910 movlw sensor_voting_logic_threshold ; threshold in 0.01 bar | |
582 | 911 cpfsgt lo |
604 | 912 retlw .0 ; within range |
913 retlw .1 ; out of range | |
914 check_sensor_voting_helper2: | |
915 ; lo < sensor_setpoint | |
582 | 916 movf sensor_setpoint,W |
917 subwf lo,F | |
604 | 918 bra check_sensor_voting_helper1 |
582 | 919 |
560 | 920 ;----------------------------------------------------------------------------- |
921 | |
604 | 922 divemodemode_togglegf: ; toggle aGF/GF |
923 bcf toggle_gf ; clear command flag | |
924 btg use_agf ; toggle status flag for GF | |
925 | |
926 btfsc use_agf ; aGF activated? | |
582 | 927 bra divemodemode_togglegf_1 ; YES - branch to using aGF |
928 movff opt_GF_low,char_I_GF_Low_percentage ; NO - use normal GF factors | |
604 | 929 movff opt_GF_high,char_I_GF_High_percentage ; - |
930 bra divemodemode_togglegf_2 ; - continue with common part | |
931 divemodemode_togglegf_1: | |
932 movff opt_aGF_low,char_I_GF_Low_percentage ; YES - use alternative GF factors | |
933 movff opt_aGF_high,char_I_GF_High_percentage ; - | |
582 | 934 divemodemode_togglegf_2: |
604 | 935 call TFT_gf_factors_mask ; update custom view mask to show which one is in use |
936 ; the custom view itself has been called from divemenu_tree before | |
582 | 937 goto restart_deco_engine ; ...and return |
560 | 938 |
939 | |
604 | 940 IFDEF _cave_mode |
941 divemodemode_toggleturn: | |
942 bcf toggle_turn_dive ; clear command flag | |
943 btg FLAG_dive_turned ; toggle dive turned state | |
944 btfsc FLAG_cave_mode_shutdown ; cave mode function shut down? | |
945 bsf FLAG_dive_turned ; YES - allow only activating turned state | |
946 goto set_logbook_marker ; set a logbook marker (and return) | |
947 ENDIF | |
948 | |
949 calc_velocity: ; called every two seconds | |
582 | 950 btfsc display_velocity |
604 | 951 bra calc_velocity1 ; always update if already displayed |
582 | 952 btfss divemode2 |
604 | 953 return ; display velocity only if deeper then 1m (Not at the surface after the dive) |
399
db25f2028074
CHANGE: New segmented speed graph in divemode
heinrichsweikamp
parents:
398
diff
changeset
|
954 calc_velocity1: |
582 | 955 SAFE_2BYTE_COPY amb_pressure, sub_a |
0 | 956 movff last_pressure_velocity+0,sub_b+0 |
957 movff last_pressure_velocity+1,sub_b+1 | |
604 | 958 movff sub_a+0,last_pressure_velocity+0 ; store old value for velocity |
0 | 959 movff sub_a+1,last_pressure_velocity+1 |
960 | |
604 | 961 call subU16 ; sub_c = amb_pressure - last_pressure |
0 | 962 |
582 | 963 bcf neg_flag_velocity |
964 btfsc neg_flag | |
965 bsf neg_flag_velocity | |
318
6d8c82fe5a01
VSIbar #3d: more filter, neg_flag_velocity close to calculation, debug color for descend bar
janos_kovacs <kovjanos@gmail.com>
parents:
315
diff
changeset
|
966 |
0 | 967 movff sub_c+0,xA+0 |
968 movff sub_c+1,xA+1 | |
582 | 969 movlw d'39' ; 77 when called every second.... |
0 | 970 movwf xB+0 |
971 clrf xB+1 | |
582 | 972 call mult16x16 ; differential pressure in mbar*77... |
0 | 973 movff xC+0,divA+0 |
974 movff xC+1,divA+1 | |
975 movlw d'7' | |
604 | 976 call div16 ; divA = divA / 2^WREG, divide by 2^7 equals velocity in m/min |
0 | 977 |
978 movlw d'99' | |
604 | 979 cpfsgt divA+0 ; velocity > 99 m/min ? |
980 bra calc_velocity3 ; NO | |
981 movwf divA+0 ; YES - set divA = 99 | |
0 | 982 |
983 calc_velocity3: | |
582 | 984 ; Copy old speeds |
985 movff old_velocity+2,old_velocity+3 | |
986 movff old_velocity+1,old_velocity+2 | |
987 movff old_velocity+0,old_velocity+1 | |
988 movff divA+0,old_velocity+0 | |
989 | |
990 ; movff old_velocity+3,WREG | |
991 ; addwf divA+0,F ; add old speed | |
992 ; bcf STATUS,C | |
993 ; rrcf divA+0,F ; /2 | |
994 ; movff old_velocity+2,WREG | |
995 ; addwf divA+0,F ; add old speed | |
996 ; bcf STATUS,C | |
997 ; rrcf divA+0,F ; /2 | |
998 ; movff old_velocity+1,WREG | |
999 ; addwf divA+0,F ; add old speed | |
1000 ; bcf STATUS,C | |
1001 ; rrcf divA+0,F ; /2 | |
1002 ; movff old_velocity+0,WREG | |
1003 ; addwf divA+0,F ; add old speed | |
1004 ; bcf STATUS,C | |
1005 ; rrcf divA+0,F ; /2 | |
604 | 1006 goto TFT_display_velocity ; with divA+0 = m/min..., and return... |
0 | 1007 |
1008 | |
1009 ;============================================================================= | |
1010 | |
604 | 1011 set_reset_safety_stop: ; set flags for safety stop and/or reset safety stop |
1012 TSTOSS opt_enable_safetystop ; safety stop enabled? (=1: show safety stop) | |
1013 bra delete_safety_stop ; NO - don't show safety stop | |
1014 | |
1015 btfsc decostop_active ; is a deco stop displayed? | |
1016 bra delete_safety_stop ; YES - don't show safety stop | |
1017 | |
1018 ; Below "opt_safety_stop_reset"? if yes, set flag and reset count-down timer | |
582 | 1019 SAFE_2BYTE_COPY rel_pressure, lo |
1020 call adjust_depth_with_salinity ; computes salinity setting into lo:hi [mbar] | |
104
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
1021 movff lo,sub_a+0 |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
1022 movff hi,sub_a+1 |
582 | 1023 movff opt_safety_stop_reset,WREG ; [cbar] |
1024 mullw .10 ; mbar in PRODL:H | |
1025 movff PRODL,sub_b+0 | |
1026 movff PRODH,sub_b+1 | |
1027 call subU16 ; sub_c = sub_a - sub_b | |
104
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
1028 btfss neg_flag |
604 | 1029 bra reset_safety_stop ; below 10m, reset safety stop |
1030 | |
1031 ; Above "opt_safety_stop_end"? if yes ,clear flag | |
582 | 1032 movff opt_safety_stop_end,WREG ; [cbar] |
1033 mullw .10 ; mbar in PRODL:H | |
604 | 1034 movff PRODL,sub_b+0 ; sub_a is still loaded with adjusted rel_pressure |
582 | 1035 movff PRODH,sub_b+1 |
1036 call subU16 ; sub_c = sub_a - sub_b | |
104
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
1037 btfsc neg_flag |
604 | 1038 bra delete_safety_stop ; above 3m, remove safety stop |
1039 | |
1040 ; Above "opt_safety_stop_start"? if yes, activate safety stop | |
582 | 1041 movff opt_safety_stop_start,WREG ; [cbar] |
1042 mullw .10 ; mbar in PRODL:H | |
604 | 1043 movff PRODL,sub_b+0 ; sub_a is still loaded with adjusted rel_pressure |
582 | 1044 movff PRODH,sub_b+1 |
1045 call subU16 ; sub_c = sub_a - sub_b | |
104
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
1046 btfsc neg_flag |
604 | 1047 bra acivate_safety_stop ; above 5m, activate safety stop |
1048 bra reset_safety_stop2 ; pause safety stop | |
104
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
1049 |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
1050 acivate_safety_stop: |
604 | 1051 tstfsz safety_stop_countdown ; countdown at zero? |
1052 bsf show_safety_stop ; NO - set flag | |
104
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
1053 return |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
1054 |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
1055 delete_safety_stop: |
582 | 1056 clrf safety_stop_countdown ; reset timer |
604 | 1057 bra reset_safety_stop2 ; remove safety stop from display |
104
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
1058 |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
1059 reset_safety_stop: |
582 | 1060 movff opt_safety_stop_length,safety_stop_countdown ; reset timer |
104
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
1061 reset_safety_stop2: |
604 | 1062 bcf show_safety_stop ; clear flag |
1063 btfss safety_stop_active ; safety stop shown? | |
1064 return ; NO - don't delete it | |
1065 bcf safety_stop_active ; clear flag | |
582 | 1066 bsf FLAG_TFT_clear_safety_stop ; Clear safety stop |
1067 return | |
428 | 1068 |
104
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
1069 |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
1070 ;============================================================================= |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
1071 |
0 | 1072 timeout_menuview: |
604 | 1073 decfsz timeout_counter2,F ; timeout for menu view? |
1074 return ; NO - done | |
582 | 1075 ; Timeout, clear e.g. "Menu?" |
604 | 1076 goto menuview_toggle_reset ; ...and return |
0 | 1077 |
1078 timeout_divemode_menu: | |
582 | 1079 decfsz timeout_counter2,F ; timeout for divemode menu |
1080 return | |
0 | 1081 |
582 | 1082 global timeout_divemode_menu2 |
604 | 1083 timeout_divemode_menu2: ; called from divemenu_tree.asm |
1084 bcf divemode_menu ; timeout, clear flag | |
1085 call TFT_clear_divemode_menu ; clear menu | |
1086 bsf FLAG_TFT_active_gas_divemode; redraw gas/setpoint/diluent | |
1087 bcf blinking_better_gas ; clear flag to have temperature updated once | |
1088 bcf blinking_better_dil ; clear flag to have temperature updated once | |
1089 bsf FLAG_TFT_temp_divemode ; display temperature | |
1090 call TFT_draw_gassep_line ; gas separator grid in spec mode only | |
1091 | |
1092 btfss decostop_active ; in deco mode ? | |
1093 bra timeout_divemode_menu_ndl ; NO - show NDL again | |
1094 ; Show deco data | |
582 | 1095 bsf FLAG_TFT_display_deko_mask |
1096 bsf FLAG_TFT_display_deko | |
1097 bsf FLAG_TFT_display_tts | |
1098 return | |
1099 | |
1100 timeout_divemode_menu_ndl: | |
1101 ; Show NDL | |
1102 bsf FLAG_TFT_display_ndl_mask | |
1103 bsf FLAG_TFT_display_ndl | |
1104 return | |
0 | 1105 |
1106 timeout_divemode: | |
604 | 1107 btfsc divemode_menu ; divemode menu active? |
1108 rcall timeout_divemode_menu ; YES - check the timeout for it... | |
1109 | |
1110 btfsc menuview ; is a menu view shown? | |
1111 rcall timeout_menuview ; YES - check the timeout for it... | |
1112 | |
1113 btfss realdive ; dive longer than one minute? | |
1114 return ; NO - done | |
1115 | |
1116 btfsc FLAG_apnoe_mode ; in apnoe mode? | |
1117 bra timeout_divemode2 ; YES - use apnoe_timeout [min] for timeout | |
1118 | |
1119 IFNDEF __DEBUG | |
1120 btfsc simulatormode_active ; in simulator mode? | |
1121 bra timeout_divemode3 ; YES - use simulator timeout | |
1122 ENDIF | |
1123 | |
1124 bcf divemode ; terminate divemode my default | |
1125 infsnz timeout_counter1+0,F ; increment timeout counter | |
582 | 1126 incf timeout_counter1+1,F ; timeout is 16 bit counter |
0 | 1127 |
604 | 1128 movff opt_diveTimeout,WREG ; get timeout in minutes |
1129 mullw .60 ; convert into seconds | |
444
d93d75ae01bf
Adjustable timeout for Divemode (Config 0x48)
heinrichsweikamp
parents:
437
diff
changeset
|
1130 movff PRODL,sub_a+0 |
604 | 1131 movff PRODH,sub_a+1 |
0 | 1132 |
582 | 1133 movff timeout_counter1+0,sub_b+0 |
1134 movff timeout_counter1+1,sub_b+1 | |
1135 call subU16 ; sub_c = sub_a - sub_b | |
604 | 1136 btfss neg_flag ; result negative, i.e. timeout? |
1137 bsf divemode ; NO - set divemode flag again | |
0 | 1138 return |
1139 | |
1140 timeout_divemode2: | |
582 | 1141 incf timeout_counter1+0,F ; seconds... |
0 | 1142 movlw d'60' |
582 | 1143 cpfseq timeout_counter1+0 ; timeout_counter1+0 = 60 ? |
1144 return ; No | |
1145 ; one minute timeout done | |
1146 clrf timeout_counter1+0 | |
0 | 1147 bcf divemode |
1148 incf apnoe_timeout_counter,F | |
1149 movlw apnoe_timeout ; apnoe timeout [min] | |
1150 cpfseq apnoe_timeout_counter | |
1151 bsf divemode | |
1152 return | |
1153 | |
1154 timeout_divemode3: | |
1155 bcf divemode | |
582 | 1156 incf timeout_counter1+0,F |
1157 movlw simulator_timeout ; simulator timeout | |
1158 cpfsgt timeout_counter1+0 | |
0 | 1159 bsf divemode |
1160 return | |
1161 | |
582 | 1162 update_divemode60: ; update any minute |
0 | 1163 call get_battery_voltage ; gets battery voltage |
604 | 1164 rcall set_powersafe ; check if battery low |
1165 ;call customview_minute ; do every-minute tasks for the custom view area | |
582 | 1166 bcf oneminupdate |
604 | 1167 IFDEF _cave_mode |
1168 movlw .1 ; prepare to add backtrack data for 1 minute | |
1169 btfsc FLAG_cave_mode ; cave mode enabled? | |
1170 rcall update_backtrack ; YES - make it so | |
1171 ENDIF | |
582 | 1172 btfss simulatormode_active ; in simulator mode? |
604 | 1173 return ; NO - done |
1174 movlw .20 ; YES - quite dive mode simulation after 21 * 256 sec = 89 min : 36 sec | |
1175 cpfsgt total_divetime_seconds+1 ; timeout? | |
1176 return ; NO - done | |
1177 IFDEF __DEBUG | |
1178 return ; YES - but no timeout in debug mode | |
1179 ENDIF | |
1180 bra divemode_option1 ; YES - set depth to 0 m and "return" | |
1181 | |
1182 IFDEF _cave_mode | |
1183 update_backtrack: | |
1184 btfsc FLAG_dive_turned ; dive turned? | |
1185 return ; YES - done | |
1186 movwf lo ; store minutes to add in lo | |
1187 lfsr FSR1,char_I_backtrack_depth ; load FSR1 with base address of backtrack storage | |
1188 movff char_I_backtrack_time,FSR1L ; adjust FSR1 to last index | |
1189 update_backtrack_loop: | |
1190 btfsc FLAG_cave_mode_shutdown ; backtrack storage full? | |
1191 return ; YES - done | |
1192 movff curr_depth,PREINC1 ; NO - increment index and write current depth to backtrack storage | |
1193 incfsz FSR1L,W ; - did a wrap-around of the index occur (backtrack storage full)? | |
1194 bra update_backtrack_loop_1 ; NO - continue loop | |
1195 bsf FLAG_cave_mode_shutdown ; YES - flag backtrack storage as being full | |
1196 return | |
1197 update_backtrack_loop_1: | |
1198 decfsz lo,F ; decrement loop counter, did it became zero? | |
1199 bra update_backtrack_loop ; NO - loop | |
1200 movff FSR1L,char_I_backtrack_time ; YES - read-back index | |
1201 return ; - done | |
1202 ENDIF | |
0 | 1203 |
1204 set_max_depth: | |
1205 movff max_pressure+0,sub_a+0 | |
1206 movff max_pressure+1,sub_a+1 | |
582 | 1207 SAFE_2BYTE_COPY rel_pressure, sub_b |
1208 call subU16 ; sub_c = sub_a - sub_b | |
604 | 1209 ; max_pressure < rel_pressure -> neg_flag=1 |
1210 ; rel_pressure <= max_pressure -> neg_flag=0 | |
582 | 1211 btfss neg_flag |
0 | 1212 return |
604 | 1213 ; max_pressure < rel_pressure |
0 | 1214 movff sub_b+0,max_pressure+0 |
1215 movff sub_b+1,max_pressure+1 | |
604 | 1216 bsf FLAG_TFT_max_depth ; set flag |
560 | 1217 return |
0 | 1218 |
1219 set_min_temp: | |
1220 movff minimum_temperature+0,sub_a+0 | |
1221 movff minimum_temperature+1,sub_a+1 | |
582 | 1222 SAFE_2BYTE_COPY temperature,sub_b |
1223 call sub16 ; sub_c = sub_a - sub_b | |
604 | 1224 ; minimum_temperature < T -> neg_flag=1 |
1225 ; T <= minimum_temperature -> neg_flag=0 | |
582 | 1226 btfsc neg_flag |
0 | 1227 return |
582 | 1228 ; minimum_temperature >= T |
0 | 1229 movff sub_b+0,minimum_temperature+0 |
1230 movff sub_b+1,minimum_temperature+1 | |
1231 return | |
1232 | |
1233 global set_dive_modes | |
1234 set_dive_modes: | |
604 | 1235 btfsc high_altitude_mode ; in high altitude (fly) mode? |
1236 bra set_dive_modes3 ; YES | |
0 | 1237 |
1238 set_dive_modes0: | |
582 | 1239 movlw LOW start_dive_threshold |
560 | 1240 movwf sub_a+0 ; dive_treshold is in cm |
582 | 1241 movlw HIGH start_dive_threshold |
560 | 1242 movwf sub_a+1 ; dive_treshold is in cm |
0 | 1243 |
1244 set_dive_modes1: | |
582 | 1245 SAFE_2BYTE_COPY rel_pressure, sub_b |
560 | 1246 call subU16 ; sub_c = sub_a - sub_b |
0 | 1247 |
582 | 1248 btfss neg_flag |
1249 bra set_dive_modes2 ; too shallow (rel_pressure < dive_threshold) | |
0 | 1250 |
604 | 1251 btfsc realdive ; dive longer than one minute? |
1252 clrf timeout_counter1+0 ; YES - reset timeout counter | |
1253 | |
1254 bsf divemode ; (re-)set divemode flag | |
560 | 1255 bsf divemode2 ; displayed divetime is running |
0 | 1256 return |
1257 | |
1258 set_dive_modes2: | |
604 | 1259 bcf divemode2 ; stop time |
560 | 1260 btfss realdive ; dive longer then one minute? |
604 | 1261 bcf divemode ; NO - this was no real dive |
1262 return ; YES - return | |
1263 | |
1264 set_dive_modes3: ; high-altitude mode | |
560 | 1265 btfsc realdive ; dive longer then one minute? |
604 | 1266 bra set_dive_modes0 ; YES - this is a real dive -> Use start_dive_threshold or ascend |
0 | 1267 |
582 | 1268 movlw LOW high_altitude_dive_threshold |
1269 movwf sub_a+0 | |
1270 movlw HIGH high_altitude_dive_threshold | |
0 | 1271 movwf sub_a+1 |
1272 bra set_dive_modes1 | |
1273 | |
1274 set_powersafe: | |
582 | 1275 movlw color_code_battery_low+1; [%] |
1276 cpfslt batt_percent | |
0 | 1277 return |
1278 | |
604 | 1279 movlw d'7' ; type of alarm (battery Low) |
1280 movwf AlarmType ; copy to alarm register | |
582 | 1281 bsf event_occured ; set event flag |
1282 movlw .0 | |
604 | 1283 movff WREG,opt_brightness ; set brightness to ECO |
560 | 1284 return ; return |
0 | 1285 |
604 | 1286 |
1287 reset_average: | |
1288 bcf reset_average_depth ; clear reset-average flag | |
1289 clrf average_depth_hold+0 ; clear the depth accumulator | |
1290 clrf average_depth_hold+1 ; ... | |
1291 clrf average_depth_hold+2 ; ... | |
1292 clrf average_depth_hold+3 ; ... | |
1293 clrf average_divesecs+0 ; clear the time accumulator | |
1294 clrf average_divesecs+1 ; ... | |
1295 SAFE_2BYTE_COPY rel_pressure,avg_rel_pressure ; prime result with current rel.pressure/depth | |
1296 return | |
1297 | |
1298 | |
0 | 1299 calc_average_depth: |
604 | 1300 ; 1. compute rel_pressure x 2, because this routine is called every 2nd second only |
1301 SAFE_2BYTE_COPY rel_pressure,xB ; copy current rel pressure to xB | |
582 | 1302 bcf STATUS,C |
604 | 1303 rlcf xB+0,F ; multiply rel pressure x 2 (via shift left) |
1304 rlcf xB+1,F ; ... | |
1305 | |
1306 ; 2a add (rel_pressure x 2) to the resettable depth accumulator | |
1307 movf xB+0,W | |
0 | 1308 addwf average_depth_hold+0,F |
604 | 1309 movf xB+1,W |
0 | 1310 addwfc average_depth_hold+1,F |
604 | 1311 movlw .0 |
0 | 1312 addwfc average_depth_hold+2,F |
604 | 1313 addwfc average_depth_hold+3,F ; will work up to 9999 mbar * 60 * 60 * 24 = 863913600 mbar (24h @ 90 m depth) |
1314 | |
1315 ; 2b add (rel_pressure x 2) to the total depth accumulator | |
1316 movf xB+0,W | |
0 | 1317 addwf average_depth_hold_total+0,F |
604 | 1318 movf xB+1,W |
0 | 1319 addwfc average_depth_hold_total+1,F |
604 | 1320 movlw .0 |
0 | 1321 addwfc average_depth_hold_total+2,F |
604 | 1322 addwfc average_depth_hold_total+3,F ; will work up to 9999 mbar * 60 * 60 * 24 = 863913600 mbar (24h @ 90 m depth) |
1323 | |
1324 ; 3a compute avg_rel_pressure on base of average_divesecs:2 | |
0 | 1325 movff average_depth_hold+0,xC+0 |
1326 movff average_depth_hold+1,xC+1 | |
1327 movff average_depth_hold+2,xC+2 | |
604 | 1328 movff average_depth_hold+3,xC+3 ; copy accumulated depth |
1329 movff average_divesecs+0,xB+0 | |
1330 movff average_divesecs+1,xB+1 ; copy accumulated time | |
1331 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | |
437 | 1332 movff xC+0,avg_rel_pressure+0 |
604 | 1333 movff xC+1,avg_rel_pressure+1 ; store result |
1334 | |
1335 btfss divemode2 ; displayed divetime is running? | |
1336 return ; NO (e.g. too shallow) | |
1337 | |
1338 ; 3b compute avg_rel_pressure_total on base of average_divesecs_total:2 | |
0 | 1339 movff average_depth_hold_total+0,xC+0 |
1340 movff average_depth_hold_total+1,xC+1 | |
1341 movff average_depth_hold_total+2,xC+2 | |
604 | 1342 movff average_depth_hold_total+3,xC+3 ; copy accumulated depth |
1343 movff average_divesecs_total+0,xB+0 | |
1344 movff average_divesecs_total+1,xB+1 ; copy accumulated time | |
1345 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | |
437 | 1346 movff xC+0,avg_rel_pressure_total+0 |
604 | 1347 movff xC+1,avg_rel_pressure_total+1 ; store result |
1348 | |
1349 btfsc reset_average_depth ; reset the resettable average depth? | |
1350 rcall reset_average ; YES - reset the resettable average depth | |
1351 | |
1352 TSTOSS opt_2ndDepthDisp ; drawing avg depth instead of max depth? | |
1353 return ; NO - done | |
1354 bsf FLAG_TFT_max_depth ; YES - flag to update display | |
0 | 1355 return |
1356 | |
604 | 1357 |
1358 test_switches_divemode: ; checks switches in divemode | |
1359 btfsc divemode_menu ; divemode menu shown? | |
1360 bra test_switches_divemode_menu ; YES - use menu processor | |
1361 btfsc switch_left ; NO - left button pressed? | |
1362 goto menuview_toggle ; YES - menu or simulator tasks; and return... | |
1363 btfss switch_right ; NO - right button pressed? | |
1364 return ; NO - done | |
1365 tstfsz menupos2 ; YES - any option shown? | |
1366 bra test_switches_divemode1 ; YES - do option tasks | |
1367 bsf toggle_customview ; NO - toggle custom view | |
1368 return ; - done | |
0 | 1369 |
1370 test_switches_divemode_menu: | |
1371 btfsc switch_left | |
604 | 1372 bra test_switches_divemode_menu2 ; move cursor |
1373 btfsc switch_right ; left button pressed? | |
1374 bra test_switches_divemode_menu3 ; YES - enter submenu or do something | |
1375 return ; NO - done | |
0 | 1376 |
1377 test_switches_divemode_menu1: | |
582 | 1378 clrf menupos1 |
0 | 1379 test_switches_divemode_menu2: |
582 | 1380 incf menupos1,F |
604 | 1381 incf menupos4,W ; menupos4 + 1 -> WREG |
1382 cpfslt menupos1 ; > menupos4 (set in menu_processor.asm)? | |
1383 bra test_switches_divemode_menu1 ; YES - set to 1 | |
1384 call TFT_divemode_menu_cursor ; update the cursor | |
582 | 1385 bcf switch_left |
604 | 1386 movlw divemode_menu_timeout ; reload timeout |
1387 movwf timeout_counter2 ; timeout for divemode menu | |
582 | 1388 return |
0 | 1389 |
604 | 1390 test_switches_divemode_menu3: ; enter submenu or do something |
582 | 1391 bcf switch_right |
1392 ; decf menupos1,F ; menu_processor needs 0-5... | |
604 | 1393 goto do_line_menu ; Warning! trashes STKPTR and returns to diveloop_loop4: |
0 | 1394 |
1395 test_switches_divemode1: | |
1396 bcf switch_right | |
582 | 1397 movlw divemode_menuview_timeout |
604 | 1398 movwf timeout_counter2 ; reload timeout |
582 | 1399 movff menupos2,WREG ; menupos2 holds number of customview/divemode menu function |
0 | 1400 dcfsnz WREG,F |
604 | 1401 bra divemode_option_gaschange ; switch to the the "better gas" / "better diluent" |
137 | 1402 dcfsnz WREG,F |
604 | 1403 bra divemode_option0 ; start/setup Divemode menu |
0 | 1404 dcfsnz WREG,F |
604 | 1405 bra divemode_option1 ; quit simulation? |
0 | 1406 dcfsnz WREG,F |
604 | 1407 bra divemode_option2 ; descent 1m |
0 | 1408 dcfsnz WREG,F |
604 | 1409 bra divemode_option3 ; ascend 1m |
0 | 1410 dcfsnz WREG,F |
604 | 1411 bra divemode_option4 ; quit Apnoe mode |
0 | 1412 dcfsnz WREG,F |
604 | 1413 bra divemode_option5 ; reset stopwatch (gauge mode only) |
216
973a0969e0ac
NEW: On-board simulator can increase divetime in 5min steps
heinrichsweikamp
parents:
206
diff
changeset
|
1414 dcfsnz WREG,F |
973a0969e0ac
NEW: On-board simulator can increase divetime in 5min steps
heinrichsweikamp
parents:
206
diff
changeset
|
1415 bra divemode_option6 ; +5mins simulation |
254
5fe7aff622f3
preparations to set a course for the compass display
heinrichsweikamp
parents:
239
diff
changeset
|
1416 dcfsnz WREG,F |
604 | 1417 bra divemode_option7 ; store heading |
560 | 1418 dcfsnz WREG,F |
604 | 1419 bra divemode_option8 ; switch to alternative layout |
582 | 1420 return |
0 | 1421 |
1422 gas_switched_common: | |
604 | 1423 bcf divemode_gaschange ; clear flag |
582 | 1424 btfss FLAG_back_to_loop ; check if it is a switchback from OC bailout to loop |
1425 bra gas_switched_common0 ; NO - continue with checking if selected gas is valid | |
1426 bcf FLAG_back_to_loop ; YES - clear flag | |
604 | 1427 movff active_dil,menupos1 ; reload last diluent |
582 | 1428 bra gas_switched_common1 ; continue with common part |
1429 gas_switched_common0: | |
604 | 1430 tstfsz menupos1 ; menupos1 = 0 ? |
582 | 1431 bra gas_switched_common1 ; NO - valid gas |
1432 return ; YES - something went wrong, invalid gas, abort | |
560 | 1433 gas_switched_common1: |
582 | 1434 movf menupos1,W ; get selected gas into WREG (1-6) |
604 | 1435 btfsc FLAG_oc_mode ; in OC mode? |
1436 bra gas_switched_common_OC ; YES | |
1437 btfsc FLAG_bailout_mode ; in bailout? | |
1438 bra gas_switched_common_OC ; YES | |
1439 gas_switched_common_loop: ; NO to both - must be loop mode then | |
1440 rcall setup_dil_registers ; with WREG = diluent 1-6 | |
1441 rcall deco_setup_cc_diluents ; with WREG = diluent 1-6 | |
560 | 1442 bra gas_switched_common3 |
604 | 1443 gas_switched_common_OC: |
1444 rcall setup_gas_registers ; with WREG = Gas 1-6 | |
1445 rcall deco_setup_oc_gases ; with WREG = Gas 1-6 | |
560 | 1446 gas_switched_common3: |
605 | 1447 banksel int_O_breathed_ppO2 |
1448 bcf int_O_breathed_ppO2+1,int_low_flag ; | clear all flags that control color-coding | |
1449 bcf int_O_breathed_ppO2+1,int_high_flag ; | to have the new gas initially displayed in | |
1450 bcf int_O_breathed_ppO2+1,int_attention_flag ; | memo color instead of a warning or attention | |
1451 bcf int_O_breathed_ppO2+1,int_warning_flag ; | color that belonged to the previous gas | |
1452 banksel common | |
1453 bsf FLAG_TFT_active_gas_divemode ; redraw gas/setpoint/diluent | |
1454 call restart_deco_engine_wo_ceiling ; abort any running deco calculations and restart the deco engine | |
604 | 1455 ; set flags for profile recording |
582 | 1456 bsf event_occured ; set event flag |
604 | 1457 btfsc FLAG_bailout_mode ; choose OC Bailouts (OC Gases) |
1458 bsf bailoutgas_event ; bailout gas change | |
1459 btfss FLAG_bailout_mode ; choose OC Bailouts (OC Gases) | |
560 | 1460 bsf stored_gas_changed ; OC gas change |
0 | 1461 return |
1462 | |
560 | 1463 |
1464 ; Code to pass all parameters to the C code | |
1465 | |
582 | 1466 global get_first_gas_to_WREG |
604 | 1467 get_first_gas_to_WREG: ; gets first gas (1-5) into WREG |
1468 lfsr FSR1,opt_gas_type ; point to gas types | |
1469 clrf lo ; start with gas 0 | |
560 | 1470 get_first_gas_to_WREG2: |
582 | 1471 movf lo,W |
604 | 1472 movf PLUSW1,W ; get type of gas #lo |
582 | 1473 sublw .1 ; it is = 1 (First Gas) |
604 | 1474 bz get_first_gas_to_WREG3 ; found the first gas! |
582 | 1475 incf lo,F ; ++ |
1476 movlw NUM_GAS+1 | |
604 | 1477 cpfseq lo ; all done? |
1478 bra get_first_gas_to_WREG2 ; NO - not yet | |
1479 ; no first gas found, use #1 | |
582 | 1480 movlw .0 |
604 | 1481 movff WREG,opt_gas_type+0 ; set gas 1 to First |
560 | 1482 incf WREG,W ; 0 -> 1 |
1483 return | |
1484 get_first_gas_to_WREG3: | |
604 | 1485 movf lo,W ; put into WREG |
560 | 1486 incf WREG,W ; 0-4 -> 1-5 |
604 | 1487 return ; done |
560 | 1488 |
582 | 1489 global get_first_dil_to_WREG |
604 | 1490 get_first_dil_to_WREG: ; gets first dil (1-5) into WREG |
1491 lfsr FSR1,opt_dil_type ; point to dil types | |
1492 clrf lo ; start with dil 0 | |
560 | 1493 get_first_dil_to_WREG2: |
582 | 1494 movf lo,W |
604 | 1495 movf PLUSW1,W ; get type of Dil #lo |
582 | 1496 sublw .1 ; it is = 1 (First Dil) |
604 | 1497 bz get_first_dil_to_WREG3 ; found the first dil! |
582 | 1498 incf lo,F ; ++ |
1499 movlw NUM_GAS+1 | |
604 | 1500 cpfseq lo ; all done? |
1501 bra get_first_dil_to_WREG2 ; NO - not yet | |
1502 ; no first dil found, use #1 | |
582 | 1503 movlw .0 |
604 | 1504 movff WREG,opt_dil_type+0 ; set dil 1 to First |
560 | 1505 incf WREG,W ; 0 -> 1 |
1506 return | |
1507 get_first_dil_to_WREG3: | |
604 | 1508 movf lo,W ; Put into WREG |
560 | 1509 incf WREG,W ; 0-4 -> 1-5 |
604 | 1510 return ; done |
1511 | |
1512 | |
560 | 1513 deco_setup_oc_gases: ; with currently breathed gas in WREG (1-5 or 6) |
1514 movff char_O_deco_status,lo ; working copy of char_O_deco_status in bank common | |
604 | 1515 deco_setup_oc_gases_pre: ; entry point with lo preloaded |
1516 movff WREG,char_I_current_gas ; set gas to start with when doing the deco calculations | |
1517 ; | |
1518 ; Memory Map: | |
1519 ; --------------------------------------------------------------------------------- | |
1520 ; opt_gas_O2_ratio res NUM_GAS | char_I_deco_O2_ratio res NUM_GAS | |
1521 ; opt_dil_O2_ratio res NUM_GAS | | |
1522 ; opt_gas_He_ratio res NUM_GAS | char_I_deco_He_ratio res NUM_GAS | |
1523 ; opt_dil_He_ratio res NUM_GAS | | |
1524 ; opt_gas_type res NUM_GAS | char_I_deco_gas_type res NUM_GAS | |
1525 ; opt_dil_type res NUM_GAS | | |
1526 ; opt_gas_change res NUM_GAS | char_I_deco_gas_change res NUM_GAS | |
1527 ; opt_dil_change res NUM_GAS | | |
1528 ; | |
1529 lfsr FSR2,char_I_deco_O2_ratio ; Load FSR2 with base address of char_I_deco_O2_ratio. | |
1530 ; FSR2 will step through all char_I_deco_... vars. | |
1531 lfsr FSR1,opt_gas_O2_ratio ; load FSR1 with base address of opt_gas_O2_ratio | |
1532 rcall deco_setup_copy ; copy all OC O2 ratios | |
1533 lfsr FSR1,opt_gas_He_ratio ; load FSR1 with base address of opt_gas_He_ratio | |
1534 rcall deco_setup_copy ; copy all OC He ratios | |
1535 lfsr FSR1,opt_gas_type ; load FSR1 with base address of opt_gas_type | |
1536 rcall deco_setup_copy ; copy all gas types | |
1537 lfsr FSR1,opt_gas_change ; load FSR1 with base address of opt_gas_change | |
1538 rcall deco_setup_copy ; copy all gas change depths | |
1539 ; switch to oc mode | |
560 | 1540 bcf lo,DECO_MODE_PSCR_FLAG ; clear the pSCR-mode flag (may not be set, but never mind) |
1541 bcf lo,DECO_MODE_LOOP_FLAG ; clear the loop/CCR-mode flag | |
1542 movff lo,char_O_deco_status ; bank safe write-back of char_O_deco_status | |
1543 return | |
1544 | |
582 | 1545 |
604 | 1546 deco_setup_cc_diluents: ; with currently breathed diluent in WREG (1-5 or 6) |
560 | 1547 movff char_O_deco_status,lo ; working copy of char_O_deco_status in bank common |
604 | 1548 deco_setup_cc_diluents_pre: ; entry point with lo preloaded |
1549 btfsc FLAG_bailout_mode ; check if in bailout condition | --------------- FOR SAFETY ONLY -------------- | |
1550 bra deco_setup_oc_gases_pre ; YES - revert to setting up OC gases | This branch should never happen to be taken... | |
1551 movff WREG,char_I_current_gas ; NO - set diluent to start with when doing the deco calculations | |
1552 ; | |
1553 ; Memory Map: | |
1554 ; --------------------------------------------------------------------------------- | |
1555 ; opt_gas_O2_ratio res NUM_GAS | | |
1556 ; opt_dil_O2_ratio res NUM_GAS | char_I_deco_O2_ratio res NUM_GAS | |
1557 ; opt_gas_He_ratio res NUM_GAS | | |
1558 ; opt_dil_He_ratio res NUM_GAS | char_I_deco_He_ratio res NUM_GAS | |
1559 ; opt_gas_type res NUM_GAS | | |
1560 ; opt_dil_type res NUM_GAS | char_I_deco_gas_type res NUM_GAS | |
1561 ; opt_gas_change res NUM_GAS | | |
1562 ; opt_dil_change res NUM_GAS | char_I_deco_gas_change res NUM_GAS | |
1563 ; | |
1564 lfsr FSR2,char_I_deco_O2_ratio ; Load FSR2 with base address of char_I_deco_O2_ratio. | |
1565 ; FSR2 will step through all char_I_deco_... vars. | |
1566 lfsr FSR1,opt_dil_O2_ratio ; load FSR1 with base address of opt_dil_O2_ratio | |
1567 rcall deco_setup_copy ; copy all dil O2 ratios | |
1568 lfsr FSR1,opt_dil_He_ratio ; load FSR1 with base address of opt_dil_He_ratio | |
1569 rcall deco_setup_copy ; copy all dil He ratios | |
1570 lfsr FSR1,opt_dil_type ; load FSR1 with base address of opt_dil_type | |
1571 rcall deco_setup_copy ; copy all dil types | |
1572 lfsr FSR1,opt_dil_change ; load FSR1 with base address of opt_dil_change | |
1573 rcall deco_setup_copy ; copy all dil change depths | |
1574 ; switch to CCR / pSCR mode | |
560 | 1575 bsf lo,DECO_MODE_LOOP_FLAG ; loop flag is set in both, CCR and pSCR mode |
1576 bcf lo,DECO_MODE_PSCR_FLAG ; clear pSCR mode flag by default | |
1577 btfsc FLAG_pscr_mode ; check if we are in pSCR mode | |
1578 bsf lo,DECO_MODE_PSCR_FLAG ; YES - set additional flag for pSCR mode | |
604 | 1579 movff lo,char_O_deco_status ; bank safe write-back of char_O_deco_status |
560 | 1580 return |
0 | 1581 |
604 | 1582 deco_setup_copy: |
1583 movlw NUM_GAS ; load loop counter with number of gases (5) | |
1584 deco_setup_copy_loop: | |
1585 movff POSTINC1,POSTINC2 ; copy from (FSR1) to (FSR2) | |
1586 decfsz WREG ; decrement loop counter and check if it became 0 | |
1587 bra deco_setup_copy_loop ; NO - not yet, loop | |
1588 return ; YES - done | |
1589 | |
1590 | |
582 | 1591 global setup_gas_registers |
1592 setup_gas_registers: ; with currently breathed gas in WREG (1-5 or 6) | |
1593 movwf active_gas ; set as current gas | |
560 | 1594 movlw .6 |
582 | 1595 cpfseq active_gas ; gas = gas6 ? |
1596 bra setup_gas_registers_15 ; NO - load gas 1-5 | |
1597 movff gas6_O2_ratio,char_I_O2_ratio ; copy gas6 O2 ratio to deco engine | |
604 | 1598 movff gas6_He_ratio,char_I_He_ratio ; copy gas6 H2 ratio to deco engine |
1599 movlw .3 ; declare gas6 as a deco gas | |
1600 movff WREG,char_I_current_gas_type; copy gas type to deco engine | |
1601 movff curr_depth,char_I_gas6_depth; set current depth as change depth | |
582 | 1602 bra setup_gas_registers_com ; continue with common part |
560 | 1603 setup_gas_registers_15: |
582 | 1604 decf active_gas,W ; 1-5 -> 0-4 |
604 | 1605 lfsr FSR1,opt_gas_O2_ratio |
582 | 1606 movff PLUSW1,char_I_O2_ratio ; copy gas 1-5 O2 ratio to deco engine |
604 | 1607 lfsr FSR1,opt_gas_He_ratio |
582 | 1608 movff PLUSW1,char_I_He_ratio ; copy gas 1-5 He ratio to deco engine |
604 | 1609 lfsr FSR1,opt_gas_type ; |
1610 movff PLUSW1,char_I_current_gas_type ; copy gas 1-5 type (0=Disabled, 1=First, 2=Travel, 3=Deco) | |
1611 setup_gas_registers_com: | |
582 | 1612 movff char_O_main_status,lo ; working copy of char_O_main_status in bank common |
1613 bcf lo,DECO_MODE_PSCR_FLAG ; clear the pSCR-mode flag (may not be set, but never mind) | |
1614 bcf lo,DECO_MODE_LOOP_FLAG ; clear the loop/CCR-mode flag | |
1615 movff lo,char_O_main_status ; bank safe write-back of char_O_main_status | |
604 | 1616 movf active_gas,W ; reload WREG with gas 1-5 or 6 (important!) |
560 | 1617 return |
137 | 1618 |
582 | 1619 global setup_dil_registers |
1620 setup_dil_registers: ; with currently breathed gas in WREG (1-5 or 6) | |
604 | 1621 btfsc FLAG_bailout_mode ; check if in bailout condition | --------------- FOR SAFETY ONLY -------------- |
1622 bra setup_gas_registers ; revert to setting up OC gases in bailout condition | This branch should never happen to be taken... | |
1623 movwf active_dil ; set as current diluent | |
560 | 1624 movlw .6 |
604 | 1625 cpfseq active_dil ; diluent = gas6 ? |
582 | 1626 bra setup_dil_registers_15 ; NO - load diluent 1-5 |
1627 movff gas6_O2_ratio,char_I_O2_ratio ; copy gas6 O2 ratio to deco engine | |
1628 movff gas6_He_ratio,char_I_He_ratio ; copy gas6 H2 ratio to deco engine | |
604 | 1629 movlw .2 ; declare gas6 as a normal diluent |
1630 movff WREG,char_I_current_gas_type; copy gas type to deco engine | |
1631 movff curr_depth,char_I_gas6_depth; set current depth as change depth | |
582 | 1632 bra setup_dil_registers_com ; continue with common part |
560 | 1633 setup_dil_registers_15: |
604 | 1634 decf active_dil,W ; 1-5 -> 0-4 |
1635 lfsr FSR1,opt_dil_O2_ratio | |
582 | 1636 movff PLUSW1,char_I_O2_ratio ; copy diluent 1-5 O2 ratio to deco engine |
604 | 1637 lfsr FSR1,opt_dil_He_ratio |
582 | 1638 movff PLUSW1,char_I_He_ratio ; copy diluent 1-5 He ratio to deco engine |
604 | 1639 lfsr FSR1,opt_dil_type ; |
1640 movff PLUSW1,char_I_current_gas_type ; copy dil type (0=Disabled, 1=First, 2=Normal) | |
560 | 1641 setup_dil_registers_com: |
582 | 1642 movff char_O_main_status,lo ; working copy of char_O_main_status in bank common |
1643 bsf lo,DECO_MODE_LOOP_FLAG ; loop flag is set in both, CCR and pSCR mode | |
1644 bcf lo,DECO_MODE_PSCR_FLAG ; clear pSCR mode flag by default | |
1645 btfsc FLAG_pscr_mode ; check if we are in pSCR mode | |
1646 bsf lo,DECO_MODE_PSCR_FLAG ; YES - set additional flag for pSCR mode | |
1647 movff lo,char_O_main_status ; bank safe write-back of char_O_main_status | |
604 | 1648 movf active_dil,W ; reload WREG with diluent 1-5 or 6 (important!) |
560 | 1649 return |
1650 | |
604 | 1651 |
1652 divemode_option_gaschange: ; switch to the "better gas" / "better diluent" | |
1653 btfsc FLAG_oc_mode ; in OC mode? | |
1654 bra divemode_option_gaschange_oc; YES | |
1655 btfsc FLAG_bailout_mode ; in bailout? | |
1656 bra divemode_option_gaschange_oc; YES | |
1657 divemode_option_gaschange_loop: ; in CCR/pSCR mode and not in bailout | |
1658 movff best_dil_number,menupos1 ; NO - select best diluent | |
1659 bcf better_dil_available ; - clear flag immediately | |
1660 bra divemode_option_gaschange3 ; - continue with common part | |
1661 divemode_option_gaschange_oc: ; in OC or bailout | |
1662 movff best_gas_number,menupos1 ; select best gas | |
1663 bcf better_gas_available ; clear flag immediately | |
1664 divemode_option_gaschange3 ; common part | |
1665 bsf divemode_gaschange ; command a gas/diluent change | |
1666 call menuview_toggle_reset ; terminate the options menu | |
560 | 1667 return |
1668 | |
604 | 1669 divemode_option0: ; start/setup dive mode menu |
1670 call TFT_clear_divemode_menu ; clear menu area | |
582 | 1671 bcf menuview |
560 | 1672 call do_main_divemenu |
1673 | |
582 | 1674 global divemode_option0_return |
0 | 1675 divemode_option0_return: |
582 | 1676 ; movlw .1 |
604 | 1677 ; movwf menupos1 ; set to first option in dive mode menu |
1678 call TFT_divemode_menu_cursor ; show the cursor | |
0 | 1679 movlw divemode_menu_timeout |
604 | 1680 movwf timeout_counter2 ; timeout for dive mode menu |
1681 bsf divemode_menu ; set flag | |
1682 clrf menupos2 ; clear option counter | |
1683 goto diveloop_loop4 ; go back to dive loop (menu processor trashes STKPTR!) | |
0 | 1684 |
1685 divemode_option4: | |
582 | 1686 movlw d'58' ; two seconds left |
1687 movwf timeout_counter1+0 | |
1688 movlw apnoe_timeout-1 ; apnoe timeout [min] | |
0 | 1689 movwf apnoe_timeout_counter |
582 | 1690 btfss simulatormode_active ; in simulator mode? |
604 | 1691 return ; NO |
1692 ;bra divemode_option1 ; YES | |
1693 | |
1694 divemode_option1: ; quit simulation mode | |
0 | 1695 banksel isr_backup |
582 | 1696 movlw LOW .1000 |
1697 movwf sim_pressure+0 | |
1698 movlw HIGH .1000 | |
604 | 1699 movwf sim_pressure+1 ; set to 0m -> end of dive |
582 | 1700 banksel common |
604 | 1701 call menuview_toggle_reset ; reset to zero (zero = no menu view) |
1702 | |
1703 btfss FLAG_apnoe_mode ; in apnoe mode? | |
1704 return ; NO - done | |
582 | 1705 movlw d'58' ; two seconds left |
1706 movwf timeout_counter1+0 | |
1707 movlw apnoe_timeout-1 ; apnoe timeout [min] | |
0 | 1708 movwf apnoe_timeout_counter |
1709 return | |
1710 | |
582 | 1711 divemode_option3: ; minus 1m |
0 | 1712 banksel isr_backup |
315
4f83470dcece
VSIbar #3: remaining changes for the split style bar
Janos Kovacs <kovjanos@gmail.com>
parents:
310
diff
changeset
|
1713 movlw d'100' |
0 | 1714 subwf sim_pressure+0 |
1715 movlw .0 | |
1716 subwfb sim_pressure+1 | |
1717 rcall divemode_simulator_check_limits | |
582 | 1718 banksel common |
0 | 1719 return |
1720 | |
582 | 1721 divemode_option2: ; plus 1m |
0 | 1722 banksel isr_backup |
315
4f83470dcece
VSIbar #3: remaining changes for the split style bar
Janos Kovacs <kovjanos@gmail.com>
parents:
310
diff
changeset
|
1723 movlw d'100' |
604 | 1724 addwf sim_pressure+0,F |
0 | 1725 movlw .0 |
604 | 1726 addwfc sim_pressure+1,F |
0 | 1727 rcall divemode_simulator_check_limits |
582 | 1728 banksel common |
0 | 1729 return |
1730 | |
1731 divemode_option5: | |
604 | 1732 call menuview_toggle_reset ; reset to zero (zero = no menu view) |
1733 bsf reset_average_depth ; set flag | |
582 | 1734 return |
0 | 1735 |
216
973a0969e0ac
NEW: On-board simulator can increase divetime in 5min steps
heinrichsweikamp
parents:
206
diff
changeset
|
1736 divemode_option6: |
604 | 1737 ; advance tissues and deco by 5 minutes |
1738 movlw .5 ; + 5 minutes | |
1739 movff WREG,char_I_sim_advance_time; copy to mailbox | |
1740 call restart_deco_engine | |
1741 | |
1742 ; stop divetime incrementing in ISR | |
1743 bcf divemode2 | |
1744 | |
1745 ; add 5 minutes to divemins | |
582 | 1746 movlw .5 |
1747 addwf divemins+0,F | |
1748 movlw .0 | |
604 | 1749 addwfc divemins+1,F |
1750 | |
1751 ; add 5 minutes (5 * 60 seconds) to total_divetime_seconds | |
1752 movlw LOW (.5*.60) | |
1753 addwf total_divetime_seconds+0,F | |
1754 movlw HIGH (.5*.60) | |
1755 addwfc total_divetime_seconds+1,F | |
1756 | |
1757 ; continue dive time incrementing in ISR | |
1758 bsf divemode2 | |
1759 | |
1760 ; add 5 minutes (5 * 60 seconds) to resettable time accumulator | |
582 | 1761 movlw LOW (.5*.60) |
1762 addwf average_divesecs+0,F | |
1763 movlw HIGH (.5*.60) | |
604 | 1764 addwfc average_divesecs+1,F |
1765 | |
1766 ; add 5 minutes (5 * 60 seconds) to total time accumulator | |
582 | 1767 movlw LOW (.5*.60) |
604 | 1768 addwf average_divesecs_total+0,F |
582 | 1769 movlw HIGH (.5*.60) |
604 | 1770 addwfc average_divesecs_total+1,F |
1771 | |
1772 | |
1773 ; calculate 300 x depth in mbar (300 = 5 min * 60 sec/min) | |
1774 SAFE_2BYTE_COPY rel_pressure, xB | |
582 | 1775 movlw LOW (.5*.60) |
1776 movwf xA+0 | |
1777 movlw HIGH (.5*.60) | |
1778 movwf xA+1 | |
1779 call mult16x16 ; xA*xB=xC | |
386 | 1780 |
604 | 1781 ; add to the resettable depth accumulator |
1782 movf xC+0,W | |
386 | 1783 addwf average_depth_hold+0,F |
604 | 1784 movf xC+1,W |
386 | 1785 addwfc average_depth_hold+1,F |
604 | 1786 movf xC+2,W |
386 | 1787 addwfc average_depth_hold+2,F |
604 | 1788 movf xC+3,W |
1789 addwfc average_depth_hold+3,F | |
1790 | |
1791 ; add to the total depth accumulator | |
386 | 1792 movf xC+0,w |
1793 addwf average_depth_hold_total+0,F | |
1794 movf xC+1,w | |
1795 addwfc average_depth_hold_total+1,F | |
1796 movf xC+2,w | |
1797 addwfc average_depth_hold_total+2,F | |
560 | 1798 movf xC+3,w |
604 | 1799 addwfc average_depth_hold_total+3,F |
1800 | |
1801 IFDEF _cave_mode | |
1802 ; update backtracking data | |
1803 movlw .5 ; add backtrack data for 5 minutes | |
1804 call update_backtrack ; make it so | |
1805 ENDIF | |
1806 | |
582 | 1807 goto menuview_toggle_reset ; and return... |
216
973a0969e0ac
NEW: On-board simulator can increase divetime in 5min steps
heinrichsweikamp
parents:
206
diff
changeset
|
1808 |
254
5fe7aff622f3
preparations to set a course for the compass display
heinrichsweikamp
parents:
239
diff
changeset
|
1809 divemode_option7: |
582 | 1810 ; Store heading for compass view |
1811 movff compass_heading_shown+0,compass_bearing+0 | |
1812 movff compass_heading_shown+1,compass_bearing+1 | |
1813 bsf compass_bearing_set ; set flag | |
604 | 1814 goto menuview_toggle_reset ; and return... |
1815 | |
560 | 1816 divemode_option8: |
604 | 1817 bsf alternative_divelayout ; set flag for alternative layout mode |
1818 call menuview_toggle_reset ; terminate the pre-menu | |
1819 call TFT_ClearScreen ; clear the whole screen | |
1820 bsf FLAG_TFT_divemode_mask_alt ; set flag to draw the alternative mask | |
1821 movff menupos3,customview_divemode; back-up the custom view shown in normal layout | |
1822 clrf menupos3 ; select the default alternative layout | |
1823 call customview_mask_alternative ; draw the default alternative layout | |
1824 return ; done | |
1825 | |
216
973a0969e0ac
NEW: On-board simulator can increase divetime in 5min steps
heinrichsweikamp
parents:
206
diff
changeset
|
1826 |
0 | 1827 divemode_simulator_check_limits: |
604 | 1828 ; check limits (150m and 0m) |
1829 movlw LOW d'16000' ; compare to 16 bar = 16000 mbar (150m) | |
582 | 1830 subwf sim_pressure+0,W |
1831 movlw HIGH d'16000' | |
1832 subwfb sim_pressure+1,W | |
604 | 1833 bnc divemode_simulator_check_limits2 ; no carry = borrow = not deeper |
1834 | |
1835 ; too deep, limit to 150m | |
582 | 1836 movlw LOW d'16000' |
0 | 1837 movwf sim_pressure+0 |
582 | 1838 movlw HIGH d'16000' |
0 | 1839 movwf sim_pressure+1 |
1840 return | |
604 | 1841 |
0 | 1842 divemode_simulator_check_limits2: |
604 | 1843 movlw LOW d'1000' ; compare to 1 bar == 0m == 1000 mbar |
582 | 1844 subwf sim_pressure+0,W |
1845 movlw HIGH d'1000' | |
1846 subwfb sim_pressure+1,W | |
604 | 1847 btfsc STATUS,C ; no carry = borrow = not deeper |
1848 return ; deeper than 0 m == ok | |
1849 ; too shallow, limit to 0m | |
582 | 1850 movlw LOW d'1000' |
0 | 1851 movwf sim_pressure+0 |
582 | 1852 movlw HIGH d'1000' |
0 | 1853 movwf sim_pressure+1 |
1854 return | |
1855 | |
1856 ;============================================================================= | |
604 | 1857 ; Find the best gas and diluent for the current depth |
1858 ; and check if a gas/diluent change is to be advised. | |
1859 ; | |
1860 ; Output: best_gas_number : number of best gas, 0= none avail, 255= not computed | |
1861 ; best_dil_number : number of best dil, 0= none avail, 255= not computed | |
1862 ; better_gas_available : flag indicating if a change is advised | |
1863 ; better_dil_available : flag indicating if a change is advised | |
1864 ; | |
1865 ; | |
1866 ; in CCR and pSCR mode: - checks both, gases and diluents for respective best gas / best diluent | |
1867 ; - if not in bailout, sets better_dil_available on diluents | |
1868 ; - if in bailout, sets better_gas_available on OC gases | |
1869 ; | |
1870 ; in OC mode : - checks only gases for best gas | |
1871 ; - sets better_gas_available on OC gases | |
0 | 1872 ; |
604 | 1873 check_gas_best: |
1874 movff amb_press_10+0,xA+0 ; copy ambient pressure / 10 into xA:2, will be used by ppO2 min/max checks later | |
1875 movff amb_press_10+1,xA+1 ; ... | |
1876 ; set maximum ppO2 allowed | |
1877 movff char_I_ppO2_max,ppO2_max ; max ppO2 for working phase (default) | |
1878 movff char_O_deco_info,lo ; bank-safe copy of deco info vector | |
1879 btfsc lo,deco_flag ; is the ppo2 deco limit enabled? | |
1880 movff char_I_ppO2_max_deco,ppO2_max ; YES - replace by max ppO2 for deco phase | |
1881 ; check dive mode | |
1882 btfsc FLAG_oc_mode ; in OC mode? | |
1883 bra check_gas_best_gas ; YES - skip diluents, check for best gas only | |
1884 | |
1885 check_gas_best_dil: | |
1886 ; set minimum ppO2 required | |
1887 movff char_I_ppO2_min,WREG ; min ppO2 for pure diluent in CCR mode (default) | |
1888 btfsc FLAG_pscr_mode ; in pSCR mode? | |
1889 movff char_I_ppO2_min_loop,ppO2_min ; YES - replace by min ppO2 for pure diluent in pSCR mode | |
1890 ; preset results to nothing found | |
1891 clrf best_gas_num ; initialize best diluent as 0 = nothing found yet | |
1892 bcf better_dil_available ; =1: a better diluent is available and a gas change is advised in divemode | |
1893 ; ; current diluent = 'gas6' ? | |
1894 ; movlw .6 ; | |
1895 ; cpfseq active_dil ; using 'gas6' as current diluent? | |
1896 ; bra check_gas_best_dil0 ; NO - continue | |
1897 ; bra check_gas_best_dil3 ; YES - suppress better diluent search in this case | |
1898 ;check_gas_best_dil0: | |
1899 ; check all diluents | |
1900 lfsr FSR1,opt_dil_O2_ratio ; set base address for diluent arrays | |
1901 movff active_dil,lo ; number of currently used diluent | |
1902 setf best_gas_depth ; initialize change depth of best dil found so far to 255 meter | |
1903 ; original code | |
1904 clrf check_gas_num | |
1905 incf check_gas_num,F | |
1906 rcall check_gas_best_common ; check diluent 1 | |
1907 incf check_gas_num,F | |
1908 rcall check_gas_best_common ; check diluent 2 | |
1909 incf check_gas_num,F | |
1910 rcall check_gas_best_common ; check diluent 3 | |
1911 incf check_gas_num,F | |
1912 rcall check_gas_best_common ; check diluent 4 | |
1913 incf check_gas_num,F | |
1914 rcall check_gas_best_common ; check diluent 5 | |
1915 ; alternative code | |
1916 ; movlw .5 | |
1917 ; movwf check_gas_num | |
1918 ;check_gas_best_dil_loop: | |
1919 ; rcall check_gas_best_common | |
1920 ; decfsz check_gas_num | |
1921 ; bra check_gas_best_dil_loop | |
0 | 1922 ; |
604 | 1923 ; store result |
1924 movff best_gas_num,best_dil_number ; store new best diluent found (1-5 or 0 of no usable diluent available) | |
1925 ; check if change advices shall be given in general | |
1926 btfsc FLAG_bailout_mode ; in bailout? | |
1927 bra check_gas_best_gas ; YES - no better diluent advice when in bailout | |
1928 check_gas_best_dil1: | |
1929 ; check if a change advice shall be given right now | |
1930 movf best_dil_number,W ; load number of best diluent into WREG (1-5) | |
1931 bz check_gas_best_dil3 ; has a best diluent been found at all? NO - nothing to signal for | |
1932 cpfseq active_dil ; is this the currently used diluent? | |
1933 bra check_gas_best_dil2 ; NO | |
1934 bra check_gas_best_dil3 ; YES - no need to signal a better diluent if this diluent is already in use | |
1935 check_gas_best_dil2: | |
1936 btfsc setpoint_fallback ; is a fallback warning active? | |
1937 bra check_gas_best_dil3 ; YES - suppress better diluent prompt in this case | |
1938 ; not using the best gas - show better diluent hint whenever a better diluent is available | |
1939 bsf better_dil_available ; signal that a better diluent is available | |
1940 bsf FLAG_TFT_active_gas_divemode ; redraw gas/setpoint/diluent | |
1941 check_gas_best_dil3: | |
1942 btfss better_dil_available ; shall a better diluent be signaled for? | |
1943 bcf blinking_better_dil ; NO - clear blinking flag | |
1944 ; continue with checking for best bailout gas | |
1945 | |
1946 check_gas_best_gas: | |
1947 ; set minimum ppO2 required | |
1948 movff char_I_ppO2_min,ppO2_min ; min ppO2 for OC/Bailout | |
1949 ; preset results to nothing found | |
1950 clrf best_gas_num ; initialize best gas as 0 = nothing found yet | |
1951 bcf better_gas_available ; =1: a better gas is available and a gas change is advised in divemode | |
1952 ; ; current gas = 'gas6' ? | |
1953 ; movlw .6 ; | |
1954 ; cpfseq active_gas ; using 'gas6' as current gas? | |
1955 ; bra check_gas_best_gas0 ; NO - continue | |
1956 ; bra check_gas_best_gas3 ; YES - suppress better gas search in this case | |
1957 ;check_gas_best_gas0: | |
1958 ; check all gases | |
1959 lfsr FSR1,opt_gas_O2_ratio ; set base address for gas arrays | |
1960 movff active_gas,lo ; number of currently used gas | |
1961 setf best_gas_depth ; initialize change depth of best gas found so far to 255 meter | |
1962 ; original code | |
1963 clrf check_gas_num | |
1964 incf check_gas_num,F | |
1965 rcall check_gas_best_common ; check gas 1 | |
1966 incf check_gas_num,F | |
1967 rcall check_gas_best_common ; check gas 2 | |
1968 incf check_gas_num,F | |
1969 rcall check_gas_best_common ; check gas 3 | |
1970 incf check_gas_num,F | |
1971 rcall check_gas_best_common ; check gas 4 | |
1972 incf check_gas_num,F | |
1973 rcall check_gas_best_common ; check gas 5 | |
1974 ; alternative code | |
1975 ; movlw .5 | |
1976 ; movwf check_gas_num | |
1977 ;check_gas_best_gas_loop: | |
1978 ; rcall check_gas_best_common | |
1979 ; decfsz check_gas_num | |
1980 ; bra check_gas_best_gas_loop | |
1981 ; | |
1982 ; store result | |
1983 movff best_gas_num,best_gas_number ; store new best gas found (1-5 or 0 of no usable gas available) | |
1984 ; check if change advices shall be given in general | |
1985 btfsc FLAG_oc_mode ; in OC mode? | |
1986 bra check_gas_best_gas1 ; YES | |
1987 btfsc FLAG_bailout_mode ; in bailout? | |
1988 bra check_gas_best_gas1 ; YES | |
1989 return ; NO - no better (OC) gas advice when not in OC or bailout mode | |
1990 check_gas_best_gas1: ; check if we are already on the best gas | |
1991 ; check if a change advice shall be given right now | |
1992 movf best_gas_number,W ; load number of best gas into WREG (1-5) | |
1993 bz check_gas_best_gas3 ; has a best gas been found at all? NO - nothing to signal for | |
1994 cpfseq active_gas ; is this the currently used gas? | |
1995 bra check_gas_best_gas2 ; NO | |
1996 bra check_gas_best_gas3 ; YES - no need to signal a better gas if this gas is already in use | |
1997 check_gas_best_gas2: | |
1998 ; not using the best gas - show better gas hint whenever a better gas is available | |
1999 bsf better_gas_available ; YES - signal that a better gas is available | |
2000 bsf FLAG_TFT_active_gas_divemode ; YES - redraw gas/setpoint/diluent | |
2001 check_gas_best_gas3: | |
2002 btfss better_gas_available ; shall a better gas be signaled for? | |
2003 bcf blinking_better_gas ; NO - clear blinking flag | |
582 | 2004 return |
0 | 2005 |
604 | 2006 check_gas_best_common: ; with gas to be checked in check_gas_num (1-5) |
2007 ; ; and current gas in lo (1-5) | |
2008 ; | |
2009 ; Memory Map: | |
2010 ; --------------------------------------------------------------------------------------- | |
2011 ; opt_gas_O2_ratio res 5 ; base address for gases | |
2012 ; opt_dil_O2_ratio res 5 ; base address for diluents | |
2013 ; opt_gas_He_ratio res 5 ; (not needed here) | |
2014 ; opt_dil_He_ratio res 5 ; (not needed here) | |
2015 ; opt_gas_type res 5 ; has offset of 20 bytes from base address for gases | |
2016 ; opt_dil_type res 5 ; has offset of 20 bytes from base address for diluents | |
2017 ; opt_gas_change res 5 ; has offset of 10 bytes from opt_gas_type | |
2018 ; opt_dil_change res 5 ; has offset of 10 bytes from opt_dil_type | |
2019 | |
2020 ; get gas data | |
2021 decf check_gas_num,W ; (1-5) -> (0-4) into WREG to be used as index | |
2022 movff PLUSW1,check_gas_O2_ratio ; load O2 ratio (%) of current gas/dil into check_gas_O2_ratio | |
2023 addlw .20 ; add offset of 20 bytes to index type in opt_gas_type/opt_dil_type | |
2024 movff PLUSW1,check_gas_type ; load type of current gas/dil into check_gas_type (0=disabled, 1=first, 2=travel/normal, 3=deco/-) | |
2025 addlw .10 ; add offset of 10 bytes to index change depth in opt_gas_change/opt_dil_change | |
2026 movff PLUSW1,check_gas_depth ; load change depth of current gas/dil into check_gas_depth | |
2027 ; check if gas is usable (i.e. not disabled) | |
2028 tstfsz check_gas_type ; type = disabled (0)? | |
2029 bra check_gas_best_common0 ; NO - continue checks | |
2030 movf check_gas_num,W ; YES - get the number of the gas to be checked (1-5) | |
2031 cpfseq lo ; - is this the currently used gas? | |
2032 return ; NO - skip disabled gases which are not the current gas | |
2033 bra check_gas_best_common1 ; YES - a gas in use overrides it's disabled status, therefore treat it as available | |
2034 check_gas_best_common0: | |
2035 ; skip deco gases (type=3) if not in deco mode, but search among all enabled gases when in loop or bailout mode | |
2036 movlw .3 | |
2037 cpfseq check_gas_type ; type = deco (3)? | |
2038 bra check_gas_best_common1 ; NO - proceed | |
2039 btfsc FLAG_bailout_mode ; YES - in bailout? | |
2040 bra check_gas_best_common1 ; YES - proceed, include deco gases | |
2041 movff char_O_main_status,WREG ; NO - get main deco mode | |
2042 btfsc WREG,DECO_MODE_LOOP_FLAG ; - in loop mode? | |
2043 bra check_gas_best_common1 ; YES - proceed, include deco gases | |
2044 movff char_O_deco_info,WREG ; NO - get deco info vector | |
2045 btfss WREG,deco_flag ; - in deco mode (deco_flag set), i.e. use of deco gases allowed? | |
2046 return ; NO - skip deco gas while not in deco mode | |
2047 check_gas_best_common1: ; YES - proceed | |
2048 ; ; check if gas change depth is below minimum change depth | |
2049 ; movlw minimum_change_depth ; for value see definition in hwos.inc | |
2050 ; cpfsgt check_gas_depth ; change depth of checked gas > minimum_change_depth? | |
2051 ; return ; NO - change depth not deep enough, skip and check next gas | |
2052 ; check if gas is usable, i.e. its change depth is below or equal to the current depth | |
2053 movf curr_depth,W ; load current depth (in m) into WREG | |
2054 cpfslt check_gas_depth ; change depth of checked gas < (shallower than) current depth? | |
2055 bra check_gas_best_common2 ; NO - gas is usable | |
2056 return ; YES - gas is not usable | |
2057 check_gas_best_common2: | |
2058 ; check if this gas is the first best gas candidate | |
2059 movf best_gas_num,W ; get best gas found so far (1-5) or 0 if none found yet | |
2060 tstfsz WREG ; has a best gas candidate been found yet? | |
2061 bra check_gas_best_common3 ; YES - check if the new one is better than the one we have so far | |
2062 bra check_gas_best_common4 ; NO - no need to do the above mentioned check | |
2063 check_gas_best_common3: | |
2064 ; check if the change depth of the checked gas is < (shallower) than the change depth of the best gas found so far | |
2065 movf best_gas_depth,W ; load change depth of best gas so far into WREG | |
2066 cpfslt check_gas_depth ; change depth of checked gas < (shallower than) change depth of best gas so far? | |
2067 return ; NO - this gas is not better than the best already found | |
2068 check_gas_best_common4: | |
2069 ; check if the gas fits into the ppO2 limits | |
2070 movff check_gas_O2_ratio,xB+0 ; xB = O2 ratio, xA is still loaded with (p_amb / 10) | |
69 | 2071 clrf xB+1 |
604 | 2072 call mult16x16 ; xC = O2 ratio * (p_amb / 10) |
2073 ; check for very high ppO2 | |
2074 tstfsz xC+2 ; O2_ratio * p_amb / 10 > 65536, i.e. ppO2 > 6.55 bar ? | |
2075 return ; YES - gas is not usable | |
2076 btfsc xC+1,7 ; check if ppO2 > 3.30 bar | |
2077 return ; YES - gas is not usable | |
2078 ; check for low ppO2 | |
526
0d1cda9f2d43
BUGFIX: Skip MOD Test for CCR in Sensor modes (OSTC cR and OSTC3 only)
heinrichsweikamp
parents:
521
diff
changeset
|
2079 movff xC+0,sub_a+0 |
0d1cda9f2d43
BUGFIX: Skip MOD Test for CCR in Sensor modes (OSTC cR and OSTC3 only)
heinrichsweikamp
parents:
521
diff
changeset
|
2080 movff xC+1,sub_a+1 |
604 | 2081 movf ppO2_min,W |
2082 mullw .100 ; char_I_ppO2_min * 100 | |
526
0d1cda9f2d43
BUGFIX: Skip MOD Test for CCR in Sensor modes (OSTC cR and OSTC3 only)
heinrichsweikamp
parents:
521
diff
changeset
|
2083 movff PRODL,sub_b+0 |
0d1cda9f2d43
BUGFIX: Skip MOD Test for CCR in Sensor modes (OSTC cR and OSTC3 only)
heinrichsweikamp
parents:
521
diff
changeset
|
2084 movff PRODH,sub_b+1 |
604 | 2085 call subU16 ; sub_c = sub_a - sub_b |
2086 btfsc neg_flag ; within limit? | |
2087 return ; NO - too low, gas is not usable | |
2088 ; check for high ppO2 | |
2089 movf ppO2_max,W | |
2090 mullw .100 ; ppO2_max * 100 | |
2091 movff PRODL,sub_b+0 | |
2092 movff PRODH,sub_b+1 | |
2093 infsnz sub_b+0,F ; add 1 mbar to allowance to avoid exclusion on equal | |
2094 incf sub_b+1,F | |
2095 call subU16 ; sub_c = sub_a - sub_b | |
2096 btfss neg_flag ; within limit? | |
2097 return ; NO - too high, gas is not usable | |
2098 ; we have a (new) best gas | |
2099 movff check_gas_num, best_gas_num ; set checked gas (1-5) as best gas | |
2100 movff check_gas_depth,best_gas_depth ; memorize its change depth | |
582 | 2101 return |
0 | 2102 |
338
2811932b4e99
NEW: Mode Auto SP: Automatically switches the SP during descent (CC Mode)
heinrichsweikamp
parents:
337
diff
changeset
|
2103 |
2811932b4e99
NEW: Mode Auto SP: Automatically switches the SP during descent (CC Mode)
heinrichsweikamp
parents:
337
diff
changeset
|
2104 ;============================================================================= |
2811932b4e99
NEW: Mode Auto SP: Automatically switches the SP during descent (CC Mode)
heinrichsweikamp
parents:
337
diff
changeset
|
2105 ; Check for Auto-SP |
2811932b4e99
NEW: Mode Auto SP: Automatically switches the SP during descent (CC Mode)
heinrichsweikamp
parents:
337
diff
changeset
|
2106 ; |
604 | 2107 check_dive_autosp: ; check for Auto-SP |
582 | 2108 movff opt_ccr_mode,WREG ; =0: Fixed SP, =1: Sensor, =2: Auto SP |
2109 sublw .2 ; opt_ccr_mode = 2 (Auto SP)? | |
604 | 2110 bz check_dive_autosp2 ; YES - check |
2111 return ; NO - return for sensor or fixed mode | |
338
2811932b4e99
NEW: Mode Auto SP: Automatically switches the SP during descent (CC Mode)
heinrichsweikamp
parents:
337
diff
changeset
|
2112 check_dive_autosp2: |
582 | 2113 ; Check SP2 |
604 | 2114 btfsc sp2_switched ; SP 2 used so far? |
2115 bra check_dive_autosp3 ; YES - continue with SP 3 | |
2116 movff char_I_setpoint_change+1,lo ; NO - get depth in m | |
2117 tstfsz lo ; - SP change depth = 0 ? | |
2118 bra check_dive_autosp2a ; NO - continue | |
2119 bra check_dive_autosp3 ; YES - continue with SP 3 | |
560 | 2120 check_dive_autosp2a: |
604 | 2121 decf lo,W ; SP change depth -1 -> WREG |
2122 cpfsgt curr_depth ; current depth > change depth - 1 ? | |
2123 bra check_dive_autosp3 ; NO - continue with SP 3 | |
582 | 2124 ; auto switch to SP2 |
604 | 2125 movff char_I_setpoint_cbar+1,char_I_const_ppO2 ; YES - use SP |
2126 rcall xmit_sp_set_flag ; - send SP to external devices | |
2127 bsf sp2_switched ; - set SP 2 used flag | |
338
2811932b4e99
NEW: Mode Auto SP: Automatically switches the SP during descent (CC Mode)
heinrichsweikamp
parents:
337
diff
changeset
|
2128 check_dive_autosp3: |
582 | 2129 ; Check SP3 |
604 | 2130 btfsc sp3_switched ; SP 3 used so far? |
2131 bra check_dive_autosp4 ; YES - continue with SP 4 | |
2132 movff char_I_setpoint_change+2,lo ; NO - get depth in m | |
2133 tstfsz lo ; - SP change depth = 0 ? | |
2134 bra check_dive_autosp3a ; NO - continue | |
2135 bra check_dive_autosp4 ; YES - continue with SP 4 | |
560 | 2136 check_dive_autosp3a: |
604 | 2137 decf lo,W ; SP change depth -1 -> WREG |
2138 cpfsgt curr_depth ; current depth > change depth - 1 ? | |
2139 bra check_dive_autosp4 ; NO - continue with SP 4 | |
582 | 2140 ; auto switch to SP3 |
604 | 2141 movff char_I_setpoint_cbar+2,char_I_const_ppO2 ; YES - use SP |
2142 rcall xmit_sp_set_flag ; - send SP to external devices | |
2143 bsf sp3_switched ; - set SP 3 used flag | |
338
2811932b4e99
NEW: Mode Auto SP: Automatically switches the SP during descent (CC Mode)
heinrichsweikamp
parents:
337
diff
changeset
|
2144 check_dive_autosp4: |
582 | 2145 ; Check SP4 |
604 | 2146 btfsc sp4_switched ; SP 4 used so far? |
2147 bra check_dive_autosp5 ; YES - continue with SP 5 | |
2148 movff char_I_setpoint_change+3,lo ; NO - get depth in m | |
2149 tstfsz lo ; - SP change depth = 0 ? | |
2150 bra check_dive_autosp4a ; NO - continue | |
2151 bra check_dive_autosp5 ; YES - continue with SP 5 | |
560 | 2152 check_dive_autosp4a: |
604 | 2153 decf lo,W ; SP change depth -1 -> WREG |
2154 cpfsgt curr_depth ; current depth > change depth - 1 ? | |
2155 bra check_dive_autosp5 ; NO - continue with SP 5 | |
582 | 2156 ; auto switch to SP4 |
604 | 2157 movff char_I_setpoint_cbar+3,char_I_const_ppO2 ; YES - use SP |
2158 rcall xmit_sp_set_flag ; - send SP to external devices | |
2159 bsf sp4_switched ; - set SP 4 used flag | |
338
2811932b4e99
NEW: Mode Auto SP: Automatically switches the SP during descent (CC Mode)
heinrichsweikamp
parents:
337
diff
changeset
|
2160 check_dive_autosp5: |
582 | 2161 ; Check SP5 |
604 | 2162 btfsc sp5_switched ; SP 5 used so far? |
2163 bra check_dive_autosp6 ; YES - done | |
2164 movff char_I_setpoint_change+4,lo ; NO - get depth in m | |
2165 tstfsz lo ; - SP change depth = 0 ? | |
2166 bra check_dive_autosp5a ; NO - continue | |
2167 bra check_dive_autosp6 ; YES - done | |
560 | 2168 check_dive_autosp5a: |
604 | 2169 decf lo,W ; SP change depth -1 -> WREG |
2170 cpfsgt curr_depth ; current depth > change depth - 1 ? | |
2171 bra check_dive_autosp6 ; NO - done | |
582 | 2172 ; auto switch to SP5 |
604 | 2173 movff char_I_setpoint_cbar+4,char_I_const_ppO2 ; YES - use SP |
2174 rcall xmit_sp_set_flag ; - send SP to external devices | |
2175 bsf sp5_switched ; - set SP 5 used flag | |
352
5c6da9fa5cb0
add setpoint change to first sample in CCR mode
heinrichsweikamp
parents:
339
diff
changeset
|
2176 check_dive_autosp6: |
582 | 2177 return |
352
5c6da9fa5cb0
add setpoint change to first sample in CCR mode
heinrichsweikamp
parents:
339
diff
changeset
|
2178 |
5c6da9fa5cb0
add setpoint change to first sample in CCR mode
heinrichsweikamp
parents:
339
diff
changeset
|
2179 xmit_sp_set_flag: |
582 | 2180 movff char_I_const_ppO2,WREG |
604 | 2181 call transmit_setpoint ; transmit current setpoint from WREG (in cbar) to external electronics |
2182 bsf setpoint_changed ; set flag (for profile) | |
2183 bsf event_occured ; set event flag | |
582 | 2184 return |
2185 | |
2186 set_logbook_marker: | |
2187 bcf FLAG_set_marker ; clear flag | |
604 | 2188 movlw d'6' ; set type of alarm (manual marker) |
2189 movwf AlarmType ; copy to alarm register | |
2190 bsf event_occured ; set event flag | |
582 | 2191 return |
338
2811932b4e99
NEW: Mode Auto SP: Automatically switches the SP during descent (CC Mode)
heinrichsweikamp
parents:
337
diff
changeset
|
2192 |
0 | 2193 ;============================================================================= |
604 | 2194 ; Setup everything to enter dive mode |
0 | 2195 ; |
604 | 2196 global dive_boot_oc_bail |
2197 dive_boot_oc_bail: | |
2198 ; copy opt_gas_types into backup (for "lost gas" feature) | |
2199 movff opt_gas_type+0,opt_gas_type_backup+0 ; 0=Disabled, 1=First, 2=Travel, 3=Deco | |
2200 movff opt_gas_type+1,opt_gas_type_backup+1 ; 0=Disabled, 1=First, 2=Travel, 3=Deco | |
2201 movff opt_gas_type+2,opt_gas_type_backup+2 ; 0=Disabled, 1=First, 2=Travel, 3=Deco | |
2202 movff opt_gas_type+3,opt_gas_type_backup+3 ; 0=Disabled, 1=First, 2=Travel, 3=Deco | |
2203 movff opt_gas_type+4,opt_gas_type_backup+4 ; 0=Disabled, 1=First, 2=Travel, 3=Deco | |
2204 ; done | |
2205 return | |
2206 | |
2207 global dive_boot_oc | |
0 | 2208 dive_boot_oc: |
604 | 2209 ; set-up registers |
2210 rcall get_first_gas_to_WREG ; get first gas (1-5) into WREG | |
582 | 2211 rcall setup_gas_registers ; set-up of gas parameters of currently breathed gas (with WREG = gas 1-5) |
2212 rcall deco_setup_oc_gases ; set-up of gas list for deco calculations (with WREG = gas 1-5) | |
2213 return | |
0 | 2214 |
604 | 2215 global dive_boot_cc |
0 | 2216 dive_boot_cc: |
604 | 2217 ; copy opt_dil_types into backup (for "lost diluent" feature) |
2218 movff opt_dil_type+0,opt_dil_type_backup+0 ; 0=Disabled, 1=First, 2=Normal | |
2219 movff opt_dil_type+1,opt_dil_type_backup+1 ; 0=Disabled, 1=First, 2=Normal | |
2220 movff opt_dil_type+2,opt_dil_type_backup+2 ; 0=Disabled, 1=First, 2=Normal | |
2221 movff opt_dil_type+3,opt_dil_type_backup+3 ; 0=Disabled, 1=First, 2=Normal | |
2222 movff opt_dil_type+4,opt_dil_type_backup+4 ; 0=Disabled, 1=First, 2=Normal | |
2223 ; clear flags | |
2224 bcf FLAG_bailout_mode ; =1: bailout | |
2225 bcf setpoint_fallback ; =1: fallback to SP1 due to external O2 sensor failure | |
2226 ; set-up registers | |
2227 rcall get_first_dil_to_WREG ; get first diluent (1-5) into WREG | |
2228 rcall setup_dil_registers ; set-up of diluent parameters for currently breathed diluent (with WREG = current diluent 1-5) | |
2229 rcall deco_setup_cc_diluents ; set-up of diluent list for deco calculations (with WREG = current diluent 1-5) | |
2230 ; done | |
2231 return | |
2232 | |
2233 dive_boot_cc_part2: | |
560 | 2234 ; revoke sensors from usage if they do not have a valid calibration |
2235 bsf use_O2_sensor1 | |
2236 bsf use_O2_sensor2 | |
2237 bsf use_O2_sensor3 | |
2238 btfss sensor1_calibrated_ok | |
2239 bcf use_O2_sensor1 | |
2240 btfss sensor2_calibrated_ok | |
2241 bcf use_O2_sensor2 | |
2242 btfss sensor3_calibrated_ok | |
2243 bcf use_O2_sensor3 | |
604 | 2244 ; check for external HUD/ppO2 Monitor |
583 | 2245 btfss optical_input ; do we have an optical input? |
604 | 2246 bra dive_boot_cc_part2_1 ; NO |
2247 ; copy (initial) valid flags from HUD/ppO2 Monitor | |
583 | 2248 btfsc sensor1_active |
604 | 2249 bsf use_O2_sensor1 |
2250 btfsc sensor2_active | |
2251 bsf use_O2_sensor2 | |
583 | 2252 btfsc sensor3_active |
604 | 2253 bsf use_O2_sensor3 |
2254 dive_boot_cc_part2_1: | |
560 | 2255 ; In pSCR mode, only settings 0 (calculated ppO2) and 1 (ppO2 from sensors) are defined. |
604 | 2256 ; In case we still have 3 (auto SP) selected out of previous CCR mode, we reset to 0. |
560 | 2257 btfss FLAG_pscr_mode |
604 | 2258 bra dive_boot_cc_part2_2 |
582 | 2259 movff opt_ccr_mode,WREG ; =0: Fixed SP (CCR) / calculated SP (pSCR), =1: Sensor, =2: Auto SP |
2260 sublw .2 ; opt_ccr_mode = 1 (Auto SP)? | |
604 | 2261 bnz dive_boot_cc_part2_2 |
560 | 2262 movlw .0 |
2263 movff WREG,opt_ccr_mode | |
604 | 2264 dive_boot_cc_part2_2: |
582 | 2265 bsf setpoint_changed ; set flag (for profile) |
604 | 2266 bcf sp2_switched ; =1: this setpoint has been auto-selected already |
2267 bcf sp3_switched ; =1: this setpoint has been auto-selected already | |
2268 bcf sp4_switched ; =1: this setpoint has been auto-selected already | |
2269 bcf sp5_switched ; =1: this setpoint has been auto-selected already | |
560 | 2270 ; Start with SP1 (CCR) or 0 (pSCR) as default. |
2271 ; If in sensor mode, this value will be overwritten by calc_deko_divemode_sensor | |
582 | 2272 clrf WREG ; preload WREG with setpoint value 0 for pSCR calculated |
604 | 2273 btfsc FLAG_ccr_mode ; are we in CCR mode? |
582 | 2274 movff char_I_setpoint_cbar+0,WREG ; YES - get value of setpoint 1 |
2275 movff WREG,char_I_const_ppO2 ; write setpoint to deco engine | |
2276 call transmit_setpoint ; transmit current setpoint from WREG (in cbar) to external electronics | |
2277 goto calc_deko_divemode_sensor ; read & process sensor data (and return) | |
0 | 2278 |
604 | 2279 |
0 | 2280 diveloop_boot: |
604 | 2281 |
2282 ; do the basic initialization | |
0 | 2283 call restart_set_modes_and_flags |
2284 | |
604 | 2285 ; stop accelerometer and compass |
2286 call I2C_sleep_accelerometer | |
2287 call I2C_sleep_compass | |
2288 | |
2289 ; reset max pressure aka max depth | |
2290 clrf WREG | |
2291 movff WREG,max_pressure+0 | |
2292 movff WREG,max_pressure+1 | |
2293 | |
2294 ; initialize press needs to zero and invalid (not yet computed) state | |
2295 clrf WREG ; set WREG to 0 | |
2296 IFDEF _cave_mode | |
2297 movff WREG,char_I_backtrack_time ; clear backtracking time (index to char_I_backtrack_depth) | |
2298 movff WREG,char_I_backtrack_depth ; prime first entry with depth 0 | |
2299 ENDIF | |
2300 bsf WREG,int_is_zero ; set zero flag | |
2301 bsf WREG,int_invalid_flag ; set invalid flag (additionally) | |
2302 banksel int_O_ascent_pres_need ; select bank with shared output vars | |
2303 movwf int_O_ascent_pres_need+1 ; Set flags for tank pressure needs = 0 before p2_deco.c | |
2304 movwf int_O_ascent_pres_need+3 ; can do it. If this is not done here and the gas needs | |
2305 movwf int_O_ascent_pres_need+5 ; custom view is shown before p2_deco.c completes the first | |
2306 movwf int_O_ascent_pres_need+7 ; deco calculation, some rubbish numbers from last dive or | |
2307 movwf int_O_ascent_pres_need+9 ; simulation may be shown | |
2308 banksel common ; back to bank common | |
2309 | |
2310 ; configure the deco engine | |
2311 clrf hi | |
2312 bsf hi,DECO_Z_FACTOR_FLAG ; enable Z factor mode by default | |
2313 TSTOSS opt_ZfactorUse ; shall use Z factor mode? | |
2314 bcf hi,DECO_Z_FACTOR_FLAG ; NO - disable again | |
2315 IFDEF _rx_functions | |
2316 bsf hi,DECO_TR_FUNCTIONS ; enable TR mode by default | |
2317 btfss FLAG_tr_enabled ; shall use TR mode? | |
2318 bcf hi,DECO_TR_FUNCTIONS ; NO - disable again | |
2319 ENDIF | |
2320 movff hi,char_O_main_status ; bank-safe copy to deco engine | |
2321 | |
2322 movff char_O_deco_status,lo ; bank-safe read | |
2323 bsf lo,DECO_STATUS_0_FLAG ; set init- | ATTENTION: The deco engine must be started in init state! If omitted, it may | |
2324 bsf lo,DECO_STATUS_1_FLAG ; state, | enter an infinite loop at some point in time and brick the OSTC! | |
2325 bcf lo,DECO_PLAN_FLAG ; normal plan mode, | |
2326 bcf lo,DECO_VOLUME_FLAG ; disable gas volume calculation, and | |
2327 bcf lo,DECO_ASCENT_FLAG ; disable delayed ascent calculation | |
2328 movff lo,char_O_deco_status ; bank-safe copy back to deco engine | |
0 | 2329 |
2330 clrf WREG | |
604 | 2331 movff WREG,char_O_deco_warnings ; clear any deco warnings remaining from last dive |
2332 movff WREG,char_O_deco_info ; clear any deco infos remaining from last dive | |
2333 | |
2334 movlw deco_distance ; load distance between actual depth and depth used for deco calculation | |
2335 movff WREG,char_I_deco_distance ; write distance to the deco engine | |
2336 | |
2337 movff opt_last_stop,char_I_depth_last_deco ; write last stop depth to deco engine | |
2338 movff opt_GF_low,char_I_GF_Low_percentage ; write GF low to deco engine | |
2339 movff opt_GF_high,char_I_GF_High_percentage ; write GF high to deco engine | |
2340 | |
2341 bcf onesectoggle ; clear toggle bit for calculation phasing | |
2342 bcf use_agf ; start with normal GF set | |
2343 bcf divemode_menu ; clear dive mode menu flag | |
2344 bcf alternative_divelayout ; start with default layout | |
582 | 2345 bcf blinking_depth_prev ; clear flag for blinking depth |
2346 bcf blinking_depth_toggle ; clear flag for blinking depth | |
604 | 2347 bcf blinking_depth_warning ; clear flag for blinking depth as warning |
2348 bcf blinking_depth_attention ; clear flag for blinking depth as attention | |
2349 bcf max_depth_greater_100m ; clear flag for last max/avg depth was > 100 m | |
582 | 2350 |
0 | 2351 movlw d'1' |
2352 movwf apnoe_max_pressure+0 | |
2353 clrf apnoe_max_pressure+1 | |
386 | 2354 ; clrf apnoe_surface_mins |
582 | 2355 ; clrf apnoe_surface_secs |
604 | 2356 |
2357 ; copy date and time for logbook | |
582 | 2358 movff year,start_year |
2359 movff month,start_month | |
2360 movff day,start_day | |
2361 movff hours,start_hours | |
2362 movff mins,start_mins | |
2363 | |
2364 movff int_O_CNS_fraction+0,CNS_start+0 ; save CNS value at beginning of dive | |
2365 movff int_O_CNS_fraction+1,WREG ; get high byte to WREG | |
604 | 2366 bcf WREG,int_warning_flag ; clear warning flag |
2367 bcf WREG,int_attention_flag ; clear attention flag | |
582 | 2368 movff WREG,CNS_start+1 ; move high byte on |
2369 movff int_O_gradient_factor+0,GF_start ; save GF value at beginning of dive (only lower byte used for value) | |
545 | 2370 |
604 | 2371 bcf no_more_divesecs ; =1: do no longer show seconds in dive mode |
0 | 2372 bcf divemode_menu_active |
582 | 2373 clrf menupos1 |
604 | 2374 clrf menupos2 ; reset to zero (Zero=no pre-menu or simulator task) |
2375 bsf sensors_agree ; init of sensors disagree warning system | |
2376 | |
2377 bcf show_safety_stop ; =1: show the safety stop | |
2378 clrf safety_stop_countdown ; clear count-down | |
2379 | |
2380 clrf samplesecs ; timer for data logging | |
0 | 2381 clrf apnoe_timeout_counter ; timeout in minutes |
582 | 2382 clrf timeout_counter1+0 ; takes care of the timeout (low byte) |
2383 clrf timeout_counter1+1 ; takes care of the timeout (high byte) | |
0 | 2384 clrf AlarmType ; Clear all alarms |
2385 bcf event_occured ; clear flag | |
604 | 2386 clrf average_divesecs_total+0 ; clear non-resettable time accumulator |
2387 clrf average_divesecs_total+1 | |
2388 clrf average_depth_hold_total+0 ; clear non-resettable average depth | |
0 | 2389 clrf average_depth_hold_total+1 |
2390 clrf average_depth_hold_total+2 | |
604 | 2391 clrf average_depth_hold_total+3 |
2392 call reset_average ; reset the resettable average depth | |
2393 | |
2394 IFDEF _rx_functions | |
2395 btfss FLAG_tr_enabled ; TR functions enabled? | |
2396 bra diveloop_boot_0 ; NO - skip TR function initialization | |
2397 ; YES - initialize TR function variables | |
2398 banksel int_O_sac_rate | |
2399 clrf int_O_sac_rate+0 ; clear low byte of SAC rate | |
2400 clrf int_O_pressure_need+0 ; clear low byte of 1st pressure need value | |
2401 clrf int_O_pressure_need+2 ; clear low byte of 2nd pressure need value | |
2402 banksel int_IO_pressure_value | |
2403 clrf int_IO_pressure_value+0 ; clear low byte of 1st pressure reading value | |
2404 clrf int_IO_pressure_value+2 ; clear low byte of 2nd pressure reading value | |
2405 clrf int_I_pressure_drop+0 ; clear low byte of 1st pressure drop value | |
2406 clrf int_I_pressure_drop+2 ; clear low byte of 2nd pressure drop value | |
2407 clrf char_I_pressure_gas+0 ; clear gas selection of 1st pressure reading | |
2408 clrf char_I_pressure_gas+1 ; clear gas selection of 2nd pressure reading | |
2409 clrf char_I_pressure_age+0 ; clear age of 1st pressure reading | |
2410 clrf char_I_pressure_age+1 ; clear age of 2nd pressure reading | |
2411 clrf char_I_pressure_stat+0 ; clear status of 1st pressure reading | |
2412 clrf char_I_pressure_stat+1 ; clear status of 2nd pressure reading | |
2413 clrf WREG ; clear WREG | |
2414 bsf WREG,int_not_avail_flag ; set WREG to coding for integer numbers -> data not available | |
2415 banksel int_O_sac_rate | |
2416 movwf int_O_sac_rate+1 ; copy to high byte of SAC rate | |
2417 movwf int_O_pressure_need+1 ; copy to high byte of 1st pressure need value | |
2418 movwf int_O_pressure_need+3 ; copy to high byte of 1st pressure need value | |
2419 banksel int_IO_pressure_value | |
2420 movwf int_IO_pressure_value+1 ; copy to high byte of 1st pressure reading value | |
2421 movwf int_IO_pressure_value+3 ; copy to high byte of 2nd pressure reading value | |
2422 movwf int_I_pressure_drop+1 ; copy to high byte of 1st pressure drop value | |
2423 movwf int_I_pressure_drop+3 ; copy to high byte of 1st pressure drop value | |
2424 banksel gas__last_1st ; select bank with vars for pressure drop calculation | |
2425 setf gas__last_1st ; invalidate last gas of 1st reading | |
2426 setf gas__last_2nd ; invalidate last gas of 2nd reading | |
2427 banksel common ; back to bank common | |
2428 ENDIF | |
2429 | |
2430 diveloop_boot_0: | |
2431 bcf decostop_active ; clear flag for being in deco | |
2432 setf best_gas_number ; initialize best gas as not computed yet (255) | |
2433 setf best_dil_number ; initialize best diluent as not computed yet (255) | |
2434 bcf better_gas_available ; =1: a better gas is available and a gas change is advised | |
2435 bcf better_dil_available ; =1: a better diluent is available and a gas change is advised | |
2436 | |
2437 rcall dive_boot_oc_bail ; basic settings required for all modes | |
2438 | |
2439 btfsc FLAG_oc_mode ; in OC mode? | |
2440 rcall dive_boot_oc ; YES - add OC mode settings | |
2441 | |
2442 btfsc FLAG_ccr_mode ; in CCR mode? | |
2443 rcall dive_boot_cc ; YES - add CC mode settings | |
2444 btfsc FLAG_ccr_mode ; in CCR mode? | |
2445 rcall dive_boot_cc_part2 ; YES - add CC sensor and SP settings | |
2446 | |
2447 btfsc FLAG_pscr_mode ; in pSCR mode? | |
2448 rcall dive_boot_cc ; YES - add CC mode settings | |
2449 btfsc FLAG_pscr_mode ; in pSCR mode? | |
2450 rcall dive_boot_cc_part2 ; YES - add CC sensor and SP settings | |
2451 | |
2452 call ghostwriter_short_header ; write short header with dive number into profile memory | |
0 | 2453 |
582 | 2454 btfsc simulatormode_active |
2455 bra diveloop_boot_1 | |
604 | 2456 |
2457 ; normal mode = surface pressure is the pressure 30 minutes before dive | |
2458 SAFE_2BYTE_COPY last_surfpressure_30min, int_I_pres_surface ;copy surface pressure to deco routine | |
2459 SAFE_2BYTE_COPY last_surfpressure_30min, last_surfpressure ;copy surface pressure to last_surfpressure for correct depth | |
582 | 2460 bra diveloop_boot_2 |
0 | 2461 |
2462 diveloop_boot_1: | |
604 | 2463 ; simulator mode: set surface pressure to 1 bar because simulated depths are also based on 1 bar surface pressure |
2464 movlw LOW .1000 | |
2465 movff WREG,int_I_pres_surface+0 ; LOW copy surface pressure to deco routine | |
582 | 2466 movlw HIGH .1000 |
2467 movff WREG,int_I_pres_surface+1 ; HIGH copy surface pressure to deco routine | |
0 | 2468 |
2469 diveloop_boot_2: | |
604 | 2470 SAFE_2BYTE_COPY temperature,minimum_temperature ; reset minimum temperature registers |
0 | 2471 |
582 | 2472 call init_recording_params ; set up all the divisors |
0 | 2473 |
604 | 2474 bsf FLAG_diluent_setup ; for CCR mode (required to have better gas working) |
2475 btfsc FLAG_ccr_mode ; =1: CCR mode (fixed ppO2 or Sensor) active | |
2476 bra diveloop_boot_3 | |
582 | 2477 btfsc FLAG_pscr_mode |
604 | 2478 bra diveloop_boot_3 |
2479 bcf FLAG_diluent_setup ; for OC mode (required to have better gas working) | |
2480 | |
2481 diveloop_boot_3: | |
582 | 2482 bcf LEDg ; switch off green LED / release reset to RX circuitry |
604 | 2483 bcf LEDr ; switch off red LED |
0 | 2484 bcf realdive |
604 | 2485 btfss simulatormode_active ; in simulator mode? |
2486 call disable_rs232 ; NO - disable RS232 | |
2487 | |
2488 IFDEF _screendump | |
2489 btfsc enable_screen_dumps ; =1: ignore vin_usb, wait for "l" command (screen dump) | |
2490 call enable_rs232 ; also sets to speed_normal | |
2491 ENDIF | |
2492 | |
2493 ; reset dive time seconds | |
2494 ; movlw .2 ; start at 2 seconds | |
2495 ; movwf total_divetime_seconds+0 | |
2496 ; clrf total_divetime_seconds+1 | |
2497 ; movwf divesecs | |
2498 ; movwf apnoe_secs | |
2499 ; bsf divemode2 ; displayed dive time is running (dive time starts HERE) | |
2500 | |
2501 ; clear the timers (start dive times at zero) | |
2502 clrf total_divetime_seconds+0 | |
582 | 2503 clrf total_divetime_seconds+1 |
604 | 2504 clrf divesecs |
2505 clrf divemins+0 | |
2506 clrf divemins+1 | |
2507 clrf apnoe_secs | |
2508 clrf apnoe_mins | |
2509 | |
2510 ; divemode2 flag will be set by pressure & timeout evaluation in function set_dive_modes | |
2511 | |
2512 return ; done with dive mode boot | |
2513 | |
2514 | |
2515 ;============================================================================= | |
0 | 2516 |
2517 divemode_check_for_warnings: | |
604 | 2518 movlw .1 ; one message at a time in alternative layout |
582 | 2519 btfss alternative_divelayout |
604 | 2520 movlw .2 ; two messages at a time in default layout |
2521 cpfsgt message_counter ; only one (or two) messages active? | |
2522 bra divemode_check_for_warnings1; YES - update every second | |
2523 | |
2524 btfss secs,0 ; every two seconds... | |
582 | 2525 return |
604 | 2526 btfss secs,1 ; every four seconds... |
582 | 2527 return |
0 | 2528 |
131 | 2529 divemode_check_for_warnings1: |
604 | 2530 bcf message_advice ; clear flag for messages of level advice |
2531 bcf message_attention ; clear flag for messages of level attention | |
2532 bcf message_warning ; clear flag for messages of level warning | |
2533 clrf message_counter ; clear message counter | |
2534 | |
2535 ; messages sorted by severity: highest severity warnings first, then attentions, advices and last info | |
2536 | |
2537 ; warnings for all modes | |
2538 call check_warn_battery ; check if the battery level should be displayed/warned | |
2539 call check_divetimeout ; check and show the dive mode timeout (not actually a warning) | |
2540 | |
2541 btfsc FLAG_apnoe_mode ; in Apnoe mode? | |
2542 bra divemode_check_for_warnings2; YES | |
2543 btfsc FLAG_gauge_mode ; in gauge mode? | |
2544 bra divemode_check_for_warnings2; YES | |
2545 | |
2546 ; warnings applicable only in deco modes | |
582 | 2547 rcall check_ppO2 ; check ppO2 and displays warning, if required |
0 | 2548 |
582 | 2549 btfss sensors_agree ; are the sensor values within the threshold range? |
2550 rcall check_warn_sensors_disagree ; NO - further evaluate | |
2551 btfsc sensors_agree ; are the sensor values within the threshold range? | |
2552 bcf sensor_warning ; YES - revoke memorized sensor warning | |
2553 | |
604 | 2554 rcall check_outside ; check of ZHL16 model violation |
560 | 2555 |
582 | 2556 rcall check_IBCD ; check for IBCD attention or warning |
2557 | |
604 | 2558 rcall check_OC_gas_avail ; check if a breathable OC gas is available |
2559 | |
2560 btfsc decostop_active ; in deco mode? | |
2561 rcall check_and_store_gf_violation; YES - sets warnings, if required | |
2562 | |
2563 rcall check_mbubbles ; check for micro bubbles | |
582 | 2564 |
2565 rcall check_cns_violation ; Check CNS value and display it, if required | |
560 | 2566 |
604 | 2567 rcall check_gas_needs_ascent ; show gas needs warning if any gas need for ascent is > threshold |
2568 | |
2569 rcall check_eod_cns_violation ; check CNS values for end-of-dive and display warning, if required | |
2570 | |
2571 rcall check_display_ftts ; show @+x time | |
2572 | |
2573 IFDEF _cave_mode | |
2574 btfsc FLAG_cave_mode ; cave mode enabled? | |
2575 rcall check_cavemode ; YES - check cave mode status | |
2576 ENDIF | |
2577 | |
2578 btfsc use_agf ; in aGF mode? | |
2579 rcall warn_agf ; YES - show memo | |
2580 | |
2581 btfsc setpoint_fallback ; fallback to SP1 due to external O2 sensor failure? | |
2582 rcall warn_fallback ; YES - show a warning | |
2583 | |
2584 btfsc better_dil_available ; is a better diluent available? | |
2585 rcall advice_gas_change ; YES - display an advice | |
2586 btfsc better_gas_available ; is a better gas available? | |
2587 rcall advice_gas_change ; YES - display an advice | |
582 | 2588 |
0 | 2589 divemode_check_for_warnings2: |
604 | 2590 IFDEF _rx_functions |
2591 btfss FLAG_tr_enabled ; TR functions enabled? | |
2592 bra divemode_check_for_warnings3 ; NO - skip | |
2593 call check_tr_functions ; YES - check transmitter functions | |
2594 call check_tr_messages ; - check SAC attention and switch advice | |
2595 ENDIF | |
2596 | |
2597 divemode_check_for_warnings3: | |
2598 ; Display the attention or warning icon? | |
2599 btfsc message_advice ; any message of level advice? | |
2600 bsf FLAG_TFT_divemode_warning ; YES | |
2601 btfsc message_attention ; any message of level attention? | |
2602 bsf FLAG_TFT_divemode_warning ; YES | |
2603 btfsc message_warning ; any message of level warning? | |
2604 bsf FLAG_TFT_divemode_warning ; YES | |
2605 btfss FLAG_TFT_divemode_warning ; any message of above levels? | |
2606 bsf FLAG_TFT_divemode_warning_clear ; NO - clear warning icon | |
2607 | |
2608 ; Setup message page number | |
2609 incf message_page,F | |
2610 movf message_page,W | |
582 | 2611 bcf STATUS,C |
604 | 2612 btfss alternative_divelayout ; in alternative layout? |
2613 rlcf message_page,W ; NO - *2 | |
2614 cpfsgt message_counter ; > message_counter? | |
2615 clrf message_page ; NO - clear | |
2616 | |
2617 ; Clear both rows of messages if there is nothing to show at all | |
2618 tstfsz message_counter ; any messages? | |
2619 bra divemode_check_for_warnings4 ; YES - look if second row needs to be cleared | |
2620 bsf FLAG_TFT_dive_warning_text_clear; set flag | |
560 | 2621 return |
604 | 2622 |
2623 divemode_check_for_warnings4: | |
2624 ; Clear 2nd row of messages if there is nothing to show (on this page) | |
2625 btfss second_row_warning ; =1: the second row contains a warning | |
2626 bsf FLAG_TFT_dive_warning_text_clr2 ; set flag for 2nd row | |
2627 return ; done | |
0 | 2628 |
582 | 2629 global check_warn_battery |
0 | 2630 check_warn_battery: |
582 | 2631 movff batt_percent,lo |
2632 movlw battery_show_level+1 | |
604 | 2633 cpfslt lo ; battery percentage ok? |
2634 return ; YES - no display, no warning | |
582 | 2635 ; Display Battery, but warn? |
2636 movff batt_percent,lo | |
2637 movlw color_code_battery_low+1 | |
604 | 2638 cpfsgt lo ; battery percent below warning threshold? |
2639 bsf message_warning ; YES - set warning flag | |
2640 btfsc alternative_divelayout ; in alternative layout? | |
2641 bra check_warn_battery2 ; YES - show warning | |
2642 movlw index_clock_batt_surfpress ; NO - index of custom view clock, battery and surface pressure | |
2643 cpfseq menupos3 ; - battery shown in custom view? | |
2644 bra check_warn_battery2 ; NO - show warning | |
2645 return ; YES - do not show twice (in custom view and in message area) | |
472
4fdf6886004b
CHANGE: Show warnings either in Customview (If active) _or_ next to warning sign
heinrichsweikamp
parents:
471
diff
changeset
|
2646 check_warn_battery2: |
604 | 2647 incf message_counter,F ; increase counter |
2648 goto TFT_update_batt_percent_divemode ; show percent (and return) | |
513 | 2649 |
55 | 2650 check_divetimeout: |
604 | 2651 btfsc divemode2 ; dive time running? |
2652 return ; YES - do nothing | |
2653 incf message_counter,F ; increase counter | |
2654 goto TFT_divetimeout ; show timeout counter (and return) | |
55 | 2655 |
560 | 2656 check_ppO2: |
604 | 2657 btfsc FLAG_oc_mode ; are we in OC mode? |
2658 bra check_ppO2_1 ; YES - continue with breathed gas | |
2659 btfsc FLAG_bailout_mode ; NO - in bailout? | |
2660 bra check_ppO2_1 ; YES - continue with breathed gas | |
2661 ; CCR / pSCR mode - checks on pure diluent | |
2662 movff int_O_pure_ppO2+0,lo ; get value and attention/warning flags for the pure diluent | |
2663 movff int_O_pure_ppO2+1,hi ; | |
2664 btfsc hi,int_warning_flag ; ppO2 of the pure diluent to low or high? | |
2665 rcall check_ppO2_dw ; YES - show warning and return on next line | |
2666 btfsc hi,int_attention_flag ; ppO2 of the pure diluent in attention state? | |
2667 rcall check_ppO2_da ; YES - show attention and return on next line | |
2668 ; all modes - checks on breathed gas (OC or from loop) | |
2669 check_ppO2_1: | |
2670 movff int_O_breathed_ppO2+0,lo ; get value and attention/warning flags for the breathed gas | |
2671 movff int_O_breathed_ppO2+1,hi ; get warnings for breathed gas | |
2672 btfsc hi,int_attention_flag ; breathed ppO2 in attention state (when in loop mode, no attention will be generated)? | |
2673 bra check_ppo2_display_a ; YES - set attention flag and show ppO2 | |
2674 btfsc hi,int_low_flag ; breathed ppO2 to low? | |
560 | 2675 bra check_ppO2_low ; YES - record the warning and show ppO2 |
604 | 2676 btfsc hi,int_high_flag ; breathed ppO2 to high? |
560 | 2677 bra check_ppO2_high ; YES - record the warning and show ppO2 |
582 | 2678 TSTOSS opt_showppo2 ; show ppO2 anyhow? (0 = no, 1 = show always) |
604 | 2679 return ; NO - no warnings, no show - done |
2680 bra check_ppO2_common_2 ; YES - but only when in OC or bailout... | |
560 | 2681 check_ppO2_low: |
582 | 2682 movlw d'4' ; set type of alarm (ppO2 low) |
2683 bra check_ppO2_common ; continue with common part | |
560 | 2684 check_ppO2_high: |
2685 movlw d'5' ; set type of alarm (ppO2 high) | |
2686 check_ppO2_common: | |
2687 movwf AlarmType ; copy alarm type to alarm register | |
604 | 2688 bsf event_occured ; set event flag |
2689 bsf message_warning ; show warning sign | |
2690 check_ppO2_common_2: | |
2691 btfsc FLAG_oc_mode ; are we in OC mode? | |
2692 bra check_ppo2_display ; YES | |
2693 btfsc FLAG_bailout_mode ; are we in bailout mode? | |
2694 bra check_ppo2_display ; YES | |
2695 return ; NO - in loop mode, ppO2 is already shown via setpoint display | |
2696 check_ppo2_display_a: | |
2697 bsf message_attention ; show attention sign | |
2698 check_ppo2_display: | |
2699 btfsc alternative_divelayout ; in alternative layout? | |
2700 bra check_ppO2_d ; YES - show warning | |
2701 movlw index_ppo2_ead_end_cns ; NO - index of custom view ppO2, EAD/END and CNS) | |
2702 cpfseq menupos3 ; ppO2 shown? | |
2703 bra check_ppO2_b ; NO | |
2704 return ; YES - do not show twice (in custom view and in warning area) | |
471
9edb1359ce43
NEW: New Customview 11 in dive mode shows ppO2, EAD/END and CNS
heinrichsweikamp
parents:
444
diff
changeset
|
2705 check_ppO2_b: |
604 | 2706 movlw index_pscr_info ; index of custom view with pSCR data |
2707 cpfseq menupos3 ; ppO2 shown? | |
2708 bra check_ppO2_d ; NO - show warning | |
2709 return ; YES - do not show twice (in custom view and in warning area) | |
2710 check_ppO2_dw: | |
2711 bsf message_warning ; show warning sign | |
2712 check_ppO2_da: | |
2713 bsf message_attention ; show attention sign (no problem if a warning sign is set as well, as it will take priority) | |
582 | 2714 check_ppO2_d: |
604 | 2715 incf message_counter,F ; increase counter |
2716 goto TFT_display_ppo2_warning ; show breathed gas or diluent ppO2 warning (and return) | |
2717 | |
2718 | |
2719 check_display_ftts: | |
2720 movff char_I_extra_time,lo ; get extra time | |
2721 tstfsz lo ; extra time > 0 ? | |
2722 bra check_display_ftts_1 ; YES - continue checking bailout condition | |
2723 return ; NO - done | |
2724 check_display_ftts_1: | |
2725 btfsc FLAG_bailout_mode ; in bailout mode? | |
2726 return ; YES - in bailout no fTTS will be computed, so nothing to display | |
2727 incf message_counter,F ; NO - increase counter | |
2728 goto TFT_display_ftts ; - show @+x time | |
582 | 2729 |
376
e99bb91f6f92
CHANGE: Do not show ppO2 in warning area if already shown in custom view
heinrichsweikamp
parents:
352
diff
changeset
|
2730 |
582 | 2731 global check_cns_violation |
0 | 2732 check_cns_violation: |
582 | 2733 ; Check if CNS should be displayed |
2734 movff int_O_CNS_fraction+1,WREG ; get high byte | |
2735 btfsc WREG,int_warning_flag ; warning flag set? | |
604 | 2736 bra check_cns_violation_1 ; YES - issue warning |
2737 btfsc WREG,int_attention_flag ; NO - attention flag set? | |
2738 bra check_cns_violation_2 ; YES - issue attention | |
2739 return ; NO - done | |
2740 check_cns_violation_1: | |
2741 bsf message_warning ; show warning sign | |
2742 check_cns_violation_2: | |
2743 bsf message_attention ; show attention sign | |
2744 btfsc alternative_divelayout ; in alternative layout? | |
2745 bra check_cns_violation_4 ; YES - show attention | |
2746 movlw index_ppo2_ead_end_cns ; NO - index of custom view ppO2, EAD/END and CNS | |
2747 cpfseq menupos3 ; - CNS shown? | |
2748 bra check_cns_violation_3 ; NO | |
2749 return ; YES - do not show twice (in custom view and in warning area) | |
2750 check_cns_violation_3: | |
2751 movlw index_CNS ; index of custom view with CNS values | |
2752 cpfseq menupos3 ; CNS shown? | |
2753 bra check_cns_violation_4 ; NO | |
2754 return ; YES - do not show twice (in custom view and in warning area) | |
2755 check_cns_violation_4: | |
2756 incf message_counter,F ; increase counter | |
2757 goto TFT_display_cns ; show CNS (and return) | |
582 | 2758 |
0 | 2759 |
582 | 2760 global check_eod_cns_violation ; check end-of-dive CNS values |
560 | 2761 check_eod_cns_violation: |
582 | 2762 movff int_O_CNS_fraction+1,WREG ; get high-byte of current CNS value |
2763 btfsc WREG,int_warning_flag ; current CNS value in warning state? | |
604 | 2764 return ; YES - inhibit end-of-dive warning if current CNS is already in warning |
582 | 2765 movff int_O_normal_CNS_fraction+1,WREG |
560 | 2766 btfsc WREG,int_invalid_flag ; flag for invalid value set? |
2767 bra check_eod_cns_violation1 ; YES - continue with checking the other CNS value | |
582 | 2768 btfsc WREG,int_warning_flag ; NO - flag for warning set? |
2769 bra check_eod_cns_violation2 ; YES - issue warning | |
2770 check_eod_cns_violation1: ; NO - continue with checking the other CNS value | |
2771 movff int_O_alternate_CNS_fraction+1,WREG | |
560 | 2772 btfsc WREG,int_invalid_flag ; flag for invalid value set? |
2773 return ; YES - done with CNS checking | |
2774 btfsc WREG,int_warning_flag ; NO - flag for warning set? | |
604 | 2775 bra check_eod_cns_violation2 ; YES - issue warning |
582 | 2776 return ; NO - done with CNS checking |
604 | 2777 check_eod_cns_violation2: ; issue warning (actually only on attention level) |
2778 bsf message_attention ; show attention sign | |
2779 btfsc alternative_divelayout ; in alternative layout? | |
2780 bra display_eod_cns_violation ; YES - show warning | |
2781 movlw index_CNS ; NO - index of custom view with CNS values | |
2782 cpfseq menupos3 ; - CNS values shown? | |
2783 bra display_eod_cns_violation ; NO - issue textual warning | |
2784 return ; YES - do not show twice (in custom view and in warning area) | |
560 | 2785 display_eod_cns_violation: |
604 | 2786 incf message_counter,F ; increase counter |
582 | 2787 goto TFT_display_eod_cns ; issue CNS at end-of-dive warning (and return) |
560 | 2788 |
2789 | |
582 | 2790 global check_and_store_gf_violation |
0 | 2791 check_and_store_gf_violation: |
560 | 2792 movff int_O_gradient_factor+1,WREG ; get upper byte of gradient factor |
2793 btfss WREG,int_warning_flag ; check if the warning flag is set | |
582 | 2794 bra check_and_store_gf_violation2 ; NO - continue with checking for attention flag |
2795 movlw d'2' ; YES - set type of alarm | |
2796 movwf AlarmType ; copy to alarm register | |
2797 bsf event_occured ; set event flag | |
604 | 2798 bsf message_warning ; set warning flag |
560 | 2799 bra check_and_store_gf_violation3 ; show gf warning |
2800 check_and_store_gf_violation2: | |
582 | 2801 btfsc WREG,int_attention_flag ; check if the attention flag is set |
2802 bra check_and_store_gf_violation3 ; YES - show gf | |
560 | 2803 TSTOSS opt_enable_IBCD ; NO - IBCD warning activated? |
582 | 2804 bra check_and_store_gf_violation4 ; NO - continue checking of deco info |
2805 movff char_O_deco_warnings,WREG ; YES - get the deco warnings vector | |
2806 btfss WREG,IBCD_warning ; is the IBCD warning flag set? | |
2807 bra check_and_store_gf_violation4 ; NO - continue checking for deco info | |
2808 check_and_store_gf_violation3: ; YES - show gf | |
604 | 2809 bsf message_attention ; show attention sign |
2810 incf message_counter,F ; increase counter | |
582 | 2811 goto TFT_warning_gf ; show GF (and return) |
560 | 2812 check_and_store_gf_violation4: ; check for deco info |
604 | 2813 btfss divemode ; in dive mode? |
560 | 2814 return ; NO - done, return |
604 | 2815 btfsc FLAG_bailout_mode ; YES - in bailout mode? |
2816 return ; YES - done, return (deco_decreasing flag is not updated when in bailout mode) | |
2817 movff char_O_deco_info,WREG ; NO - get the deco info vector | |
2818 btfss WREG,deco_decreasing ; check if the deco_decreasing flag is set | |
2819 return ; NO - done, return | |
2820 incf message_counter,F ; YES - increase counter | |
2821 goto TFT_info_deco ; - show deco info | |
2822 | |
2823 | |
2824 check_outside: | |
2825 movff char_O_deco_warnings,WREG ; bank-safe copy of deco warnings | |
2826 btfss WREG,outside_warning_lock ; are we outside of the ZH-L16 model? | |
2827 return ; NO - done | |
2828 incf message_counter,F ; YES - increase counter | |
2829 bsf message_attention ; - show attention sign | |
2830 btfsc WREG,outside_warning ; - are we outside the ZH-L16 model right now (-> warning)? | |
2831 bsf message_warning ; - set warning flag | |
2832 goto TFT_warning_outside ; - show outside-ZHL-model warning/attention (and return) | |
2833 | |
2834 | |
2835 global check_mbubbles | |
2836 check_mbubbles: | |
2837 movff char_O_deco_warnings,WREG ; bank-safe copy for deco warnings | |
2838 btfsc WREG,mbubble_warning ; are we in micro bubbling zone right now? | |
2839 bra check_mbubbles_warn ; YES | |
2840 btfss WREG,mbubble_warning_lock ; were we in micro bubbling zone? | |
2841 return ; NO - done | |
2842 check_mbubble_att ; YES - attention level | |
2843 incf message_counter,F ; increase counter | |
2844 bsf message_attention ; show attention sign | |
2845 goto TFT_warning_mbubbles ; show micro bubble attention (and return) - TFT_warning_mbubbles switches by itself between attention and warning | |
2846 check_mbubbles_warn: ; locked micro bubbles - warning level if at issue, attention level if locked | |
2847 incf message_counter,F ; increase counter | |
2848 bsf message_warning ; set warning flag | |
2849 goto TFT_warning_mbubbles ; show micro bubbles warning (and return) | |
2850 | |
2851 IFDEF _cave_mode | |
2852 check_cavemode: | |
2853 incf message_counter,F ; increase counter | |
2854 btfsc FLAG_dive_turned ; dive turned? | |
2855 goto TFT_info_dive_turned ; YES - show info that dive is turned | |
2856 btfsc FLAG_cave_mode_shutdown ; NO - has cave mode shut down? | |
2857 goto TFT_warn_cave_shutdown ; YES - show that cave mode has shut down | |
2858 goto TFT_info_cave_mode ; NO - show that cave mode is active | |
2859 ENDIF | |
2860 | |
0 | 2861 warn_agf: |
604 | 2862 incf message_counter,F ; increase counter |
2863 goto TFT_warning_agf ; show aGF warning (and return) | |
145
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
138
diff
changeset
|
2864 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
138
diff
changeset
|
2865 warn_fallback: |
604 | 2866 incf message_counter,F ; increase counter |
2867 bsf message_warning ; set warning flag | |
2868 goto TFT_warning_fallback ; show fallback warning (and return) | |
2869 | |
2870 | |
2871 IFDEF _rx_functions | |
2872 | |
2873 check_tr_messages: | |
2874 movff int_O_sac_rate+1,WREG ; bank-safe copy of current SAC rate | |
2875 btfss WREG,int_attention_flag ; attention flag set? | |
2876 bra check_tr_messages2 ; NO - skip | |
2877 btfsc WREG,int_not_avail_flag ; SAC rate available? | |
2878 bra check_tr_messages2 ; NO - continue with swap advice | |
2879 bsf message_attention ; YES - show attention sign | |
2880 btfsc alternative_divelayout ; - in alternative layout? | |
2881 bra check_tr_messages1 ; YES - show attention message | |
2882 movlw index_pressures_SAC ; NO - index of custom view with SAC rate | |
2883 cpfseq menupos3 ; - SAC rate shown right now? | |
2884 bra check_tr_messages1 ; NO - show attention message | |
2885 bra check_tr_messages2 ; YES - do not show twice, continue with swap advice | |
2886 check_tr_messages1: | |
2887 incf message_counter,F ; increase counter | |
2888 call TFT_attention_sac ; show SAC attention | |
2889 check_tr_messages2: | |
2890 movff char_O_deco_info,WREG ; bank-safe copy of deco info vector | |
2891 btfss WREG,ind_double_switch ; swap tank flag set? | |
2892 return ; NO | |
2893 incf message_counter,F ; YES - increase counter | |
2894 bsf message_advice ; - show advice sign | |
2895 goto TFT_advice_switch ; - show swap advice | |
2896 | |
2897 | |
2898 #DEFINE show_custview ul,0 ; show pressure readings custom view | |
2899 #DEFINE show_transmitter ul,1 ; show transmitter attention | |
2900 #DEFINE show_pres_warning ul,2 ; show transmitter pressure warning | |
2901 #DEFINE show_pres_attention ul,3 ; show transmitter pressure attention | |
2902 | |
2903 check_tr_functions: | |
2904 clrf ul ; set all messages as not shown yet | |
2905 btfsc alternative_divelayout ; in alternative layout? | |
2906 bra check_tr_functions_tr1 ; YES - continue with checking transmitter 1 | |
2907 movlw index_pressures_SAC ; NO - index of custom view pressure readings | |
2908 cpfseq menupos3 ; - pressure readings shown? | |
2909 bra check_tr_functions_tr1 ; NO - continue with checking transmitter 1 | |
2910 bsf show_custview ; YES - suppress redraw by faking it has already been redrawn | |
2911 check_tr_functions_tr1: | |
2912 movff char_I_pressure_stat+0,WREG ; get status of 1st pressure reading | |
2913 rcall check_tr_functions_helper1 ; check for transmitter 1 lost | |
2914 rcall check_tr_functions_helper2 ; check for transmitter 1 low battery | |
2915 movff int_IO_pressure_value+1,WREG ; get high byte of 1st pressure reading | |
2916 rcall check_tr_functions_helper3 ; check for transmitter 1 pressure warning | |
2917 rcall check_tr_functions_helper4 ; check for transmitter 1 pressure attention | |
2918 check_tr_functions_tr2: | |
2919 movff char_I_pressure_stat+1,WREG ; get status of 2nd pressure reading | |
2920 rcall check_tr_functions_helper5 ; check for transmitter 2 lost | |
2921 rcall check_tr_functions_helper6 ; check for transmitter 2 low battery | |
2922 movff int_IO_pressure_value+3,WREG ; get high byte of 2nd pressure reading | |
2923 rcall check_tr_functions_helper7 ; check for transmitter 2 pressure warning | |
2924 rcall check_tr_functions_helper8 ; check for transmitter 2 pressure attention | |
2925 check_tr_functions_show_xmtr: | |
2926 btfss show_transmitter ; shall show transmitter message? | |
2927 bra check_tr_functions_show_warn ; NO - continue with pressure warning | |
2928 bsf message_attention ; YES - set flag for attention | |
2929 incf message_counter,F ; - increase counter | |
2930 call TFT_attention_transmitter ; - show transmitter attention message | |
2931 check_tr_functions_show_warn: | |
2932 btfss show_pres_warning ; shall show pressure warning? | |
2933 bra check_tr_functions_show_att ; NO - continue with pressure attention | |
2934 bsf message_warning ; YES - set flag for warning | |
2935 incf message_counter,F ; - increase counter | |
2936 goto TFT_warning_pres_reading ; - pressure reading warning message and done then | |
2937 check_tr_functions_show_att: | |
2938 btfss show_pres_attention ; shall show pressure attention? | |
2939 return ; NO - done | |
2940 bsf message_attention ; YES - set flag for attention | |
2941 incf message_counter,F ; - increase counter | |
2942 goto TFT_attention_pres_reading ; - pressure reading warning message and done then | |
2943 | |
2944 check_tr_functions_helper1: | |
2945 btfsc WREG,char_transmitter_lost ; transmitter 1 lost? | |
2946 bra check_tr_functions_helper1a ; YES - show transmitter attention message | |
2947 bcf transmitter1_lost ; NO - clear flag for old lost attention | |
2948 return ; - done | |
2949 check_tr_functions_helper1a: | |
2950 bsf show_transmitter ; show transmitter attention | |
2951 btfsc transmitter1_lost ; is it a new message? | |
2952 return ; NO - do not show the pressure readings custom view again | |
2953 bsf transmitter1_lost ; YES - memorize it's an old message now | |
2954 bra check_tr_functions_show_cv ; - show custom view | |
2955 | |
2956 check_tr_functions_helper2: | |
2957 btfsc WREG,char_transmitter_low_bat ; transmitter 1 low battery? | |
2958 bra check_tr_functions_helper2a ; YES - show transmitter attention message | |
2959 bcf transmitter1_battery ; NO - clear flag for old battery attention | |
2960 return ; - done | |
2961 check_tr_functions_helper2a: | |
2962 bsf show_transmitter ; show transmitter attention | |
2963 btfsc transmitter1_battery ; is it a new message? | |
2964 return ; NO - do not show the pressure readings custom view again | |
2965 bsf transmitter1_battery ; YES - memorize it's an old message now | |
2966 bra check_tr_functions_show_cv ; - show custom view | |
2967 | |
2968 check_tr_functions_helper3: | |
2969 btfsc WREG,int_warning_flag ; transmitter 1 pressure warning? | |
2970 bra check_tr_functions_helper3a ; YES - show pressure reading message as warning | |
2971 bcf transmitter1_pres_warn ; NO - clear flag for old warning | |
2972 return ; - done | |
2973 check_tr_functions_helper3a: | |
2974 bsf show_pres_warning ; show pressure warning | |
2975 btfsc transmitter1_pres_warn ; is it a new message? | |
2976 return ; NO - do not show the pressure readings custom view again | |
2977 bsf transmitter1_pres_warn ; YES - memorize it's an old message now | |
2978 bra check_tr_functions_show_cv ; - show custom view | |
2979 | |
2980 check_tr_functions_helper4: | |
2981 btfsc WREG,int_attention_flag ; transmitter 1 pressure attention? | |
2982 bra check_tr_functions_helper4a ; YES - show pressure reading message as attention | |
2983 bcf transmitter1_pres_att ; NO - clear flag for old attention | |
2984 return ; - done | |
2985 check_tr_functions_helper4a | |
2986 bsf show_pres_attention ; show pressure attention | |
2987 btfsc transmitter1_pres_att ; is it a new message? | |
2988 return ; NO - do not show the pressure readings custom view again | |
2989 bsf transmitter1_pres_att ; YES - memorize it's an old message now | |
2990 bra check_tr_functions_show_cv ; - show custom view | |
2991 | |
2992 check_tr_functions_helper5: | |
2993 btfsc WREG,char_transmitter_lost ; transmitter 2 lost? | |
2994 bra check_tr_functions_helper5a ; YES - show transmitter attention message | |
2995 bcf transmitter2_lost ; NO - clear flag for old lost attention | |
2996 return ; - done | |
2997 check_tr_functions_helper5a: | |
2998 bsf show_transmitter ; show transmitter attention | |
2999 btfsc transmitter2_lost ; is it a new message? | |
3000 return ; NO - do not show the pressure readings custom view again | |
3001 bsf transmitter2_lost ; YES - memorize it's an old message now | |
3002 bra check_tr_functions_show_cv ; - show custom view | |
3003 | |
3004 check_tr_functions_helper6: | |
3005 btfsc WREG,char_transmitter_low_bat ; transmitter 2 low battery? | |
3006 bra check_tr_functions_helper6a ; YES - show transmitter attention message | |
3007 bcf transmitter2_battery ; NO - clear flag for old battery attention | |
3008 return ; - done | |
3009 check_tr_functions_helper6a: | |
3010 bsf show_transmitter ; show transmitter attention | |
3011 btfsc transmitter2_battery ; is it a new message? | |
3012 return ; NO - do not show the pressure readings custom view again | |
3013 bsf transmitter2_battery ; YES - memorize it's an old message now | |
3014 bra check_tr_functions_show_cv ; - show custom view | |
3015 | |
3016 check_tr_functions_helper7: | |
3017 btfsc WREG,int_warning_flag ; transmitter 2 pressure warning? | |
3018 bra check_tr_functions_helper7a ; YES - show pressure reading message as warning | |
3019 bcf transmitter2_pres_warn ; NO - clear flag for old warning | |
3020 return ; - done | |
3021 check_tr_functions_helper7a: | |
3022 bsf show_pres_warning ; show pressure warning | |
3023 btfsc transmitter2_pres_warn ; is it a new message? | |
3024 return ; NO - do not show the pressure readings custom view again | |
3025 bsf transmitter2_pres_warn ; YES - memorize it's an old message now | |
3026 bra check_tr_functions_show_cv ; - show custom view | |
3027 | |
3028 check_tr_functions_helper8: | |
3029 btfsc WREG,int_attention_flag ; transmitter 2 pressure attention? | |
3030 bra check_tr_functions_helper8a ; YES - show pressure reading message as attention | |
3031 bcf transmitter2_pres_att ; NO - clear flag for old attention | |
3032 return ; - done | |
3033 check_tr_functions_helper8a | |
3034 bsf show_pres_attention ; show pressure attention | |
3035 btfsc transmitter2_pres_att ; is it a new message? | |
3036 return ; NO - do not show the pressure readings custom view again | |
3037 bsf transmitter2_pres_att ; YES - memorize it's an old message now | |
3038 ;bra check_tr_functions_show_cv ; - show custom view | |
3039 | |
3040 check_tr_functions_show_cv: | |
3041 btfsc show_custview ; is the pressure readings custom view not shown yet shown? | |
3042 return ; NO - already shown, done | |
3043 bsf show_custview ; YES - mark as shown | |
3044 btfsc alternative_divelayout ; - in alternative layout? | |
3045 call switch_layout_to_normal ; YES - switch to normal layout | |
3046 movlw index_pressures_SAC-1 ; custom view number one below pressure readings | |
3047 movwf menupos3 ; set custom view number | |
3048 bsf toggle_customview ; initiate toggle to desired custom view -> pressure readings view will be shown | |
3049 return ; done | |
3050 | |
3051 ENDIF | |
3052 | |
3053 | |
3054 check_gas_needs_ascent: | |
3055 banksel int_O_ascent_pres_need | |
3056 movf int_O_ascent_pres_need+1,w ; get high byte from pres need of 1st tank | |
3057 iorwf int_O_ascent_pres_need+3,w ; inclusive or with high byte from pres need of 2nd tank | |
3058 iorwf int_O_ascent_pres_need+5,w ; inclusive or with high byte from pres need of 3rd tank | |
3059 iorwf int_O_ascent_pres_need+7,w ; inclusive or with high byte from pres need of 4th tank | |
3060 iorwf int_O_ascent_pres_need+9,w ; inclusive or with high byte from pres need of 5th tank | |
560 | 3061 banksel common |
582 | 3062 btfsc WREG,int_invalid_flag ; check if invalid flag is set |
560 | 3063 return ; YES - no further checking required |
604 | 3064 btfsc WREG,int_warning_flag ; check if any gas has a pres_need >= pres_fill |
3065 bsf message_warning ; YES - set warning flag | |
3066 btfsc WREG,int_warning_flag ; check if any gas has a pres_need >= pres_fill | |
560 | 3067 goto TFT_warning_gas_needs_warn ; Yes - show a warning |
604 | 3068 btfsc WREG,int_attention_flag ; check if any gas has a pres_need >= pres_fill * threshold |
3069 bsf message_attention ; YES - set attention flag | |
3070 btfsc WREG,int_attention_flag ; check if any gas has a pres_need >= pres_fill * threshold | |
560 | 3071 goto TFT_warning_gas_needs_att ; YES - show an attention |
3072 bcf gas_needs_attention ; NO - clear flag for a new attention | |
3073 bcf gas_needs_warning ; clear flag for a new warning | |
3074 return | |
0 | 3075 |
582 | 3076 |
560 | 3077 check_warn_sensors_disagree: |
604 | 3078 incf message_counter,F ; increase counter |
3079 bsf message_warning ; YES - set warning flag | |
582 | 3080 goto TFT_warning_sensor_disagree ; show sensor disagree warning (and return) |
560 | 3081 |
3082 | |
3083 check_IBCD: | |
3084 TSTOSS opt_enable_IBCD ; IBCD warning activated? | |
3085 return ; NO - done | |
3086 movff char_O_deco_warnings,WREG ; YES - get deco warnings vector | |
582 | 3087 btfss WREG,IBCD_warning ; IBCD warning flag set? |
3088 return ; NO - return | |
604 | 3089 incf message_counter,F ; YES - increase counter |
582 | 3090 goto TFT_warning_IBCD ; write warning to display |
560 | 3091 |
3092 | |
604 | 3093 check_OC_gas_avail: |
3094 tstfsz best_gas_number ; is a breathable gas available? | |
3095 return ; > 0 : a breathable gas is available | |
3096 btfsc FLAG_ccr_mode ; = 0 : problem - in CCR mode? | |
3097 bra check_OC_gas_avail_1 ; YES - real problem | |
3098 btfsc FLAG_pscr_mode ; NO - in PSCR mode? | |
3099 bra check_OC_gas_avail_1 ; YES - real problem | |
3100 return ; NO - neither CCR nor pSCR mode, suppress warning | |
3101 check_OC_gas_avail_1: | |
3102 btfsc FLAG_bailout_mode ; in bailout? | |
3103 return ; YES - suppress warning | |
3104 incf message_counter,F ; NO - increase counter | |
3105 bsf message_attention ; set attention flag | |
3106 goto TFT_warning_no_BO_gas ; show message (and return) | |
3107 | |
3108 | |
3109 advice_gas_change: | |
3110 bsf message_advice ; show advice sign | |
3111 incf message_counter,F ; increase counter | |
3112 goto TFT_advice_gas_change | |
3113 | |
3114 | |
560 | 3115 global restart_deco_engine |
3116 global restart_deco_engine_wo_ceiling | |
3117 restart_deco_engine: | |
604 | 3118 ; invalidate ceiling |
560 | 3119 movff int_O_ceiling+1,WREG |
3120 bsf WREG,char_invalid_flag ; int_O_ceiling has its invalid flag on a char's position! | |
3121 movff WREG,int_O_ceiling+1 | |
3122 | |
3123 restart_deco_engine_wo_ceiling: | |
604 | 3124 ; invalidate deco data (stop table data) |
560 | 3125 movff char_O_deco_gas+0,WREG |
3126 bsf WREG,char_invalid_flag | |
3127 movff WREG,char_O_deco_gas+0 | |
3128 | |
604 | 3129 ; invalidate ascent time (normal plan) |
560 | 3130 movff int_O_ascenttime+1,WREG |
3131 bsf WREG,int_invalid_flag | |
3132 movff WREG,int_O_ascenttime+1 | |
3133 | |
604 | 3134 ; invalidate CNS at end of dive in normal plan |
560 | 3135 movff int_O_normal_CNS_fraction+1,WREG |
3136 bsf WREG,int_invalid_flag | |
3137 movff WREG,int_O_normal_CNS_fraction+1 | |
3138 | |
604 | 3139 ; restart deco engine |
3140 movff char_O_main_status,WREG ; get current main engine configuration | |
3141 bcf WREG,DECO_COMPLETED_NORM ; eventually clear flag stating completion of normal plan | |
3142 bsf WREG,DECO_COMPLETED_ALT ; fake we came from alternative plan to force normal plan to be done next | |
3143 movff WREG,char_O_main_status ; write back new configuration | |
3144 movff char_O_deco_status,WREG ; get current deco engine status | |
3145 bcf WREG,DECO_STATUS_0_FLAG ; set status flags to... | |
3146 bcf WREG,DECO_STATUS_1_FLAG ; ... DECO_STATUS_START | |
3147 movff WREG,char_O_deco_status ; write back new configuration to restart deco computations | |
3148 | |
3149 inval_alternative_plan_data: | |
3150 ; invalidate ascent time (alternative plan) | |
3151 movff int_O_alternate_ascenttime+1,WREG | |
3152 bsf WREG,int_invalid_flag | |
3153 movff WREG,int_O_alternate_ascenttime+1 | |
3154 | |
3155 ; invalidate CNS at end of dive in alternative plan | |
560 | 3156 movff int_O_alternate_CNS_fraction+1,WREG |
3157 bsf WREG,int_invalid_flag | |
3158 movff WREG,int_O_alternate_CNS_fraction+1 | |
3159 | |
604 | 3160 ; invalidate ascent gas needs |
3161 movff int_O_ascent_pres_need+1,WREG | |
560 | 3162 bsf WREG,int_invalid_flag |
604 | 3163 movff WREG,int_O_ascent_pres_need+1 |
3164 | |
3165 IFDEF _rx_functions | |
3166 ; invalidate pressure needs (TR functions) | |
3167 movff int_O_pressure_need+1,WREG | |
3168 bsf WREG,int_not_avail_flag | |
3169 movff WREG,int_O_pressure_need+1 | |
3170 movff int_O_pressure_need+3,WREG | |
3171 bsf WREG,int_not_avail_flag | |
3172 movff WREG,int_O_pressure_need+3 | |
3173 ENDIF | |
3174 | |
3175 ; update display depended on NDL or deco mode | |
3176 bsf FLAG_TFT_display_ndl_or_deko | |
582 | 3177 |
3178 return | |
3179 | |
3180 ;============================================================================= | |
604 | 3181 ; Simulator Mode |
582 | 3182 ; |
3183 | |
3184 global do_demo_divemode | |
3185 do_demo_divemode: | |
604 | 3186 call TFT_ClearScreen ; blank screen |
3187 call option_save_all ; save all settings into EEPROM before starting simulation | |
582 | 3188 call deco_push_tissues_to_vault ; C-code: back-up status of the real tissues |
604 | 3189 banksel common ; bank 1 |
3190 | |
3191 ; +++ COMMENT OUT FOR TESTING PURPOSE ONLY !!! +++ | |
3192 bsf restore_deco_data ; restore tissue and CNS after simulator use | |
3193 ; +++ DO NOT COMMENT OUT IN OPERATIONAL USE !!! +++ | |
560 | 3194 |
582 | 3195 bcf pressure_refresh |
604 | 3196 btfss pressure_refresh ; wait for sensor |
582 | 3197 bra $-2 |
3198 | |
604 | 3199 bsf simulatormode_active ; set flag |
3200 | |
3201 banksel char_I_bottom_depth ; compute dive ambient conditions | |
582 | 3202 movf char_I_bottom_depth,W |
3203 mullw .100 | |
3204 movff PRODL,rel_pressure+0 | |
3205 movff PRODH,rel_pressure+1 | |
3206 movlw LOW (.1000) | |
3207 addwf PRODL,W | |
3208 movff WREG,sim_pressure+0 | |
3209 movlw HIGH (.1000) | |
3210 addwfc PRODH,W | |
3211 movff WREG,sim_pressure+1 | |
604 | 3212 banksel common ; bank 1 |
582 | 3213 |
3214 bsf divemode | |
604 | 3215 goto diveloop ; switch into dive mode |
582 | 3216 |
3217 END |