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