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