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