Mercurial > public > hwos_code
annotate src/divemode.asm @ 89:c34516c99ca8
BUGFIX: No average depth for end-of-dive portion (<1m)
BUGFIX: Show "CC Diluents" in logbook instead of OC Gas List
author | heinrichsweikamp |
---|---|
date | Tue, 15 Apr 2014 12:16:28 +0200 |
parents | 3bbbfab9818f |
children | 53a99a2dc6a1 |
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 | |
797 lfsr FSR1,opt_dil_O2_ratio+0 | |
798 movff PLUSW1,char_I_O2_ratio ; O2 (For ppO2 calculations) | |
799 lfsr FSR1,opt_dil_He_ratio+0 | |
800 movff PLUSW1,char_I_He_ratio ; He | |
801 incf WREG,W ; Gas# 1-5 | |
802 movff WREG,char_I_current_gas ; Set gas | |
803 movff WREG,active_gas ; Set for logbook and display | |
804 banksel char_I_O2_ratio | |
805 movf char_I_O2_ratio,W ; Add O2... | |
806 addwf char_I_He_ratio,W ; ...and He... | |
807 sublw .100 ; ...subtract both from 100 | |
808 movwf char_I_N2_ratio ; -> N2! | |
809 banksel common | |
810 return | |
811 | |
812 divemode_option0: ; Start/Setup Divemode menu | |
813 call TFT_clear_divemode_menu ; Clear menu area | |
814 bcf menuview | |
815 extern do_main_divemenu | |
816 call do_main_divemenu | |
817 global divemode_option0_return | |
818 divemode_option0_return: | |
819 ; movlw .1 | |
820 ; movwf menupos ; Set to first option in divemode menu | |
821 call TFT_divemode_menu_cursor; Show the cursor | |
822 movlw divemode_menu_timeout | |
823 movwf timeout_counter3 ; timeout for divemode menu | |
824 bsf divemode_menu ; Set flag | |
825 clrf menupos2 ; Clear option counter | |
826 bra diveloop_loop4 ; Goto back to diveloop (Menuprocessor trashes STKPTR!) | |
827 | |
828 divemode_option4: | |
829 movlw d'58' ; two seconds left | |
830 movwf timeout_counter | |
831 movlw apnoe_timeout-1 ; apnoe timeout [min] | |
832 movwf apnoe_timeout_counter | |
833 btfss simulatormode_active ; in simulator mode? | |
834 return ; No | |
835 divemode_option1: ; Quit simulation mode | |
836 banksel isr_backup | |
837 movlw low .1000 | |
838 movwf sim_pressure+0 | |
839 movlw high .1000 | |
840 movwf sim_pressure+1 ; Set to 0m -> End of Dive | |
841 banksel common | |
842 call menuview_toggle_reset ; Reset to zero (Zero=no menuview) | |
843 | |
844 btfss FLAG_apnoe_mode ; In Apnoe mode? | |
845 return ; No | |
846 movlw d'58' ; two seconds left | |
847 movwf timeout_counter | |
848 movlw apnoe_timeout-1 ; apnoe timeout [min] | |
849 movwf apnoe_timeout_counter | |
850 return | |
851 | |
852 divemode_option3: ; minus 1m | |
853 banksel isr_backup | |
854 movlw d'100' | |
855 subwf sim_pressure+0 | |
856 movlw .0 | |
857 subwfb sim_pressure+1 | |
858 rcall divemode_simulator_check_limits | |
859 banksel common | |
860 return | |
861 | |
862 divemode_option2: ; plus 1m | |
863 banksel isr_backup | |
864 movlw d'100' | |
865 addwf sim_pressure+0 | |
866 movlw .0 | |
867 addwfc sim_pressure+1 | |
868 rcall divemode_simulator_check_limits | |
869 banksel common | |
870 return | |
871 | |
872 divemode_option5: | |
873 call menuview_toggle_reset ; Reset to zero (Zero=no menuview) | |
874 bsf reset_average_depth ; Set Flag | |
875 return | |
876 | |
877 divemode_simulator_check_limits: | |
878 ; Check limits (150m and 0m) | |
879 movlw LOW d'16000' ; Compare to 16bar=16000mbar (150m). | |
880 subwf sim_pressure+0,W | |
881 movlw HIGH d'16000' | |
882 subwfb sim_pressure+1,W | |
883 bnc divemode_simulator_check_limits2 ; No-carry = borrow = not deeper | |
884 | |
885 ; Too deep, limit to 150m | |
886 movlw LOW d'16000' | |
887 movwf sim_pressure+0 | |
888 movlw HIGH d'16000' | |
889 movwf sim_pressure+1 | |
890 return | |
891 divemode_simulator_check_limits2: | |
892 movlw LOW d'1000' ; Compare to 1bar == 0m == 1000 mbar. | |
893 subwf sim_pressure+0,W | |
894 movlw HIGH d'1000' | |
895 subwfb sim_pressure+1,W | |
896 btfsc STATUS,C ; No-carry = borrow = not deeper. | |
897 return ; Deeper than 0m == Ok. | |
898 ; Too shallow, limit to 0m | |
899 movlw LOW d'1000' | |
900 movwf sim_pressure+0 | |
901 movlw HIGH d'1000' | |
902 movwf sim_pressure+1 | |
903 return | |
904 | |
905 ;============================================================================= | |
906 ; Compare all enabled gas in list, to see if a better one is available. | |
907 ; | |
908 ; Output: better_gas_available, better_gas_number | |
909 ; | |
910 check_gas_change: ; Checks if a better gas should be selected (by user) | |
911 bcf better_gas_available ;=1: A better gas is available and a gas change is advised in divemode | |
912 clrf better_gas_number ; Clear better gas register | |
913 | |
914 SAFE_2BYTE_COPY rel_pressure,xA | |
915 movlw d'100' | |
916 movwf xB+0 | |
917 clrf xB+1 | |
918 call div16x16 ; compute depth in full m -> result in xC+0 | |
919 | |
920 btfss FLAG_ccr_mode ; In CCR mode... | |
921 bra check_gas_change_OC_bail; No, check for OC or bailout | |
922 btfsc is_bailout ; Bailout? | |
923 bra check_gas_change_OC_bail; Yes, check for OC or bailout | |
924 | |
925 ; Check Diluents | |
926 movlw .0 | |
927 rcall check_dil_common ; With Gas 0-4 in WREG | |
928 movlw .1 | |
929 rcall check_dil_common ; With Gas 0-4 in WREG | |
930 movlw .2 | |
931 rcall check_dil_common ; With Gas 0-4 in WREG | |
932 movlw .3 | |
933 rcall check_dil_common ; With Gas 0-4 in WREG | |
934 movlw .4 | |
935 rcall check_dil_common ; With Gas 0-4 in WREG | |
936 bra check_gas_change_exit | |
937 | |
938 check_gas_change_OC_bail: | |
939 movlw .0 | |
940 rcall check_gas_common ; With Gas 0-4 in WREG | |
941 movlw .1 | |
942 rcall check_gas_common ; With Gas 0-4 in WREG | |
943 movlw .2 | |
944 rcall check_gas_common ; With Gas 0-4 in WREG | |
945 movlw .3 | |
946 rcall check_gas_common ; With Gas 0-4 in WREG | |
947 movlw .4 | |
948 rcall check_gas_common ; With Gas 0-4 in WREG | |
949 ; bra check_gas_change_exit | |
950 check_gas_change_exit: | |
951 btfss better_gas_available ; Is a better gas available | |
952 bcf blinking_better_gas ; No, Clear blinking flag | |
953 btfss better_gas_available ; Is a better gas available | |
954 clrf better_gas_number ; No, Clear better_gas_number (For gaslist display) | |
955 call TFT_active_gas_divemode ; Display gas/Setpoint | |
956 return | |
957 | |
958 check_gas_common: ; With Gas 0-4 in WREG | |
959 btfsc better_gas_available ; Better Gas already found? | |
960 return ; Yes, return | |
961 lfsr FSR1,opt_gas_type ; 0=Disabled, 1=First, 2=Travel, 3=Deco | |
962 btfss PLUSW1,0 ; Test for Bit0 and 1 -> type=3 -> Deco | |
963 return ; No | |
964 btfss PLUSW1,1 ; Test for Bit0 and 1 -> type=3 -> Deco | |
965 return ; No | |
966 incf WREG,W ; 1-5 | |
967 cpfseq active_gas ; is this gas currently selected? | |
968 bra check_gas_common2 ; No | |
969 return ; Yes, skip test for active gas | |
970 check_gas_common2: | |
971 decf WREG,W ; 0-4 | |
972 movwf hi ; Save tested gas 0-4 | |
973 lfsr FSR1,char_I_deco_gas_change | |
974 movff PLUSW1,lo ; Change depth into lo | |
975 movlw minimum_change_depth | |
976 cpfsgt lo ; Change depth>minimum_change_depth? | |
977 return ; No, Change depth not deep enough, skip! | |
978 movf xC+0,W ; load depth in m into WREG | |
979 cpfsgt lo ; gas_change_depth < current depth? | |
69 | 980 bra check_gas_common3 ; No, check if we are within the better_gas_window_pos window |
981 incf hi,W ; 1-5 | |
982 movwf better_gas_number ; number (1-5) of the "better gas" in divemode, =0: no better gas available | |
983 movlw better_gas_window_neg | |
984 subwf lo,W ; Change depth-better_gas_window_neg | |
985 cpfslt xC+0 ; current depth<Change depth-better_gas_window_neg? | |
986 bsf better_gas_available ;=1: A better gas is available and a gas change is advised in divemode | |
987 return | |
988 | |
989 check_gas_common3: | |
0 | 990 incf hi,W ; 1-5 |
991 movwf better_gas_number ; number (1-5) of the "better gas" in divemode, =0: no better gas available | |
69 | 992 movlw better_gas_window_pos |
993 addwf lo,W ; Change depth+better_gas_window_pos | |
994 cpfsgt xC+0 ; current depth>Change depth+better_gas_window_pos? | |
995 bra check_gas_common4 ; Ok, now check the better gas ppO2<opt_ppO2_max | |
996 return | |
997 | |
998 check_gas_common4: | |
999 movf hi,W ; 0-4 | |
1000 lfsr FSR1,char_I_deco_N2_ratio | |
1001 movff PLUSW1,lo ; N2 ratio into lo | |
1002 lfsr FSR1,char_I_deco_He_ratio | |
1003 movff PLUSW1,xB+0 ; He ratio into xB+0 | |
1004 movf xB+0,W | |
1005 addwf lo,F | |
1006 movlw .101 | |
1007 bcf STATUS,C | |
1008 subfwb lo,F ; O2 ratio in lo | |
1009 | |
1010 SAFE_2BYTE_COPY amb_pressure, xA | |
1011 movlw d'10' | |
1012 movwf xB+0 | |
1013 clrf xB+1 | |
1014 call div16x16 ; xC=p_amb/10 | |
1015 movff xC+0,xA+0 | |
1016 movff xC+1,xA+1 | |
1017 movff lo,xB+0 ; =O2 ratio | |
1018 clrf xB+1 | |
1019 call mult16x16 ; lo * p_amb/10 | |
1020 | |
1021 ; Check very high ppO2 manually | |
1022 tstfsz xC+2 ; char_I_O2_ratio * p_amb/10 > 65536, ppO2>6,55bar? | |
1023 return ; Done. | |
1024 ; Check if ppO2>3,30bar | |
1025 btfsc xC+1,7 | |
1026 return ; Done. | |
1027 | |
1028 ; ; Check for low ppo2 | |
1029 ; movff xC+0,sub_b+0 | |
1030 ; movff xC+1,sub_b+1 | |
1031 ; movff opt_ppO2_min,WREG | |
1032 ; mullw d'100' ; opt_ppO2_min*100 | |
1033 ; movff PRODL,sub_a+0 | |
1034 ; movff PRODH,sub_a+1 | |
1035 ; call subU16 | |
1036 ; btfss neg_flag | |
1037 ; return ; Done (Too low). | |
1038 | |
1039 ;check if we are within our warning thresholds! | |
1040 movff xC+0,sub_b+0 | |
1041 movff xC+1,sub_b+1 | |
1042 movff opt_ppO2_max,WREG ; PPO2 Max for MOD calculation and color coding in divemode | |
1043 addlw .1 ; e.g. >1.60 | |
1044 mullw d'100' ; opt_ppO2_max*100 | |
1045 movff PRODL,sub_a+0 | |
1046 movff PRODH,sub_a+1 | |
1047 call subU16 | |
1048 btfss neg_flag | |
0 | 1049 bsf better_gas_available ;=1: A better gas is available and a gas change is advised in divemode |
69 | 1050 return ; Done. |
0 | 1051 |
1052 check_dil_common: ; With Dil 0-4 in WREG | |
1053 btfsc better_gas_available ; Better Diluent already found? | |
1054 return ; Yes, return | |
1055 lfsr FSR1,opt_dil_type ; 0=Disabled, 1=First, 2=Normal | |
1056 tstfsz PLUSW1 ; =0? | |
1057 bra check_dil_common1 ; No | |
1058 return ; Yes, skip inactive diluents for test | |
1059 check_dil_common1: | |
1060 incf WREG,W ; 1-5 | |
1061 cpfseq active_gas ; is this diluent currently selected? | |
1062 bra check_dil_common2 ; No | |
1063 return ; Yes, skip test for active diluent | |
1064 check_dil_common2: | |
1065 decf WREG,W ; 0-4 | |
1066 movwf hi ; Save tested diluent 0-4 | |
1067 lfsr FSR1,char_I_dil_change | |
1068 movff PLUSW1,lo ; Change depth into lo | |
1069 movlw minimum_change_depth | |
1070 cpfsgt lo ; Change depth>minimum_change_depth? | |
1071 return ; No, Change depth not deep enough, skip! | |
1072 movf xC+0,W ; load depth in m into WREG | |
1073 cpfsgt lo ; gas_change_depth < current depth? | |
1074 return ; No, check next gas | |
1075 incf hi,W ; 1-5 | |
1076 addlw .5 ; 6-10 | |
1077 movwf better_gas_number ; number (1-5) of the "better gas" in divemode, =0: no better gas available | |
69 | 1078 movlw better_gas_window_neg |
1079 subwf lo,W ; Change depth-better_gas_window_neg | |
1080 cpfslt xC+0 ; current depth<Change depth-better_gas_window_neg? | |
0 | 1081 bsf better_gas_available ;=1: A better gas is available and a gas change is advised in divemode |
1082 return | |
1083 | |
1084 ;============================================================================= | |
1085 ; Setup everything to enter divemode. | |
1086 ; | |
1087 | |
1088 dive_boot_oc: | |
1089 extern get_first_gas_to_WREG | |
1090 call get_first_gas_to_WREG ; Gets first gas (0-4) into WREG | |
1091 movff WREG,char_I_first_gas ; Copy for compatibility | |
1092 movff WREG,active_gas ; Set for logbook and display | |
1093 rcall setup_gas_registers ; With WREG=Gas 0-4 | |
1094 return | |
1095 | |
1096 dive_boot_cc: | |
1097 rcall divemode_setup_sensor_values ; setup sensor values | |
1098 TSTOSS opt_ccr_mode ; =0: Fixed SP, =1: Sensor | |
1099 movff char_I_setpoint_cbar+0,char_I_const_ppO2 ; Setup fixed Setpoint (Always start with SP1) | |
1100 extern get_first_dil_to_WREG | |
1101 call get_first_dil_to_WREG ; Gets first gas (0-4) into WREG | |
1102 movff WREG,char_I_first_gas ; Copy for compatibility | |
1103 movff WREG,active_gas ; Set for logbook and display | |
1104 rcall setup_dil_registers ; With WREG=Gas 0-4 | |
1105 return | |
1106 | |
1107 diveloop_boot: | |
1108 call restart_set_modes_and_flags | |
1109 | |
1110 call I2C_sleep_accelerometer ; Stop accelerometer | |
1111 call I2C_sleep_compass ; Stop compass | |
1112 | |
1113 clrf WREG | |
1114 movff WREG,max_pressure+0 ; clear some variables | |
1115 movff WREG,max_pressure+1 | |
1116 | |
1117 bcf use_agf ; Start with normal GF set | |
1118 bcf divemode_menu ; clear divemode menu flag | |
1119 movlw d'1' | |
1120 movwf apnoe_max_pressure+0 | |
1121 clrf apnoe_max_pressure+1 | |
1122 clrf apnoe_surface_mins | |
1123 clrf apnoe_surface_secs | |
1124 clrf apnoe_mins | |
1125 clrf divemins+0 | |
1126 clrf divemins+1 | |
1127 bcf no_more_divesecs ; =1: Do no longer show seconds in divemode | |
1128 bcf divemode_menu_active | |
1129 clrf menupos | |
1130 clrf menupos2 ; Reset to zero (Zero=no premenu or simulator task) | |
1131 | |
1132 bcf is_bailout ; =1: Bailout | |
1133 btfss FLAG_ccr_mode | |
1134 rcall dive_boot_oc | |
1135 btfsc FLAG_ccr_mode | |
1136 rcall dive_boot_cc | |
1137 | |
1138 bcf better_gas_available ;=1: A better gas is available and a gas change is advised in divemode | |
1139 clrf better_gas_number ; Clear better gas register | |
1140 | |
1141 clrf samplesecs | |
1142 clrf apnoe_timeout_counter ; timeout in minutes | |
1143 clrf timeout_counter ; takes care of the timeout (Low byte) | |
1144 clrf timeout_counter2 ; takes care of the timeout (High byte) | |
1145 clrf AlarmType ; Clear all alarms | |
1146 bcf event_occured ; clear flag | |
1147 clrf total_divetime_seconds+1 | |
1148 clrf average_depth_hold_total+0 | |
1149 clrf average_depth_hold_total+1 | |
1150 clrf average_depth_hold_total+2 | |
1151 clrf average_depth_hold_total+3 ; Clear Non-Resettable Average | |
1152 rcall reset_average1 ; Reset the resettable average depth | |
1153 bcf decostop_active | |
1154 bcf better_gas_available ;=1: A better gas is available and a gas change is advised in divemode | |
1155 call ghostwriter_short_header ; Write short header with divenumber into profile memory | |
1156 | |
1157 btfsc simulatormode_active | |
1158 bra diveloop_boot_1 | |
1159 ; Normal mode = Surface pressure is the pressure 30mn before dive. | |
1160 SAFE_2BYTE_COPY last_surfpressure_30min, int_I_pres_surface ;copy surfacepressure to deco routine | |
1161 SAFE_2BYTE_COPY last_surfpressure_30min, last_surfpressure ;copy surfacepressure to last_surfpressure for correct depth | |
1162 bra diveloop_boot_2 | |
1163 | |
1164 diveloop_boot_1: | |
1165 ; Simulator mode: Surface pressure is 1bar. | |
1166 movlw LOW .1000 | |
1167 movff WREG,int_I_pres_surface+0 ; LOW copy surfacepressure to deco routine | |
1168 movlw HIGH .1000 | |
1169 movff WREG,int_I_pres_surface+1 ; HIGH copy surfacepressure to deco routine | |
1170 | |
1171 diveloop_boot_2: | |
1172 SAFE_2BYTE_COPY temperature,minimum_temperature ; Reset Min-Temp registers | |
1173 | |
1174 ; Init profile recording parameters | |
23
e402813343b6
new option to switch samplingrate between 10s and 2s
heinrichsweikamp
parents:
0
diff
changeset
|
1175 movff samplingrate,samplesecs_value ; to avoid EEPROM access in the ISR |
0 | 1176 movlw div_temperature |
1177 movwf divisor_temperature ; load divisors for profile storage | |
1178 movlw div_deco | |
1179 movwf divisor_deco | |
1180 movlw div_gf | |
1181 movwf divisor_gf | |
1182 movlw div_ppo2_sensors | |
1183 movwf divisor_ppo2_sensors | |
1184 movlw div_decoplan | |
1185 movwf divisor_decoplan | |
1186 movlw div_cns | |
1187 movwf divisor_cns | |
1188 movlw div_tank | |
1189 movwf divisor_tank | |
1190 | |
1191 btfss FLAG_apnoe_mode ; In Apnoe mode? | |
1192 bra divemode1 | |
1193 ; Overwrite some parameters in Apnoe mode.... | |
1194 movlw samplingrate_apnoe | |
1195 movwf samplesecs_value ; to avoid EEPROM access in the ISR | |
1196 | |
1197 divemode1: | |
1198 bcf LEDg | |
1199 bcf LEDr | |
1200 bcf realdive | |
1201 btfss simulatormode_active ; do not disable in simulator mode! | |
1202 call disable_rs232 ; Disable RS232 | |
1203 btfsc enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump) | |
1204 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
|
1205 ; Reset divetime seconds |
e4e91fe8b09d
remember last customview in dive and surface mode
mh@mh-THINK.fritz.box
parents:
38
diff
changeset
|
1206 movlw .2 ; Start at 2seconds |
0 | 1207 movwf total_divetime_seconds+0 |
39
e4e91fe8b09d
remember last customview in dive and surface mode
mh@mh-THINK.fritz.box
parents:
38
diff
changeset
|
1208 movwf divesecs |
e4e91fe8b09d
remember last customview in dive and surface mode
mh@mh-THINK.fritz.box
parents:
38
diff
changeset
|
1209 movwf apnoe_secs |
0 | 1210 bsf divemode2 ; displayed divetime is running (Divetime starts HERE) |
1211 | |
1212 movff int_O_CNS_fraction+0,CNS_start+0 | |
1213 movff int_O_CNS_fraction+1,CNS_start+1 ; Save CNS value at beginning of dive | |
1214 movff char_O_relative_gradient_GF,GF_start ; Save GF value at beginning of dive | |
1215 return ; Done with divemode boot | |
1216 | |
1217 divemode_check_for_warnings: | |
1218 btfss secs,1 ; Every four seconds | |
1219 return | |
1220 | |
1221 movf warning_counter_backup,W | |
1222 cpfseq warning_counter ; warning_counter_backup = warning_counter? | |
1223 call TFT_clear_warning_text ; No, clear all warnings | |
1224 movff warning_counter,warning_counter_backup ; copy warning_counter | |
1225 | |
1226 bcf warning_active ; Clear flag | |
1227 clrf warning_counter ; Clear counter | |
1228 | |
1229 ; Warnings for all modes | |
1230 call check_warn_battery ; Check if the battery level should be displayed/warned | |
55 | 1231 call check_divetimeout ; Not actually a warning. Check and show the divemode timeout |
0 | 1232 |
1233 btfsc FLAG_apnoe_mode ; Done for Apnoe or Gauge mode | |
1234 bra divemode_check_for_warnings2 | |
1235 btfsc FLAG_gauge_mode ; Done for Apnoe or Gauge mode | |
1236 bra divemode_check_for_warnings2 | |
1237 | |
1238 ; Warnings only in deco modes | |
1239 btfss FLAG_ccr_mode ; Don't check in CCR mode | |
1240 rcall check_ppO2 ; check ppO2 and displays warning, if required | |
1241 btfsc is_bailout ; But check in Bailout case... | |
1242 rcall check_ppO2 ; check ppO2 and displays warning, if required | |
1243 rcall check_cns_violation ; Check CNS value and display it, if required | |
1244 btfsc decostop_active ; In deco mode? | |
1245 rcall check_and_store_gf_violation ; Yes, Sets warnings, if required | |
1246 btfsc decostop_active ; In deco mode? | |
1247 call TFT_ftts ; Show @+x time | |
1248 btfsc use_agf ; In aGF mode? | |
1249 rcall warn_agf ; Yes, show a warning for it | |
1250 | |
1251 divemode_check_for_warnings2: | |
1252 ; Display the warning icon? | |
1253 btfsc warning_active ; Any warning active? | |
1254 call TFT_divemode_warning ; Yes | |
1255 btfss warning_active ; Any warning active? | |
1256 call TFT_divemode_warning_clear ; No, clear warning icon | |
1257 | |
1258 ; Setup warning_page number | |
1259 incf warning_page,F | |
1260 bcf STATUS,C | |
1261 rlcf warning_page,W ; *2 | |
1262 cpfsgt warning_counter ; > warning_counter | |
1263 clrf warning_page ; No, clear | |
1264 | |
1265 ; Clear 2nd row of warnings if there is nothing to show (on this page) | |
1266 btfss second_row_warning ; =1: The second row contains a warning | |
1267 call TFT_clear_warning_text_2nd_row ; No, clear this row | |
1268 return ; Done. | |
1269 | |
1270 global check_warn_battery | |
1271 check_warn_battery: | |
1272 movff batt_percent,lo | |
1273 movlw battery_show_level+1 | |
1274 cpfslt lo | |
1275 return ; No Display, no warning | |
1276 ; Display Battery, but warn? | |
1277 incf warning_counter,F ; increase counter | |
1278 call TFT_update_batt_percent_divemode ; Show percent | |
1279 | |
86 | 1280 movff batt_percent,lo |
0 | 1281 movlw color_code_battery_low+1 |
1282 cpfslt lo ; | |
1283 return ; No warning | |
1284 bsf warning_active ; Set Warning flag | |
1285 return | |
1286 | |
55 | 1287 check_divetimeout: |
1288 btfsc divemode2 | |
1289 return ; displayed divetime is not running | |
1290 incf warning_counter,F ; increase counter | |
1291 call TFT_divetimeout ; Show timeout counter | |
1292 return | |
1293 | |
1294 | |
0 | 1295 check_ppO2: ; check current ppO2 and display warning if required |
1296 SAFE_2BYTE_COPY amb_pressure, xA | |
1297 movlw d'10' | |
1298 movwf xB+0 | |
1299 clrf xB+1 | |
1300 call div16x16 ; xC=p_amb/10 | |
1301 | |
1302 movff xC+0,xA+0 | |
1303 movff xC+1,xA+1 | |
1304 movff char_I_O2_ratio,xB+0 ; =O2 ratio | |
1305 clrf xB+1 | |
1306 call mult16x16 ; char_I_O2_ratio * p_amb/10 | |
1307 | |
1308 ; Check very high ppO2 manually | |
1309 tstfsz xC+2 ; char_I_O2_ratio * p_amb/10 > 65536, ppO2>6,55bar? | |
1310 bra check_ppO2_1 ; Yes, display Value! | |
1311 ; Check if ppO2>3,30bar | |
1312 btfsc xC+1,7 | |
1313 bra check_ppO2_1 ; Yes! | |
1314 | |
1315 ; Check for low ppo2 | |
1316 movff xC+0,sub_b+0 | |
1317 movff xC+1,sub_b+1 | |
1318 movff opt_ppO2_min,WREG | |
1319 mullw d'100' ; opt_ppO2_min*100 | |
1320 movff PRODL,sub_a+0 | |
1321 movff PRODH,sub_a+1 | |
1322 call subU16 | |
1323 btfsc neg_flag | |
1324 bra check_ppO2_0 ; Not too low | |
1325 ; ppO2 low | |
1326 incf warning_counter,F ; increase counter | |
1327 call TFT_display_ppo2 ; Show ppO2 | |
1328 movlw d'4' ; Type of Alarm (ppO2 low) | |
1329 movwf AlarmType ; Copy to Alarm Register | |
1330 bsf event_occured ; Set Event Flag | |
1331 bsf warning_active ; Set Warning flag | |
1332 return ; Done. | |
1333 | |
1334 check_ppO2_0: | |
1335 ; Check if ppO2 should be displayed | |
1336 movlw ppo2_display_high | |
1337 mullw d'100' ; ppo2_display_high*100 | |
1338 movff PRODL,sub_a+0 | |
1339 movff PRODH,sub_a+1 | |
1340 call subU16 | |
1341 btfss neg_flag | |
1342 return ; No Display, no warning | |
1343 ; Display ppO2, but warn? | |
1344 incf warning_counter,F ; increase counter | |
1345 call TFT_display_ppo2 ; Show ppO2 | |
1346 | |
1347 ;check if we are within our warning thresholds! | |
1348 movff xC+0,sub_b+0 | |
1349 movff xC+1,sub_b+1 | |
1350 movff opt_ppO2_max,WREG ; PPO2 Max for MOD calculation and color coding in divemode | |
69 | 1351 addlw .1 ; e.g. >1.60 |
0 | 1352 mullw d'100' ; opt_ppO2_max*100 |
1353 movff PRODL,sub_a+0 | |
1354 movff PRODH,sub_a+1 | |
1355 call subU16 | |
1356 btfss neg_flag | |
1357 return ; Done. Not too high | |
1358 movlw d'5' ; Type of Alarm (ppO2 high) | |
1359 movwf AlarmType ; Copy to Alarm Register | |
1360 bsf event_occured ; Set Event Flag | |
1361 bsf warning_active ; Set Warning flag | |
1362 return ; Done. | |
1363 | |
1364 check_ppO2_1: ; ppO2 very high | |
1365 incf warning_counter,F ; increase counter | |
1366 call TFT_display_ppo2 ; Show ppO2 | |
1367 movlw d'5' ; Type of Alarm | |
1368 movwf AlarmType ; Copy to Alarm Register | |
1369 bsf event_occured ; Set Event Flag | |
1370 bsf warning_active ; Set Warning flag | |
1371 return ; Done. | |
1372 | |
1373 global check_cns_violation | |
1374 check_cns_violation: | |
1375 ; Check if CNS should be displayed | |
1376 movff int_O_CNS_fraction+1,lo ; copy into bank1 | |
1377 tstfsz lo ; >255% ? | |
1378 bra check_cns_violation2 ; Yes | |
1379 movff int_O_CNS_fraction+0,lo ; copy into bank1 | |
1380 | |
1381 movlw cns_warning_high ; cns_warning_high | |
1382 subwf lo,W | |
1383 btfsc STATUS,C | |
1384 bsf warning_active ; Set Warning flag | |
1385 | |
1386 movlw cns_display_high ; cns_display_high | |
1387 subwf lo,W | |
1388 btfss STATUS,C | |
1389 return ; No Display, no warning | |
1390 ; Display CNS | |
1391 incf warning_counter,F ; increase counter | |
1392 call TFT_display_cns ; Show CNS | |
1393 return | |
1394 | |
1395 check_cns_violation2: | |
1396 incf warning_counter,F ; increase counter | |
1397 call TFT_display_cns ; Show CNS | |
1398 bsf warning_active ; Set Warning flag | |
1399 return | |
1400 | |
1401 global check_and_store_gf_violation | |
1402 check_and_store_gf_violation: | |
1403 movff char_O_gradient_factor,lo ; gradient factor absolute (Non-GF model) | |
1404 movff char_I_deco_model,hi | |
1405 decfsz hi,F ; jump over next line if char_I_deco_model == 1 | |
1406 movff char_O_relative_gradient_GF,lo ; gradient factor relative (GF model) | |
1407 | |
1408 movlw gf_warning_high | |
1409 cpfsgt lo | |
1410 bra check_and_store_gf_violation2 ; No warning | |
1411 movlw d'2' ; Type of Alarm | |
1412 movwf AlarmType ; Copy to Alarm Register | |
1413 bsf event_occured ; Set Event Flag | |
1414 bsf warning_active ; Set Warning flag | |
1415 check_and_store_gf_violation2: | |
1416 movlw gf_display_high | |
1417 cpfsgt lo | |
1418 return ; No Display, no warning | |
1419 ; Display GF | |
1420 incf warning_counter,F ; increase counter | |
1421 call TFT_warning_gf ; Show GF Warning | |
1422 return | |
1423 | |
1424 warn_agf: | |
1425 incf warning_counter,F ; increase counter | |
1426 call TFT_warning_agf ; Show aGF warning | |
86 | 1427 ; bsf warning_active ; Set Warning flag |
0 | 1428 return |
1429 | |
1430 | |
1431 END |