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