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