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