Mercurial > public > hwos_code
annotate src/divemode.asm @ 591:146e50d2672f
BUGFIX: handle two deco gases configured to the same change depth
author | heinrichsweikamp |
---|---|
date | Thu, 15 Mar 2018 20:43:38 +0100 |
parents | bf0c76e9b01b |
children | 08a0162d3ca1 |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
582 | 3 ; File divemode.asm REFACTORED VERSION V2.98 |
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 | |
582 | 12 #include "hwos.inc" ; Mandatory header |
13 #include "shared_definitions.h" ; Mailbox from/to p2_deco.c | |
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 | |
0 | 29 |
582 | 30 extern TFT_dive_compass_heading |
31 extern do_line_menu | |
32 extern do_main_divemenu | |
33 extern option_save_all | |
34 extern init_recording_params | |
35 | |
36 | |
37 ;---- Private local variables ------------------------------------------------- | |
38 | |
39 CBLOCK local1 ; max size is 16 Byte !!! | |
40 apnoe_timeout_counter ; timeout counter for apnoe mode | |
41 average_depth_hold:4 ; used in calculation of the average depth | |
42 sensor_setpoint ; sensor ppo2 in 0.01bar for deco routine | |
43 active_diluent ; backup of diluent gas for when switching back from bailout to CCR/pSCR loop | |
44 average_depth_hold_total:4 ; used to calculate the average depth | |
45 ENDC ; used: 11 byte, remaining: 5 byte | |
46 | |
47 gui CODE | |
48 | |
49 ;============================================================================= | |
0 | 50 |
51 global diveloop | |
52 diveloop: | |
582 | 53 banksel common |
54 call speed_normal | |
55 call diveloop_boot ; Boot tasks for all modes | |
0 | 56 |
582 | 57 ; Startup Tasks for all modes |
58 call TFT_boot ; Initialize TFT (includes clear screen) | |
59 bsf FLAG_TFT_divemode_mask ; Display mask | |
60 movff customview_divemode,menupos3; Reload last customview | |
61 call customview_mask ; Redraw last custom view | |
0 | 62 |
582 | 63 btfsc FLAG_apnoe_mode |
64 bsf realdive ; Set Realdive flag in Apnoe mode | |
0 | 65 |
582 | 66 btfsc FLAG_apnoe_mode ; Done for Apnoe or Gauge mode |
67 bra diveloop_loop_start | |
68 btfsc FLAG_gauge_mode ; Done for Apnoe or Gauge mode | |
69 bra diveloop_loop_start | |
0 | 70 |
582 | 71 bsf FLAG_TFT_display_ndl_mask ; display "NDL" |
0 | 72 |
73 ; +@5 init | |
582 | 74 clrf WREG ; WAIT marker: display "---" |
75 movff WREG,char_I_sim_advance_time | |
76 movff WREG,int_O_alternate_ascenttime+0 | |
560 | 77 bsf WREG,int_not_yet_computed |
78 bsf WREG,int_invalid_flag | |
582 | 79 movff WREG,int_O_alternate_ascenttime+1 |
560 | 80 |
81 diveloop_loop_start: | |
582 | 82 btfsc FLAG_TFT_display_ndl_mask |
83 call TFT_display_ndl_mask | |
560 | 84 |
85 | |
86 diveloop_loop: ; The diveloop starts here | |
582 | 87 btfss quarter_second_update |
88 bra diveloop_loop1 | |
89 | |
90 ; tasks any 1/4 second, any mode | |
91 bcf quarter_second_update ; clear flag | |
0 | 92 |
582 | 93 movlw .6 |
94 cpfseq menupos3 ; in compass view? | |
95 bra diveloop_loop1 ; No, done. | |
560 | 96 |
582 | 97 btfsc alternative_divelayout ; In alternative layout mode? |
98 bra diveloop_loop1 ; Yes, done. No Compass. | |
560 | 99 |
582 | 100 ; TFT Output routines |
101 call TFT_dive_compass_heading ; Yes, update compass heading value | |
102 bsf FLAG_TFT_temp_divemode ; Redraw temperature (is slightly affected from compass heading arrow) | |
103 ; TFT Output routines | |
560 | 104 |
582 | 105 diveloop_loop1: |
106 btfss onesecupdate | |
0 | 107 bra diveloop_loop3 |
582 | 108 |
0 | 109 ; tasks any new second... |
582 | 110 bcf onesecupdate ; one seconds update, clear flag here in case it's set again in ISR before all tasks are done. |
178 | 111 |
582 | 112 ;bsf LEDg ; ### USE FOR DEBUG ONLY - RESETS RX CIRCUITRY ### |
0 | 113 |
560 | 114 ; display depth based on full seconds interval (nicer blinking) |
582 | 115 btfss alternative_divelayout |
116 rcall TFT_output4_normal | |
117 btfsc alternative_divelayout | |
118 rcall TFT_output4_alternative | |
119 | |
560 | 120 btfsc FLAG_apnoe_mode ; Only in apnoe mode |
582 | 121 bra diveloop_loop1_nonedeco ; One Second Tasks in Apnoe mode |
122 | |
560 | 123 ; tasks any new second - only for deco modes |
582 | 124 diveloop_loop1_decomodes: |
560 | 125 bsf FLAG_TFT_divemins ; Display (new) divetime! |
126 btfsc show_safety_stop ; Show the safety stop? | |
127 bsf FLAG_TFT_show_safety_stop ; Yes, show/delete if done. | |
0 | 128 |
560 | 129 btfss alternative_divelayout |
130 rcall TFT_output1_normal | |
131 btfsc alternative_divelayout | |
132 rcall TFT_output1_alternative | |
0 | 133 |
582 | 134 btfsc FLAG_ccr_mode ; in CCR mode... |
135 call check_dive_autosp ; ...check for Auto-SP | |
136 | |
560 | 137 call calc_deko_divemode ; calculate decompression and set resulting display flags |
138 | |
139 btfss alternative_divelayout | |
140 rcall TFT_output2_normal | |
141 btfsc alternative_divelayout | |
142 rcall TFT_output2_alternative | |
143 | |
144 call divemode_check_for_warnings ; Check for any warnings | |
145 | |
582 | 146 bra diveloop_loop2 ; Common Tasks |
147 | |
560 | 148 |
149 ; tasks any new second - only for apnoe mode | |
582 | 150 diveloop_loop1_nonedeco: |
560 | 151 rcall divemode_apnoe_tasks ; 1 sec. Apnoe tasks |
152 call customview_second ; Do every-second tasks for the custom view area | |
582 | 153 ;bra diveloop_loop2 ; Common Tasks |
560 | 154 |
155 ; continue tasks any new second, any mode | |
582 | 156 diveloop_loop2: |
560 | 157 rcall timeout_divemode ; ** menu timeout? ** This routine sets the required flags |
582 | 158 rcall set_dive_modes ; tests if depth > threshold |
560 | 159 rcall set_min_temp ; store min. temp if required (Future hardware will need this to be checked 1/second...) |
0 | 160 |
560 | 161 btfsc oneminupdate ; one minute tasks |
162 rcall update_divemode60 ; Update clock, etc. | |
0 | 163 |
560 | 164 btfss alternative_divelayout |
165 rcall TFT_output3_normal | |
166 btfsc alternative_divelayout | |
167 rcall TFT_output3_alternative | |
168 | |
582 | 169 ;bcf LEDg ; ### USE FOR DEBUG ONLY - RESETS RX CIRCUITRY ### |
0 | 170 |
560 | 171 ; tasks any round, any mode |
0 | 172 diveloop_loop3: |
582 | 173 call test_switches_divemode ; Check switches in divemode |
174 | |
175 global diveloop_loop4 | |
560 | 176 diveloop_loop4: ; Menu-Exit returns here... |
177 btfsc divemode_menu ; in the big divemode menu? | |
178 bra diveloop_loop4b ; YES - no space for CCR/pSCR info | |
179 btfsc menuview ; NO - in the small yellow menu? | |
582 | 180 bra diveloop_loop4b ; YES - no space for CCR/pSCR info |
181 btfsc alternative_divelayout ; NO - in the alternative layout? | |
182 bra diveloop_loop4b ; YES - no space for CCR/pSCR info | |
183 call TFT_show_mode_divemode ; NO - (re)write CCR/pSCR mode info to display | |
560 | 184 diveloop_loop4b: |
582 | 185 btfsc toggle_customview ; Next view? |
186 call customview_toggle ; Yes, show next customview (and delete this flag) | |
0 | 187 |
582 | 188 btfsc divemode_gaschange ; Gas switch flag set? |
189 call gas_switched_common ; YES | |
0 | 190 |
582 | 191 btfsc toggle_gf ; Toggle GF/aGF? |
192 rcall divemodemode_togglegf ; YES | |
0 | 193 |
582 | 194 btfsc FLAG_set_marker ; shall a marker be set? |
195 call set_logbook_marker ; YES | |
196 | |
197 btfsc store_sample ; store new sample? | |
198 call store_dive_data ; Store profile data | |
199 | |
200 btfss divemode ; Dive finished? | |
201 goto ghostwriter_end_dive ; Dive finished! | |
83 | 202 |
582 | 203 btfsc pressure_refresh ; new pressure available? |
204 rcall set_max_depth ; update max. depth if required | |
205 btfsc pressure_refresh ; new pressure available? | |
206 bsf FLAG_TFT_depth ; Yes, update depth | |
207 bcf pressure_refresh ; clear flag | |
560 | 208 |
582 | 209 btfsc temp_changed |
210 bsf FLAG_TFT_temp_divemode ; Displays temperature | |
560 | 211 |
212 ; display depth based on as-fast-as-possible (no nice blinking) | |
582 | 213 ;btfss alternative_divelayout |
214 ;rcall TFT_output4_normal | |
215 ;btfsc alternative_divelayout | |
216 ;rcall TFT_output4_alternative | |
217 | |
218 btfsc enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump) | |
219 bra diveloop_loop5 | |
220 bra diveloop_loop6 | |
560 | 221 |
0 | 222 diveloop_loop5: |
582 | 223 btfss vusb_in ; USB (still) plugged in? |
224 bcf enable_screen_dumps ; No, clear flag | |
225 call rs232_get_byte | |
226 btfsc rs232_receive_overflow | |
227 bra diveloop_loop6 | |
228 movlw "l" | |
229 cpfseq RCREG1 | |
230 bra diveloop_loop6 | |
231 call TFT_dump_screen ; Dump the screen contents | |
232 | |
0 | 233 diveloop_loop6: |
560 | 234 bra diveloop_loop ; Loop the divemode |
582 | 235 |
560 | 236 ;-------------------------------------------------------------------------------------------------------- |
582 | 237 |
238 TFT_output1_normal: ; beginning of any new second - only for deco modes | |
239 btfsc FLAG_TFT_divemode_mask | |
240 call TFT_divemode_mask | |
560 | 241 btfsc FLAG_TFT_divemins |
242 call TFT_divemins ; Display (new) divetime! | |
243 call customview_second ; Do every-second tasks for the custom view area (In sync with the divetime) mH | |
244 btfsc FLAG_TFT_show_safety_stop | |
245 call TFT_show_safety_stop ; Show safety stop | |
246 btfsc FLAG_TFT_clear_safety_stop | |
247 call TFT_clear_safety_stop ; Clear safety stop | |
248 return | |
582 | 249 |
560 | 250 TFT_output1_alternative: ; beginning of any new second - only for deco modes |
251 btfsc FLAG_TFT_divemins | |
252 call TFT_divemins_alternative ; Display (new) divetime! | |
253 btfsc FLAG_TFT_divemode_mask_alt | |
582 | 254 call TFT_divemode_mask_alternative ; Alt. mask |
255 call customview_alternative_second ; Do every-second tasks for the custom view area (In sync with the divetime) mH | |
588 | 256 btfsc FLAG_TFT_big_deco_alt |
257 call TFT_big_deco_alt ; Big deco and safety stop | |
560 | 258 return |
582 | 259 |
260 TFT_output2_normal: ; any new second - only for deco modes | |
261 btfsc FLAG_TFT_display_ndl_mask | |
262 call TFT_display_ndl_mask | |
263 btfsc FLAG_TFT_display_ndl | |
264 call TFT_display_ndl | |
560 | 265 btfsc FLAG_TFT_display_deko_mask |
266 call TFT_display_deko_mask | |
267 btfsc FLAG_TFT_display_deko | |
268 call TFT_display_deko | |
269 btfsc FLAG_TFT_display_tts | |
270 call TFT_display_tts | |
271 return | |
0 | 272 |
582 | 273 TFT_output2_alternative: ; any new second - only for deco modes |
560 | 274 return |
582 | 275 |
276 TFT_output3_normal: ; tasks any new second, any mode | |
560 | 277 btfsc FLAG_TFT_max_depth |
278 call TFT_max_depth ; use normal max. depth | |
279 btfsc FLAG_TFT_divemode_warning | |
280 call TFT_divemode_warning | |
281 btfsc FLAG_TFT_divemode_warning_clear | |
282 call TFT_divemode_warning_clear | |
283 btfsc FLAG_TFT_active_gas_divemode | |
582 | 284 call TFT_active_gas_divemode ; Display gas/Setpoint |
560 | 285 btfsc FLAG_TFT_dive_warning_text_clear |
582 | 286 call TFT_clear_warning_text ; clear complete warnings area |
287 btfsc FLAG_TFT_dive_warning_text_clr2 | |
288 call TFT_clear_warning_text_2nd_row; clear 2nd row of warnings | |
560 | 289 return |
582 | 290 |
291 TFT_output3_alternative: ; tasks any new second, any mode | |
560 | 292 btfsc FLAG_TFT_max_depth_alt |
293 call TFT_max_depth_alternative ; big max. depth | |
294 btfsc FLAG_TFT_dive_warning_text_clear | |
295 call TFT_clear_warning_text ; clear complete warnings area (In alt mode only 2nd. row...) | |
296 return | |
297 | |
298 TFT_output4_normal: ; tasks any round, any mode | |
299 btfsc FLAG_TFT_depth | |
300 call TFT_depth ; Displays new depth | |
582 | 301 btfsc FLAG_TFT_temp_divemode |
560 | 302 call TFT_temp_divemode ; Update temperature |
303 return | |
582 | 304 |
305 TFT_output4_alternative: ; tasks any round, any mode | |
306 btfsc FLAG_TFT_depth | |
560 | 307 call TFT_depth ; Displays new depth |
308 return | |
582 | 309 |
310 | |
0 | 311 ;-------------------------------------------------------------------------------------------------------- |
312 | |
560 | 313 divemode_apnoe_tasks: ; 1 sec. Apnoe tasks |
314 call TFT_display_apnoe_descent ; Yes, Show descent timer | |
315 call TFT_max_depth ; use normal max. depth | |
0 | 316 |
560 | 317 btfsc divemode2 ; Time running? |
318 bra divemode_apnoe_tasks2 ; New descent, reset data if flag is set | |
0 | 319 |
320 rcall apnoe_calc_maxdepth | |
321 call TFT_display_apnoe_surface | |
560 | 322 call TFT_display_apnoe_last_max ; Show last max. depth |
0 | 323 incf apnoe_surface_secs,F |
324 movlw d'60' | |
325 cpfseq apnoe_surface_secs | |
326 bra divemode_apnoe_tasks1 | |
327 clrf apnoe_surface_secs | |
328 incf apnoe_surface_mins,F | |
329 | |
582 | 330 divemode_apnoe_tasks1: |
331 bcf FLAG_active_descent ; Clear flag | |
560 | 332 btfsc divemode2 ; Time running? |
333 return ; Yes, return | |
582 | 334 bsf FLAG_active_descent ; Set Flag |
0 | 335 return |
336 | |
337 divemode_apnoe_tasks2: | |
560 | 338 btfss FLAG_active_descent ; Are we descending? |
339 return ; No, We are at the surface | |
340 rcall apnoe_calc_maxdepth ; Yes! | |
341 call TFT_apnoe_clear_surface ; Clear Surface timer | |
342 clrf apnoe_timeout_counter ; Delete timeout | |
0 | 343 clrf apnoe_surface_secs |
344 clrf apnoe_surface_mins | |
345 clrf apnoe_secs | |
560 | 346 clrf apnoe_mins ; Reset Descent time |
0 | 347 movlw .0 |
348 movff WREG,max_pressure+0 | |
560 | 349 movff WREG,max_pressure+1 ; Reset Max. Depth |
350 bcf FLAG_active_descent ; Clear flag | |
0 | 351 return |
352 | |
353 global apnoe_calc_maxdepth | |
354 apnoe_calc_maxdepth: | |
355 movff apnoe_max_pressure+0,sub_a+0 | |
356 movff apnoe_max_pressure+1,sub_a+1 | |
357 movff max_pressure+0,sub_b+0 | |
358 movff max_pressure+1,sub_b+1 | |
560 | 359 call subU16 ; sub_c = sub_a - sub_b |
360 ; apnoe_max_pressure<max_pressure -> neg_flag=1 | |
361 ; max_pressure<=apnoe_max_pressure -> neg_flag=0 | |
582 | 362 btfss neg_flag |
0 | 363 return |
560 | 364 ;apnoe_max_pressure<max_pressure |
0 | 365 movff max_pressure+0,apnoe_max_pressure+0 |
366 movff max_pressure+1,apnoe_max_pressure+1 | |
367 return | |
368 | |
560 | 369 ; -------------------------------------------------------------------------------------- |
0 | 370 |
371 calc_deko_divemode: | |
560 | 372 rcall calc_deko_divemode2 ; all deco relevant code is now invoked every second |
373 btfsc twosecupdate | |
374 bra calc_deko_divemode1 | |
375 bsf twosecupdate | |
376 return | |
582 | 377 |
560 | 378 calc_deko_divemode1: ; the following code is invoked every 2 seconds |
379 bcf twosecupdate | |
582 | 380 |
560 | 381 call calc_average_depth ; calculate average depth |
382 call calc_velocity ; calculate vertical velocity and display if > threshold (every two seconds) | |
383 call set_reset_safety_stop ; Set flags for safety stop and/or reset safety stop | |
0 | 384 call TFT_debug_output |
385 | |
560 | 386 btfsc FLAG_apnoe_mode ; Done for Apnoe or Gauge mode |
387 return | |
388 btfsc FLAG_gauge_mode ; Done for Apnoe or Gauge mode | |
389 return | |
390 | |
391 ; Check for a gas change | |
392 goto check_gas_change ; Checks if a better gas should be selected (by user) and return... | |
393 | |
582 | 394 |
560 | 395 calc_deko_divemode2: |
396 btfsc FLAG_gauge_mode ; Done for Apnoe or Gauge mode | |
0 | 397 return |
398 | |
560 | 399 btfsc FLAG_ccr_mode ; In CCR mode? |
400 rcall calc_deko_divemode_sensor ; do sensor data acquisition if applicable by OSTC model | |
0 | 401 |
582 | 402 btfsc FLAG_pscr_mode ; In PSCR mode? |
403 rcall calc_deko_divemode_sensor ; do sensor data acquisition if applicable by OSTC model | |
404 | |
560 | 405 SAFE_2BYTE_COPY amb_pressure,int_I_pres_respiration ; transfer ambient pressure to deco engine |
0 | 406 |
195 | 407 |
560 | 408 ; check deco engine state and switch between normal and alternative plan calculations |
409 ; | |
410 ; Remark: Any reconfigurations done here do only affect the ascent & deco calculation settings, | |
582 | 411 ; not the settings for the calculations done on the real tissues. The later ones are only |
412 ; altered in case of a gas change, or in case of a real bailout or switchback to setpoint | |
413 ; or sensor, respectively. | |
414 ; In case of a gas change or real bailout/switchback, the settings for the deco calculations | |
415 ; are also changed to match the settings for the real tissues. This is done on signal through | |
416 ; 'divemode_gaschange' and will also leave the deco engine status in state as if having done | |
417 ; the alternative plan last. | |
418 | |
560 | 419 ; check state of ascent/deco calculations |
420 movff char_O_deco_status,lo ; get a working copy of char_O_deco_status into bank common | |
421 movlw DECO_STATUS_MASK ; load bit mask covering the deco status bits | |
422 andwf lo,W ; mask out bits showing deco engine computations state | |
423 tstfsz WREG ; check if the last compute cycle has finished (bits 1 and 0 cleared) | |
424 bra calc_deko_divemode2e ; NO - computations still in progress, needs more computation cycles | |
425 btfss lo,DECO_PLAN_FLAG ; YES - computation cycle finished, so check what has been computed | |
426 bra calc_deko_divemode2b ; PLAN bit is cleared i.e. normal plan was done, may do alternative next | |
485 | 427 |
560 | 428 ; The PLAN bit is set, i.e. an alternative plan was computed in the last cycle, or the deco engine has |
429 ; been restarted because of a gas change etc. --> Reconfigure to normal plan for next computation cycle. | |
582 | 430 |
560 | 431 ; reset flags for special calculations |
432 bcf lo,DECO_PLAN_FLAG ; clear flag for alternative plan | |
433 bcf lo,DECO_ASCENT_FLAG ; clear flag for delayed ascent calculation | |
434 bcf lo,DECO_VOLUME_FLAG ; clear flag for gas needs calculation | |
435 movff lo,char_O_deco_status ; write-back char_O_deco_status to deco engine interface | |
0 | 436 |
560 | 437 ; check if a switchback from CCR or pSCR bailout calculation is to be done |
438 btfsc FLAG_ccr_mode ; may a switchback from a CCR bailout calculation be needed? | |
439 bra calc_deko_divemode2a ; in CCR mode, so may need to switch back from bailout calculation | |
440 btfsc FLAG_pscr_mode ; may a switchback from a pSCR bailout calculation be needed? | |
441 bra calc_deko_divemode2a ; in pSCR mode, so may need to switch back from bailout calculation | |
442 bra calc_deko_divemode2e ; not in CCR nor pSCR, so no switchback needed, start normal plan now | |
443 ; (first cycle omits gas needs calculation in OC without delayed ascent) | |
485 | 444 |
560 | 445 ; switch back to loop calculation if last cycle was doing a bailout calculation |
446 calc_deko_divemode2a: | |
447 movff opt_calc_asc_gasvolume,hi ; get the gas volume needs calculation setting | |
448 movf hi,W ; are gas volume calculations turned on? | |
449 bz calc_deko_divemode2e ; NO - can't have done a bailout calculation then, start normal plan | |
450 btfsc is_bailout ; YES - check if a real bailout situation is present | |
451 bra calc_deko_divemode2e ; YES - OC gases have been set by bailout action then, start normal plan | |
452 movff active_gas,WREG ; NO - switch back to loop calculation: get current (diluent) gas, ... | |
582 | 453 call deco_setup_cc_diluents ; ... set up deco calculations in CCR/pSCR mode with diluents, |
454 bra calc_deko_divemode2e ; ... and start in normal plan mode | |
560 | 455 |
456 ; The PLAN bit was cleared, i.e. a normal plan was computed in the last cycle. For the next | |
457 ; computation cycle the mode may be switched to alternative plan, or stay in normal mode... | |
582 | 458 |
560 | 459 calc_deko_divemode2b: |
460 bcf lo,DECO_ASCENT_FLAG ; clear flag for delayed ascent calculation (for safety only) | |
461 btfsc is_bailout ; check if a real bailout situation is present | |
462 bra calc_deko_divemode2c ; YES - stay in normal plan mode and preclude delayed ascent calculation | |
463 movff char_I_extra_time,hi ; NO - get the delayed ascent setting | |
582 | 464 tstfsz hi ; check if delayed ascent calculation is enabled |
465 bsf lo,DECO_ASCENT_FLAG ; YES - set flag for delayed ascent calculation | |
466 tstfsz hi ; check if delayed ascent calculation is enabled (again) | |
467 bsf lo,DECO_PLAN_FLAG ; YES - set flag for alternative plan | |
480
ad8acade5567
NEW: PSCR mode (Passive semi-closed rebreather)
heinrichsweikamp
parents:
473
diff
changeset
|
468 |
560 | 469 ; check if a gas needs calculation shall be done |
470 calc_deko_divemode2c: | |
471 bsf lo,DECO_VOLUME_FLAG ; set gas needs calculation flag (may be cleared again next) | |
582 | 472 TSTOSS opt_calc_asc_gasvolume ; check if gas needs calculation is enabled |
560 | 473 bcf lo,DECO_VOLUME_FLAG ; NO - reset flag again |
474 movff lo,char_O_deco_status ; write-back char_O_deco_status to deco engine interface | |
582 | 475 TSTOSS opt_calc_asc_gasvolume ; check if gas volume calculation is enabled (again) |
560 | 476 bra calc_deko_divemode2e ; NO - no volume calculation, no simulated bailout plan in no case |
582 | 477 |
560 | 478 ; check if conditions are met to calculate a bailout plan |
479 btfsc is_bailout ; check if a real bailout situation is present | |
480 bra calc_deko_divemode2e ; YES - normal plan already does bailout (OC) calculation "for real" | |
481 btfss lo,DECO_MODE_LOOP_FLAG ; NO - have loop mode calculation been done during the normal plan? | |
482 bra calc_deko_divemode2e ; NO - when not in loop mode, no simulated bailout to be done | |
483 bsf lo,DECO_PLAN_FLAG ; YES - set flag for alternative plan | |
582 | 484 movff lo,char_O_deco_status ; write-back char_O_deco_status to deco engine interface |
485 call get_first_gas_to_WREG ; get first OC gas, ... | |
560 | 486 call deco_setup_oc_gases ; ... set up deco calculations in OC mode with OC gases, |
487 ;bra calc_deko_divemode2e ; ... and start in alternative plan mode | |
488 | |
489 | |
490 calc_deko_divemode2e: | |
582 | 491 clrf TMR5L |
492 clrf TMR5H ; 30,51757813µs/bit in TMR5L:TMR5H | |
0 | 493 call deco_calc_hauptroutine ; calc_tissue |
582 | 494 banksel common |
0 | 495 |
582 | 496 ; Check if deco stops are necessary |
497 movff char_O_first_deco_depth,WREG; get ceiling | |
498 tstfsz WREG ; ceiling < 0m (aka in deco) ? | |
499 bra calc_deko_divemode3 ; YES | |
500 ; NO - within NDL | |
501 btfsc decostop_active ; already in no deco mode ? | |
502 bsf FLAG_TFT_display_ndl_mask ; NO - clear deco data, display NDL time | |
503 bsf FLAG_TFT_display_ndl ; display NDL time | |
504 bcf decostop_active ; clear flag (again) | |
560 | 505 return |
0 | 506 |
507 calc_deko_divemode3: | |
582 | 508 ; YES - in deco |
509 btfss decostop_active ; already in deco mode ? | |
510 bsf FLAG_TFT_display_deko_mask ; NO - clear NDL time, display deco data | |
511 bsf FLAG_TFT_display_deko ; display deco data | |
512 bsf FLAG_TFT_display_tts ; display TTS | |
513 bsf decostop_active ; set flag (again) | |
560 | 514 return |
515 | |
516 ; -------------------------------------------------------------------------------------- | |
0 | 517 |
560 | 518 global calc_deko_divemode_sensor |
519 calc_deko_divemode_sensor: | |
520 ; sensor acquisition code | |
582 | 521 btfss s8_digital ; check if we have a digital interface to the sensors |
522 bra calc_deko_divemode_sensor_analog ; NO - check if we have an analog interface | |
523 btfss new_s8_data_available ; YES - check if a new data frame was received | |
524 bra calc_deko_divemode_sensor_common ; NO - use old values -- TODO: add timeout for no new data | |
525 call compute_mvolts_for_all_sensors ; YES - compute mV values from digital data | |
526 bra calc_deko_divemode_sensor_common | |
560 | 527 |
583 | 528 calc_deko_divemode_sensor_opt: |
529 btfss optical_input ; do we have an optical input? | |
530 return ; No, return (We have no sensors at all. Not analog, not S8 and not optical) | |
531 ;o2_ppo2_sensor1, o2_ppo2_sensor2 and o2_ppo2_sensor3 are already filled in ISR | |
532 ;clear use_O2_sensorX for timeout case | |
533 btfss sensor1_active | |
534 bcf use_O2_sensor1 | |
535 btfss sensor2_active | |
536 bcf use_O2_sensor2 | |
537 btfss sensor3_active | |
538 bcf use_O2_sensor3 | |
539 bra calc_deko_divemode_sensor1 | |
540 | |
560 | 541 calc_deko_divemode_sensor_analog: |
582 | 542 btfss analog_o2_input ; do we have an analog input? |
583 | 543 bra calc_deko_divemode_sensor_opt ; NO - check if we have an optical interface |
582 | 544 call get_analog_inputs ; YES - get the analog voltages and continue with the common part |
560 | 545 |
546 calc_deko_divemode_sensor_common: | |
547 ; Check for each sensor if it is calibrated and if its mv value is within min_mv and max_mv limits. | |
582 | 548 ; If ok: compute o2_ppo2_sensorX := o2_mv_sensorX * opt_x_sX / 1000 |
549 ; If not ok: reset o2_ppo2_sensorX, reset use_O2_sensorX and show the customview 1 in case the sensor was ok before | |
0 | 550 |
560 | 551 ; Check min_mv of sensor 1 |
582 | 552 btfss sensor1_calibrated_ok ; check if sensor is usable at all |
553 bra check_sensor_1_fail ; NO - handle it as failed | |
554 movff o2_mv_sensor1+0, sub_a+0 ; load sensor mV value | |
560 | 555 movff o2_mv_sensor1+1, sub_a+1 |
582 | 556 movlw LOW min_mv ; load minimum mV value |
560 | 557 movwf sub_b+0 |
582 | 558 movlw HIGH min_mv |
560 | 559 movwf sub_b+1 |
582 | 560 call sub16 ; sub_c = sensor_mv - min_mv |
561 btfsc neg_flag ; check if result is negative, i.e. sensor_mv < min_mv | |
562 bra check_sensor_1_fail ; YES - declare sensor as failed | |
563 ; Check max_mv of sensor 1 ; NO - continue with next check | |
560 | 564 movff o2_mv_sensor1+0, sub_a+0 |
565 movff o2_mv_sensor1+1, sub_a+1 | |
582 | 566 movlw LOW max_mv |
560 | 567 movwf sub_b+0 |
582 | 568 movlw HIGH max_mv |
560 | 569 movwf sub_b+1 |
582 | 570 call sub16 ; sub_c = sensor_mv - max_mv |
571 btfss neg_flag ; check if result is negative, i.e. sensor_mv < max_mv | |
572 bra check_sensor_1_fail ; NO - declare sensor as failed | |
573 ; Check HUD data, if available ; YES - continue with next check | |
574 btfss hud_connection_ok ; check if there is a HUD connected | |
575 bra check_sensor_1_ok ; NO - all checks done then and positive | |
576 btfss sensor1_active ; YES - check HUD report on sensor | |
577 bra check_sensor_1_fail ; HUD reports a fail | |
560 | 578 |
579 check_sensor_1_ok: | |
580 ; o2_ppo2_sensor1 := o2_mv_sensor1:2 * opt_x_s1:2 / 1000 | |
581 movff o2_mv_sensor1+0,xA+0 | |
582 movff o2_mv_sensor1+1,xA+1 | |
583 movff opt_x_s1+0,xB+0 | |
584 movff opt_x_s1+1,xB+1 | |
585 rcall compute_ppo2_helper | |
582 | 586 movff xC+0,o2_ppo2_sensor1 ; result in 0.01bar |
587 bra check_sensor_2 ; continue with next sensor | |
560 | 588 |
589 check_sensor_1_fail: | |
590 clrf WREG | |
582 | 591 movff WREG,o2_ppo2_sensor1 ; set ppO2 reading to zero |
592 btfss use_O2_sensor1 ; check if sensor was in use before | |
593 bra check_sensor_1_fail_1 ; NO - no new news then | |
594 call check_sensor_custview_helper; YES - show customview 1 (sensor values) on further conditions met | |
560 | 595 check_sensor_1_fail_1: |
582 | 596 bcf use_O2_sensor1 ; revoke sensor from usage |
597 ;bra check_sensor_2 ; continue with next sensor | |
277
24daa6523218
1.79beta - update internal sensor registers during boot
heinrichsweikamp
parents:
275
diff
changeset
|
598 |
582 | 599 check_sensor_2: ; Check min_mv of sensor 2 |
600 btfss sensor2_calibrated_ok ; check if sensor is usable at all | |
601 bra check_sensor_2_fail ; NO - handle it as failed | |
602 movff o2_mv_sensor2+0, sub_a+0 ; load sensor mV value | |
560 | 603 movff o2_mv_sensor2+1, sub_a+1 |
582 | 604 movlw LOW min_mv ; load minimum mV value |
560 | 605 movwf sub_b+0 |
582 | 606 movlw HIGH min_mv |
560 | 607 movwf sub_b+1 |
582 | 608 call sub16 ; sub_c = sensor_mv - min_mv |
609 btfsc neg_flag ; check if result is negative, i.e. sensor_mv < min_mv | |
610 bra check_sensor_2_fail ; YES - declare sensor as failed | |
611 ; Check max_mv of sensor 2 ; NO - continue with next check | |
560 | 612 movff o2_mv_sensor2+0, sub_a+0 |
613 movff o2_mv_sensor2+1, sub_a+1 | |
582 | 614 movlw LOW max_mv |
560 | 615 movwf sub_b+0 |
582 | 616 movlw HIGH max_mv |
560 | 617 movwf sub_b+1 |
582 | 618 call sub16 ; sub_c = sensor_mv - max_mv |
619 btfss neg_flag ; check if result is nagative, i.e. sensor_mv < max_mv | |
620 bra check_sensor_2_fail ; NO - declare sensor as failed | |
621 ; Check HUD data, if available ; YES - continue with next check | |
622 btfss hud_connection_ok ; check if there is a HUD connected | |
623 bra check_sensor_2_ok ; NO - all checks done then and positive | |
624 btfss sensor2_active ; YES - check HUD report on sensor | |
625 bra check_sensor_2_fail ; HUD reports a fail | |
277
24daa6523218
1.79beta - update internal sensor registers during boot
heinrichsweikamp
parents:
275
diff
changeset
|
626 |
560 | 627 check_sensor_2_ok: |
628 ; o2_ppo2_sensor2 := o2_mv_sensor2:2 * opt_x_s2:2 / 1000 | |
629 movff o2_mv_sensor2+0,xA+0 | |
630 movff o2_mv_sensor2+1,xA+1 | |
631 movff opt_x_s2+0,xB+0 | |
632 movff opt_x_s2+1,xB+1 | |
633 rcall compute_ppo2_helper | |
582 | 634 movff xC+0,o2_ppo2_sensor2 ; result in 0.01bar |
635 bra check_sensor_3 ; continue with next sensor | |
560 | 636 |
637 check_sensor_2_fail: | |
638 clrf WREG | |
582 | 639 movff WREG,o2_ppo2_sensor2 ; set ppO2 reading to zero |
640 btfss use_O2_sensor2 ; check if sensor was in use before | |
641 bra check_sensor_2_fail_1 ; NO - no new news then | |
642 call check_sensor_custview_helper; YES - show customview 1 (sensor values) on further conditions met | |
560 | 643 check_sensor_2_fail_1: |
582 | 644 bcf use_O2_sensor2 ; revoke sensor from usage |
645 ;bra check_sensor_3 ; continue with next sensor | |
277
24daa6523218
1.79beta - update internal sensor registers during boot
heinrichsweikamp
parents:
275
diff
changeset
|
646 |
582 | 647 check_sensor_3: ; Check min_mv of sensor 2 |
648 btfss sensor3_calibrated_ok ; check if sensor is usable at all | |
649 bra check_sensor_3_fail ; NO - handle it as failed | |
650 movff o2_mv_sensor3+0, sub_a+0 ; load sensor mV value | |
560 | 651 movff o2_mv_sensor3+1, sub_a+1 |
582 | 652 movlw LOW min_mv ; load minimum mV value |
560 | 653 movwf sub_b+0 |
582 | 654 movlw HIGH min_mv |
560 | 655 movwf sub_b+1 |
582 | 656 call sub16 ; sub_c = sensor_mv - min_mv |
657 btfsc neg_flag ; check if result is negative, i.e. sensor_mv < min_mv | |
658 bra check_sensor_3_fail ; YES - declare sensor as failed | |
659 ; Check max_mv of sensor 2 ; NO - continue with next check | |
560 | 660 movff o2_mv_sensor3+0, sub_a+0 |
661 movff o2_mv_sensor3+1, sub_a+1 | |
582 | 662 movlw LOW max_mv |
560 | 663 movwf sub_b+0 |
582 | 664 movlw HIGH max_mv |
560 | 665 movwf sub_b+1 |
582 | 666 call sub16 ; sub_c = sensor_mv - max_mv |
667 btfss neg_flag ; check if result is negative, i.e. sensor_mv < max_mv | |
668 bra check_sensor_3_fail ; NO - declare sensor as failed | |
669 ; Check HUD data, if available ; YES - continue with next check | |
670 btfss hud_connection_ok ; check if there is a HUD connected | |
671 bra check_sensor_3_ok ; NO - all checks done then and positive | |
672 btfss sensor3_active ; YES - check HUD report on sensor | |
673 bra check_sensor_3_fail ; HUD reports a fail | |
0 | 674 |
560 | 675 check_sensor_3_ok: |
676 ; o2_ppo2_sensor3 := o2_mv_sensor3:2 * opt_x_s1:2 / 1000 | |
677 movff o2_mv_sensor3+0,xA+0 | |
678 movff o2_mv_sensor3+1,xA+1 | |
679 movff opt_x_s3+0,xB+0 | |
680 movff opt_x_s3+1,xB+1 | |
681 rcall compute_ppo2_helper | |
582 | 682 movff xC+0,o2_ppo2_sensor3 ; result in 0.01bar |
683 bra calc_deko_divemode_sensor1 ; continue with calculating sensor average | |
0 | 684 |
560 | 685 check_sensor_3_fail: |
686 clrf WREG | |
582 | 687 movff WREG,o2_ppo2_sensor3 ; set ppO2 reading to zero |
688 btfss use_O2_sensor3 ; check if sensor was in use before | |
689 bra check_sensor_3_fail_1 ; NO - no new news then | |
690 call check_sensor_custview_helper; YES - show customview 1 (sensor values) on further conditions met | |
560 | 691 check_sensor_3_fail_1: |
582 | 692 bcf use_O2_sensor3 ; revoke sensor from usage |
693 ;bra calc_deko_divemode_sensor1 ; continue with calculating sensor average | |
694 | |
695 calc_deko_divemode_sensor1: ; calculate sensor average | |
560 | 696 ; exit here if not in divemode |
697 btfss divemode | |
698 return | |
699 | |
700 ; compute sensor_setpoint := average of all o2_ppo2_sensorX of those sensors that have use_O2_sensorX == true | |
582 | 701 ; sum up sensor values (in xA:2) and active sensors in (xB:2) |
702 clrf xB+0 | |
703 clrf xB+1 | |
704 clrf xA+0 | |
705 clrf xA+1 | |
706 btfss use_O2_sensor1 ; Sensor1 active? | |
707 bra divemode_setup_sensor_values2 ; No | |
708 movf o2_ppo2_sensor1,W | |
709 addwf xA+0 | |
710 movlw .0 | |
711 addwfc xA+1 ; Add into xA:2 | |
712 incf xB+0,F ; Add a sensor | |
0 | 713 divemode_setup_sensor_values2: |
582 | 714 btfss use_O2_sensor2 ; Sensor2 active? |
715 bra divemode_setup_sensor_values3 ; No | |
716 movf o2_ppo2_sensor2,W | |
717 addwf xA+0 | |
718 movlw .0 | |
719 addwfc xA+1 ; Add into xA:2 | |
720 incf xB+0,F ; Add a sensor | |
0 | 721 divemode_setup_sensor_values3: |
582 | 722 btfss use_O2_sensor3 ; Sensor3 active? |
723 bra divemode_setup_sensor_values4 ; No | |
724 movf o2_ppo2_sensor3,W | |
725 addwf xA+0 | |
726 movlw .0 | |
727 addwfc xA+1 ; Add into xA:2 | |
728 incf xB+0,F ; Add a sensor | |
560 | 729 |
730 ; Divide sum of sensor values by number of active sensors found. | |
0 | 731 divemode_setup_sensor_values4: |
582 | 732 call div16x16 ; xA/xB=xC with xA+0 as remainder |
733 movff xC+0,sensor_setpoint ; copy result | |
734 | |
560 | 735 ; set default value for pSCR mode: 0 = let p2_deco.c compute the ppO2 based on current dil gas and depth |
736 ; will be overwritten later in case we are in sensor mode and have at least one usable sensor | |
582 | 737 clrf WREG ; preload a zero |
738 btfsc FLAG_pscr_mode ; check if we are in pSCR mode | |
739 movff WREG,char_I_const_ppO2 ; YES - write 0 to char_I_const_ppo2, | |
740 ; it will be overwritten if we have a usable sensor reading | |
741 | |
742 btfsc is_bailout ; check if we are in bailout | |
743 bra calc_deko_divemode_sensor2 ; YES - no sensor data transfer to char_I_const_ppO2 in this case | |
744 movff opt_ccr_mode,WREG ; =0: Fixed SP, =1: Sensor, =2: Auto SP | |
745 sublw .1 ; opt_ccr_mode = 1 (Sensor)? | |
746 bnz calc_deko_divemode_sensor2 ; not in sensor mode - no transfer of sensor data to char_I_const_ppO2 | |
747 tstfsz xB+0 ; check if we have found at least one usable sensor | |
748 bra calc_deko_divemode_sensor1a ; YES - we have at least one usable sensor | |
749 bsf setpoint_fallback ; NO - we have NO usable sensors -> initiate fallback | |
750 btfss FLAG_ccr_mode ; check if we are in CCR mode | |
751 bra calc_deko_divemode_sensor2 ; NO - continue with voting logic flags | |
560 | 752 movff char_I_setpoint_cbar+0,char_I_const_ppO2 ; YES - select fixed setpoint no. 1 for fallback |
582 | 753 bra calc_deko_divemode_sensor2 ; done - continue with voting logic flags |
754 calc_deko_divemode_sensor1a: ; we have at least one usable sensor with a value > 0 | |
755 bcf setpoint_fallback ; clear fallback condition | |
560 | 756 movff sensor_setpoint,char_I_const_ppO2 ; transfer average sensor value to p2_deco.c code |
582 | 757 ;bra calc_deko_divemode_sensor2 |
560 | 758 |
759 calc_deko_divemode_sensor2: | |
582 | 760 bsf voting_logic_sensor1 |
761 movff o2_ppo2_sensor1,lo | |
762 rcall check_sensor_voting_helper | |
763 incfsz WREG ; Was WREG = 255? | |
764 bcf voting_logic_sensor1 ; No, ignore this sensor | |
560 | 765 |
582 | 766 bsf voting_logic_sensor2 |
767 movff o2_ppo2_sensor2,lo | |
768 rcall check_sensor_voting_helper | |
769 incfsz WREG ; Was WREG=255? | |
770 bcf voting_logic_sensor2 ; No, ignore this sensor | |
560 | 771 |
582 | 772 bsf voting_logic_sensor3 |
773 movff o2_ppo2_sensor3,lo | |
774 rcall check_sensor_voting_helper | |
775 incfsz WREG ; Was WREG=255? | |
776 bcf voting_logic_sensor3 ; No, ignore this sensor | |
777 | |
560 | 778 ; check if a warning shall be issued on sensor disagreement |
779 | |
582 | 780 btfsc FLAG_ccr_mode ; check if we are in CCR mode |
781 bra check_warn_sensor_1 ; YES - continue with further checks | |
782 btfsc FLAG_pscr_mode ; check if we are in pSCR mode | |
783 bra check_warn_sensor_1 ; YES - continue with further checks | |
784 bra check_warn_sensor_agree ; not in CCR and not in pSCR, so no warning | |
785 check_warn_sensor_1: ; we are in CCR or pSCR mode | |
786 btfsc is_bailout ; check if we are in bailout | |
787 bra check_warn_sensor_agree ; YES - no warning in this case | |
788 movff opt_ccr_mode,WREG ; =0: Fixed SP, =1: Sensor, =2: Auto SP | |
789 sublw .1 ; opt_ccr_mode = 1 (Sensor)? | |
790 bnz check_warn_sensor_agree ; not in sensor mode - no warning in this case | |
791 ; check sensor 1 | |
792 btfss sensor1_calibrated_ok ; check if sensor has a valid calibration | |
793 bra check_warn_sensor_2 ; NO - sensor can not cause a warning then | |
794 btfss use_O2_sensor1 ; YES - check if sensor is in use | |
795 bra check_warn_sensor_2 ; NO - sensor can not cause a warning then | |
796 btfsc voting_logic_sensor1 ; YES - check if sensor value is within agreement range | |
797 bra check_warn_sensor_2 ; YES - continue with next sensor | |
798 bcf sensors_agree ; NO - issue a warning | |
560 | 799 return |
800 | |
582 | 801 check_warn_sensor_2: ; check sensor 2 |
802 btfss sensor2_calibrated_ok ; check if sensor has a valid calibration | |
803 bra check_warn_sensor_3 ; NO - sensor can not cause a warning then | |
804 btfss use_O2_sensor2 ; YES - check if sensor is in use | |
805 bra check_warn_sensor_3 ; NO - sensor can not cause a warning then | |
806 btfsc voting_logic_sensor2 ; YES - check if sensor value is within agreement range | |
807 bra check_warn_sensor_3 ; YES - continue with next sensor | |
808 bcf sensors_agree ; NO - issue a warning | |
560 | 809 return |
582 | 810 |
811 check_warn_sensor_3: ; check sensor 2 | |
812 btfss sensor3_calibrated_ok ; check if sensor has a valid calibration | |
813 bra check_warn_sensor_agree ; NO - sensor can not cause a warning then | |
814 btfss use_O2_sensor3 ; YES - check if sensor is in use | |
815 bra check_warn_sensor_agree ; NO - sensor can not cause a warning then | |
816 btfsc voting_logic_sensor3 ; YES - check if sensor value is within agreement range | |
817 bra check_warn_sensor_agree ; YES - continue with next sensor | |
818 bcf sensors_agree ; NO - issue a warning | |
560 | 819 return |
582 | 820 |
560 | 821 check_warn_sensor_agree: |
822 bsf sensors_agree | |
823 return | |
824 | |
825 compute_ppo2_helper: | |
582 | 826 call mult16x16 ; xA:2*xB:2=xC:4 |
827 movlw LOW .1000 | |
560 | 828 movwf xB+0 |
582 | 829 movlw HIGH .1000 |
560 | 830 movwf xB+1 |
582 | 831 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder |
560 | 832 movlw d'1' |
582 | 833 addwf xC+0,W ; we are just interested in the carry flag |
560 | 834 movlw d'0' |
582 | 835 addwfc xC+1,W ; we are still just interested in the carry flag |
836 tstfsz WREG ; ppO2 is higher than 2.55bar? | |
837 setf xC+0 ; Yes. | |
838 return | |
0 | 839 |
560 | 840 check_sensor_custview_helper: |
582 | 841 btfss divemode ; check if we are in divemode |
842 return ; NO - not in dive mode, return | |
843 movff opt_ccr_mode,WREG ; =0: Fixed SP, =1: Sensor, =2: Auto SP | |
844 sublw .1 ; opt_ccr_mode = 1 (Sensors)? | |
845 bnz check_sensor_helper_1 ; NO - not using the sensors in the moment | |
846 clrf menupos3 ; YES - arm customview 1 (sensor values) | |
847 bsf toggle_customview ; and request a customview toggle | |
560 | 848 check_sensor_helper_1: |
849 return | |
850 | |
582 | 851 |
560 | 852 check_sensor_voting_helper: |
582 | 853 movf lo,W |
854 cpfsgt sensor_setpoint | |
855 bra check_sensor_voting_common2 ; lo < sensor_setpoint | |
856 ; lo > sensor_setpoint | |
857 movf lo,W | |
858 subwf sensor_setpoint,W | |
859 movwf lo | |
560 | 860 check_sensor_voting_common1: |
582 | 861 movlw sensor_voting_logic_threshold ; Threshold in 0.01 bar |
862 cpfsgt lo | |
863 retlw .255 ; Within range | |
864 retlw .0 ; Out of range | |
560 | 865 check_sensor_voting_common2: |
582 | 866 ; lo<sensor_setpoint |
867 movf sensor_setpoint,W | |
868 subwf lo,F | |
869 bra check_sensor_voting_common1 | |
870 | |
560 | 871 ;----------------------------------------------------------------------------- |
872 | |
582 | 873 divemodemode_togglegf: ; Toggle aGF/GF |
874 bcf toggle_gf ; clear flag | |
875 btg use_agf ; toggle GF | |
560 | 876 |
582 | 877 btfsc use_agf ; switch to aGF? |
878 bra divemodemode_togglegf_1 ; YES - branch to using aGF | |
879 movff opt_GF_low,char_I_GF_Low_percentage ; NO - use normal GF factors | |
880 movff opt_GF_high,char_I_GF_High_percentage ; | |
881 bra divemodemode_togglegf_2 ; continue with common part | |
560 | 882 |
582 | 883 divemodemode_togglegf_1: ; use alternative GF factors |
560 | 884 movff opt_aGF_low,char_I_GF_Low_percentage |
885 movff opt_aGF_high,char_I_GF_High_percentage | |
886 | |
582 | 887 divemodemode_togglegf_2: |
888 call TFT_gf_mask ; update customview mask to show which one is in use | |
889 ; the customview itself has been called from divemenu_tree before | |
890 goto restart_deco_engine ; ...and return | |
560 | 891 |
892 | |
582 | 893 calc_velocity: ; called every two seconds |
894 btfsc display_velocity | |
895 bra calc_velocity1 ; Always update if already displayed | |
896 btfss divemode2 | |
897 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
|
898 calc_velocity1: |
582 | 899 SAFE_2BYTE_COPY amb_pressure, sub_a |
0 | 900 movff last_pressure_velocity+0,sub_b+0 |
901 movff last_pressure_velocity+1,sub_b+1 | |
902 movff sub_a+0,last_pressure_velocity+0 ; store old value for velocity | |
903 movff sub_a+1,last_pressure_velocity+1 | |
904 | |
582 | 905 call subU16 ; sub_c = amb_pressure - last_pressure |
0 | 906 |
582 | 907 bcf neg_flag_velocity |
908 btfsc neg_flag | |
909 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
|
910 |
0 | 911 movff sub_c+0,xA+0 |
912 movff sub_c+1,xA+1 | |
582 | 913 movlw d'39' ; 77 when called every second.... |
0 | 914 movwf xB+0 |
915 clrf xB+1 | |
582 | 916 call mult16x16 ; differential pressure in mbar*77... |
0 | 917 movff xC+0,divA+0 |
918 movff xC+1,divA+1 | |
919 movlw d'7' | |
920 movwf divB+0 | |
582 | 921 call div16 ; divided by 2^7 equals velocity in m/min |
0 | 922 |
923 movlw d'99' | |
582 | 924 cpfsgt divA+0 ; limit to 99m/min |
0 | 925 bra calc_velocity3 |
582 | 926 movwf divA+0 ; divA=99 |
0 | 927 |
928 calc_velocity3: | |
582 | 929 ; Copy old speeds |
930 movff old_velocity+2,old_velocity+3 | |
931 movff old_velocity+1,old_velocity+2 | |
932 movff old_velocity+0,old_velocity+1 | |
933 movff divA+0,old_velocity+0 | |
934 | |
935 ; movff old_velocity+3,WREG | |
936 ; addwf divA+0,F ; add old speed | |
937 ; bcf STATUS,C | |
938 ; rrcf divA+0,F ; /2 | |
939 ; movff old_velocity+2,WREG | |
940 ; addwf divA+0,F ; add old speed | |
941 ; bcf STATUS,C | |
942 ; rrcf divA+0,F ; /2 | |
943 ; movff old_velocity+1,WREG | |
944 ; addwf divA+0,F ; add old speed | |
945 ; bcf STATUS,C | |
946 ; rrcf divA+0,F ; /2 | |
947 ; movff old_velocity+0,WREG | |
948 ; addwf divA+0,F ; add old speed | |
949 ; bcf STATUS,C | |
950 ; rrcf divA+0,F ; /2 | |
951 goto TFT_display_velocity ; With divA+0 = m/min..., and return... | |
0 | 952 |
953 | |
954 ;============================================================================= | |
955 | |
582 | 956 set_reset_safety_stop: ; Set flags for safety stop and/or reset safety stop |
957 TSTOSS opt_enable_safetystop ; =1: A safety stop is shown | |
958 bra delete_safety_stop ; No, don't show safety stop | |
104
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
959 |
582 | 960 btfsc decostop_active ; Is a deco stop displayed? |
961 bra delete_safety_stop ; Yes, don't show safety stop | |
560 | 962 |
399
db25f2028074
CHANGE: New segmented speed graph in divemode
heinrichsweikamp
parents:
398
diff
changeset
|
963 ; Below "opt_safety_stop_reset"? Set flag and reset count-down timer |
582 | 964 SAFE_2BYTE_COPY rel_pressure, lo |
965 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
|
966 movff lo,sub_a+0 |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
967 movff hi,sub_a+1 |
582 | 968 movff opt_safety_stop_reset,WREG ; [cbar] |
969 mullw .10 ; mbar in PRODL:H | |
970 movff PRODL,sub_b+0 | |
971 movff PRODH,sub_b+1 | |
972 call subU16 ; sub_c = sub_a - sub_b | |
104
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
973 btfss neg_flag |
582 | 974 bra reset_safety_stop ; Below 10m, reset safety stop |
104
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
975 |
399
db25f2028074
CHANGE: New segmented speed graph in divemode
heinrichsweikamp
parents:
398
diff
changeset
|
976 ; Above "opt_safety_stop_end"? Clear flag. |
582 | 977 SAFE_2BYTE_COPY rel_pressure, lo |
978 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
|
979 movff lo,sub_a+0 |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
980 movff hi,sub_a+1 |
582 | 981 movff opt_safety_stop_end,WREG ; [cbar] |
982 mullw .10 ; mbar in PRODL:H | |
983 movff PRODL,sub_b+0 | |
984 movff PRODH,sub_b+1 | |
985 call subU16 ; sub_c = sub_a - sub_b | |
104
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
986 btfsc neg_flag |
582 | 987 bra delete_safety_stop ; Above 3m, remove safety stop |
104
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
988 |
399
db25f2028074
CHANGE: New segmented speed graph in divemode
heinrichsweikamp
parents:
398
diff
changeset
|
989 ; Above "opt_safety_stop_start"? Activate safety stop |
582 | 990 SAFE_2BYTE_COPY rel_pressure, lo |
991 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
|
992 movff lo,sub_a+0 |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
993 movff hi,sub_a+1 |
582 | 994 movff opt_safety_stop_start,WREG ; [cbar] |
995 mullw .10 ; mbar in PRODL:H | |
996 movff PRODL,sub_b+0 | |
997 movff PRODH,sub_b+1 | |
998 call subU16 ; sub_c = sub_a - sub_b | |
104
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
999 btfsc neg_flag |
582 | 1000 bra acivate_safety_stop ; Above 5m, activate safety stop |
1001 bra reset_safety_stop2 ; Pause safety stop | |
104
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
1002 |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
1003 acivate_safety_stop: |
582 | 1004 tstfsz safety_stop_countdown ; Countdown at zero? |
1005 bsf show_safety_stop ; No, Set flag! | |
104
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
1006 return |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
1007 |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
1008 delete_safety_stop: |
582 | 1009 clrf safety_stop_countdown ; reset timer |
1010 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
|
1011 |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
1012 reset_safety_stop: |
582 | 1013 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
|
1014 reset_safety_stop2: |
582 | 1015 bcf show_safety_stop ; Clear flag |
1016 btfss safety_stop_active ; Safety stop shown | |
1017 return ; No, don't delete it | |
1018 bcf safety_stop_active ; Clear flag | |
1019 bsf FLAG_TFT_clear_safety_stop ; Clear safety stop | |
1020 return | |
428 | 1021 |
104
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
1022 |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
1023 ;============================================================================= |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
1024 |
0 | 1025 timeout_menuview: |
582 | 1026 decfsz timeout_counter2,F ; timeout for menuview |
1027 return ; No timeout, return | |
1028 ; Timeout, clear e.g. "Menu?" | |
1029 goto menuview_toggle_reset ; "returns" | |
0 | 1030 |
1031 timeout_divemode_menu: | |
582 | 1032 decfsz timeout_counter2,F ; timeout for divemode menu |
1033 return | |
0 | 1034 |
582 | 1035 global timeout_divemode_menu2 |
1036 timeout_divemode_menu2: ; Called from divemenu_tree.asm | |
1037 bcf divemode_menu ; Timeout! Clear flag | |
1038 call TFT_clear_divemode_menu ; Clear menu | |
1039 bsf FLAG_TFT_active_gas_divemode; Redraw gas/setpoint/diluent | |
1040 bcf blinking_better_gas ; Clear flag to have temperature updated once | |
1041 bsf FLAG_TFT_temp_divemode ; Displays temperature | |
1042 call TFT_draw_gassep_line ; Gas separator grid in spec mode only | |
0 | 1043 |
582 | 1044 btfss decostop_active ; In deco mode ? |
1045 bra timeout_divemode_menu_ndl ; No, show NDL again | |
1046 ; Show deco | |
1047 bsf FLAG_TFT_display_deko_mask | |
1048 bsf FLAG_TFT_display_deko | |
1049 bsf FLAG_TFT_display_tts | |
1050 return | |
1051 | |
1052 timeout_divemode_menu_ndl: | |
1053 ; Show NDL | |
1054 bsf FLAG_TFT_display_ndl_mask | |
1055 bsf FLAG_TFT_display_ndl | |
1056 return | |
0 | 1057 |
1058 timeout_divemode: | |
582 | 1059 btfsc divemode_menu ; Divemode menu active? |
1060 rcall timeout_divemode_menu ; Yes, check the timeout for it... | |
0 | 1061 |
582 | 1062 btfsc menuview ; is a menuview shown? |
1063 rcall timeout_menuview ; Yes, check the timeout for it... | |
0 | 1064 |
1065 btfss realdive ; Dive longer then one minute | |
1066 return | |
582 | 1067 |
0 | 1068 btfsc FLAG_apnoe_mode ; In Apnoe mode? |
35
eca4a201d8cf
change apnea timeout, do no longer store apnea dives in logbook
heinrichsweikamp
parents:
23
diff
changeset
|
1069 bra timeout_divemode2 ; Yes, use apnoe_timeout [min] for timeout |
0 | 1070 |
582 | 1071 ifndef __DEBUG |
1072 btfsc simulatormode_active ; In Simulator mode? | |
1073 bra timeout_divemode3 ; Yes, use simulator timeout | |
1074 endif | |
1075 | |
0 | 1076 bcf divemode |
582 | 1077 infsnz timeout_counter1+0,F |
1078 incf timeout_counter1+1,F ; timeout is 16 bit counter | |
0 | 1079 |
582 | 1080 movff opt_diveTimeout,WREG ; in [min] |
444
d93d75ae01bf
Adjustable timeout for Divemode (Config 0x48)
heinrichsweikamp
parents:
437
diff
changeset
|
1081 mullw .60 |
d93d75ae01bf
Adjustable timeout for Divemode (Config 0x48)
heinrichsweikamp
parents:
437
diff
changeset
|
1082 movff PRODL,sub_a+0 |
582 | 1083 movff PRODH,sub_a+1 ; in [s] |
0 | 1084 |
582 | 1085 movff timeout_counter1+0,sub_b+0 |
1086 movff timeout_counter1+1,sub_b+1 | |
1087 call subU16 ; sub_c = sub_a - sub_b | |
0 | 1088 btfss neg_flag ; Result negative? |
1089 bsf divemode ; No, set flag | |
1090 return | |
1091 | |
1092 timeout_divemode2: | |
582 | 1093 incf timeout_counter1+0,F ; seconds... |
0 | 1094 movlw d'60' |
582 | 1095 cpfseq timeout_counter1+0 ; timeout_counter1+0 = 60 ? |
1096 return ; No | |
1097 ; one minute timeout done | |
1098 clrf timeout_counter1+0 | |
0 | 1099 bcf divemode |
1100 incf apnoe_timeout_counter,F | |
1101 movlw apnoe_timeout ; apnoe timeout [min] | |
1102 cpfseq apnoe_timeout_counter | |
1103 bsf divemode | |
1104 return | |
1105 | |
1106 timeout_divemode3: | |
1107 bcf divemode | |
582 | 1108 incf timeout_counter1+0,F |
1109 movlw simulator_timeout ; simulator timeout | |
1110 cpfsgt timeout_counter1+0 | |
0 | 1111 bsf divemode |
1112 return | |
1113 | |
582 | 1114 update_divemode60: ; update any minute |
0 | 1115 call get_battery_voltage ; gets battery voltage |
218 | 1116 rcall set_powersafe ; Battery low? |
0 | 1117 call customview_minute ; Do every-minute tasks for the custom view area |
582 | 1118 bcf oneminupdate |
0 | 1119 |
582 | 1120 btfss simulatormode_active ; in simulator mode? |
1121 return ; No | |
0 | 1122 ; Yes, quite dive mode simulation after 21*256s=89min:36s |
1123 movlw .20 | |
1124 cpfsgt total_divetime_seconds+1 ; Timeout? | |
582 | 1125 return ; No |
1126 | |
1127 ifdef __DEBUG | |
1128 return ; No simulator timeout in debug mode | |
1129 endif | |
1130 | |
1131 bra divemode_option1 ; Yes, set to 0m and "return" | |
0 | 1132 |
1133 set_max_depth: | |
1134 movff max_pressure+0,sub_a+0 | |
1135 movff max_pressure+1,sub_a+1 | |
582 | 1136 SAFE_2BYTE_COPY rel_pressure, sub_b |
1137 call subU16 ; sub_c = sub_a - sub_b | |
1138 ; max_pressure<rel_pressure -> neg_flag=1 | |
1139 ; rel_pressure<=max_pressure -> neg_flag=0 | |
1140 btfss neg_flag | |
0 | 1141 return |
582 | 1142 ; max_pressure<rel_pressure |
0 | 1143 movff sub_b+0,max_pressure+0 |
1144 movff sub_b+1,max_pressure+1 | |
582 | 1145 bsf FLAG_TFT_max_depth ; Set flag |
560 | 1146 return |
0 | 1147 |
1148 set_min_temp: | |
1149 movff minimum_temperature+0,sub_a+0 | |
1150 movff minimum_temperature+1,sub_a+1 | |
582 | 1151 SAFE_2BYTE_COPY temperature,sub_b |
1152 call sub16 ; sub_c = sub_a - sub_b | |
1153 ; minimum_temperature<T -> neg_flag=1 | |
1154 ; T<=minimum_temperature -> neg_flag=0 | |
1155 btfsc neg_flag | |
0 | 1156 return |
582 | 1157 ; minimum_temperature >= T |
0 | 1158 movff sub_b+0,minimum_temperature+0 |
1159 movff sub_b+1,minimum_temperature+1 | |
1160 return | |
1161 | |
1162 global set_dive_modes | |
1163 set_dive_modes: | |
560 | 1164 btfsc high_altitude_mode ; In high altitude (Fly) mode? |
1165 bra set_dive_modes3 ; Yes! | |
0 | 1166 |
1167 set_dive_modes0: | |
582 | 1168 movlw LOW start_dive_threshold |
560 | 1169 movwf sub_a+0 ; dive_treshold is in cm |
582 | 1170 movlw HIGH start_dive_threshold |
560 | 1171 movwf sub_a+1 ; dive_treshold is in cm |
0 | 1172 |
1173 set_dive_modes1: | |
582 | 1174 SAFE_2BYTE_COPY rel_pressure, sub_b |
560 | 1175 call subU16 ; sub_c = sub_a - sub_b |
0 | 1176 |
582 | 1177 btfss neg_flag |
1178 bra set_dive_modes2 ; too shallow (rel_pressure < dive_threshold) | |
0 | 1179 |
560 | 1180 btfsc realdive ; Dive longer than one minute? |
582 | 1181 clrf timeout_counter1+0 ; Yes, reset timeout counter +++ |
0 | 1182 |
560 | 1183 bsf divemode ; (Re-)Set divemode flag |
1184 bsf divemode2 ; displayed divetime is running | |
0 | 1185 return |
1186 | |
1187 set_dive_modes2: | |
560 | 1188 bcf divemode2 ; Stop time |
1189 btfss realdive ; dive longer then one minute? | |
1190 bcf divemode ; no -> this was no real dive | |
1191 return ; No, return | |
0 | 1192 |
1193 | |
560 | 1194 set_dive_modes3: ; High-altitude mode |
1195 btfsc realdive ; dive longer then one minute? | |
1196 bra set_dive_modes0 ; Yes -> this is a real dive -> Use start_dive_threshold or ascend | |
0 | 1197 |
582 | 1198 movlw LOW high_altitude_dive_threshold |
1199 movwf sub_a+0 | |
1200 movlw HIGH high_altitude_dive_threshold | |
0 | 1201 movwf sub_a+1 |
1202 bra set_dive_modes1 | |
1203 | |
1204 set_powersafe: | |
582 | 1205 movlw color_code_battery_low+1; [%] |
1206 cpfslt batt_percent | |
0 | 1207 return |
1208 | |
560 | 1209 movlw d'7' ; Type of Alarm (Battery Low) |
1210 movwf AlarmType ; Copy to Alarm Register | |
582 | 1211 bsf event_occured ; set event flag |
1212 movlw .0 | |
1213 movff WREG,opt_brightness ; Set Brightness to ECO | |
560 | 1214 return ; return |
0 | 1215 |
1216 calc_average_depth: | |
560 | 1217 btfsc reset_average_depth ; Reset the Average depth? |
1218 rcall reset_average1 ; Reset the resettable average depth | |
0 | 1219 |
1220 ; 1. Add new 2xdepth to the Sum of depths registers | |
582 | 1221 SAFE_2BYTE_COPY rel_pressure,xB ; Buffer... |
1222 bcf STATUS,C | |
1223 rlcf xB+0,F | |
1224 rlcf xB+1,F ; x2 | |
0 | 1225 |
1226 movf xB+0,w | |
1227 addwf average_depth_hold+0,F | |
1228 movf xB+1,w | |
1229 addwfc average_depth_hold+1,F | |
1230 movlw d'0' | |
1231 addwfc average_depth_hold+2,F | |
582 | 1232 addwfc average_depth_hold+3,F ; Will work up to 9999mbar*60*60*24=863913600mbar |
0 | 1233 |
560 | 1234 ; Do the same for the _total registers (Non-Resettable) |
0 | 1235 movf xB+0,w |
1236 addwf average_depth_hold_total+0,F | |
1237 movf xB+1,w | |
1238 addwfc average_depth_hold_total+1,F | |
1239 movlw d'0' | |
1240 addwfc average_depth_hold_total+2,F | |
582 | 1241 addwfc average_depth_hold_total+3,F; Will work up to 9999mbar*60*60*24=863913600mbar |
0 | 1242 |
1243 ; 2. Compute Average Depth on base of average_divesecs:2 | |
1244 movff average_divesecs+0,xB+0 | |
1245 movff average_divesecs+1,xB+1 ; Copy | |
1246 movff average_depth_hold+0,xC+0 | |
1247 movff average_depth_hold+1,xC+1 | |
1248 movff average_depth_hold+2,xC+2 | |
1249 movff average_depth_hold+3,xC+3 | |
1250 | |
582 | 1251 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder |
437 | 1252 movff xC+0,avg_rel_pressure+0 |
1253 movff xC+1,avg_rel_pressure+1 | |
0 | 1254 |
582 | 1255 btfss divemode2 ; displayed divetime is running? |
1256 return ; No (e.g. too shallow) | |
89
c34516c99ca8
BUGFIX: No average depth for end-of-dive portion (<1m)
heinrichsweikamp
parents:
86
diff
changeset
|
1257 |
0 | 1258 ; 3. Compute Total Average Depth on base of total_divetime_seconds:2 |
1259 movff total_divetime_seconds+0,xB+0 | |
582 | 1260 movff total_divetime_seconds+1,xB+1 ; Copy |
0 | 1261 movff average_depth_hold_total+0,xC+0 |
1262 movff average_depth_hold_total+1,xC+1 | |
1263 movff average_depth_hold_total+2,xC+2 | |
1264 movff average_depth_hold_total+3,xC+3 | |
582 | 1265 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder |
437 | 1266 movff xC+0,avg_rel_pressure_total+0 |
1267 movff xC+1,avg_rel_pressure_total+1 | |
0 | 1268 return |
1269 | |
1270 reset_average1: | |
1271 clrf average_depth_hold+0 | |
1272 clrf average_depth_hold+1 | |
1273 clrf average_depth_hold+2 | |
1274 clrf average_depth_hold+3 ; Clear average depth register | |
1275 movlw d'2' | |
1276 movwf average_divesecs+0 | |
1277 clrf average_divesecs+1 | |
1278 bcf reset_average_depth ; Clear flag | |
1279 return | |
1280 | |
560 | 1281 test_switches_divemode: ; checks switches in divemode |
582 | 1282 btfsc divemode_menu ; Divemode menu shown? |
1283 bra test_switches_divemode_menu ; Yes, use menu processor | |
0 | 1284 btfsc switch_left |
582 | 1285 ;bra test_switches_divemode2 ; Enter button pressed, check if we need to do something |
1286 goto menuview_toggle ; Menu or Simulator tasks; and return... | |
0 | 1287 btfss switch_right |
582 | 1288 return ; No button press |
1289 tstfsz menupos2 ; any option shown? | |
1290 bra test_switches_divemode1 ; Yes, do option tasks | |
1291 bsf toggle_customview ; No, toggle custom view | |
1292 return | |
0 | 1293 |
1294 test_switches_divemode_menu: | |
1295 btfsc switch_left | |
582 | 1296 bra test_switches_divemode_menu2; Move cursor |
0 | 1297 btfsc switch_right |
582 | 1298 bra test_switches_divemode_menu3; Enter submenu or do something |
1299 return ; No button press | |
0 | 1300 |
1301 test_switches_divemode_menu1: | |
582 | 1302 clrf menupos1 |
0 | 1303 test_switches_divemode_menu2: |
582 | 1304 incf menupos1,F |
1305 incf menupos4,W ; menupos4+1 -> WREG | |
1306 cpfslt menupos1 ; > menupos4 (Set in menu_processor.asm)? | |
1307 bra test_switches_divemode_menu1; > Yes, set to 1 | |
1308 call TFT_divemode_menu_cursor ; Update the cursor | |
1309 bcf switch_left | |
1310 movlw divemode_menu_timeout ; Reload timeout | |
1311 movwf timeout_counter2 ; timeout for divemode menu | |
1312 return | |
0 | 1313 |
582 | 1314 test_switches_divemode_menu3: ; Enter submenu or do something |
1315 bcf switch_right | |
1316 ; decf menupos1,F ; menu_processor needs 0-5... | |
1317 goto do_line_menu ; Warning! Trashes STKPTR and returns to diveloop_loop4: | |
0 | 1318 |
1319 test_switches_divemode1: | |
1320 bcf switch_right | |
582 | 1321 movlw divemode_menuview_timeout |
1322 movwf timeout_counter2 ; Reload timeout | |
1323 movff menupos2,WREG ; menupos2 holds number of customview/divemode menu function | |
0 | 1324 dcfsnz WREG,F |
582 | 1325 bra divemode_option_gaschange ; Switch to the indicated "better gas" |
137 | 1326 dcfsnz WREG,F |
582 | 1327 bra divemode_option0 ; Start/Setup Divemode menu |
0 | 1328 dcfsnz WREG,F |
1329 bra divemode_option1 ; Quit Simulation? | |
1330 dcfsnz WREG,F | |
1331 bra divemode_option2 ; Descent 1m | |
1332 dcfsnz WREG,F | |
1333 bra divemode_option3 ; Ascend 1m | |
1334 dcfsnz WREG,F | |
1335 bra divemode_option4 ; Quit Apnoe mode | |
1336 dcfsnz WREG,F | |
1337 bra divemode_option5 ; Reset Stopwatch (In Gauge mode) | |
216
973a0969e0ac
NEW: On-board simulator can increase divetime in 5min steps
heinrichsweikamp
parents:
206
diff
changeset
|
1338 dcfsnz WREG,F |
973a0969e0ac
NEW: On-board simulator can increase divetime in 5min steps
heinrichsweikamp
parents:
206
diff
changeset
|
1339 bra divemode_option6 ; +5mins simulation |
254
5fe7aff622f3
preparations to set a course for the compass display
heinrichsweikamp
parents:
239
diff
changeset
|
1340 dcfsnz WREG,F |
5fe7aff622f3
preparations to set a course for the compass display
heinrichsweikamp
parents:
239
diff
changeset
|
1341 bra divemode_option7 ; Store heading |
560 | 1342 dcfsnz WREG,F |
1343 bra divemode_option8 ; Switch to alt. layout | |
582 | 1344 return |
0 | 1345 |
1346 gas_switched_common: | |
582 | 1347 bcf divemode_gaschange ; Clear flag |
1348 btfss FLAG_back_to_loop ; check if it is a switchback from OC bailout to loop | |
1349 bra gas_switched_common0 ; NO - continue with checking if selected gas is valid | |
1350 bcf FLAG_back_to_loop ; YES - clear flag | |
1351 movff active_diluent,menupos1 ; reload last diluent | |
1352 bra gas_switched_common1 ; continue with common part | |
1353 gas_switched_common0: | |
1354 tstfsz menupos1 ; menupos1=0? | |
1355 bra gas_switched_common1 ; NO - valid gas | |
1356 return ; YES - something went wrong, invalid gas, abort | |
560 | 1357 gas_switched_common1: |
582 | 1358 movf menupos1,W ; get selected gas into WREG (1-6) |
274
9347893b74ce
BUGFIX: Fast Gas change near the ppO2 limit could cause switching to a non-available Gas #0
heinrichsweikamp
parents:
256
diff
changeset
|
1359 |
582 | 1360 btfsc FLAG_ccr_mode ; in CCR mode? |
560 | 1361 bra gas_switched_common2 ; YES - configure diluent or bailout |
582 | 1362 btfsc FLAG_pscr_mode ; in pSCR mode? |
560 | 1363 bra gas_switched_common2 ; YES - configure diluent or bailout |
582 | 1364 |
560 | 1365 ; OC |
1366 rcall setup_gas_registers ; With WREG = Gas 1-6 | |
582 | 1367 rcall deco_setup_oc_gases ; With WREG = Gas 1-6 |
560 | 1368 bra gas_switched_common3 |
1369 | |
582 | 1370 ; loop or bailout |
506
b9f06f1a1f74
BUGFIX: PSCR mode "Better Gas" showed bailout gases instead of diluents
heinrichsweikamp
parents:
485
diff
changeset
|
1371 gas_switched_common2: |
582 | 1372 rcall setup_dil_registers ; With WREG = diluent 1-6, in case of is_bailout reverts to OC gases |
1373 rcall deco_setup_cc_diluents ; With WREG = diluent 1-6, in case of is_bailout reverts to OC gases | |
1374 | |
560 | 1375 gas_switched_common3: |
582 | 1376 bsf FLAG_TFT_active_gas_divemode ; Redraw gas/setpoint/diluent |
1377 call restart_deco_engine_wo_ceiling ; abort any running deco calculations and restart the deco engine | |
98 | 1378 |
582 | 1379 ; Set flags for profile recording |
1380 bsf event_occured ; set event flag | |
1381 btfsc is_bailout ; Choose OC Bailouts (OC Gases) | |
1382 bsf bailoutgas_event ; Bailout gas change | |
1383 btfss is_bailout ; Choose OC Bailouts (OC Gases) | |
560 | 1384 bsf stored_gas_changed ; OC gas change |
0 | 1385 return |
1386 | |
560 | 1387 |
1388 ; Code to pass all parameters to the C code | |
1389 | |
582 | 1390 global get_first_gas_to_WREG |
560 | 1391 get_first_gas_to_WREG: ; Gets first gas (1-5) into WREG |
582 | 1392 lfsr FSR1,opt_gas_type ; Point to gas types |
1393 clrf lo ; start with Gas0 | |
560 | 1394 get_first_gas_to_WREG2: |
582 | 1395 movf lo,W |
1396 movf PLUSW1,W ; Get Type of Gas #lo | |
1397 sublw .1 ; it is = 1 (First Gas) | |
1398 bz get_first_gas_to_WREG3 ; Found the first gas! | |
1399 incf lo,F ; ++ | |
1400 movlw NUM_GAS+1 | |
1401 cpfseq lo ; All done? | |
1402 bra get_first_gas_to_WREG2 ; Not yet | |
560 | 1403 ; No first gas found, use #1 |
582 | 1404 movlw .0 |
1405 movff WREG,opt_gas_type+0 ; Set Gas1 to First | |
560 | 1406 incf WREG,W ; 0 -> 1 |
1407 return | |
1408 get_first_gas_to_WREG3: | |
582 | 1409 movf lo,W ; Put into Wreg |
560 | 1410 incf WREG,W ; 0-4 -> 1-5 |
1411 return ; Done | |
1412 | |
582 | 1413 global get_first_dil_to_WREG |
560 | 1414 get_first_dil_to_WREG: ; Gets first dil (1-5) into WREG |
582 | 1415 lfsr FSR1,opt_dil_type ; Point to dil types |
1416 clrf lo ; start with Gas0 | |
560 | 1417 get_first_dil_to_WREG2: |
582 | 1418 movf lo,W |
1419 movf PLUSW1,W ; Get Type of Dil #lo | |
1420 sublw .1 ; it is = 1 (First Dil) | |
1421 bz get_first_dil_to_WREG3 ; Found the first dil! | |
1422 incf lo,F ; ++ | |
1423 movlw NUM_GAS+1 | |
1424 cpfseq lo ; All done? | |
1425 bra get_first_dil_to_WREG2 ; Not yet | |
560 | 1426 ; No first dil found, use #1 |
582 | 1427 movlw .0 |
1428 movff WREG,opt_dil_type+0 ; Set Dil1 to First | |
560 | 1429 incf WREG,W ; 0 -> 1 |
1430 return | |
1431 get_first_dil_to_WREG3: | |
582 | 1432 movf lo,W ; Put into Wreg |
560 | 1433 incf WREG,W ; 0-4 -> 1-5 |
1434 return ; Done | |
1435 | |
1436 global deco_setup_oc_gases | |
1437 deco_setup_oc_gases: ; with currently breathed gas in WREG (1-5 or 6) | |
1438 movff WREG,char_I_current_gas ; gas to start with when doing the deco calculations | |
1439 | |
582 | 1440 banksel opt_gas_type ; opt_gas_type[] and opt_OC_bail_gas_change[] are together in bank common2 |
1441 | |
1442 movff opt_gas_He_ratio+0,char_I_deco_He_ratio+0 | |
1443 movff opt_gas_O2_ratio+0,char_I_deco_O2_ratio+0 | |
560 | 1444 |
582 | 1445 movlw .3 ; 3=Deco |
1446 cpfseq opt_gas_type+0 ; Gas is deco type? | |
1447 clrf opt_OC_bail_gas_change+0 ; No, clear depth for 0=Disabled, 1=First and 2=Travel | |
1448 | |
1449 movff opt_gas_He_ratio+1,char_I_deco_He_ratio+1 | |
1450 movff opt_gas_O2_ratio+1,char_I_deco_O2_ratio+1 | |
1451 movlw .3 ; 3=Deco | |
1452 cpfseq opt_gas_type+1 ; Gas is deco type? | |
1453 clrf opt_OC_bail_gas_change+1 ; No, clear depth for 0=Disabled, 1=First and 2=Travel | |
560 | 1454 |
582 | 1455 movff opt_gas_He_ratio+2,char_I_deco_He_ratio+2 |
1456 movff opt_gas_O2_ratio+2,char_I_deco_O2_ratio+2 | |
1457 movlw .3 ; 3=Deco | |
1458 cpfseq opt_gas_type+2 ; Gas is deco type? | |
1459 clrf opt_OC_bail_gas_change+2 ; No, clear depth for 0=Disabled, 1=First and 2=Travel | |
560 | 1460 |
582 | 1461 movff opt_gas_He_ratio+3,char_I_deco_He_ratio+3 |
1462 movff opt_gas_O2_ratio+3,char_I_deco_O2_ratio+3 | |
1463 movlw .3 ; 3=Deco | |
1464 cpfseq opt_gas_type+3 ; Gas is deco type? | |
1465 clrf opt_OC_bail_gas_change+3 ; No, clear depth for 0=Disabled, 1=First and 2=Travel | |
560 | 1466 |
582 | 1467 movff opt_gas_He_ratio+4,char_I_deco_He_ratio+4 |
1468 movff opt_gas_O2_ratio+4,char_I_deco_O2_ratio+4 | |
1469 movlw .3 ; 3=Deco | |
1470 cpfseq opt_gas_type+4 ; Gas is deco type? | |
1471 clrf opt_OC_bail_gas_change+4 ; No, clear depth for 0=Disabled, 1=First and 2=Travel | |
1472 | |
560 | 1473 banksel common |
1474 | |
1475 ; Setup char_I_deco_gas_change array | |
582 | 1476 movff opt_OC_bail_gas_change+0, char_I_deco_gas_change+0 |
1477 movff opt_OC_bail_gas_change+1, char_I_deco_gas_change+1 | |
1478 movff opt_OC_bail_gas_change+2, char_I_deco_gas_change+2 | |
1479 movff opt_OC_bail_gas_change+3, char_I_deco_gas_change+3 | |
1480 movff opt_OC_bail_gas_change+4, char_I_deco_gas_change+4 | |
560 | 1481 |
1482 ; switch to oc mode | |
1483 movff char_O_deco_status,lo ; working copy of char_O_deco_status in bank common | |
1484 bcf lo,DECO_MODE_PSCR_FLAG ; clear the pSCR-mode flag (may not be set, but never mind) | |
1485 bcf lo,DECO_MODE_LOOP_FLAG ; clear the loop/CCR-mode flag | |
1486 movff lo,char_O_deco_status ; bank safe write-back of char_O_deco_status | |
582 | 1487 |
560 | 1488 return |
1489 | |
582 | 1490 |
560 | 1491 global deco_setup_cc_diluents |
1492 deco_setup_cc_diluents: ; with currently breathed gas in WREG (1-5 or 6) | |
1493 btfsc is_bailout ; check if in bailout condition | |
1494 bra deco_setup_oc_gases ; revert to setting up OC gases in bailout condition | |
582 | 1495 |
560 | 1496 movff WREG,char_I_current_gas ; gas to start with when doing the deco calculations |
0 | 1497 |
582 | 1498 movff opt_dil_He_ratio+0,char_I_deco_He_ratio+0 |
1499 movff opt_dil_O2_ratio+0,char_I_deco_O2_ratio+0 | |
1500 movff opt_dil_type+0,WREG ; 0=Disabled, 1=First, 2=Normal | |
1501 tstfsz WREG ; Disabled? | |
1502 bra $+4 ; No | |
1503 movff WREG,char_I_dil_change+0 ; Yes, clear char_I_deco_gas_change (Bank safe) | |
560 | 1504 |
582 | 1505 movff opt_dil_He_ratio+1,char_I_deco_He_ratio+1 |
1506 movff opt_dil_O2_ratio+1,char_I_deco_O2_ratio+1 | |
1507 movff opt_dil_type+1,WREG ; 0=Disabled, 1=First, 2=Normal | |
1508 tstfsz WREG ; Disabled? | |
1509 bra $+4 ; No | |
1510 movff WREG,char_I_dil_change+1 ; Yes, clear char_I_dil_change | |
560 | 1511 |
582 | 1512 movff opt_dil_He_ratio+2,char_I_deco_He_ratio+2 |
1513 movff opt_dil_O2_ratio+2,char_I_deco_O2_ratio+2 | |
1514 movff opt_dil_type+2,WREG ; 0=Disabled, 1=First, 2=Normal | |
1515 tstfsz WREG ; Disabled? | |
1516 bra $+4 ; No | |
1517 movff WREG,char_I_dil_change+2 ; Yes, clear char_I_dil_change | |
560 | 1518 |
582 | 1519 movff opt_dil_He_ratio+3,char_I_deco_He_ratio+3 |
1520 movff opt_dil_O2_ratio+3,char_I_deco_O2_ratio+3 | |
1521 movff opt_dil_type+3,WREG ; 0=Disabled, 1=First, 2=Normal | |
1522 tstfsz WREG ; Disabled? | |
1523 bra $+4 ; No | |
1524 movff WREG,char_I_dil_change+3 ; Yes, clear char_I_dil_change | |
560 | 1525 |
582 | 1526 movff opt_dil_He_ratio+4,char_I_deco_He_ratio+4 |
1527 movff opt_dil_O2_ratio+4,char_I_deco_O2_ratio+4 | |
1528 movff opt_dil_type+4,WREG ; 0=Disabled, 1=First, 2=Normal | |
1529 tstfsz WREG ; Disabled? | |
1530 bra $+4 ; No | |
1531 movff WREG,char_I_dil_change+4 ; Yes, clear char_I_dil_change | |
560 | 1532 |
1533 ; Setup char_I_deco_gas_change array | |
582 | 1534 movff char_I_dil_change+0, char_I_deco_gas_change+0 |
1535 movff char_I_dil_change+1, char_I_deco_gas_change+1 | |
1536 movff char_I_dil_change+2, char_I_deco_gas_change+2 | |
1537 movff char_I_dil_change+3, char_I_deco_gas_change+3 | |
1538 movff char_I_dil_change+4, char_I_deco_gas_change+4 | |
560 | 1539 |
1540 ; switch to CCR / pSCR mode | |
1541 movff char_O_deco_status,lo ; working copy of char_O_deco_status in bank common | |
1542 bsf lo,DECO_MODE_LOOP_FLAG ; loop flag is set in both, CCR and pSCR mode | |
1543 bcf lo,DECO_MODE_PSCR_FLAG ; clear pSCR mode flag by default | |
1544 btfsc FLAG_pscr_mode ; check if we are in pSCR mode | |
1545 bsf lo,DECO_MODE_PSCR_FLAG ; YES - set additional flag for pSCR mode | |
1546 movff lo,char_O_deco_status ; bank safe write-back of char_O_deco_status | |
582 | 1547 |
560 | 1548 return |
0 | 1549 |
582 | 1550 global setup_gas_registers |
1551 setup_gas_registers: ; with currently breathed gas in WREG (1-5 or 6) | |
1552 movwf active_gas ; set as current gas | |
560 | 1553 movlw .6 |
582 | 1554 cpfseq active_gas ; gas = gas6 ? |
1555 bra setup_gas_registers_15 ; NO - load gas 1-5 | |
1556 movff gas6_O2_ratio,char_I_O2_ratio ; copy gas6 O2 ratio to deco engine | |
1557 movff gas6_He_ratio,char_I_He_ratio ; copy gas6 H2 ratio to deco engine | |
1558 bra setup_gas_registers_com ; continue with common part | |
560 | 1559 setup_gas_registers_15: |
582 | 1560 decf active_gas,W ; 1-5 -> 0-4 |
560 | 1561 lfsr FSR1,opt_gas_O2_ratio+0 |
582 | 1562 movff PLUSW1,char_I_O2_ratio ; copy gas 1-5 O2 ratio to deco engine |
560 | 1563 lfsr FSR1,opt_gas_He_ratio+0 |
582 | 1564 movff PLUSW1,char_I_He_ratio ; copy gas 1-5 He ratio to deco engine |
560 | 1565 setup_gas_registers_com: |
582 | 1566 ;lfsr FSR1,opt_gas_type ; commented out - currently not used anywhere |
1567 ;movff PLUSW1,active_gas_type ; 0=Disabled, 1=First, 2=Travel, 3=Deco | |
1568 movff char_O_main_status,lo ; working copy of char_O_main_status in bank common | |
1569 bcf lo,DECO_MODE_PSCR_FLAG ; clear the pSCR-mode flag (may not be set, but never mind) | |
1570 bcf lo,DECO_MODE_LOOP_FLAG ; clear the loop/CCR-mode flag | |
1571 movff lo,char_O_main_status ; bank safe write-back of char_O_main_status | |
1572 movf active_gas,W ; reload WREG with diluent 1-5 or 6 (important!) | |
560 | 1573 return |
137 | 1574 |
582 | 1575 global setup_dil_registers |
1576 setup_dil_registers: ; with currently breathed gas in WREG (1-5 or 6) | |
1577 btfsc is_bailout ; check if in bailout condition | |
1578 bra setup_gas_registers ; revert to setting up OC gases in bailout condition | |
1579 movwf active_gas ; set as current gas | |
1580 movff WREG,active_diluent ; remember for when switching back from bailout to loop | |
560 | 1581 movlw .6 |
582 | 1582 cpfseq active_gas ; diluent = gas6 ? |
1583 bra setup_dil_registers_15 ; NO - load diluent 1-5 | |
1584 movff gas6_O2_ratio,char_I_O2_ratio ; copy gas6 O2 ratio to deco engine | |
1585 movff gas6_He_ratio,char_I_He_ratio ; copy gas6 H2 ratio to deco engine | |
1586 bra setup_dil_registers_com ; continue with common part | |
560 | 1587 setup_dil_registers_15: |
582 | 1588 decf active_gas,W ; 1-5 -> 0-4 |
560 | 1589 lfsr FSR1,opt_dil_O2_ratio+0 |
582 | 1590 movff PLUSW1,char_I_O2_ratio ; copy diluent 1-5 O2 ratio to deco engine |
560 | 1591 lfsr FSR1,opt_dil_He_ratio+0 |
582 | 1592 movff PLUSW1,char_I_He_ratio ; copy diluent 1-5 He ratio to deco engine |
560 | 1593 setup_dil_registers_com: |
582 | 1594 ;lfsr FSR1,opt_dil_type ; commented out - currently not used anywhere |
1595 ;movff PLUSW1,active_gas_type ; 0=Disabled, 1=First, 2=Normal (there is no type 3 for diluents) | |
1596 movff char_O_main_status,lo ; working copy of char_O_main_status in bank common | |
1597 bsf lo,DECO_MODE_LOOP_FLAG ; loop flag is set in both, CCR and pSCR mode | |
1598 bcf lo,DECO_MODE_PSCR_FLAG ; clear pSCR mode flag by default | |
1599 btfsc FLAG_pscr_mode ; check if we are in pSCR mode | |
1600 bsf lo,DECO_MODE_PSCR_FLAG ; YES - set additional flag for pSCR mode | |
1601 movff lo,char_O_main_status ; bank safe write-back of char_O_main_status | |
1602 movf active_gas,W ; reload WREG with diluent 1-5 or 6 (important!) | |
560 | 1603 return |
1604 | |
582 | 1605 divemode_option_gaschange: ; Switch to the better gas |
1606 movff better_gas_number,menupos1 ; 1-5 | |
1607 bsf divemode_gaschange ; Change the gas in the dive mode loop... | |
1608 call menuview_toggle_reset ; Reset to zero (Zero=no menuview) | |
1609 bcf better_gas_available ; Clear flag immediately | |
560 | 1610 return |
1611 | |
582 | 1612 divemode_option0: ; Start/Setup Divemode menu |
1613 call TFT_clear_divemode_menu ; Clear menu area | |
1614 bcf menuview | |
560 | 1615 call do_main_divemenu |
1616 | |
582 | 1617 global divemode_option0_return |
0 | 1618 divemode_option0_return: |
582 | 1619 ; movlw .1 |
1620 ; movwf menupos1 ; Set to first option in divemode menu | |
1621 call TFT_divemode_menu_cursor ; Show the cursor | |
0 | 1622 movlw divemode_menu_timeout |
582 | 1623 movwf timeout_counter2 ; timeout for divemode menu |
1624 bsf divemode_menu ; Set flag | |
1625 clrf menupos2 ; Clear option counter | |
1626 goto diveloop_loop4 ; Goto back to diveloop (menu processor trashes STKPTR!) | |
0 | 1627 |
1628 divemode_option4: | |
582 | 1629 movlw d'58' ; two seconds left |
1630 movwf timeout_counter1+0 | |
1631 movlw apnoe_timeout-1 ; apnoe timeout [min] | |
0 | 1632 movwf apnoe_timeout_counter |
582 | 1633 btfss simulatormode_active ; in simulator mode? |
1634 return ; No | |
1635 divemode_option1: ; Quit simulation mode | |
0 | 1636 banksel isr_backup |
582 | 1637 movlw LOW .1000 |
1638 movwf sim_pressure+0 | |
1639 movlw HIGH .1000 | |
1640 movwf sim_pressure+1 ; Set to 0m -> End of Dive | |
1641 banksel common | |
1642 call menuview_toggle_reset ; Reset to zero (Zero=no menuview) | |
1643 | |
1644 btfss FLAG_apnoe_mode ; In Apnoe mode? | |
1645 return ; No | |
1646 movlw d'58' ; two seconds left | |
1647 movwf timeout_counter1+0 | |
1648 movlw apnoe_timeout-1 ; apnoe timeout [min] | |
0 | 1649 movwf apnoe_timeout_counter |
1650 return | |
1651 | |
582 | 1652 divemode_option3: ; minus 1m |
0 | 1653 banksel isr_backup |
315
4f83470dcece
VSIbar #3: remaining changes for the split style bar
Janos Kovacs <kovjanos@gmail.com>
parents:
310
diff
changeset
|
1654 movlw d'100' |
0 | 1655 subwf sim_pressure+0 |
1656 movlw .0 | |
1657 subwfb sim_pressure+1 | |
1658 rcall divemode_simulator_check_limits | |
582 | 1659 banksel common |
0 | 1660 return |
1661 | |
582 | 1662 divemode_option2: ; plus 1m |
0 | 1663 banksel isr_backup |
315
4f83470dcece
VSIbar #3: remaining changes for the split style bar
Janos Kovacs <kovjanos@gmail.com>
parents:
310
diff
changeset
|
1664 movlw d'100' |
0 | 1665 addwf sim_pressure+0 |
1666 movlw .0 | |
1667 addwfc sim_pressure+1 | |
1668 rcall divemode_simulator_check_limits | |
582 | 1669 banksel common |
0 | 1670 return |
1671 | |
1672 divemode_option5: | |
582 | 1673 call menuview_toggle_reset ; Reset to zero (Zero=no menuview) |
1674 bsf reset_average_depth ; Set Flag | |
1675 return | |
0 | 1676 |
216
973a0969e0ac
NEW: On-board simulator can increase divetime in 5min steps
heinrichsweikamp
parents:
206
diff
changeset
|
1677 divemode_option6: |
582 | 1678 bcf divemode2 ; Stop divetime |
1679 movlw .5 | |
1680 addwf divemins+0,F | |
1681 movlw .0 | |
1682 addwfc divemins+1,F ; Add 5 mins | |
1683 movlw LOW (.5*.60) | |
1684 addwf average_divesecs+0,F | |
1685 movlw HIGH (.5*.60) | |
1686 addwfc average_divesecs+1,F ; Add 5*60 seconds | |
1687 movlw LOW (.5*.60) | |
1688 addwf total_divetime_seconds+0,F | |
1689 movlw HIGH (.5*.60) | |
1690 addwfc total_divetime_seconds+1,F ; Add 5*60 seconds | |
560 | 1691 |
582 | 1692 ; 1. Add 300xdepth to the sum of depths registers |
1693 SAFE_2BYTE_COPY rel_pressure, xB ; Buffer... | |
1694 movlw LOW (.5*.60) | |
1695 movwf xA+0 | |
1696 movlw HIGH (.5*.60) | |
1697 movwf xA+1 | |
1698 call mult16x16 ; xA*xB=xC | |
386 | 1699 |
1700 movf xC+0,w | |
1701 addwf average_depth_hold+0,F | |
1702 movf xC+1,w | |
1703 addwfc average_depth_hold+1,F | |
1704 movf xC+2,w | |
1705 addwfc average_depth_hold+2,F | |
582 | 1706 movf xC+3,w |
560 | 1707 addwfc average_depth_hold+3,F ; Will work up to 9999mbar*60*60*24=863913600mbar |
386 | 1708 |
560 | 1709 ; Do the same for the _total registers (Non-Resettable) |
386 | 1710 movf xC+0,w |
1711 addwf average_depth_hold_total+0,F | |
1712 movf xC+1,w | |
1713 addwfc average_depth_hold_total+1,F | |
1714 movf xC+2,w | |
1715 addwfc average_depth_hold_total+2,F | |
560 | 1716 movf xC+3,w |
1717 addwfc average_depth_hold_total+3,F; Will work up to 9999mbar*60*60*24=863913600mbar | |
386 | 1718 |
560 | 1719 movlw .5 ; + 5 minutes |
1720 movff WREG,char_I_sim_advance_time; copy to mailbox | |
582 | 1721 bsf divemode2 ; continue divetime |
560 | 1722 call restart_deco_engine |
582 | 1723 goto menuview_toggle_reset ; and return... |
216
973a0969e0ac
NEW: On-board simulator can increase divetime in 5min steps
heinrichsweikamp
parents:
206
diff
changeset
|
1724 |
254
5fe7aff622f3
preparations to set a course for the compass display
heinrichsweikamp
parents:
239
diff
changeset
|
1725 divemode_option7: |
582 | 1726 ; Store heading for compass view |
1727 movff compass_heading_shown+0,compass_bearing+0 | |
1728 movff compass_heading_shown+1,compass_bearing+1 | |
1729 bsf compass_bearing_set ; set flag | |
1730 goto menuview_toggle_reset ; Done and return... | |
1731 | |
560 | 1732 divemode_option8: |
582 | 1733 bsf alternative_divelayout ; Set flag for mode |
1734 bsf FLAG_TFT_divemode_mask_alt ; Set flag for mask | |
1735 movlw .1 | |
1736 movwf menupos3 ; For the customviews... | |
1737 call TFT_ClearScreen ; Clear screen | |
1738 goto menuview_toggle_reset ; Done and return... | |
216
973a0969e0ac
NEW: On-board simulator can increase divetime in 5min steps
heinrichsweikamp
parents:
206
diff
changeset
|
1739 |
0 | 1740 divemode_simulator_check_limits: |
1741 ; Check limits (150m and 0m) | |
582 | 1742 movlw LOW d'16000' ; Compare to 16bar=16000mbar (150m). |
1743 subwf sim_pressure+0,W | |
1744 movlw HIGH d'16000' | |
1745 subwfb sim_pressure+1,W | |
1746 bnc divemode_simulator_check_limits2 ; No-carry = borrow = not deeper | |
0 | 1747 |
1748 ; Too deep, limit to 150m | |
582 | 1749 movlw LOW d'16000' |
0 | 1750 movwf sim_pressure+0 |
582 | 1751 movlw HIGH d'16000' |
0 | 1752 movwf sim_pressure+1 |
1753 return | |
1754 divemode_simulator_check_limits2: | |
582 | 1755 movlw LOW d'1000' ; Compare to 1bar == 0m == 1000 mbar. |
1756 subwf sim_pressure+0,W | |
1757 movlw HIGH d'1000' | |
1758 subwfb sim_pressure+1,W | |
1759 btfsc STATUS,C ; No-carry = borrow = not deeper. | |
1760 return ; Deeper than 0m == Ok. | |
0 | 1761 ; Too shallow, limit to 0m |
582 | 1762 movlw LOW d'1000' |
0 | 1763 movwf sim_pressure+0 |
582 | 1764 movlw HIGH d'1000' |
0 | 1765 movwf sim_pressure+1 |
1766 return | |
1767 | |
1768 ;============================================================================= | |
1769 ; Compare all enabled gas in list, to see if a better one is available. | |
1770 ; | |
1771 ; Output: better_gas_available, better_gas_number | |
1772 ; | |
582 | 1773 check_gas_change: ; Checks if a better gas should be selected (by user) |
1774 bcf better_gas_available ; =1: A better gas is available and a gas change is advised in divemode | |
1775 clrf WREG | |
1776 movff WREG,better_gas_number ; clear better gas register | |
0 | 1777 |
582 | 1778 SAFE_2BYTE_COPY rel_pressure,xA |
0 | 1779 movlw d'100' |
1780 movwf xB+0 | |
1781 clrf xB+1 | |
582 | 1782 call div16x16 ; compute depth in full m -> result in xC+0 |
0 | 1783 |
582 | 1784 btfsc FLAG_pscr_mode ; in PSCR mode? |
1785 bra check_gas_change2 ; YES - check for diluents | |
1786 btfss FLAG_ccr_mode ; in CCR mode? | |
1787 bra check_gas_change_OC_bail ; NO - check for OC | |
485 | 1788 check_gas_change2: |
582 | 1789 btfsc is_bailout ; in bailout? |
1790 bra check_gas_change_OC_bail ; YES - check for OC | |
0 | 1791 |
582 | 1792 ; Check Diluents |
1793 movlw .0 | |
1794 rcall check_dil_common ; With Gas 0-4 in WREG | |
1795 movlw .1 | |
1796 rcall check_dil_common ; With Gas 0-4 in WREG | |
1797 movlw .2 | |
1798 rcall check_dil_common ; With Gas 0-4 in WREG | |
1799 movlw .3 | |
1800 rcall check_dil_common ; With Gas 0-4 in WREG | |
1801 movlw .4 | |
1802 rcall check_dil_common ; With Gas 0-4 in WREG | |
1803 bra check_gas_change_exit | |
0 | 1804 |
1805 check_gas_change_OC_bail: | |
582 | 1806 movlw .0 |
1807 rcall check_gas_common ; With Gas 0-4 in WREG | |
1808 movlw .1 | |
1809 rcall check_gas_common ; With Gas 0-4 in WREG | |
1810 movlw .2 | |
1811 rcall check_gas_common ; With Gas 0-4 in WREG | |
1812 movlw .3 | |
1813 rcall check_gas_common ; With Gas 0-4 in WREG | |
1814 movlw .4 | |
1815 rcall check_gas_common ; With Gas 0-4 in WREG | |
1816 ;bra check_gas_change_exit | |
560 | 1817 |
0 | 1818 check_gas_change_exit: |
582 | 1819 bsf FLAG_TFT_active_gas_divemode; redraw gas/setpoint/diluent |
1820 btfss better_gas_available ; is a better gas available? | |
1821 bcf blinking_better_gas ; NO - clear blinking flag | |
1822 btfsc better_gas_available ; is a better gas available? | |
1823 return ; YES | |
1824 clrf WREG ; NO - clear better_gas_number (for gaslist display) | |
1825 movff WREG,better_gas_number | |
1826 return | |
0 | 1827 |
582 | 1828 check_gas_common: ; With Gas 0-4 in WREG |
1829 btfsc better_gas_available ; Better Gas already found? | |
1830 return ; Yes, return | |
1831 lfsr FSR1,opt_gas_type ; 0=Disabled, 1=First, 2=Travel, 3=Deco | |
1832 btfss PLUSW1,0 ; Test for Bit0 and 1 -> type=3 -> Deco | |
1833 return ; No | |
1834 btfss PLUSW1,1 ; Test for Bit0 and 1 -> type=3 -> Deco | |
1835 return ; No | |
1836 incf WREG,W ; 1-5 | |
1837 cpfseq active_gas ; is this gas current gas? | |
1838 bra check_gas_common2 ; No | |
1839 return ; Yes, skip test for active gas | |
0 | 1840 check_gas_common2: |
582 | 1841 decf WREG,W ; 0-4 |
1842 movwf hi ; Save tested gas 0-4 | |
1843 lfsr FSR1,opt_OC_bail_gas_change | |
1844 movff PLUSW1,lo ; Change depth into lo | |
0 | 1845 movlw minimum_change_depth |
582 | 1846 cpfsgt lo ; Change depth>minimum_change_depth? |
1847 return ; No, Change depth not deep enough, skip! | |
1848 movf xC+0,W ; load depth in m into WREG | |
1849 cpfsgt lo ; gas_change_depth < current depth? | |
1850 bra check_gas_common3 ; No, check if we are within the better_gas_window_pos window | |
1851 incf hi,W ; 1-5 | |
1852 movff WREG,better_gas_number ; number (1-5) of the "better gas" in divemode, =0: no better gas available | |
69 | 1853 movlw better_gas_window_neg |
582 | 1854 subwf lo,W ; Change depth-better_gas_window_neg |
1855 cpfslt xC+0 ; current depth<Change depth-better_gas_window_neg? | |
1856 bra check_gas_common4 ; Ok, now check the better gas ppO2<char_I_ppO2_max | |
1857 return | |
69 | 1858 check_gas_common3: |
582 | 1859 incf hi,W ; 1-5 |
1860 movff WREG,better_gas_number ; number (1-5) of the "better gas" in divemode, =0: no better gas available | |
69 | 1861 movlw better_gas_window_pos |
582 | 1862 addwf lo,W ; Change depth+better_gas_window_pos |
1863 cpfsgt xC+0 ; current depth>Change depth+better_gas_window_pos? | |
1864 bra check_gas_common4 ; Ok, now check the better gas ppO2<char_I_ppO2_max | |
1865 return | |
69 | 1866 check_gas_common4: |
582 | 1867 movf hi,W ; gas 0-4 into WREG |
1868 lfsr FSR1,char_I_deco_O2_ratio ; load base address char_I_deco_O2_ratio array | |
1869 movff PLUSW1,lo ; read O2 ratio from array into lo | |
69 | 1870 |
582 | 1871 SAFE_2BYTE_COPY amb_pressure, xA |
69 | 1872 movlw d'10' |
1873 movwf xB+0 | |
1874 clrf xB+1 | |
582 | 1875 call div16x16 ; xC=p_amb/10 |
69 | 1876 movff xC+0,xA+0 |
1877 movff xC+1,xA+1 | |
582 | 1878 movff lo,xB+0 ; =O2 ratio |
69 | 1879 clrf xB+1 |
582 | 1880 call mult16x16 ; lo * p_amb/10 |
69 | 1881 |
582 | 1882 ; Check very high ppO2 manually |
1883 tstfsz xC+2 ; char_I_O2_ratio * p_amb/10 > 65536, ppO2>6,55bar? | |
1884 return ; Done. | |
1885 ; Check if ppO2>3,30bar | |
1886 btfsc xC+1,7 | |
1887 return ; Done. | |
69 | 1888 |
582 | 1889 ; 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
|
1890 movff xC+0,sub_b+0 |
0d1cda9f2d43
BUGFIX: Skip MOD Test for CCR in Sensor modes (OSTC cR and OSTC3 only)
heinrichsweikamp
parents:
521
diff
changeset
|
1891 movff xC+1,sub_b+1 |
582 | 1892 movff char_I_ppO2_min,WREG |
1893 mullw d'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
|
1894 movff PRODL,sub_a+0 |
0d1cda9f2d43
BUGFIX: Skip MOD Test for CCR in Sensor modes (OSTC cR and OSTC3 only)
heinrichsweikamp
parents:
521
diff
changeset
|
1895 movff PRODH,sub_a+1 |
582 | 1896 call subU16 ; sub_c = sub_a - sub_b |
526
0d1cda9f2d43
BUGFIX: Skip MOD Test for CCR in Sensor modes (OSTC cR and OSTC3 only)
heinrichsweikamp
parents:
521
diff
changeset
|
1897 btfss neg_flag |
582 | 1898 return ; Done (Too low). |
69 | 1899 |
560 | 1900 ;check if we are within our warning thresholds! |
526
0d1cda9f2d43
BUGFIX: Skip MOD Test for CCR in Sensor modes (OSTC cR and OSTC3 only)
heinrichsweikamp
parents:
521
diff
changeset
|
1901 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
|
1902 movff xC+1,sub_a+1 |
560 | 1903 movff char_I_ppO2_max_deco,WREG ; ppO2 max for MOD calculation and color coding in divemode |
582 | 1904 addlw .1 ; e.g. >1.60 |
1905 mullw d'100' ; char_I_ppO2_max*100 | |
526
0d1cda9f2d43
BUGFIX: Skip MOD Test for CCR in Sensor modes (OSTC cR and OSTC3 only)
heinrichsweikamp
parents:
521
diff
changeset
|
1906 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
|
1907 movff PRODH,sub_b+1 |
582 | 1908 call subU16 ; sub_c = sub_a - sub_b |
526
0d1cda9f2d43
BUGFIX: Skip MOD Test for CCR in Sensor modes (OSTC cR and OSTC3 only)
heinrichsweikamp
parents:
521
diff
changeset
|
1909 btfsc neg_flag |
582 | 1910 bsf better_gas_available ;=1: A better gas is available and a gas change is advised in divemode |
1911 return ; Done. | |
1912 | |
0 | 1913 |
582 | 1914 check_dil_common: ; With Dil 0-4 in WREG |
1915 btfsc better_gas_available ; Better Diluent already found? | |
1916 return ; Yes, return | |
1917 lfsr FSR1,opt_dil_type ; 0=Disabled, 1=First, 2=Normal | |
1918 tstfsz PLUSW1 ; =0? | |
1919 bra check_dil_common1 ; No | |
1920 return ; Yes, skip inactive diluents for test | |
0 | 1921 check_dil_common1: |
582 | 1922 incf WREG,W ; 1-5 |
1923 cpfseq active_gas ; is this the current diluent? | |
1924 bra check_dil_common2 ; No | |
1925 return ; Yes, skip test for active diluent | |
0 | 1926 check_dil_common2: |
582 | 1927 decf WREG,W ; 0-4 |
1928 movwf hi ; Save tested diluent 0-4 | |
1929 lfsr FSR1,char_I_dil_change | |
1930 movff PLUSW1,lo ; Change depth into lo | |
0 | 1931 movlw minimum_change_depth |
582 | 1932 cpfsgt lo ; Change depth>minimum_change_depth? |
1933 return ; No, Change depth not deep enough, skip! | |
1934 movf xC+0,W ; load depth in m into WREG | |
1935 cpfsgt lo ; gas_change_depth < current depth? | |
1936 return ; No, check next gas | |
1937 incf hi,W ; 1-5 | |
1938 movff WREG,better_gas_number ; number (1-5) of the "better gas" in divemode, =0: no better gas available | |
69 | 1939 movlw better_gas_window_neg |
582 | 1940 subwf lo,W ; Change depth-better_gas_window_neg |
1941 cpfslt xC+0 ; current depth<Change depth-better_gas_window_neg? | |
1942 bsf better_gas_available ;=1: A better gas is available and a gas change is advised in divemode | |
1943 return | |
0 | 1944 |
338
2811932b4e99
NEW: Mode Auto SP: Automatically switches the SP during descent (CC Mode)
heinrichsweikamp
parents:
337
diff
changeset
|
1945 |
2811932b4e99
NEW: Mode Auto SP: Automatically switches the SP during descent (CC Mode)
heinrichsweikamp
parents:
337
diff
changeset
|
1946 ;============================================================================= |
2811932b4e99
NEW: Mode Auto SP: Automatically switches the SP during descent (CC Mode)
heinrichsweikamp
parents:
337
diff
changeset
|
1947 ; Check for Auto-SP |
2811932b4e99
NEW: Mode Auto SP: Automatically switches the SP during descent (CC Mode)
heinrichsweikamp
parents:
337
diff
changeset
|
1948 ; |
582 | 1949 check_dive_autosp: ; Check for Auto-SP |
1950 movff opt_ccr_mode,WREG ; =0: Fixed SP, =1: Sensor, =2: Auto SP | |
1951 sublw .2 ; opt_ccr_mode = 2 (Auto SP)? | |
1952 bz check_dive_autosp2 ; Yes, check | |
1953 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
|
1954 check_dive_autosp2: |
582 | 1955 SAFE_2BYTE_COPY rel_pressure,xA |
338
2811932b4e99
NEW: Mode Auto SP: Automatically switches the SP during descent (CC Mode)
heinrichsweikamp
parents:
337
diff
changeset
|
1956 movlw d'100' |
2811932b4e99
NEW: Mode Auto SP: Automatically switches the SP during descent (CC Mode)
heinrichsweikamp
parents:
337
diff
changeset
|
1957 movwf xB+0 |
2811932b4e99
NEW: Mode Auto SP: Automatically switches the SP during descent (CC Mode)
heinrichsweikamp
parents:
337
diff
changeset
|
1958 clrf xB+1 |
582 | 1959 call div16x16 ; compute depth in full m -> result in xC+0 |
1960 ; Check SP2 | |
1961 btfsc sp2_switched ; =1: This setpoint has been autoselected already | |
1962 bra check_dive_autosp3 ; Skip check | |
1963 movff char_I_setpoint_change+1,lo ; Get depth in m | |
1964 tstfsz lo ; =0? | |
1965 bra check_dive_autosp2a ; No, continue | |
1966 bra check_dive_autosp3 ; Skip check | |
560 | 1967 check_dive_autosp2a: |
582 | 1968 decf lo,W ; -1 -> WREG |
1969 cpfsgt xC+0 ; Compare with depth | |
1970 bra check_dive_autosp3 ; lower depth, do not switch | |
1971 ; auto switch to SP2 | |
560 | 1972 movff char_I_setpoint_cbar+1,char_I_const_ppO2 ; Use SetPoint |
582 | 1973 rcall xmit_sp_set_flag |
1974 bsf sp2_switched ; Set flag | |
338
2811932b4e99
NEW: Mode Auto SP: Automatically switches the SP during descent (CC Mode)
heinrichsweikamp
parents:
337
diff
changeset
|
1975 check_dive_autosp3: |
582 | 1976 ; Check SP3 |
1977 btfsc sp3_switched ;=1: This setpoint has been autoselected already | |
1978 bra check_dive_autosp4 ; Skip check | |
1979 movff char_I_setpoint_change+2,lo ; Get depth in m | |
1980 tstfsz lo ; =0? | |
1981 bra check_dive_autosp3a ; No, continue | |
1982 bra check_dive_autosp4 ; Skip check | |
560 | 1983 check_dive_autosp3a: |
582 | 1984 decf lo,W ; -1 -> WREG |
1985 cpfsgt xC+0 ; Compare with depth | |
1986 bra check_dive_autosp4 ; lower depth, do not switch | |
1987 ; auto switch to SP3 | |
560 | 1988 movff char_I_setpoint_cbar+2,char_I_const_ppO2 ; Use SetPoint |
582 | 1989 rcall xmit_sp_set_flag |
1990 bsf sp3_switched ; Set flag | |
338
2811932b4e99
NEW: Mode Auto SP: Automatically switches the SP during descent (CC Mode)
heinrichsweikamp
parents:
337
diff
changeset
|
1991 check_dive_autosp4: |
582 | 1992 ; Check SP4 |
1993 btfsc sp4_switched ;=1: This setpoint has been autoselected already | |
1994 bra check_dive_autosp5 ; Skip check | |
1995 movff char_I_setpoint_change+3,lo ; Get depth in m | |
1996 tstfsz lo ; =0? | |
1997 bra check_dive_autosp4a ; No, continue | |
1998 bra check_dive_autosp5 ; Skip check | |
560 | 1999 check_dive_autosp4a: |
582 | 2000 decf lo,W ; -1 -> WREG |
2001 cpfsgt xC+0 ; Compare with depth | |
2002 bra check_dive_autosp5 ; lower depth, do not switch | |
2003 ; auto switch to SP4 | |
2004 movff char_I_setpoint_cbar+3,char_I_const_ppO2 ; Use SetPoint | |
2005 rcall xmit_sp_set_flag | |
2006 bsf sp4_switched ; Set flag | |
338
2811932b4e99
NEW: Mode Auto SP: Automatically switches the SP during descent (CC Mode)
heinrichsweikamp
parents:
337
diff
changeset
|
2007 check_dive_autosp5: |
582 | 2008 ; Check SP5 |
2009 btfsc sp5_switched ;=1: This setpoint has been autoselected already | |
2010 bra check_dive_autosp6 ; Skip check | |
2011 movff char_I_setpoint_change+4,lo ; Get depth in m | |
2012 tstfsz lo ; =0? | |
2013 bra check_dive_autosp5a ; No, continue | |
2014 bra check_dive_autosp6 ; Skip check | |
560 | 2015 check_dive_autosp5a: |
582 | 2016 decf lo,W ; -1 -> WREG |
2017 cpfsgt xC+0 ; Compare with depth | |
2018 bra check_dive_autosp6 ; lower depth, do not switch | |
2019 ; auto switch to SP5 | |
2020 movff char_I_setpoint_cbar+4,char_I_const_ppO2 ; Use SetPoint | |
2021 rcall xmit_sp_set_flag | |
2022 bsf sp5_switched ; Set flag | |
352
5c6da9fa5cb0
add setpoint change to first sample in CCR mode
heinrichsweikamp
parents:
339
diff
changeset
|
2023 check_dive_autosp6: |
582 | 2024 return |
352
5c6da9fa5cb0
add setpoint change to first sample in CCR mode
heinrichsweikamp
parents:
339
diff
changeset
|
2025 |
5c6da9fa5cb0
add setpoint change to first sample in CCR mode
heinrichsweikamp
parents:
339
diff
changeset
|
2026 xmit_sp_set_flag: |
582 | 2027 movff char_I_const_ppO2,WREG |
2028 call transmit_setpoint ; Transmit current setpoint from WREG (in cbar) to external electronics | |
2029 bsf setpoint_changed ; Set flag (for profile) | |
2030 bsf event_occured ; Set event flag | |
2031 return | |
2032 | |
2033 set_logbook_marker: | |
2034 bcf FLAG_set_marker ; clear flag | |
2035 movlw d'6' ; set type of Alarm (manual marker) | |
2036 movwf AlarmType ; copy to Alarm Register | |
2037 bsf event_occured ; Set event flag | |
2038 return | |
338
2811932b4e99
NEW: Mode Auto SP: Automatically switches the SP during descent (CC Mode)
heinrichsweikamp
parents:
337
diff
changeset
|
2039 |
0 | 2040 ;============================================================================= |
2041 ; Setup everything to enter divemode. | |
2042 ; | |
2043 dive_boot_oc: | |
582 | 2044 rcall get_first_gas_to_WREG ; Gets first gas (1-5) into WREG |
2045 rcall setup_gas_registers ; set-up of gas parameters of currently breathed gas (with WREG = gas 1-5) | |
2046 rcall deco_setup_oc_gases ; set-up of gas list for deco calculations (with WREG = gas 1-5) | |
2047 return | |
0 | 2048 |
2049 dive_boot_cc: | |
582 | 2050 bcf is_bailout ; =1: Bailout |
2051 bcf setpoint_fallback ; =1: Fallback to SP1 due to external O2 sensor failure | |
2052 bcf blinking_setpoint ; Reset blinking SP flag | |
192 | 2053 |
560 | 2054 ; revoke sensors from usage if they do not have a valid calibration |
2055 bsf use_O2_sensor1 | |
2056 bsf use_O2_sensor2 | |
2057 bsf use_O2_sensor3 | |
2058 btfss sensor1_calibrated_ok | |
2059 bcf use_O2_sensor1 | |
2060 btfss sensor2_calibrated_ok | |
2061 bcf use_O2_sensor2 | |
2062 btfss sensor3_calibrated_ok | |
2063 bcf use_O2_sensor3 | |
582 | 2064 |
583 | 2065 btfss optical_input ; do we have an optical input? |
2066 bra dive_boot_cc_0 ; No | |
2067 ; Copy (initial) valid flags from HUD/ppO2 Monitor | |
2068 btfsc sensor1_active | |
2069 bsf use_O2_sensor1 | |
2070 btfsc sensor2_active | |
2071 bsf use_O2_sensor2 | |
2072 btfsc sensor3_active | |
2073 bsf use_O2_sensor3 | |
2074 | |
2075 dive_boot_cc_0: | |
560 | 2076 ; In pSCR mode, only settings 0 (calculated ppO2) and 1 (ppO2 from sensors) are defined. |
2077 ; In case we still have 3 (auto SP) selected out of previous ccr mode, we reset to 0. | |
2078 btfss FLAG_pscr_mode | |
2079 bra dive_boot_cc_1 | |
582 | 2080 movff opt_ccr_mode,WREG ; =0: Fixed SP (CCR) / calculated SP (pSCR), =1: Sensor, =2: Auto SP |
2081 sublw .2 ; opt_ccr_mode = 1 (Auto SP)? | |
2082 bnz dive_boot_cc_1 | |
560 | 2083 movlw .0 |
2084 movff WREG,opt_ccr_mode | |
549 | 2085 |
560 | 2086 dive_boot_cc_1: |
582 | 2087 bsf setpoint_changed ; set flag (for profile) |
2088 bcf sp2_switched ; =1: This setpoint has been auto-selected already | |
2089 bcf sp3_switched ; =1: This setpoint has been auto-selected already | |
2090 bcf sp4_switched ; =1: This setpoint has been auto-selected already | |
2091 bcf sp5_switched ; =1: This setpoint has been auto-selected already | |
338
2811932b4e99
NEW: Mode Auto SP: Automatically switches the SP during descent (CC Mode)
heinrichsweikamp
parents:
337
diff
changeset
|
2092 |
582 | 2093 rcall get_first_dil_to_WREG ; get first gas (1-5) into WREG |
2094 rcall setup_dil_registers ; set-up of gas parameters for currently breathed gas (with WREG = current gas 1-5) | |
2095 rcall deco_setup_cc_diluents ; set-up of gas list for deco calculations (with WREG = current gas 1-5) | |
560 | 2096 |
2097 ; Start with SP1 (CCR) or 0 (pSCR) as default. | |
2098 ; If in sensor mode, this value will be overwritten by calc_deko_divemode_sensor | |
582 | 2099 clrf WREG ; preload WREG with setpoint value 0 for pSCR calculated |
2100 btfss FLAG_ccr_mode ; are we in CCR mode? | |
2101 bra dive_boot_cc_2 ; NO - keep preloaded value | |
2102 movff char_I_setpoint_cbar+0,WREG ; YES - get value of setpoint 1 | |
560 | 2103 dive_boot_cc_2: |
582 | 2104 movff WREG,char_I_const_ppO2 ; write setpoint to deco engine |
2105 call transmit_setpoint ; transmit current setpoint from WREG (in cbar) to external electronics | |
2106 goto calc_deko_divemode_sensor ; read & process sensor data (and return) | |
0 | 2107 |
2108 diveloop_boot: | |
2109 call restart_set_modes_and_flags | |
2110 | |
582 | 2111 call I2C_sleep_accelerometer ; stop accelerometer |
2112 call I2C_sleep_compass ; stop compass | |
0 | 2113 |
2114 clrf WREG | |
582 | 2115 movff WREG,max_pressure+0 ; clear some variables |
0 | 2116 movff WREG,max_pressure+1 |
582 | 2117 |
560 | 2118 ; init in invalid data state |
582 | 2119 clrf WREG ; set WREG to 0 |
2120 bsf WREG,int_invalid_flag ; set invalid flag | |
2121 bsf WREG,int_is_zero ; set zero flag | |
2122 movff WREG,int_O_tank_pres_need+1 ; Set flags for tank pressure needs = 0 before p2_deco.c | |
2123 movff WREG,int_O_tank_pres_need+3 ; can do it. If this is not done here and the gas needs | |
2124 movff WREG,int_O_tank_pres_need+5 ; custom view is shown before p2_deco.c completes the first | |
2125 movff WREG,int_O_tank_pres_need+7 ; deco calculation, some rubbish numbers from last dive of | |
2126 movff WREG,int_O_tank_pres_need+9 ; simulation may be shown | |
2127 | |
560 | 2128 ; configure the deco engine: |
582 | 2129 movff char_O_deco_status,WREG ; bank-safe copy |
2130 bsf WREG,DECO_STATUS_0_FLAG ; configure init ... | |
2131 bsf WREG,DECO_STATUS_1_FLAG ; ... state, | |
2132 bcf WREG,DECO_PLAN_FLAG ; normal plan mode, | |
2133 bsf WREG,DECO_CNS_FLAG ; enable CNS calculation (CNS at end of dive), | |
2134 bcf WREG,DECO_VOLUME_FLAG ; disable gas volume calculation, and | |
2135 bcf WREG,DECO_ASCENT_FLAG ; disable delayed ascent calculation | |
2136 movff WREG,char_O_deco_status ; bank-safe copy back | |
2137 | |
560 | 2138 clrf WREG |
582 | 2139 movff WREG,char_O_main_status ; reset char_O_main_status |
0 | 2140 |
560 | 2141 movlw deco_distance |
2142 movff WREG,char_I_deco_distance | |
2143 movff opt_last_stop,char_I_depth_last_deco | |
2144 movff opt_GF_low,char_I_GF_Low_percentage | |
2145 movff opt_GF_high,char_I_GF_High_percentage | |
582 | 2146 |
2147 bcf use_agf ; Start with normal GF set | |
2148 bcf divemode_menu ; clear divemode menu flag | |
2149 | |
2150 bcf alternative_divelayout ; Start with default layout | |
2151 | |
2152 bcf blinking_depth_prev ; clear flag for blinking depth | |
2153 bcf blinking_depth_warning ; clear flag for blinking depth | |
2154 bcf blinking_depth_toggle ; clear flag for blinking depth | |
2155 | |
0 | 2156 movlw d'1' |
2157 movwf apnoe_max_pressure+0 | |
2158 clrf apnoe_max_pressure+1 | |
386 | 2159 ; clrf apnoe_surface_mins |
582 | 2160 ; clrf apnoe_surface_secs |
0 | 2161 clrf apnoe_mins |
2162 clrf divemins+0 | |
2163 clrf divemins+1 | |
582 | 2164 |
560 | 2165 ; Copy date and time for logbook |
582 | 2166 movff year,start_year |
2167 movff month,start_month | |
2168 movff day,start_day | |
2169 movff hours,start_hours | |
2170 movff mins,start_mins | |
2171 | |
2172 movff int_O_CNS_fraction+0,CNS_start+0 ; save CNS value at beginning of dive | |
2173 movff int_O_CNS_fraction+1,WREG ; get high byte to WREG | |
2174 bcf WREG,int_warning_flag ; clear warning flag bit | |
2175 movff WREG,CNS_start+1 ; move high byte on | |
2176 movff int_O_gradient_factor+0,GF_start ; save GF value at beginning of dive (only lower byte used for value) | |
545 | 2177 |
582 | 2178 bcf no_more_divesecs ; =1: do no longer show seconds in divemode |
0 | 2179 bcf divemode_menu_active |
582 | 2180 clrf menupos1 |
2181 clrf menupos2 ; Reset to zero (Zero=no premenu or simulator task) | |
2182 bsf sensors_agree ; init of sensors disagree warning system | |
2183 | |
2184 btfsc FLAG_ccr_mode | |
2185 bra diveloop_boot_cc | |
2186 btfsc FLAG_pscr_mode | |
2187 bra diveloop_boot_cc | |
2188 rcall dive_boot_oc | |
2189 bra diveloop_boot_cont | |
560 | 2190 |
545 | 2191 diveloop_boot_cc: |
582 | 2192 rcall dive_boot_cc |
2193 | |
545 | 2194 diveloop_boot_cont: |
582 | 2195 ; Copy opt_dil_types into backup (For "lost gas" feature) |
2196 movff opt_dil_type+0,opt_dil_type_backup+0 ; 0=Disabled, 1=First, 2=Normal | |
2197 movff opt_dil_type+1,opt_dil_type_backup+1 ; 0=Disabled, 1=First, 2=Normal | |
2198 movff opt_dil_type+2,opt_dil_type_backup+2 ; 0=Disabled, 1=First, 2=Normal | |
2199 movff opt_dil_type+3,opt_dil_type_backup+3 ; 0=Disabled, 1=First, 2=Normal | |
2200 movff opt_dil_type+4,opt_dil_type_backup+4 ; 0=Disabled, 1=First, 2=Normal | |
2201 ; Copy opt_gas_types into backup (For "lost gas" feature) | |
2202 movff opt_gas_type+0,opt_gas_type_backup+0 ; 0=Disabled, 1=First, 2=Travel, 3=Deco | |
2203 movff opt_gas_type+1,opt_gas_type_backup+1 ; 0=Disabled, 1=First, 2=Travel, 3=Deco | |
2204 movff opt_gas_type+2,opt_gas_type_backup+2 ; 0=Disabled, 1=First, 2=Travel, 3=Deco | |
2205 movff opt_gas_type+3,opt_gas_type_backup+3 ; 0=Disabled, 1=First, 2=Travel, 3=Deco | |
2206 movff opt_gas_type+4,opt_gas_type_backup+4 ; 0=Disabled, 1=First, 2=Travel, 3=Deco | |
2207 ; Also copy change depths into backup (For "lost gas" feature) | |
2208 movff char_I_dil_change+0,opt_dil_change_backup+0 ; Gas change depths Diluents | |
2209 movff char_I_dil_change+1,opt_dil_change_backup+1 ; Gas change depths Diluents | |
2210 movff char_I_dil_change+2,opt_dil_change_backup+2 ; Gas change depths Diluents | |
2211 movff char_I_dil_change+3,opt_dil_change_backup+3 ; Gas change depths Diluents | |
2212 movff char_I_dil_change+4,opt_dil_change_backup+4 ; Gas change depths Diluents | |
2213 ; Also copy change depths into backup (For "lost gas" feature) | |
2214 movff opt_OC_bail_gas_change+0,opt_OC_bail_gas_change_backup+0; Gas change depths OC/Bailout | |
2215 movff opt_OC_bail_gas_change+1,opt_OC_bail_gas_change_backup+1; Gas change depths OC/Bailout | |
2216 movff opt_OC_bail_gas_change+2,opt_OC_bail_gas_change_backup+2; Gas change depths OC/Bailout | |
2217 movff opt_OC_bail_gas_change+3,opt_OC_bail_gas_change_backup+3; Gas change depths OC/Bailout | |
2218 movff opt_OC_bail_gas_change+4,opt_OC_bail_gas_change_backup+4; Gas change depths OC/Bailout | |
403
6e60012bb3fc
NEW: "Lost Gas" feature allows disabling gases during the dive
heinrichsweikamp
parents:
399
diff
changeset
|
2219 |
582 | 2220 clrf WREG |
2221 movff WREG,better_gas_number ; clear better gas register | |
0 | 2222 |
560 | 2223 bcf show_safety_stop ; =1: Show the safety stop |
104
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
2224 clrf safety_stop_countdown ; Clear count-down |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
2225 |
582 | 2226 clrf samplesecs |
0 | 2227 clrf apnoe_timeout_counter ; timeout in minutes |
582 | 2228 clrf timeout_counter1+0 ; takes care of the timeout (low byte) |
2229 clrf timeout_counter1+1 ; takes care of the timeout (high byte) | |
0 | 2230 clrf AlarmType ; Clear all alarms |
2231 bcf event_occured ; clear flag | |
2232 clrf average_depth_hold_total+0 | |
2233 clrf average_depth_hold_total+1 | |
2234 clrf average_depth_hold_total+2 | |
2235 clrf average_depth_hold_total+3 ; Clear Non-Resettable Average | |
582 | 2236 rcall reset_average1 ; Reset the resettable average depth |
2237 bcf decostop_active | |
2238 bcf better_gas_available ; =1: A better gas is available and a gas change is advised in divemode | |
204 | 2239 call ghostwriter_short_header ; Write short header with divenumber into profile memory |
0 | 2240 |
582 | 2241 btfsc simulatormode_active |
2242 bra diveloop_boot_1 | |
2243 ; Normal mode = Surface pressure is the pressure 30mn before dive. | |
0 | 2244 SAFE_2BYTE_COPY last_surfpressure_30min, int_I_pres_surface ;copy surfacepressure to deco routine |
2245 SAFE_2BYTE_COPY last_surfpressure_30min, last_surfpressure ;copy surfacepressure to last_surfpressure for correct depth | |
582 | 2246 bra diveloop_boot_2 |
0 | 2247 |
2248 diveloop_boot_1: | |
582 | 2249 ; Simulator mode: Surface pressure is 1bar. |
2250 movlw LOW .1000 | |
2251 movff WREG,int_I_pres_surface+0 ; LOW copy surface pressure to deco routine | |
2252 movlw HIGH .1000 | |
2253 movff WREG,int_I_pres_surface+1 ; HIGH copy surface pressure to deco routine | |
0 | 2254 |
2255 diveloop_boot_2: | |
582 | 2256 SAFE_2BYTE_COPY temperature,minimum_temperature ; Reset Min-Temp registers |
0 | 2257 |
582 | 2258 call init_recording_params ; set up all the divisors |
0 | 2259 |
582 | 2260 bsf ccr_diluent_setup ; For CCR mode (Required to have better gas working) |
2261 btfsc FLAG_ccr_mode ; =1: CCR mode (Fixed ppO2 or Sensor) active | |
2262 bra divemode_boot2 | |
2263 btfsc FLAG_pscr_mode | |
2264 bra divemode_boot2 | |
2265 bcf ccr_diluent_setup ; For OC mode (Required to have better gas working) | |
560 | 2266 |
102
37275e0fa7f5
NEW: Show End-of-Dive time together with clock during deco
heinrichsweikamp
parents:
99
diff
changeset
|
2267 divemode_boot2: |
582 | 2268 bcf LEDg ; switch off green LED / release reset to RX circuitry |
2269 bcf LEDr ; switch off red LED | |
0 | 2270 bcf realdive |
582 | 2271 btfss simulatormode_active ; do not disable in simulator mode! |
2272 call disable_rs232 ; Disable RS232 | |
2273 btfsc enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump) | |
2274 call enable_rs232 ; Also sets to speed_normal ... | |
2275 ; Reset divetime seconds | |
2276 movlw .2 ; Start at 2seconds | |
2277 movwf total_divetime_seconds+0 | |
2278 clrf total_divetime_seconds+1 | |
2279 movwf divesecs | |
2280 movwf apnoe_secs | |
2281 bsf divemode2 ; displayed divetime is running (Divetime starts HERE) | |
2282 return ; Done with divemode boot | |
2283 | |
0 | 2284 |
2285 divemode_check_for_warnings: | |
582 | 2286 movlw .1 ; One warning at a time in alt. layout mode |
2287 btfss alternative_divelayout | |
2288 movlw .2 ; Two warnings at a time in default layout mode | |
2289 cpfsgt warning_counter ; only one (or two) warnings active? | |
2290 bra divemode_check_for_warnings1 ; Yes, update every second | |
131 | 2291 |
582 | 2292 btfss secs,0 ; Every two seconds... |
2293 return | |
2294 btfss secs,1 ; Every four seconds... | |
2295 return | |
0 | 2296 |
131 | 2297 divemode_check_for_warnings1: |
582 | 2298 bcf warning_active ; Clear flag |
2299 clrf warning_counter ; Clear counter | |
0 | 2300 |
560 | 2301 ; warnings sorted by severity, highest severity first |
582 | 2302 |
2303 ; Warnings for all modes | |
2304 call check_warn_battery ; Check if the battery level should be displayed/warned | |
2305 call check_divetimeout ; Not actually a warning. Check and show the divemode timeout | |
2306 | |
2307 btfsc FLAG_apnoe_mode ; Done for Apnoe or Gauge mode | |
2308 bra divemode_check_for_warnings2 | |
2309 btfsc FLAG_gauge_mode ; Done for Apnoe or Gauge mode | |
2310 bra divemode_check_for_warnings2 | |
0 | 2311 |
582 | 2312 ; Warnings only in deco modes |
2313 rcall check_ppO2 ; check ppO2 and displays warning, if required | |
0 | 2314 |
582 | 2315 btfss sensors_agree ; are the sensor values within the threshold range? |
2316 rcall check_warn_sensors_disagree ; NO - further evaluate | |
2317 btfsc sensors_agree ; are the sensor values within the threshold range? | |
2318 bcf sensor_warning ; YES - revoke memorized sensor warning | |
2319 | |
2320 movff char_O_deco_warnings,WREG ; bank-safe copy for deco warnings | |
2321 btfsc WREG,outside_warning_lock ; are we outside of the ZH-L16 model? | |
2322 rcall warn_outside ; YES | |
560 | 2323 |
582 | 2324 rcall check_IBCD ; check for IBCD attention or warning |
2325 | |
2326 btfsc decostop_active ; In deco mode? | |
2327 rcall check_and_store_gf_violation; Yes, sets warnings, if required | |
2328 | |
2329 movff char_O_deco_warnings,WREG ; bank-safe copy for deco warnings | |
2330 btfsc WREG,mbubble_warning_lock ; do we have a microbubbles warning? | |
2331 rcall warn_mbubbles ; YES | |
2332 | |
2333 rcall check_cns_violation ; Check CNS value and display it, if required | |
560 | 2334 |
582 | 2335 ;btfsc decostop_active ; In deco mode? |
2336 rcall check_gas_needs ; show gas needs warning if any gas need is > threshold | |
2337 | |
2338 rcall check_eod_cns_violation ; Check CNS values for end-of-dive and display warning, if required | |
2339 | |
2340 call TFT_display_ftts ; Show @+x time | |
560 | 2341 |
582 | 2342 btfsc use_agf ; In aGF mode? |
2343 rcall warn_agf ; Yes, show a warning for it | |
560 | 2344 |
582 | 2345 btfsc setpoint_fallback ; =1: Fallback to SP1 due to external O2 sensor failure |
2346 rcall warn_fallback ; Show the warning | |
2347 | |
0 | 2348 divemode_check_for_warnings2: |
2349 ; Display the warning icon? | |
582 | 2350 btfsc warning_active ; Any warning active? |
2351 bsf FLAG_TFT_divemode_warning ; Yes | |
2352 btfss warning_active ; Any warning active? | |
2353 bsf FLAG_TFT_divemode_warning_clear ; No, clear warning icon | |
0 | 2354 |
2355 ; Setup warning_page number | |
582 | 2356 incf warning_page,F |
2357 movf warning_page,W | |
2358 bcf STATUS,C | |
2359 btfss alternative_divelayout | |
2360 rlcf warning_page,W ; *2 (But only in standard layout mode) | |
2361 cpfsgt warning_counter ; > warning_counter | |
2362 clrf warning_page ; No, clear | |
2363 | |
560 | 2364 ; Clear both rows of warnings if there is nothing to show at all |
582 | 2365 tstfsz warning_counter ; any warnings? |
2366 bra divemode_check_for_warnings3 ; YES - look if second row needs to be cleared | |
2367 bsf FLAG_TFT_dive_warning_text_clear ; Set flag | |
560 | 2368 return |
2369 divemode_check_for_warnings3: | |
582 | 2370 |
2371 | |
0 | 2372 ; Clear 2nd row of warnings if there is nothing to show (on this page) |
582 | 2373 btfss second_row_warning ; =1: The second row contains a warning |
2374 bsf FLAG_TFT_dive_warning_text_clr2 ; Set flag for 2nd row | |
2375 return ; Done. | |
0 | 2376 |
582 | 2377 global check_warn_battery |
0 | 2378 check_warn_battery: |
582 | 2379 movff batt_percent,lo |
2380 movlw battery_show_level+1 | |
2381 cpfslt lo | |
2382 return ; No Display, no warning | |
2383 ; Display Battery, but warn? | |
2384 movff batt_percent,lo | |
2385 movlw color_code_battery_low+1 | |
2386 cpfsgt lo | |
2387 bsf warning_active ; Set Warning flag | |
2388 | |
2389 movlw .4 | |
2390 cpfseq menupos3 ; battery shown in Custom View 4? | |
2391 bra check_warn_battery2 ; No | |
2392 return ; Yes, do not show twice (in custom view and in warning area) | |
472
4fdf6886004b
CHANGE: Show warnings either in Customview (If active) _or_ next to warning sign
heinrichsweikamp
parents:
471
diff
changeset
|
2393 check_warn_battery2: |
582 | 2394 incf warning_counter,F ; increase counter |
2395 goto TFT_update_batt_percent_divemode ; Show percent (And return) | |
513 | 2396 |
55 | 2397 check_divetimeout: |
582 | 2398 btfsc divemode2 |
2399 return ; displayed divetime is not running | |
2400 incf warning_counter,F ; increase counter | |
2401 goto TFT_divetimeout ; Show timeout counter (and return) | |
55 | 2402 |
2403 | |
560 | 2404 check_ppO2: |
582 | 2405 btfsc FLAG_ccr_mode ; are we in CCR mode? |
560 | 2406 bra check_ppO2_loop ; YES |
2407 btfsc FLAG_pscr_mode ; are we in pSCR mode? | |
2408 bra check_ppO2_loop ; YES | |
2409 bra check_ppO2_oc_1 ; NO - neither CCR nor pSCR | |
2410 check_ppO2_loop: | |
2411 btfsc is_bailout ; in bailout? | |
2412 bra check_ppO2_oc_1 ; YES - continue with OC | |
2413 movff int_O_pure_ppO2+1,hi ; NO - get upper part of int_O_pure_ppO2 | |
582 | 2414 btfsc hi,int_warning_flag ; ppO2 of the pure diluent to low or high? |
2415 rcall check_ppo2_display ; YES - show warning and return on next line | |
2416 btfsc hi,int_attention_flag ; ppO2 of the pure diluent close to setpoint? | |
2417 rcall check_ppo2_display ; YES - show warning and return on next line | |
2418 bra check_ppO2_oc_2 ; skip attention threshold test on breathed ppO2 | |
560 | 2419 check_ppO2_oc_1: |
2420 movff int_O_breathed_ppO2+1,WREG ; get upper part of int_O_breathed_ppO2 | |
582 | 2421 btfsc WREG,int_attention_flag ; breathed ppO2 just above attention threshold? |
560 | 2422 bra check_ppo2_display ; YES - show ppO2 |
2423 check_ppO2_oc_2: | |
2424 movff int_O_breathed_ppO2+1,WREG ; get upper part of int_O_breathed_ppO2 (perhaps again) | |
2425 btfsc WREG,int_low_flag ; breathed ppO2 to low? | |
2426 bra check_ppO2_low ; YES - record the warning and show ppO2 | |
2427 btfsc WREG,int_high_flag ; breathed ppO2 to high? | |
2428 bra check_ppO2_high ; YES - record the warning and show ppO2 | |
582 | 2429 TSTOSS opt_showppo2 ; show ppO2 anyhow? (0 = no, 1 = show always) |
560 | 2430 return ; NO - no warnings, no show |
2431 bra check_ppo2_display ; YES - just show ppO2 | |
2432 check_ppO2_low: | |
582 | 2433 movlw d'4' ; set type of alarm (ppO2 low) |
2434 bra check_ppO2_common ; continue with common part | |
560 | 2435 check_ppO2_high: |
2436 movlw d'5' ; set type of alarm (ppO2 high) | |
2437 check_ppO2_common: | |
2438 movwf AlarmType ; copy alarm type to alarm register | |
582 | 2439 bsf event_occured ; set event flag |
560 | 2440 bsf warning_active ; set warning flag |
2441 btfsc is_bailout ; are we in bailout? | |
2442 bra check_ppo2_display ; YES - skip CCR/pSCR checks | |
582 | 2443 btfsc FLAG_ccr_mode ; are we in CCR mode? |
560 | 2444 return ; YES - no extra warning required |
2445 btfsc FLAG_pscr_mode ; are we in pSCR mode? | |
2446 return ; YES - no extra warning required | |
2447 check_ppo2_display: ; display warning if ppO2 is not already shown in custom view | |
582 | 2448 movlw .9 |
2449 cpfseq menupos3 ; ppO2 shown in Custom View 9? | |
2450 bra check_ppO2_a ; No | |
2451 return ; Yes, do not show twice (in custom view and in warning area) | |
376
e99bb91f6f92
CHANGE: Do not show ppO2 in warning area if already shown in custom view
heinrichsweikamp
parents:
352
diff
changeset
|
2452 check_ppO2_a: |
582 | 2453 movlw .11 |
2454 cpfseq menupos3 ; ppO2 shown in Custom View 11? | |
2455 bra check_ppO2_b ; No | |
2456 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
|
2457 check_ppO2_b: |
582 | 2458 movlw .12 |
2459 cpfseq menupos3 ; ppO2 shown in Custom View 12? | |
2460 bra check_ppO2_c ; No | |
2461 return ; Yes, do not show twice (in custom view and in warning area) | |
482
c0ee33f1f399
New customview #12 for PSCR mode shows ppO2, O2 drop and lung ratio
heinrichsweikamp
parents:
480
diff
changeset
|
2462 check_ppO2_c: |
582 | 2463 movlw .10 |
2464 cpfseq menupos3 ; ppO2 shown in Custom View 10? | |
2465 bra check_ppO2_d ; No | |
2466 return ; Yes, do not show twice (in custom view and in warning area) | |
2467 check_ppO2_d: | |
2468 incf warning_counter,F ; increase counter | |
2469 goto TFT_display_ppo2 ; show breathed gas or diluent ppO2 warning (and return) | |
2470 | |
376
e99bb91f6f92
CHANGE: Do not show ppO2 in warning area if already shown in custom view
heinrichsweikamp
parents:
352
diff
changeset
|
2471 |
582 | 2472 global check_cns_violation |
0 | 2473 check_cns_violation: |
582 | 2474 ; Check if CNS should be displayed |
2475 movff int_O_CNS_fraction+1,WREG ; get high byte | |
2476 btfsc WREG,int_warning_flag ; warning flag set? | |
2477 bra check_cns_violation2 ; Yes - issue warning | |
2478 btfsc WREG,int_attention_flag ; attention flag set? | |
560 | 2479 bra display_cns_violation ; YES - just display CNS |
582 | 2480 return ; No - no display, no warning |
560 | 2481 check_cns_violation2: |
2482 bsf warning_active ; Set Warning flag | |
2483 display_cns_violation: ; Show CNS if not shown in the custom view | |
582 | 2484 movlw .11 |
2485 cpfseq menupos3 ; CNS shown in Custom View? | |
2486 bra display_cns_violation2 ; No | |
2487 return ; Yes, do not show twice (in custom view and in warning area) | |
560 | 2488 display_cns_violation2: |
582 | 2489 movlw .8 |
2490 cpfseq menupos3 ; CNS shown through Custom View 8 right now? | |
2491 bra display_cns_violation3 ; No | |
2492 return ; Yes, do not show twice (in custom view and in warning area) | |
560 | 2493 display_cns_violation3: |
582 | 2494 incf warning_counter,F ; increase counter |
2495 goto TFT_display_cns ; Show CNS (and return) | |
2496 | |
0 | 2497 |
582 | 2498 global check_eod_cns_violation ; check end-of-dive CNS values |
560 | 2499 check_eod_cns_violation: |
582 | 2500 movff int_O_CNS_fraction+1,WREG ; get high-byte of current CNS value |
2501 btfsc WREG,int_warning_flag ; current CNS value in warning state? | |
2502 return ; YES - inhibit eod warning if current CNS is already in warning | |
2503 movff int_O_normal_CNS_fraction+1,WREG | |
560 | 2504 btfsc WREG,int_invalid_flag ; flag for invalid value set? |
2505 bra check_eod_cns_violation1 ; YES - continue with checking the other CNS value | |
582 | 2506 btfsc WREG,int_warning_flag ; NO - flag for warning set? |
2507 bra check_eod_cns_violation2 ; YES - issue warning | |
2508 check_eod_cns_violation1: ; NO - continue with checking the other CNS value | |
2509 movff int_O_alternate_CNS_fraction+1,WREG | |
560 | 2510 btfsc WREG,int_invalid_flag ; flag for invalid value set? |
2511 return ; YES - done with CNS checking | |
2512 btfsc WREG,int_warning_flag ; NO - flag for warning set? | |
582 | 2513 bra check_eod_cns_violation2 ; Yes - issue warning |
2514 return ; NO - done with CNS checking | |
560 | 2515 check_eod_cns_violation2: ; YES - issue warning |
2516 bsf warning_active ; set Warning flag | |
582 | 2517 movlw .8 ; issue textual warning if CNS values are not shown in the custom view right now |
2518 cpfseq menupos3 ; CNS values shown through Custom View 8 right now? | |
2519 bra display_eod_cns_violation ; NO - issue textual warning | |
560 | 2520 return ; YES - do not show twice (in custom view and in warning area) |
2521 display_eod_cns_violation: | |
582 | 2522 incf warning_counter,F ; increase counter |
2523 goto TFT_display_eod_cns ; issue CNS at end-of-dive warning (and return) | |
560 | 2524 |
2525 | |
582 | 2526 global check_and_store_gf_violation |
0 | 2527 check_and_store_gf_violation: |
560 | 2528 movff int_O_gradient_factor+1,WREG ; get upper byte of gradient factor |
2529 btfss WREG,int_warning_flag ; check if the warning flag is set | |
582 | 2530 bra check_and_store_gf_violation2 ; NO - continue with checking for attention flag |
2531 movlw d'2' ; YES - set type of alarm | |
2532 movwf AlarmType ; copy to alarm register | |
2533 bsf event_occured ; set event flag | |
2534 bsf warning_active ; set warning flag | |
560 | 2535 bra check_and_store_gf_violation3 ; show gf warning |
2536 check_and_store_gf_violation2: | |
582 | 2537 btfsc WREG,int_attention_flag ; check if the attention flag is set |
2538 bra check_and_store_gf_violation3 ; YES - show gf | |
560 | 2539 TSTOSS opt_enable_IBCD ; NO - IBCD warning activated? |
582 | 2540 bra check_and_store_gf_violation4 ; NO - continue checking of deco info |
2541 movff char_O_deco_warnings,WREG ; YES - get the deco warnings vector | |
2542 btfss WREG,IBCD_warning ; is the IBCD warning flag set? | |
2543 bra check_and_store_gf_violation4 ; NO - continue checking for deco info | |
2544 check_and_store_gf_violation3: ; YES - show gf | |
560 | 2545 bsf warning_active ; set Warning flag |
2546 incf warning_counter,F ; increase counter | |
582 | 2547 goto TFT_warning_gf ; show GF (and return) |
560 | 2548 check_and_store_gf_violation4: ; check for deco info |
2549 btfss divemode ; in divemode? | |
2550 return ; NO - done, return | |
2551 movff char_O_deco_warnings,WREG ; YES - get the deco warnings vector | |
582 | 2552 btfss WREG,deco_flag ; check if the deco flag is set |
2553 return ; NO - all done, return | |
2554 incf warning_counter,F ; YES - increase counter | |
2555 goto TFT_info_deco ; show deco info | |
2556 | |
2557 | |
560 | 2558 warn_outside: |
2559 incf warning_counter,F ; increase counter | |
582 | 2560 bsf warning_active ; Set Warning flag |
2561 goto TFT_warning_outside ; show outside warning (and return) | |
560 | 2562 |
582 | 2563 |
560 | 2564 global warn_mbubbles |
2565 warn_mbubbles: | |
0 | 2566 incf warning_counter,F ; increase counter |
582 | 2567 bsf warning_active ; Set Warning flag |
2568 goto TFT_warning_mbubbles ; show microbubbles warning (and return) | |
560 | 2569 |
0 | 2570 warn_agf: |
2571 incf warning_counter,F ; increase counter | |
582 | 2572 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
|
2573 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
138
diff
changeset
|
2574 warn_fallback: |
582 | 2575 incf warning_counter,F ; increase counter |
2576 bsf warning_active ; Set Warning flag | |
2577 goto TFT_warning_fallback ; Show fallback warning (and return) | |
0 | 2578 |
582 | 2579 |
560 | 2580 check_gas_needs: |
2581 banksel int_O_tank_pres_need | |
582 | 2582 movf int_O_tank_pres_need+1,w ; get HIGH(pres need of 1st tank) |
560 | 2583 iorwf int_O_tank_pres_need+3,w ; inclusive or with HIGH(pres need of 2nd tank) |
2584 iorwf int_O_tank_pres_need+5,w ; inclusive or with HIGH(pres need of 3rd tank) | |
2585 iorwf int_O_tank_pres_need+7,w ; inclusive or with HIGH(pres need of 4th tank) | |
2586 iorwf int_O_tank_pres_need+9,w ; inclusive or with HIGH(pres need of 5th tank) | |
2587 banksel common | |
582 | 2588 btfsc WREG,int_invalid_flag ; check if invalid flag is set |
560 | 2589 return ; YES - no further checking required |
2590 btfsc WREG,int_warning_flag ; NO - check if any gas has a pres_need >= pres_fill | |
2591 bsf warning_active ; YES - set warning flag | |
2592 btfsc WREG,int_warning_flag ; NO - check if any gas has a pres_need >= pres_fill | |
2593 goto TFT_warning_gas_needs_warn ; Yes - show a warning | |
582 | 2594 btfsc WREG,int_attention_flag ; NO - check if any gas has a pres_need >= pres_fill * threshold |
560 | 2595 goto TFT_warning_gas_needs_att ; YES - show an attention |
2596 bcf gas_needs_attention ; NO - clear flag for a new attention | |
2597 bcf gas_needs_warning ; clear flag for a new warning | |
2598 return | |
0 | 2599 |
582 | 2600 |
560 | 2601 check_warn_sensors_disagree: |
582 | 2602 incf warning_counter,F ; increase counter |
560 | 2603 bsf warning_active ; YES - set Warning flag |
582 | 2604 goto TFT_warning_sensor_disagree ; show sensor disagree warning (and return) |
560 | 2605 |
2606 | |
2607 check_IBCD: | |
2608 TSTOSS opt_enable_IBCD ; IBCD warning activated? | |
2609 return ; NO - done | |
2610 movff char_O_deco_warnings,WREG ; YES - get deco warnings vector | |
582 | 2611 btfss WREG,IBCD_warning ; IBCD warning flag set? |
2612 return ; NO - return | |
2613 incf warning_counter,F ; YES - increase counter | |
2614 goto TFT_warning_IBCD ; write warning to display | |
560 | 2615 |
2616 | |
2617 global restart_deco_engine | |
2618 global restart_deco_engine_wo_ceiling | |
2619 restart_deco_engine: | |
2620 ; make bank save copies and set flags for invalid data | |
2621 movff int_O_ceiling+1,WREG | |
2622 bsf WREG,char_invalid_flag ; int_O_ceiling has its invalid flag on a char's position! | |
2623 movff WREG,int_O_ceiling+1 | |
2624 | |
2625 restart_deco_engine_wo_ceiling: | |
2626 ; make more bank save copies and set more flags for invalid data | |
2627 movff char_O_deco_gas+0,WREG | |
2628 bsf WREG,char_invalid_flag | |
2629 movff WREG,char_O_deco_gas+0 | |
2630 | |
2631 movff int_O_ascenttime+1,WREG | |
2632 bsf WREG,int_invalid_flag | |
2633 movff WREG,int_O_ascenttime+1 | |
2634 | |
2635 movff int_O_alternate_ascenttime+1,WREG | |
2636 bsf WREG,int_invalid_flag | |
2637 movff WREG,int_O_alternate_ascenttime+1 | |
2638 | |
2639 movff int_O_normal_CNS_fraction+1,WREG | |
2640 bsf WREG,int_invalid_flag | |
2641 movff WREG,int_O_normal_CNS_fraction+1 | |
2642 | |
2643 movff int_O_alternate_CNS_fraction+1,WREG | |
2644 bsf WREG,int_invalid_flag | |
2645 movff WREG,int_O_alternate_CNS_fraction+1 | |
2646 | |
2647 movff int_O_tank_pres_need+1,WREG | |
2648 bsf WREG,int_invalid_flag | |
2649 movff WREG,int_O_tank_pres_need+1 | |
582 | 2650 |
560 | 2651 ; restart deco engine |
582 | 2652 movff char_O_deco_status,WREG ; get current deco engine configuration |
2653 bcf WREG,DECO_STATUS_0_FLAG ; set status flags to... | |
2654 bcf WREG,DECO_STATUS_1_FLAG ; ... DECO_STATUS_START | |
2655 bsf WREG,DECO_PLAN_FLAG ; fake we came from alternative plan to force normal plan to be done next | |
2656 movff WREG,char_O_deco_status ; write back new configuration to restart deco computations | |
2657 | |
2658 return | |
2659 | |
2660 ;============================================================================= | |
2661 ; simulator mode | |
2662 ; | |
2663 | |
2664 global do_demo_divemode | |
2665 do_demo_divemode: | |
2666 call option_save_all ; Save all settings into EEPROM before starting simulation | |
2667 call deco_push_tissues_to_vault ; C-code: back-up status of the real tissues | |
2668 banksel common ; Bank1 | |
2669 | |
2670 ; +++ COMMENTED OUT FOR TESTING PURPOSE ONLY !!! +++ | |
2671 ; +++ DO NOT COMMENT OUT IN OPERATIONAL USE !!! +++ | |
2672 ; | |
2673 bsf restore_deco_data ; Restore tissue and CNS after simulator use | |
560 | 2674 |
582 | 2675 bcf pressure_refresh |
2676 btfss pressure_refresh ; Wait for sensor | |
2677 bra $-2 | |
2678 | |
2679 bsf simulatormode_active ; Set Flag | |
2680 ; Compute dive ambient conditions | |
2681 banksel char_I_bottom_depth | |
2682 movf char_I_bottom_depth,W | |
2683 mullw .100 | |
2684 movff PRODL,rel_pressure+0 | |
2685 movff PRODH,rel_pressure+1 | |
2686 movlw LOW (.1000) | |
2687 addwf PRODL,W | |
2688 movff WREG,sim_pressure+0 | |
2689 movlw HIGH (.1000) | |
2690 addwfc PRODH,W | |
2691 movff WREG,sim_pressure+1 | |
2692 banksel common ; Bank1 | |
2693 | |
2694 bsf divemode | |
2695 goto diveloop ; Switch into Divemode! | |
2696 | |
2697 END |