Mercurial > public > hwos_code
annotate src/divemode.asm @ 97:53a99a2dc6a1
CHANGE: Always compute bailout plan based on all active gases
CHANGE: Re-select last diluent when returning from bailout to OC
author | heinrichsweikamp |
---|---|
date | Mon, 28 Apr 2014 16:26:31 +0200 |
parents | c34516c99ca8 |
children | 24b3fd59e61f |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
3 ; File divemode.asm | |
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 | |
12 #include "ostc3.inc" ; Mandatory header | |
13 #include "shared_definitions.h" ; Mailbox from/to p2_deco.c | |
14 #include "tft_outputs.inc" | |
15 #include "strings.inc" | |
16 #include "tft.inc" | |
17 #include "eeprom_rs232.inc" | |
18 #include "isr.inc" | |
19 #include "math.inc" | |
20 #include "wait.inc" | |
21 #include "customview.inc" | |
22 #include "start.inc" | |
23 #include "adc_lightsensor.inc" | |
24 #include "ghostwriter.inc" | |
25 #include "i2c.inc" | |
26 | |
27 gui CODE | |
28 | |
29 global diveloop | |
30 diveloop: | |
31 banksel common | |
32 call speed_normal | |
33 call diveloop_boot ; Boot tasks for all modes | |
34 | |
35 ; Startup Tasks for all modes | |
36 call TFT_ClearScreen ; clean up TFT | |
37 call TFT_divemode_mask ; Display mask | |
38 call TFT_temp_divemode ; Displays temperature | |
39
e4e91fe8b09d
remember last customview in dive and surface mode
mh@mh-THINK.fritz.box
parents:
38
diff
changeset
|
39 movff customview_divemode,menupos3 ; Reload last customview |
e4e91fe8b09d
remember last customview in dive and surface mode
mh@mh-THINK.fritz.box
parents:
38
diff
changeset
|
40 call customview_mask ; Redraw last custom view |
0 | 41 |
42 btfsc FLAG_apnoe_mode | |
43 bsf realdive ; Set Realdive flag in Apnoe mode | |
44 | |
45 btfsc FLAG_apnoe_mode ; Done for Apnoe or Gauge mode | |
46 bra diveloop_loop | |
47 btfsc FLAG_gauge_mode ; Done for Apnoe or Gauge mode | |
48 bra diveloop_loop | |
49 | |
50 call TFT_active_gas_divemode ; Display gas/Setpoint | |
51 call TFT_display_ndl_mask ; display "NDL" | |
52 | |
53 ; +@5 init | |
54 setf WREG ; WAIT marker: display "---" | |
55 movff WREG,int_O_extra_ascenttime+0 | |
56 movff WREG,int_O_extra_ascenttime+1 | |
57 movlw 1 | |
58 movwf apnoe_mins ; Start compute after next cycle. | |
59 | |
60 ;-------------------------------------------------------------------------------------------------------- | |
61 diveloop_loop: ; The diveloop starts here | |
62 btfss onesecupdate | |
63 bra diveloop_loop3 | |
64 | |
65 ; tasks any new second... | |
66 btfsc FLAG_apnoe_mode ; Only in apnoe mode | |
67 bra diveloop_loop1b ; One Second Tasks in Apnoe mode | |
68 | |
69 call TFT_divemins ; Display (new) divetime! | |
70 call customview_second ; Do every-second tasks for the custom view area | |
71 | |
72 ; Tasks only for deco modes | |
73 call calc_deko_divemode ; calculate decompression and display result (any two seconds) | |
74 bra diveloop_loop1x ; Common Tasks | |
75 | |
76 diveloop_loop1b: | |
77 ; Tasks only for Apnoe mode | |
78 call divemode_apnoe_tasks ; 1 sec. Apnoe tasks | |
79 bra diveloop_loop1x ; Common Tasks | |
80 | |
81 diveloop_loop1x: | |
82 ; Common 1sec. tasks for all modes | |
83 call timeout_divemode ; dive finished? This routine sets the required flags | |
84 call set_dive_modes ; tests if depth>threshold | |
85 call set_min_temp ; store min. temp if required | |
86 | |
87 btfsc store_sample ; store new sample? | |
88 call store_dive_data ; Store profile data | |
89 | |
90 btfss divemode ; Dive finished? | |
91 goto ghostwriter_end_dive ; Dive finished! | |
92 | |
93 btfsc divemode_gaschange ; Gas switch flag set? | |
94 rcall gas_switched_common ; Yes | |
95 | |
96 btfsc toggle_gf ; =1: Toggle GF/aGF | |
97 rcall divemodemode_togglegf ; Toggle aGF/GF | |
98 | |
99 ; btfsc FLAG_ccr_mode ; In CCR mode | |
100 ; call TFT_active_gas_divemode ; Update Setpoint every second | |
101 | |
102 bcf onesecupdate ; one seconds update done | |
103 | |
104 diveloop_loop3: | |
105 rcall test_switches_divemode ; Check switches in divemode | |
106 | |
107 global diveloop_loop4 | |
108 diveloop_loop4: ; Menu-Exit returns here... | |
109 btfsc toggle_customview ; Next view? | |
110 call customview_toggle ; Yes, show next customview (and delete this flag) | |
111 | |
112 btfsc pressure_refresh ; new pressure available? | |
113 rcall update_temp_and_or_depth ; Yes, display new depth and clear "pressure_refresh" flag | |
114 | |
115 btfsc oneminupdate ; one minute tasks | |
116 rcall update_divemode60 ; Update clock, etc. | |
117 | |
118 btfss quarter_second_update | |
119 bra diveloop_loop4a | |
83 | 120 |
0 | 121 bcf quarter_second_update |
122 movlw .6 | |
123 cpfseq menupos3 ; in compass view? | |
124 bra diveloop_loop4a ; No | |
125 call TFT_dive_compass_heading ; Yes, update compass heading value | |
126 diveloop_loop4a: | |
127 btfsc enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump) | |
128 bra diveloop_loop5 | |
129 bra diveloop_loop6 | |
130 diveloop_loop5: | |
131 btfss vusb_in ; USB (still) plugged in? | |
132 bcf enable_screen_dumps ; No, clear flag | |
133 call rs232_get_byte | |
134 btfsc rs232_recieve_overflow | |
135 bra diveloop_loop6 | |
136 movlw "l" | |
137 cpfseq RCREG1 | |
138 bra diveloop_loop6 | |
139 call TFT_dump_screen ; Dump the screen contents | |
140 diveloop_loop6: | |
141 | |
142 bra diveloop_loop ; Loop the divemode | |
143 ;-------------------------------------------------------------------------------------------------------- | |
144 | |
145 | |
146 divemode_apnoe_tasks: ; 1 sec. Apnoe tasks | |
147 call TFT_display_apnoe_descent ; Show descent timer | |
148 call TFT_max_pressure ; use normal max. depth | |
149 | |
150 btfsc divemode2 ; Time running? | |
151 bra divemode_apnoe_tasks2 ; New descent, reset data if flag is set | |
152 | |
153 rcall apnoe_calc_maxdepth | |
154 call TFT_display_apnoe_surface | |
155 call TFT_display_apnoe_last_max ; Show last max. depth | |
156 incf apnoe_surface_secs,F | |
157 movlw d'60' | |
158 cpfseq apnoe_surface_secs | |
159 bra divemode_apnoe_tasks1 | |
160 clrf apnoe_surface_secs | |
161 incf apnoe_surface_mins,F | |
162 | |
163 divemode_apnoe_tasks1: | |
164 bcf FLAG_active_descent ; Clear flag | |
165 btfsc divemode2 ; Time running? | |
166 return ; Yes, return | |
167 bsf FLAG_active_descent ; Set Flag | |
168 return | |
169 | |
170 divemode_apnoe_tasks2: | |
171 btfss FLAG_active_descent ; Are we descending? | |
172 return ; No, We are at the surface | |
173 rcall apnoe_calc_maxdepth ; Yes! | |
174 call TFT_apnoe_clear_surface ; Clear Surface timer | |
175 clrf apnoe_timeout_counter ; Delete timeout | |
176 clrf apnoe_surface_secs | |
177 clrf apnoe_surface_mins | |
178 clrf apnoe_secs | |
179 clrf apnoe_mins ; Reset Descent time | |
180 movlw .0 | |
181 movff WREG,max_pressure+0 | |
182 movff WREG,max_pressure+1 ; Reset Max. Depth | |
183 bcf FLAG_active_descent ; Clear flag | |
184 return | |
185 | |
186 global apnoe_calc_maxdepth | |
187 apnoe_calc_maxdepth: | |
188 movff apnoe_max_pressure+0,sub_a+0 | |
189 movff apnoe_max_pressure+1,sub_a+1 | |
190 movff max_pressure+0,sub_b+0 | |
191 movff max_pressure+1,sub_b+1 | |
192 call subU16 ; sub_c = sub_a - sub_b | |
193 ; apnoe_max_pressure<max_pressure -> neg_flag=1 | |
194 ; max_pressure<=apnoe_max_pressure -> neg_flag=0 | |
195 btfss neg_flag | |
196 return | |
197 ;apnoe_max_pressure<max_pressure | |
198 movff max_pressure+0,apnoe_max_pressure+0 | |
199 movff max_pressure+1,apnoe_max_pressure+1 | |
200 return | |
201 | |
202 | |
203 calc_deko_divemode: | |
204 btfsc twosecupdate ; two seconds after the last call | |
205 bra calc_deko_divemode2 ; Yes, calculate and display deco data ("first second") | |
206 | |
207 bsf twosecupdate ; No, but next second! | |
208 ; Routines used in the "other second" | |
209 call calc_average_depth ; calculate average depth | |
210 call calc_velocity ; calculate vertical velocity and display if > threshold (every two seconds) | |
211 call divemode_check_for_warnings ; Check for any warnings | |
212 call TFT_debug_output | |
213 | |
214 btfsc FLAG_apnoe_mode ; Done for Apnoe or Gauge mode | |
215 return | |
216 btfsc FLAG_gauge_mode ; Done for Apnoe or Gauge mode | |
217 return | |
218 | |
219 ; Calculate CNS | |
220 rcall set_actual_ppo2 ; Set char_I_actual_ppO2 | |
221 clrf WREG | |
222 movff WREG,char_I_step_is_1min ; Make sure to be in 2sec mode. | |
223 call deco_calc_CNS_fraction ; calculate CNS | |
224 movlb b'00000001' ; rambank 1 selected | |
225 | |
226 ; Check for a gas change | |
227 rcall check_gas_change ; Checks if a better gas should be selected (by user) | |
228 | |
229 return | |
230 | |
231 global set_actual_ppo2 | |
232 set_actual_ppo2: ; calculate ppO2 in 0.01bar (e.g. 150 = 1.50 bar ppO2) | |
233 SAFE_2BYTE_COPY amb_pressure, xA ; P_amb in millibar (1000 = 1.00 bar). | |
234 movlw d'10' | |
235 movwf xB+0 | |
236 clrf xB+1 | |
237 call div16x16 ; xC=p_amb/10 (100 = 1.00 bar). | |
238 movff xC+0,xA+0 | |
239 movff xC+1,xA+1 | |
240 movff char_I_O2_ratio,xB+0 | |
241 clrf xB+1 | |
242 call mult16x16 ; char_I_O2_ratio * (p_amb/10) | |
243 movff xC+0,xA+0 | |
244 movff xC+1,xA+1 | |
245 movlw d'100' | |
246 movwf xB+0 | |
247 clrf xB+1 | |
248 call div16x16 ; xC=(char_I_O2_ratio * p_amb/10)/100 | |
249 | |
250 ; Copy ppO2 for CNS calculation | |
251 tstfsz xC+1 ; Is ppO2 > 2.55bar ? | |
252 setf xC+0 ; yes: bound to 2.55... better than wrap around. | |
253 | |
254 movff xC+0, char_I_actual_ppO2 ; copy last ppO2 to buffer register | |
255 btfsc is_bailout ; In Bailout? | |
256 return ; Yes, done. | |
257 ; No Bailout, check for ccr mode | |
258 btfsc FLAG_ccr_mode ; If FLAG_ccr_mode=1... | |
259 movff char_I_const_ppO2, char_I_actual_ppO2 ; ...copy last ppO2 to buffer register | |
260 return | |
261 | |
262 | |
263 calc_deko_divemode2: | |
264 bcf twosecupdate | |
265 | |
266 btfsc FLAG_apnoe_mode ; Done for Apnoe or Gauge mode | |
267 return | |
268 btfsc FLAG_gauge_mode ; Done for Apnoe or Gauge mode | |
269 return | |
270 | |
271 extern deco_setup_dive | |
272 call deco_setup_dive ; Pass all parameters to the C code | |
273 | |
274 TSTOSS opt_ccr_mode ; =0: Fixed SP, =1: Sensor | |
275 bra calc_deko_divemode2a | |
276 rcall divemode_setup_sensor_values ; Setup sensor values | |
277 | |
278 calc_deko_divemode2a: | |
279 SAFE_2BYTE_COPY amb_pressure,int_I_pres_respiration ; C-code needs the ambient pressure | |
280 clrf WREG | |
281 movff WREG,char_I_step_is_1min ; Force 2 second deco mode | |
282 | |
283 clrf TMR5L | |
284 clrf TMR5H ; 30,51757813µs/bit in TMR5L:TMR5H | |
285 call deco_calc_hauptroutine ; calc_tissue | |
286 movlb .1 | |
287 | |
288 movff char_O_deco_status,WREG ; Is a compute cycle finished ? | |
289 iorwf WREG,F | |
290 btfss STATUS,Z | |
291 return ; Return is status <> 0 | |
292 | |
293 ; Check if deco stops are necessary ? | |
294 movff char_O_first_deco_depth,wait_temp ; copy ceiling to temp register | |
295 tstfsz wait_temp ; Ceiling<0m? | |
296 bra calc_deko_divemode3 ; Yes! | |
297 | |
298 btfsc decostop_active ; Already in nodeco mode ? | |
299 call TFT_display_ndl_mask ; No, Clear deco data, display nostop time | |
300 bcf decostop_active ; clear flag (again) | |
301 | |
302 ; Copy for profile recording | |
303 clrf decodata+0 | |
304 movff char_O_nullzeit,decodata+1 ; NDL | |
305 | |
306 call TFT_display_ndl ; display no deco limit | |
307 return | |
308 | |
309 calc_deko_divemode3: | |
310 btfss decostop_active ; Already in deco mode ? | |
311 call TFT_display_deko_mask ; No, clear nostop time, display decodata | |
312 bsf decostop_active ; Set flag (again) | |
313 | |
314 ; Copy for profile recording | |
315 movff char_O_first_deco_depth,decodata+0 ; ceiling | |
316 movff char_O_first_deco_time,decodata+1 ; length of first stop in minues | |
317 call TFT_display_deko ; display decodata | |
318 call TFT_show_TTS_divemode ; display TTS | |
319 | |
320 movff char_I_extra_time,WREG | |
321 tstfsz WREG ; extra time = 0? | |
322 bra calc_deko_divemode4 ; No, compute it | |
323 return | |
324 | |
325 calc_deko_divemode4: | |
326 ; Check if extra cycles are needed to compute @5 variant: | |
327 decfsz apnoe_mins,F ; Reached count-down ? | |
328 return ; No: don't compute yet. | |
329 | |
330 movlw .6 | |
331 movff WREG,char_O_deco_status ; Stole next cycles for @5 variant. | |
332 | |
333 movlw .2 ; Restart countdown. | |
334 movwf apnoe_mins | |
335 return ; done. | |
336 | |
337 ;----------------------------------------------------------------------------- | |
338 | |
339 divemodemode_togglegf: ; Toggle aGF/GF | |
340 bcf toggle_gf ; clear flag | |
341 btg use_agf ; Toggle GF | |
342 call TFT_gf_mask ; Setup Mask | |
343 clrf WREG | |
344 movff WREG,char_O_deco_status ; Restart decoplan computation | |
345 return | |
346 | |
347 divemode_setup_sensor_values: | |
348 ; sum up sensor values (in xA:2) and active sensors in (xB:2) | |
349 clrf xB+0 | |
350 clrf xB+1 | |
351 clrf xA+0 | |
352 clrf xA+1 | |
353 btfss hud_status_byte,3 ; Sensor1 active? | |
354 bra divemode_setup_sensor_values2 ; No | |
355 movf o2_ppo2_sensor1,W | |
356 addwf xA+0 | |
357 movlw .0 | |
358 addwfc xA+1 ; Add into xA:2 | |
359 incf xB+0,F ; Add a sensor | |
360 divemode_setup_sensor_values2: | |
361 btfss hud_status_byte,4 ; Sensor2 active? | |
362 bra divemode_setup_sensor_values3 ; No | |
363 movf o2_ppo2_sensor2,W | |
364 addwf xA+0 | |
365 movlw .0 | |
366 addwfc xA+1 ; Add into xA:2 | |
367 incf xB+0,F ; Add a sensor | |
368 divemode_setup_sensor_values3: | |
369 btfss hud_status_byte,5 ; Sensor3 active? | |
370 bra divemode_setup_sensor_values4 ; No | |
371 movf o2_ppo2_sensor3,W | |
372 addwf xA+0 | |
373 movlw .0 | |
374 addwfc xA+1 ; Add into xA:2 | |
375 incf xB+0,F ; Add a sensor | |
376 divemode_setup_sensor_values4: | |
377 call div16x16 ; xA/xB=xC with xA+0 as remainder | |
378 movff xC+0,sensor_setpoint ; Copy result | |
379 movff sensor_setpoint,char_I_const_ppO2 ; use sensor ppO2 | |
380 return | |
381 | |
382 calc_velocity: ; called every two seconds | |
383 btfss divemode | |
384 bra do_not_display_velocity ; display velocity only in divemode (Not at the surface after dive) | |
385 | |
386 calc_velocity2: | |
387 SAFE_2BYTE_COPY amb_pressure, sub_a | |
388 movff last_pressure_velocity+0,sub_b+0 | |
389 movff last_pressure_velocity+1,sub_b+1 | |
390 movff sub_a+0,last_pressure_velocity+0 ; store old value for velocity | |
391 movff sub_a+1,last_pressure_velocity+1 | |
392 | |
393 call subU16 ; sub_c = amb_pressure - last_pressure | |
394 | |
395 movff sub_c+0,xA+0 | |
396 movff sub_c+1,xA+1 | |
397 movlw d'39' ; 77 when called every second.... | |
398 movwf xB+0 | |
399 clrf xB+1 | |
400 call mult16x16 ; differential pressure in mbar*77... | |
401 movff xC+0,divA+0 | |
402 movff xC+1,divA+1 | |
403 movlw d'7' | |
404 movwf divB+0 | |
405 call div16 ; devided by 2^7 equals velocity in m/min | |
406 | |
407 movlw d'99' | |
408 cpfsgt divA+0 ; limit to 99m/min | |
409 bra calc_velocity3 | |
410 movwf divA+0 ; divA=99 | |
411 | |
412 calc_velocity3: | |
413 movlw velocity_warning_level_1 ; lowest threshold for display vertical velocity | |
414 subwf divA+0,W ; | |
415 btfss STATUS,C | |
416 bra do_not_display_velocity | |
417 | |
418 bsf display_velocity | |
419 call TFT_display_velocity ; With divA+0 = m/min... | |
420 return | |
421 | |
422 do_not_display_velocity: | |
423 btfss display_velocity ; Velocity was not displayed, do not delete | |
424 return | |
425 bcf display_velocity ; Velocity was displayed, delete velocity now | |
426 call TFT_display_velocity_clear | |
427 return | |
428 | |
429 ;============================================================================= | |
430 | |
431 timeout_menuview: | |
432 decfsz timeout_counter3,F ; timeout for menuview | |
433 return ; No timeout, return | |
434 ; Timeout, clear e.g. "Menu?" | |
435 goto menuview_toggle_reset ; "returns" | |
436 | |
437 timeout_divemode_menu: | |
438 decfsz timeout_counter3,F ; timeout for divemode menu | |
439 return | |
440 | |
441 global timeout_divemode_menu2 | |
442 timeout_divemode_menu2: ; Called from divemenu_tree.asm | |
443 bcf divemode_menu ; Timeout! Clear flag | |
444 call TFT_clear_divemode_menu ; Clear menu | |
445 call TFT_active_gas_divemode ; Redraw gas/setpoint/diluent | |
446 bcf blinking_better_gas ; Clear flag to have temperature updated once | |
447 call TFT_temp_divemode ; Displays temperature | |
448 | |
449 btfss decostop_active ; In deco mode ? | |
450 bra timeout_divemode_menu_ndl ; No, show NDL again | |
451 ; Show deco | |
452 call TFT_display_deko_mask ; clear nostop time, display decodata | |
453 call TFT_display_deko | |
454 call TFT_show_TTS_divemode | |
455 return | |
456 timeout_divemode_menu_ndl: ; Show NDL | |
457 call TFT_display_ndl_mask ; Clear deco data, display nostop time | |
458 call TFT_display_ndl | |
459 return | |
460 | |
461 timeout_divemode: | |
462 btfsc divemode_menu ; Divemode menu active? | |
463 rcall timeout_divemode_menu ; Yes, check the timeout for it... | |
464 | |
465 btfsc menuview ; is a menuview shown? | |
466 rcall timeout_menuview ; Yes, check the timeout for it... | |
467 | |
468 btfss realdive ; Dive longer then one minute | |
469 return | |
470 | |
471 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
|
472 bra timeout_divemode2 ; Yes, use apnoe_timeout [min] for timeout |
0 | 473 |
474 ifndef __DEBUG | |
475 btfsc simulatormode_active ; In Simulator mode? | |
476 bra timeout_divemode3 ; Yes, use simulator timeout | |
477 endif | |
478 | |
479 bcf divemode | |
480 incf timeout_counter,F | |
481 movlw d'0' | |
482 addwfc timeout_counter2,F ; timeout is 15bits | |
483 | |
484 movlw LOW divemode_timeout | |
485 movwf sub_a+0 | |
486 movlw HIGH divemode_timeout | |
487 movwf sub_a+1 | |
488 | |
489 movff timeout_counter, sub_b+0 | |
490 movff timeout_counter2, sub_b+1 | |
491 call subU16 ; sub_c = sub_a - sub_b | |
492 btfss neg_flag ; Result negative? | |
493 bsf divemode ; No, set flag | |
494 return | |
495 | |
496 timeout_divemode2: | |
497 incf timeout_counter,F ; seconds... | |
498 movlw d'60' | |
499 cpfseq timeout_counter ; timeout_counter=60? | |
500 return ; No. | |
501 ; One minute timeout done. | |
502 clrf timeout_counter | |
503 bcf divemode | |
504 incf apnoe_timeout_counter,F | |
505 movlw apnoe_timeout ; apnoe timeout [min] | |
506 cpfseq apnoe_timeout_counter | |
507 bsf divemode | |
508 return | |
509 | |
510 timeout_divemode3: | |
511 bcf divemode | |
512 incf timeout_counter,F | |
513 movlw simulator_timeout ; simulator timeout | |
514 cpfsgt timeout_counter | |
515 bsf divemode | |
516 return | |
517 | |
518 update_temp_and_or_depth: ; New sensor data arrived... | |
519 btfsc temp_changed | |
520 call TFT_temp_divemode ; Displays temperature | |
521 | |
522 btfsc pressure_refresh | |
523 call TFT_depth ; Displays new depth | |
524 | |
525 rcall set_max_depth ; update max. depth if required | |
526 bcf pressure_refresh ; until new pressure is available | |
527 return | |
528 | |
529 update_divemode60: ; update any minute | |
530 call get_battery_voltage ; gets battery voltage | |
531 call set_powersafe ; Battery low? | |
532 call TFT_max_pressure ; Update max. depth | |
533 call customview_minute ; Do every-minute tasks for the custom view area | |
534 bcf oneminupdate | |
535 | |
536 btfss simulatormode_active ; in simulator mode? | |
537 return ; No | |
538 ; Yes, quite dive mode simulation after 21*256s=89min:36s | |
539 movlw .20 | |
540 cpfsgt total_divetime_seconds+1 ; Timeout? | |
541 return ; No | |
542 ifdef __DEBUG | |
543 return ; No simulator timeout in debug mode | |
544 endif | |
545 bra divemode_option1 ; Yes, set to 0m and "return" | |
546 | |
547 set_max_depth: | |
548 movff max_pressure+0,sub_a+0 | |
549 movff max_pressure+1,sub_a+1 | |
550 SAFE_2BYTE_COPY rel_pressure, sub_b | |
551 call subU16 ; sub_c = sub_a - sub_b | |
552 ; max_pressure<rel_pressure -> neg_flag=1 | |
553 ; rel_pressure<=max_pressure -> neg_flag=0 | |
554 btfss neg_flag | |
555 return | |
556 ; max_pressure<rel_pressure | |
557 movff sub_b+0,max_pressure+0 | |
558 movff sub_b+1,max_pressure+1 | |
559 call TFT_max_pressure ; No, use normal max. depth | |
560 return | |
561 | |
562 set_min_temp: | |
563 movff minimum_temperature+0,sub_a+0 | |
564 movff minimum_temperature+1,sub_a+1 | |
565 SAFE_2BYTE_COPY temperature,sub_b | |
566 call sub16 ; sub_c = sub_a - sub_b | |
567 ; minimum_temperature<T -> neg_flag=1 | |
568 ; T<=minimum_temperature -> neg_flag=0 | |
569 btfsc neg_flag | |
570 return | |
571 ; minimum_temperature>=T | |
572 movff sub_b+0,minimum_temperature+0 | |
573 movff sub_b+1,minimum_temperature+1 | |
574 return | |
575 | |
576 global set_dive_modes | |
577 set_dive_modes: | |
578 btfsc high_altitude_mode ; In high altitude (Fly) mode? | |
579 bra set_dive_modes3 ; Yes! | |
580 | |
581 set_dive_modes0: | |
582 movlw LOW start_dive_threshold | |
583 movwf sub_a+0 ; dive_treshold is in cm | |
584 movlw HIGH start_dive_threshold | |
585 movwf sub_a+1 ; dive_treshold is in cm | |
586 | |
587 set_dive_modes1: | |
588 SAFE_2BYTE_COPY rel_pressure, sub_b | |
589 call subU16 ; sub_c = sub_a - sub_b | |
590 | |
591 btfss neg_flag | |
592 bra set_dive_modes2 ; too shallow (rel_pressure<dive_threshold) | |
593 | |
594 btfsc realdive ; Dive longer than one minute? | |
595 clrf timeout_counter ; Yes, reset timout counter | |
596 | |
597 set_dive_modes_common: | |
598 bsf divemode ; (Re-)Set divemode flag | |
599 bsf divemode2 ; displayed divetime is running | |
600 return | |
601 | |
602 set_dive_modes2: | |
603 bcf divemode2 ; Stop time | |
604 btfss realdive ; dive longer then one minute? | |
605 bcf divemode ; no -> this was no real dive | |
606 return ; No, return | |
607 | |
608 | |
609 set_dive_modes3: ; High-altitude mode | |
610 btfsc realdive ; dive longer then one minute? | |
611 bra set_dive_modes0 ; Yes -> this is a real dive -> Use start_dive_threshold or ascend | |
612 | |
613 movlw HIGH high_altitude_dive_threshold | |
614 movwf sub_a+1 | |
615 movlw LOW high_altitude_dive_threshold | |
616 movwf sub_a+0 | |
617 bra set_dive_modes1 | |
618 | |
619 set_powersafe: | |
620 movlw color_code_battery_low+1; [%] | |
621 cpfslt batt_percent | |
622 return | |
623 | |
624 movlw d'7' ; Type of Alarm (Battery Low) | |
625 movwf AlarmType ; Copy to Alarm Register | |
626 bsf event_occured ; Set Event Flag | |
627 movlw .0 | |
628 movff WREG,opt_brightness ; Set Brightness to ECO | |
629 return ; return | |
630 | |
631 calc_average_depth: | |
632 btfsc reset_average_depth ; Reset the Avewrage depth? | |
633 rcall reset_average1 ; Reset the resettable average depth | |
634 | |
635 ; 1. Add new 2xdepth to the Sum of depths registers | |
636 SAFE_2BYTE_COPY rel_pressure, xB ; Buffer... | |
637 bcf STATUS,C | |
638 rlcf xB+0,F | |
639 rlcf xB+1,F ; x2 | |
640 | |
641 movf xB+0,w | |
642 addwf average_depth_hold+0,F | |
643 movf xB+1,w | |
644 addwfc average_depth_hold+1,F | |
645 movlw d'0' | |
646 addwfc average_depth_hold+2,F | |
647 addwfc average_depth_hold+3,F ; Will work up to 9999mbar*60*60*24=863913600mbar | |
648 | |
649 ; Do the same for the _total registers (Non-Resettable) | |
650 movf xB+0,w | |
651 addwf average_depth_hold_total+0,F | |
652 movf xB+1,w | |
653 addwfc average_depth_hold_total+1,F | |
654 movlw d'0' | |
655 addwfc average_depth_hold_total+2,F | |
656 addwfc average_depth_hold_total+3,F ; Will work up to 9999mbar*60*60*24=863913600mbar | |
657 | |
658 ; 2. Compute Average Depth on base of average_divesecs:2 | |
659 movff average_divesecs+0,xB+0 | |
660 movff average_divesecs+1,xB+1 ; Copy | |
661 movff average_depth_hold+0,xC+0 | |
662 movff average_depth_hold+1,xC+1 | |
663 movff average_depth_hold+2,xC+2 | |
664 movff average_depth_hold+3,xC+3 | |
665 | |
666 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | |
667 movff xC+0,avr_rel_pressure+0 | |
668 movff xC+1,avr_rel_pressure+1 | |
669 | |
89
c34516c99ca8
BUGFIX: No average depth for end-of-dive portion (<1m)
heinrichsweikamp
parents:
86
diff
changeset
|
670 btfss divemode2 ; displayed divetime is running? |
c34516c99ca8
BUGFIX: No average depth for end-of-dive portion (<1m)
heinrichsweikamp
parents:
86
diff
changeset
|
671 return ; No (e.g. too shallow) |
c34516c99ca8
BUGFIX: No average depth for end-of-dive portion (<1m)
heinrichsweikamp
parents:
86
diff
changeset
|
672 |
0 | 673 ; 3. Compute Total Average Depth on base of total_divetime_seconds:2 |
674 movff total_divetime_seconds+0,xB+0 | |
675 movff total_divetime_seconds+1,xB+1 ; Copy | |
676 movff average_depth_hold_total+0,xC+0 | |
677 movff average_depth_hold_total+1,xC+1 | |
678 movff average_depth_hold_total+2,xC+2 | |
679 movff average_depth_hold_total+3,xC+3 | |
680 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | |
681 movff xC+0,avr_rel_pressure_total+0 | |
682 movff xC+1,avr_rel_pressure_total+1 | |
683 | |
684 return | |
685 | |
686 reset_average1: | |
687 clrf average_depth_hold+0 | |
688 clrf average_depth_hold+1 | |
689 clrf average_depth_hold+2 | |
690 clrf average_depth_hold+3 ; Clear average depth register | |
691 movlw d'2' | |
692 movwf average_divesecs+0 | |
693 clrf average_divesecs+1 | |
694 bcf reset_average_depth ; Clear flag | |
695 return | |
696 | |
697 test_switches_divemode: ; checks switches in divemode | |
698 btfsc divemode_menu ; Divemode menu shown? | |
699 bra test_switches_divemode_menu ; Yes, use menu processor | |
700 btfsc switch_left | |
701 bra test_switches_divemode2 ; Enter button pressed, check if we need to do something | |
702 btfss switch_right | |
703 return ; No button press | |
704 tstfsz menupos2 ; any option shown? | |
705 bra test_switches_divemode1 ; Yes, do option tasks | |
706 bsf toggle_customview ; No, toggle custom view | |
707 return | |
708 | |
709 test_switches_divemode_menu: | |
710 btfsc switch_left | |
711 bra test_switches_divemode_menu2 ; Move cursor | |
712 btfsc switch_right | |
713 bra test_switches_divemode_menu3 ; Enter submenu or do something | |
714 return ; No button press | |
715 | |
716 test_switches_divemode_menu1: | |
717 clrf menupos | |
718 test_switches_divemode_menu2: | |
719 incf menupos,F | |
720 incf menupos4,W ; menupos4+1 -> WREG | |
721 cpfslt menupos ; >menupos4 (Set in menu_processor.asm)? | |
722 bra test_switches_divemode_menu1; > Yes, set to 1 | |
723 call TFT_divemode_menu_cursor ; Update the cursor | |
724 bcf switch_left | |
725 movlw divemode_menu_timeout ; Reload timeout | |
726 movwf timeout_counter3 ; timeout for divemode menu | |
727 return | |
728 | |
729 test_switches_divemode_menu3: ; Enter submenu or do something | |
730 bcf switch_right | |
731 ; decf menupos,F ; menu_processor needs 0-5... | |
732 extern do_line_menu | |
733 goto do_line_menu ; Warning! Trashes STKPTR and returns to diveloop_loop4: | |
734 | |
735 test_switches_divemode1: | |
736 bcf switch_right | |
737 movlw divemode_menuview_timeout | |
738 movwf timeout_counter3 ; Reload timeout | |
739 movff menupos2,WREG ; Menupos3 holds number of customview/divemode menu function | |
740 dcfsnz WREG,F | |
741 bra divemode_option0 ; Start/Setup Divemode menu | |
742 dcfsnz WREG,F | |
743 bra divemode_option1 ; Quit Simulation? | |
744 dcfsnz WREG,F | |
745 bra divemode_option2 ; Descent 1m | |
746 dcfsnz WREG,F | |
747 bra divemode_option3 ; Ascend 1m | |
748 dcfsnz WREG,F | |
749 bra divemode_option4 ; Quit Apnoe mode | |
750 dcfsnz WREG,F | |
751 bra divemode_option5 ; Reset Stopwatch (In Gauge mode) | |
752 return | |
753 | |
754 test_switches_divemode2: | |
755 bcf switch_left | |
756 call menuview_toggle ; Menu or Simulator tasks | |
757 return | |
758 | |
759 gas_switched_common: | |
760 decf menupos,W ; 1-5 -> 0-4 | |
761 btfss FLAG_ccr_mode ; Choose OC Gases | |
762 rcall setup_gas_registers ; With WREG=Gas 0-4 | |
763 btfsc FLAG_ccr_mode ; Choose CC Diluents | |
764 rcall setup_dil_registers ; With WREG=Gas 0-4 | |
765 | |
766 decf menupos,W ; 1-5 -> 0-4 | |
767 btfsc is_bailout ; Choose OC Bailouts (OC Gases) | |
768 rcall setup_gas_registers ; With WREG=Gas 0-4 | |
769 | |
770 call TFT_active_gas_divemode ; Display gas/Setpoint | |
771 bsf event_occured ; Set global event byte | |
772 bsf stored_gas_changed ; Set Flag for profile | |
773 bcf divemode_gaschange ; Clear flag | |
774 clrf WREG | |
775 movff WREG,char_O_deco_status ; Restart decoplan computation | |
776 return | |
777 | |
778 global setup_gas_registers | |
779 setup_gas_registers: ; With WREG=Gas 0-4 | |
780 lfsr FSR1,opt_gas_O2_ratio+0 | |
781 movff PLUSW1,char_I_O2_ratio ; O2 (For ppO2 calculations) | |
782 lfsr FSR1,opt_gas_He_ratio+0 | |
783 movff PLUSW1,char_I_He_ratio ; He | |
784 incf WREG,W ; Gas# 1-5 | |
785 movff WREG,char_I_current_gas ; Set gas | |
786 movff WREG,active_gas ; Set for logbook and display | |
787 banksel char_I_O2_ratio | |
788 movf char_I_O2_ratio,W ; Add O2... | |
789 addwf char_I_He_ratio,W ; ...and He... | |
790 sublw .100 ; ...subtract both from 100 | |
791 movwf char_I_N2_ratio ; -> N2! | |
792 banksel common | |
793 return | |
794 | |
795 global setup_dil_registers | |
796 setup_dil_registers: ; With WREG=dil 0-4 | |
97
53a99a2dc6a1
CHANGE: Always compute bailout plan based on all active gases
heinrichsweikamp
parents:
89
diff
changeset
|
797 btfsc is_bailout |
53a99a2dc6a1
CHANGE: Always compute bailout plan based on all active gases
heinrichsweikamp
parents:
89
diff
changeset
|
798 return ; Ignore in bailout |
0 | 799 lfsr FSR1,opt_dil_O2_ratio+0 |
800 movff PLUSW1,char_I_O2_ratio ; O2 (For ppO2 calculations) | |
801 lfsr FSR1,opt_dil_He_ratio+0 | |
802 movff PLUSW1,char_I_He_ratio ; He | |
803 incf WREG,W ; Gas# 1-5 | |
804 movff WREG,char_I_current_gas ; Set gas | |
805 movff WREG,active_gas ; Set for logbook and display | |
97
53a99a2dc6a1
CHANGE: Always compute bailout plan based on all active gases
heinrichsweikamp
parents:
89
diff
changeset
|
806 movff WREG,active_diluent ; As a backup when switching back from Bailout to CCR |
0 | 807 banksel char_I_O2_ratio |
808 movf char_I_O2_ratio,W ; Add O2... | |
809 addwf char_I_He_ratio,W ; ...and He... | |
810 sublw .100 ; ...subtract both from 100 | |
811 movwf char_I_N2_ratio ; -> N2! | |
812 banksel common | |
813 return | |
814 | |
815 divemode_option0: ; Start/Setup Divemode menu | |
816 call TFT_clear_divemode_menu ; Clear menu area | |
817 bcf menuview | |
818 extern do_main_divemenu | |
819 call do_main_divemenu | |
820 global divemode_option0_return | |
821 divemode_option0_return: | |
822 ; movlw .1 | |
823 ; movwf menupos ; Set to first option in divemode menu | |
824 call TFT_divemode_menu_cursor; Show the cursor | |
825 movlw divemode_menu_timeout | |
826 movwf timeout_counter3 ; timeout for divemode menu | |
827 bsf divemode_menu ; Set flag | |
828 clrf menupos2 ; Clear option counter | |
829 bra diveloop_loop4 ; Goto back to diveloop (Menuprocessor trashes STKPTR!) | |
830 | |
831 divemode_option4: | |
832 movlw d'58' ; two seconds left | |
833 movwf timeout_counter | |
834 movlw apnoe_timeout-1 ; apnoe timeout [min] | |
835 movwf apnoe_timeout_counter | |
836 btfss simulatormode_active ; in simulator mode? | |
837 return ; No | |
838 divemode_option1: ; Quit simulation mode | |
839 banksel isr_backup | |
840 movlw low .1000 | |
841 movwf sim_pressure+0 | |
842 movlw high .1000 | |
843 movwf sim_pressure+1 ; Set to 0m -> End of Dive | |
844 banksel common | |
845 call menuview_toggle_reset ; Reset to zero (Zero=no menuview) | |
846 | |
847 btfss FLAG_apnoe_mode ; In Apnoe mode? | |
848 return ; No | |
849 movlw d'58' ; two seconds left | |
850 movwf timeout_counter | |
851 movlw apnoe_timeout-1 ; apnoe timeout [min] | |
852 movwf apnoe_timeout_counter | |
853 return | |
854 | |
855 divemode_option3: ; minus 1m | |
856 banksel isr_backup | |
857 movlw d'100' | |
858 subwf sim_pressure+0 | |
859 movlw .0 | |
860 subwfb sim_pressure+1 | |
861 rcall divemode_simulator_check_limits | |
862 banksel common | |
863 return | |
864 | |
865 divemode_option2: ; plus 1m | |
866 banksel isr_backup | |
867 movlw d'100' | |
868 addwf sim_pressure+0 | |
869 movlw .0 | |
870 addwfc sim_pressure+1 | |
871 rcall divemode_simulator_check_limits | |
872 banksel common | |
873 return | |
874 | |
875 divemode_option5: | |
876 call menuview_toggle_reset ; Reset to zero (Zero=no menuview) | |
877 bsf reset_average_depth ; Set Flag | |
878 return | |
879 | |
880 divemode_simulator_check_limits: | |
881 ; Check limits (150m and 0m) | |
882 movlw LOW d'16000' ; Compare to 16bar=16000mbar (150m). | |
883 subwf sim_pressure+0,W | |
884 movlw HIGH d'16000' | |
885 subwfb sim_pressure+1,W | |
886 bnc divemode_simulator_check_limits2 ; No-carry = borrow = not deeper | |
887 | |
888 ; Too deep, limit to 150m | |
889 movlw LOW d'16000' | |
890 movwf sim_pressure+0 | |
891 movlw HIGH d'16000' | |
892 movwf sim_pressure+1 | |
893 return | |
894 divemode_simulator_check_limits2: | |
895 movlw LOW d'1000' ; Compare to 1bar == 0m == 1000 mbar. | |
896 subwf sim_pressure+0,W | |
897 movlw HIGH d'1000' | |
898 subwfb sim_pressure+1,W | |
899 btfsc STATUS,C ; No-carry = borrow = not deeper. | |
900 return ; Deeper than 0m == Ok. | |
901 ; Too shallow, limit to 0m | |
902 movlw LOW d'1000' | |
903 movwf sim_pressure+0 | |
904 movlw HIGH d'1000' | |
905 movwf sim_pressure+1 | |
906 return | |
907 | |
908 ;============================================================================= | |
909 ; Compare all enabled gas in list, to see if a better one is available. | |
910 ; | |
911 ; Output: better_gas_available, better_gas_number | |
912 ; | |
913 check_gas_change: ; Checks if a better gas should be selected (by user) | |
914 bcf better_gas_available ;=1: A better gas is available and a gas change is advised in divemode | |
915 clrf better_gas_number ; Clear better gas register | |
916 | |
917 SAFE_2BYTE_COPY rel_pressure,xA | |
918 movlw d'100' | |
919 movwf xB+0 | |
920 clrf xB+1 | |
921 call div16x16 ; compute depth in full m -> result in xC+0 | |
922 | |
923 btfss FLAG_ccr_mode ; In CCR mode... | |
924 bra check_gas_change_OC_bail; No, check for OC or bailout | |
925 btfsc is_bailout ; Bailout? | |
926 bra check_gas_change_OC_bail; Yes, check for OC or bailout | |
927 | |
928 ; Check Diluents | |
929 movlw .0 | |
930 rcall check_dil_common ; With Gas 0-4 in WREG | |
931 movlw .1 | |
932 rcall check_dil_common ; With Gas 0-4 in WREG | |
933 movlw .2 | |
934 rcall check_dil_common ; With Gas 0-4 in WREG | |
935 movlw .3 | |
936 rcall check_dil_common ; With Gas 0-4 in WREG | |
937 movlw .4 | |
938 rcall check_dil_common ; With Gas 0-4 in WREG | |
939 bra check_gas_change_exit | |
940 | |
941 check_gas_change_OC_bail: | |
942 movlw .0 | |
943 rcall check_gas_common ; With Gas 0-4 in WREG | |
944 movlw .1 | |
945 rcall check_gas_common ; With Gas 0-4 in WREG | |
946 movlw .2 | |
947 rcall check_gas_common ; With Gas 0-4 in WREG | |
948 movlw .3 | |
949 rcall check_gas_common ; With Gas 0-4 in WREG | |
950 movlw .4 | |
951 rcall check_gas_common ; With Gas 0-4 in WREG | |
952 ; bra check_gas_change_exit | |
953 check_gas_change_exit: | |
954 btfss better_gas_available ; Is a better gas available | |
955 bcf blinking_better_gas ; No, Clear blinking flag | |
956 btfss better_gas_available ; Is a better gas available | |
957 clrf better_gas_number ; No, Clear better_gas_number (For gaslist display) | |
958 call TFT_active_gas_divemode ; Display gas/Setpoint | |
959 return | |
960 | |
961 check_gas_common: ; With Gas 0-4 in WREG | |
962 btfsc better_gas_available ; Better Gas already found? | |
963 return ; Yes, return | |
964 lfsr FSR1,opt_gas_type ; 0=Disabled, 1=First, 2=Travel, 3=Deco | |
965 btfss PLUSW1,0 ; Test for Bit0 and 1 -> type=3 -> Deco | |
966 return ; No | |
967 btfss PLUSW1,1 ; Test for Bit0 and 1 -> type=3 -> Deco | |
968 return ; No | |
969 incf WREG,W ; 1-5 | |
970 cpfseq active_gas ; is this gas currently selected? | |
971 bra check_gas_common2 ; No | |
972 return ; Yes, skip test for active gas | |
973 check_gas_common2: | |
974 decf WREG,W ; 0-4 | |
975 movwf hi ; Save tested gas 0-4 | |
97
53a99a2dc6a1
CHANGE: Always compute bailout plan based on all active gases
heinrichsweikamp
parents:
89
diff
changeset
|
976 lfsr FSR1,opt_OC_bail_gas_change |
0 | 977 movff PLUSW1,lo ; Change depth into lo |
978 movlw minimum_change_depth | |
979 cpfsgt lo ; Change depth>minimum_change_depth? | |
980 return ; No, Change depth not deep enough, skip! | |
981 movf xC+0,W ; load depth in m into WREG | |
982 cpfsgt lo ; gas_change_depth < current depth? | |
69 | 983 bra check_gas_common3 ; No, check if we are within the better_gas_window_pos window |
984 incf hi,W ; 1-5 | |
985 movwf better_gas_number ; number (1-5) of the "better gas" in divemode, =0: no better gas available | |
986 movlw better_gas_window_neg | |
987 subwf lo,W ; Change depth-better_gas_window_neg | |
988 cpfslt xC+0 ; current depth<Change depth-better_gas_window_neg? | |
989 bsf better_gas_available ;=1: A better gas is available and a gas change is advised in divemode | |
990 return | |
991 | |
992 check_gas_common3: | |
0 | 993 incf hi,W ; 1-5 |
994 movwf better_gas_number ; number (1-5) of the "better gas" in divemode, =0: no better gas available | |
69 | 995 movlw better_gas_window_pos |
996 addwf lo,W ; Change depth+better_gas_window_pos | |
997 cpfsgt xC+0 ; current depth>Change depth+better_gas_window_pos? | |
998 bra check_gas_common4 ; Ok, now check the better gas ppO2<opt_ppO2_max | |
999 return | |
1000 | |
1001 check_gas_common4: | |
1002 movf hi,W ; 0-4 | |
1003 lfsr FSR1,char_I_deco_N2_ratio | |
1004 movff PLUSW1,lo ; N2 ratio into lo | |
1005 lfsr FSR1,char_I_deco_He_ratio | |
1006 movff PLUSW1,xB+0 ; He ratio into xB+0 | |
1007 movf xB+0,W | |
1008 addwf lo,F | |
1009 movlw .101 | |
1010 bcf STATUS,C | |
1011 subfwb lo,F ; O2 ratio in lo | |
1012 | |
1013 SAFE_2BYTE_COPY amb_pressure, xA | |
1014 movlw d'10' | |
1015 movwf xB+0 | |
1016 clrf xB+1 | |
1017 call div16x16 ; xC=p_amb/10 | |
1018 movff xC+0,xA+0 | |
1019 movff xC+1,xA+1 | |
1020 movff lo,xB+0 ; =O2 ratio | |
1021 clrf xB+1 | |
1022 call mult16x16 ; lo * p_amb/10 | |
1023 | |
1024 ; Check very high ppO2 manually | |
1025 tstfsz xC+2 ; char_I_O2_ratio * p_amb/10 > 65536, ppO2>6,55bar? | |
1026 return ; Done. | |
1027 ; Check if ppO2>3,30bar | |
1028 btfsc xC+1,7 | |
1029 return ; Done. | |
1030 | |
1031 ; ; Check for low ppo2 | |
1032 ; movff xC+0,sub_b+0 | |
1033 ; movff xC+1,sub_b+1 | |
1034 ; movff opt_ppO2_min,WREG | |
1035 ; mullw d'100' ; opt_ppO2_min*100 | |
1036 ; movff PRODL,sub_a+0 | |
1037 ; movff PRODH,sub_a+1 | |
1038 ; call subU16 | |
1039 ; btfss neg_flag | |
1040 ; return ; Done (Too low). | |
1041 | |
1042 ;check if we are within our warning thresholds! | |
1043 movff xC+0,sub_b+0 | |
1044 movff xC+1,sub_b+1 | |
1045 movff opt_ppO2_max,WREG ; PPO2 Max for MOD calculation and color coding in divemode | |
1046 addlw .1 ; e.g. >1.60 | |
1047 mullw d'100' ; opt_ppO2_max*100 | |
1048 movff PRODL,sub_a+0 | |
1049 movff PRODH,sub_a+1 | |
1050 call subU16 | |
1051 btfss neg_flag | |
0 | 1052 bsf better_gas_available ;=1: A better gas is available and a gas change is advised in divemode |
69 | 1053 return ; Done. |
0 | 1054 |
1055 check_dil_common: ; With Dil 0-4 in WREG | |
1056 btfsc better_gas_available ; Better Diluent already found? | |
1057 return ; Yes, return | |
1058 lfsr FSR1,opt_dil_type ; 0=Disabled, 1=First, 2=Normal | |
1059 tstfsz PLUSW1 ; =0? | |
1060 bra check_dil_common1 ; No | |
1061 return ; Yes, skip inactive diluents for test | |
1062 check_dil_common1: | |
1063 incf WREG,W ; 1-5 | |
1064 cpfseq active_gas ; is this diluent currently selected? | |
1065 bra check_dil_common2 ; No | |
1066 return ; Yes, skip test for active diluent | |
1067 check_dil_common2: | |
1068 decf WREG,W ; 0-4 | |
1069 movwf hi ; Save tested diluent 0-4 | |
1070 lfsr FSR1,char_I_dil_change | |
1071 movff PLUSW1,lo ; Change depth into lo | |
1072 movlw minimum_change_depth | |
1073 cpfsgt lo ; Change depth>minimum_change_depth? | |
1074 return ; No, Change depth not deep enough, skip! | |
1075 movf xC+0,W ; load depth in m into WREG | |
1076 cpfsgt lo ; gas_change_depth < current depth? | |
1077 return ; No, check next gas | |
1078 incf hi,W ; 1-5 | |
1079 addlw .5 ; 6-10 | |
1080 movwf better_gas_number ; number (1-5) of the "better gas" in divemode, =0: no better gas available | |
69 | 1081 movlw better_gas_window_neg |
1082 subwf lo,W ; Change depth-better_gas_window_neg | |
1083 cpfslt xC+0 ; current depth<Change depth-better_gas_window_neg? | |
0 | 1084 bsf better_gas_available ;=1: A better gas is available and a gas change is advised in divemode |
1085 return | |
1086 | |
1087 ;============================================================================= | |
1088 ; Setup everything to enter divemode. | |
1089 ; | |
1090 | |
1091 dive_boot_oc: | |
1092 extern get_first_gas_to_WREG | |
1093 call get_first_gas_to_WREG ; Gets first gas (0-4) into WREG | |
1094 movff WREG,char_I_first_gas ; Copy for compatibility | |
1095 movff WREG,active_gas ; Set for logbook and display | |
1096 rcall setup_gas_registers ; With WREG=Gas 0-4 | |
1097 return | |
1098 | |
1099 dive_boot_cc: | |
1100 rcall divemode_setup_sensor_values ; setup sensor values | |
1101 TSTOSS opt_ccr_mode ; =0: Fixed SP, =1: Sensor | |
1102 movff char_I_setpoint_cbar+0,char_I_const_ppO2 ; Setup fixed Setpoint (Always start with SP1) | |
1103 extern get_first_dil_to_WREG | |
1104 call get_first_dil_to_WREG ; Gets first gas (0-4) into WREG | |
1105 movff WREG,char_I_first_gas ; Copy for compatibility | |
1106 movff WREG,active_gas ; Set for logbook and display | |
1107 rcall setup_dil_registers ; With WREG=Gas 0-4 | |
1108 return | |
1109 | |
1110 diveloop_boot: | |
1111 call restart_set_modes_and_flags | |
1112 | |
1113 call I2C_sleep_accelerometer ; Stop accelerometer | |
1114 call I2C_sleep_compass ; Stop compass | |
1115 | |
1116 clrf WREG | |
1117 movff WREG,max_pressure+0 ; clear some variables | |
1118 movff WREG,max_pressure+1 | |
1119 | |
1120 bcf use_agf ; Start with normal GF set | |
1121 bcf divemode_menu ; clear divemode menu flag | |
1122 movlw d'1' | |
1123 movwf apnoe_max_pressure+0 | |
1124 clrf apnoe_max_pressure+1 | |
1125 clrf apnoe_surface_mins | |
1126 clrf apnoe_surface_secs | |
1127 clrf apnoe_mins | |
1128 clrf divemins+0 | |
1129 clrf divemins+1 | |
1130 bcf no_more_divesecs ; =1: Do no longer show seconds in divemode | |
1131 bcf divemode_menu_active | |
1132 clrf menupos | |
1133 clrf menupos2 ; Reset to zero (Zero=no premenu or simulator task) | |
1134 | |
1135 bcf is_bailout ; =1: Bailout | |
1136 btfss FLAG_ccr_mode | |
1137 rcall dive_boot_oc | |
1138 btfsc FLAG_ccr_mode | |
1139 rcall dive_boot_cc | |
1140 | |
1141 bcf better_gas_available ;=1: A better gas is available and a gas change is advised in divemode | |
1142 clrf better_gas_number ; Clear better gas register | |
1143 | |
1144 clrf samplesecs | |
1145 clrf apnoe_timeout_counter ; timeout in minutes | |
1146 clrf timeout_counter ; takes care of the timeout (Low byte) | |
1147 clrf timeout_counter2 ; takes care of the timeout (High byte) | |
1148 clrf AlarmType ; Clear all alarms | |
1149 bcf event_occured ; clear flag | |
1150 clrf total_divetime_seconds+1 | |
1151 clrf average_depth_hold_total+0 | |
1152 clrf average_depth_hold_total+1 | |
1153 clrf average_depth_hold_total+2 | |
1154 clrf average_depth_hold_total+3 ; Clear Non-Resettable Average | |
1155 rcall reset_average1 ; Reset the resettable average depth | |
1156 bcf decostop_active | |
1157 bcf better_gas_available ;=1: A better gas is available and a gas change is advised in divemode | |
1158 call ghostwriter_short_header ; Write short header with divenumber into profile memory | |
1159 | |
1160 btfsc simulatormode_active | |
1161 bra diveloop_boot_1 | |
1162 ; Normal mode = Surface pressure is the pressure 30mn before dive. | |
1163 SAFE_2BYTE_COPY last_surfpressure_30min, int_I_pres_surface ;copy surfacepressure to deco routine | |
1164 SAFE_2BYTE_COPY last_surfpressure_30min, last_surfpressure ;copy surfacepressure to last_surfpressure for correct depth | |
1165 bra diveloop_boot_2 | |
1166 | |
1167 diveloop_boot_1: | |
1168 ; Simulator mode: Surface pressure is 1bar. | |
1169 movlw LOW .1000 | |
1170 movff WREG,int_I_pres_surface+0 ; LOW copy surfacepressure to deco routine | |
1171 movlw HIGH .1000 | |
1172 movff WREG,int_I_pres_surface+1 ; HIGH copy surfacepressure to deco routine | |
1173 | |
1174 diveloop_boot_2: | |
1175 SAFE_2BYTE_COPY temperature,minimum_temperature ; Reset Min-Temp registers | |
1176 | |
1177 ; Init profile recording parameters | |
23
e402813343b6
new option to switch samplingrate between 10s and 2s
heinrichsweikamp
parents:
0
diff
changeset
|
1178 movff samplingrate,samplesecs_value ; to avoid EEPROM access in the ISR |
0 | 1179 movlw div_temperature |
1180 movwf divisor_temperature ; load divisors for profile storage | |
1181 movlw div_deco | |
1182 movwf divisor_deco | |
1183 movlw div_gf | |
1184 movwf divisor_gf | |
1185 movlw div_ppo2_sensors | |
1186 movwf divisor_ppo2_sensors | |
1187 movlw div_decoplan | |
1188 movwf divisor_decoplan | |
1189 movlw div_cns | |
1190 movwf divisor_cns | |
1191 movlw div_tank | |
1192 movwf divisor_tank | |
1193 | |
1194 btfss FLAG_apnoe_mode ; In Apnoe mode? | |
1195 bra divemode1 | |
1196 ; Overwrite some parameters in Apnoe mode.... | |
1197 movlw samplingrate_apnoe | |
1198 movwf samplesecs_value ; to avoid EEPROM access in the ISR | |
1199 | |
1200 divemode1: | |
1201 bcf LEDg | |
1202 bcf LEDr | |
1203 bcf realdive | |
1204 btfss simulatormode_active ; do not disable in simulator mode! | |
1205 call disable_rs232 ; Disable RS232 | |
1206 btfsc enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump) | |
1207 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
|
1208 ; Reset divetime seconds |
e4e91fe8b09d
remember last customview in dive and surface mode
mh@mh-THINK.fritz.box
parents:
38
diff
changeset
|
1209 movlw .2 ; Start at 2seconds |
0 | 1210 movwf total_divetime_seconds+0 |
39
e4e91fe8b09d
remember last customview in dive and surface mode
mh@mh-THINK.fritz.box
parents:
38
diff
changeset
|
1211 movwf divesecs |
e4e91fe8b09d
remember last customview in dive and surface mode
mh@mh-THINK.fritz.box
parents:
38
diff
changeset
|
1212 movwf apnoe_secs |
0 | 1213 bsf divemode2 ; displayed divetime is running (Divetime starts HERE) |
1214 | |
1215 movff int_O_CNS_fraction+0,CNS_start+0 | |
1216 movff int_O_CNS_fraction+1,CNS_start+1 ; Save CNS value at beginning of dive | |
1217 movff char_O_relative_gradient_GF,GF_start ; Save GF value at beginning of dive | |
1218 return ; Done with divemode boot | |
1219 | |
1220 divemode_check_for_warnings: | |
1221 btfss secs,1 ; Every four seconds | |
1222 return | |
1223 | |
1224 movf warning_counter_backup,W | |
1225 cpfseq warning_counter ; warning_counter_backup = warning_counter? | |
1226 call TFT_clear_warning_text ; No, clear all warnings | |
1227 movff warning_counter,warning_counter_backup ; copy warning_counter | |
1228 | |
1229 bcf warning_active ; Clear flag | |
1230 clrf warning_counter ; Clear counter | |
1231 | |
1232 ; Warnings for all modes | |
1233 call check_warn_battery ; Check if the battery level should be displayed/warned | |
55 | 1234 call check_divetimeout ; Not actually a warning. Check and show the divemode timeout |
0 | 1235 |
1236 btfsc FLAG_apnoe_mode ; Done for Apnoe or Gauge mode | |
1237 bra divemode_check_for_warnings2 | |
1238 btfsc FLAG_gauge_mode ; Done for Apnoe or Gauge mode | |
1239 bra divemode_check_for_warnings2 | |
1240 | |
1241 ; Warnings only in deco modes | |
1242 btfss FLAG_ccr_mode ; Don't check in CCR mode | |
1243 rcall check_ppO2 ; check ppO2 and displays warning, if required | |
1244 btfsc is_bailout ; But check in Bailout case... | |
1245 rcall check_ppO2 ; check ppO2 and displays warning, if required | |
1246 rcall check_cns_violation ; Check CNS value and display it, if required | |
1247 btfsc decostop_active ; In deco mode? | |
1248 rcall check_and_store_gf_violation ; Yes, Sets warnings, if required | |
1249 btfsc decostop_active ; In deco mode? | |
1250 call TFT_ftts ; Show @+x time | |
1251 btfsc use_agf ; In aGF mode? | |
1252 rcall warn_agf ; Yes, show a warning for it | |
1253 | |
1254 divemode_check_for_warnings2: | |
1255 ; Display the warning icon? | |
1256 btfsc warning_active ; Any warning active? | |
1257 call TFT_divemode_warning ; Yes | |
1258 btfss warning_active ; Any warning active? | |
1259 call TFT_divemode_warning_clear ; No, clear warning icon | |
1260 | |
1261 ; Setup warning_page number | |
1262 incf warning_page,F | |
1263 bcf STATUS,C | |
1264 rlcf warning_page,W ; *2 | |
1265 cpfsgt warning_counter ; > warning_counter | |
1266 clrf warning_page ; No, clear | |
1267 | |
1268 ; Clear 2nd row of warnings if there is nothing to show (on this page) | |
1269 btfss second_row_warning ; =1: The second row contains a warning | |
1270 call TFT_clear_warning_text_2nd_row ; No, clear this row | |
1271 return ; Done. | |
1272 | |
1273 global check_warn_battery | |
1274 check_warn_battery: | |
1275 movff batt_percent,lo | |
1276 movlw battery_show_level+1 | |
1277 cpfslt lo | |
1278 return ; No Display, no warning | |
1279 ; Display Battery, but warn? | |
1280 incf warning_counter,F ; increase counter | |
1281 call TFT_update_batt_percent_divemode ; Show percent | |
1282 | |
86 | 1283 movff batt_percent,lo |
0 | 1284 movlw color_code_battery_low+1 |
1285 cpfslt lo ; | |
1286 return ; No warning | |
1287 bsf warning_active ; Set Warning flag | |
1288 return | |
1289 | |
55 | 1290 check_divetimeout: |
1291 btfsc divemode2 | |
1292 return ; displayed divetime is not running | |
1293 incf warning_counter,F ; increase counter | |
1294 call TFT_divetimeout ; Show timeout counter | |
1295 return | |
1296 | |
1297 | |
0 | 1298 check_ppO2: ; check current ppO2 and display warning if required |
1299 SAFE_2BYTE_COPY amb_pressure, xA | |
1300 movlw d'10' | |
1301 movwf xB+0 | |
1302 clrf xB+1 | |
1303 call div16x16 ; xC=p_amb/10 | |
1304 | |
1305 movff xC+0,xA+0 | |
1306 movff xC+1,xA+1 | |
1307 movff char_I_O2_ratio,xB+0 ; =O2 ratio | |
1308 clrf xB+1 | |
1309 call mult16x16 ; char_I_O2_ratio * p_amb/10 | |
1310 | |
1311 ; Check very high ppO2 manually | |
1312 tstfsz xC+2 ; char_I_O2_ratio * p_amb/10 > 65536, ppO2>6,55bar? | |
1313 bra check_ppO2_1 ; Yes, display Value! | |
1314 ; Check if ppO2>3,30bar | |
1315 btfsc xC+1,7 | |
1316 bra check_ppO2_1 ; Yes! | |
1317 | |
1318 ; Check for low ppo2 | |
1319 movff xC+0,sub_b+0 | |
1320 movff xC+1,sub_b+1 | |
1321 movff opt_ppO2_min,WREG | |
1322 mullw d'100' ; opt_ppO2_min*100 | |
1323 movff PRODL,sub_a+0 | |
1324 movff PRODH,sub_a+1 | |
1325 call subU16 | |
1326 btfsc neg_flag | |
1327 bra check_ppO2_0 ; Not too low | |
1328 ; ppO2 low | |
1329 incf warning_counter,F ; increase counter | |
1330 call TFT_display_ppo2 ; Show ppO2 | |
1331 movlw d'4' ; Type of Alarm (ppO2 low) | |
1332 movwf AlarmType ; Copy to Alarm Register | |
1333 bsf event_occured ; Set Event Flag | |
1334 bsf warning_active ; Set Warning flag | |
1335 return ; Done. | |
1336 | |
1337 check_ppO2_0: | |
1338 ; Check if ppO2 should be displayed | |
1339 movlw ppo2_display_high | |
1340 mullw d'100' ; ppo2_display_high*100 | |
1341 movff PRODL,sub_a+0 | |
1342 movff PRODH,sub_a+1 | |
1343 call subU16 | |
1344 btfss neg_flag | |
1345 return ; No Display, no warning | |
1346 ; Display ppO2, but warn? | |
1347 incf warning_counter,F ; increase counter | |
1348 call TFT_display_ppo2 ; Show ppO2 | |
1349 | |
1350 ;check if we are within our warning thresholds! | |
1351 movff xC+0,sub_b+0 | |
1352 movff xC+1,sub_b+1 | |
1353 movff opt_ppO2_max,WREG ; PPO2 Max for MOD calculation and color coding in divemode | |
69 | 1354 addlw .1 ; e.g. >1.60 |
0 | 1355 mullw d'100' ; opt_ppO2_max*100 |
1356 movff PRODL,sub_a+0 | |
1357 movff PRODH,sub_a+1 | |
1358 call subU16 | |
1359 btfss neg_flag | |
1360 return ; Done. Not too high | |
1361 movlw d'5' ; Type of Alarm (ppO2 high) | |
1362 movwf AlarmType ; Copy to Alarm Register | |
1363 bsf event_occured ; Set Event Flag | |
1364 bsf warning_active ; Set Warning flag | |
1365 return ; Done. | |
1366 | |
1367 check_ppO2_1: ; ppO2 very high | |
1368 incf warning_counter,F ; increase counter | |
1369 call TFT_display_ppo2 ; Show ppO2 | |
1370 movlw d'5' ; Type of Alarm | |
1371 movwf AlarmType ; Copy to Alarm Register | |
1372 bsf event_occured ; Set Event Flag | |
1373 bsf warning_active ; Set Warning flag | |
1374 return ; Done. | |
1375 | |
1376 global check_cns_violation | |
1377 check_cns_violation: | |
1378 ; Check if CNS should be displayed | |
1379 movff int_O_CNS_fraction+1,lo ; copy into bank1 | |
1380 tstfsz lo ; >255% ? | |
1381 bra check_cns_violation2 ; Yes | |
1382 movff int_O_CNS_fraction+0,lo ; copy into bank1 | |
1383 | |
1384 movlw cns_warning_high ; cns_warning_high | |
1385 subwf lo,W | |
1386 btfsc STATUS,C | |
1387 bsf warning_active ; Set Warning flag | |
1388 | |
1389 movlw cns_display_high ; cns_display_high | |
1390 subwf lo,W | |
1391 btfss STATUS,C | |
1392 return ; No Display, no warning | |
1393 ; Display CNS | |
1394 incf warning_counter,F ; increase counter | |
1395 call TFT_display_cns ; Show CNS | |
1396 return | |
1397 | |
1398 check_cns_violation2: | |
1399 incf warning_counter,F ; increase counter | |
1400 call TFT_display_cns ; Show CNS | |
1401 bsf warning_active ; Set Warning flag | |
1402 return | |
1403 | |
1404 global check_and_store_gf_violation | |
1405 check_and_store_gf_violation: | |
1406 movff char_O_gradient_factor,lo ; gradient factor absolute (Non-GF model) | |
1407 movff char_I_deco_model,hi | |
1408 decfsz hi,F ; jump over next line if char_I_deco_model == 1 | |
1409 movff char_O_relative_gradient_GF,lo ; gradient factor relative (GF model) | |
1410 | |
1411 movlw gf_warning_high | |
1412 cpfsgt lo | |
1413 bra check_and_store_gf_violation2 ; No warning | |
1414 movlw d'2' ; Type of Alarm | |
1415 movwf AlarmType ; Copy to Alarm Register | |
1416 bsf event_occured ; Set Event Flag | |
1417 bsf warning_active ; Set Warning flag | |
1418 check_and_store_gf_violation2: | |
1419 movlw gf_display_high | |
1420 cpfsgt lo | |
1421 return ; No Display, no warning | |
1422 ; Display GF | |
1423 incf warning_counter,F ; increase counter | |
1424 call TFT_warning_gf ; Show GF Warning | |
1425 return | |
1426 | |
1427 warn_agf: | |
1428 incf warning_counter,F ; increase counter | |
1429 call TFT_warning_agf ; Show aGF warning | |
86 | 1430 ; bsf warning_active ; Set Warning flag |
0 | 1431 return |
1432 | |
1433 | |
1434 END |