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