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