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