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