Mercurial > public > hwos_code
annotate src/divemode.asm @ 118:abd30446e1cd
show heading with leading zeros
author | heinrichsweikamp |
---|---|
date | Fri, 27 Jun 2014 10:18:41 +0200 |
parents | f3062a611eef |
children | 35b9da423de6 |
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 | |
72 | |
73 ; Tasks only for deco modes | |
104
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
74 btfsc show_safety_stop ; Show the safety stop? |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
75 call TFT_show_safety_stop ; Yes, show/delete if done. |
0 | 76 call calc_deko_divemode ; calculate decompression and display result (any two seconds) |
77 bra diveloop_loop1x ; Common Tasks | |
78 | |
79 diveloop_loop1b: | |
80 ; Tasks only for Apnoe mode | |
81 call divemode_apnoe_tasks ; 1 sec. Apnoe tasks | |
82 bra diveloop_loop1x ; Common Tasks | |
83 | |
84 diveloop_loop1x: | |
85 ; Common 1sec. tasks for all modes | |
86 call timeout_divemode ; dive finished? This routine sets the required flags | |
87 call set_dive_modes ; tests if depth>threshold | |
88 call set_min_temp ; store min. temp if required | |
89 | |
90 btfsc store_sample ; store new sample? | |
91 call store_dive_data ; Store profile data | |
92 | |
93 btfss divemode ; Dive finished? | |
94 goto ghostwriter_end_dive ; Dive finished! | |
95 | |
96 btfsc divemode_gaschange ; Gas switch flag set? | |
97 rcall gas_switched_common ; Yes | |
98 | |
99 btfsc toggle_gf ; =1: Toggle GF/aGF | |
100 rcall divemodemode_togglegf ; Toggle aGF/GF | |
101 | |
102 ; btfsc FLAG_ccr_mode ; In CCR mode | |
103 ; call TFT_active_gas_divemode ; Update Setpoint every second | |
104 | |
113 | 105 call compute_ppo2 ; compute mv_sensorX and ppo2_sensorX arrays |
106 | |
0 | 107 bcf onesecupdate ; one seconds update done |
108 | |
109 diveloop_loop3: | |
110 rcall test_switches_divemode ; Check switches in divemode | |
111 | |
112 global diveloop_loop4 | |
113 diveloop_loop4: ; Menu-Exit returns here... | |
114 btfsc toggle_customview ; Next view? | |
115 call customview_toggle ; Yes, show next customview (and delete this flag) | |
116 | |
117 btfsc pressure_refresh ; new pressure available? | |
118 rcall update_temp_and_or_depth ; Yes, display new depth and clear "pressure_refresh" flag | |
119 | |
120 btfsc oneminupdate ; one minute tasks | |
121 rcall update_divemode60 ; Update clock, etc. | |
122 | |
123 btfss quarter_second_update | |
124 bra diveloop_loop4a | |
83 | 125 |
0 | 126 bcf quarter_second_update |
127 movlw .6 | |
128 cpfseq menupos3 ; in compass view? | |
129 bra diveloop_loop4a ; No | |
130 call TFT_dive_compass_heading ; Yes, update compass heading value | |
131 diveloop_loop4a: | |
132 btfsc enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump) | |
133 bra diveloop_loop5 | |
134 bra diveloop_loop6 | |
135 diveloop_loop5: | |
136 btfss vusb_in ; USB (still) plugged in? | |
137 bcf enable_screen_dumps ; No, clear flag | |
138 call rs232_get_byte | |
139 btfsc rs232_recieve_overflow | |
140 bra diveloop_loop6 | |
141 movlw "l" | |
142 cpfseq RCREG1 | |
143 bra diveloop_loop6 | |
144 call TFT_dump_screen ; Dump the screen contents | |
145 diveloop_loop6: | |
146 | |
147 bra diveloop_loop ; Loop the divemode | |
148 ;-------------------------------------------------------------------------------------------------------- | |
149 | |
150 | |
151 divemode_apnoe_tasks: ; 1 sec. Apnoe tasks | |
152 call TFT_display_apnoe_descent ; Show descent timer | |
153 call TFT_max_pressure ; use normal max. depth | |
154 | |
155 btfsc divemode2 ; Time running? | |
156 bra divemode_apnoe_tasks2 ; New descent, reset data if flag is set | |
157 | |
158 rcall apnoe_calc_maxdepth | |
159 call TFT_display_apnoe_surface | |
160 call TFT_display_apnoe_last_max ; Show last max. depth | |
161 incf apnoe_surface_secs,F | |
162 movlw d'60' | |
163 cpfseq apnoe_surface_secs | |
164 bra divemode_apnoe_tasks1 | |
165 clrf apnoe_surface_secs | |
166 incf apnoe_surface_mins,F | |
167 | |
168 divemode_apnoe_tasks1: | |
169 bcf FLAG_active_descent ; Clear flag | |
170 btfsc divemode2 ; Time running? | |
171 return ; Yes, return | |
172 bsf FLAG_active_descent ; Set Flag | |
173 return | |
174 | |
175 divemode_apnoe_tasks2: | |
176 btfss FLAG_active_descent ; Are we descending? | |
177 return ; No, We are at the surface | |
178 rcall apnoe_calc_maxdepth ; Yes! | |
179 call TFT_apnoe_clear_surface ; Clear Surface timer | |
180 clrf apnoe_timeout_counter ; Delete timeout | |
181 clrf apnoe_surface_secs | |
182 clrf apnoe_surface_mins | |
183 clrf apnoe_secs | |
184 clrf apnoe_mins ; Reset Descent time | |
185 movlw .0 | |
186 movff WREG,max_pressure+0 | |
187 movff WREG,max_pressure+1 ; Reset Max. Depth | |
188 bcf FLAG_active_descent ; Clear flag | |
189 return | |
190 | |
191 global apnoe_calc_maxdepth | |
192 apnoe_calc_maxdepth: | |
193 movff apnoe_max_pressure+0,sub_a+0 | |
194 movff apnoe_max_pressure+1,sub_a+1 | |
195 movff max_pressure+0,sub_b+0 | |
196 movff max_pressure+1,sub_b+1 | |
197 call subU16 ; sub_c = sub_a - sub_b | |
198 ; apnoe_max_pressure<max_pressure -> neg_flag=1 | |
199 ; max_pressure<=apnoe_max_pressure -> neg_flag=0 | |
200 btfss neg_flag | |
201 return | |
202 ;apnoe_max_pressure<max_pressure | |
203 movff max_pressure+0,apnoe_max_pressure+0 | |
204 movff max_pressure+1,apnoe_max_pressure+1 | |
205 return | |
206 | |
207 | |
208 calc_deko_divemode: | |
209 btfsc twosecupdate ; two seconds after the last call | |
210 bra calc_deko_divemode2 ; Yes, calculate and display deco data ("first second") | |
211 | |
212 bsf twosecupdate ; No, but next second! | |
213 ; Routines used in the "other second" | |
214 call calc_average_depth ; calculate average depth | |
215 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
|
216 call divemode_check_for_warnings ; Check for any warnings |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
217 call set_reset_safety_stop ; Set flags for safety stop and/or reset safety stop |
0 | 218 call TFT_debug_output |
219 | |
220 btfsc FLAG_apnoe_mode ; Done for Apnoe or Gauge mode | |
221 return | |
222 btfsc FLAG_gauge_mode ; Done for Apnoe or Gauge mode | |
223 return | |
224 | |
225 ; Calculate CNS | |
226 rcall set_actual_ppo2 ; Set char_I_actual_ppO2 | |
227 clrf WREG | |
228 movff WREG,char_I_step_is_1min ; Make sure to be in 2sec mode. | |
229 call deco_calc_CNS_fraction ; calculate CNS | |
230 movlb b'00000001' ; rambank 1 selected | |
231 | |
232 ; Check for a gas change | |
233 rcall check_gas_change ; Checks if a better gas should be selected (by user) | |
234 | |
235 return | |
236 | |
237 global set_actual_ppo2 | |
238 set_actual_ppo2: ; calculate ppO2 in 0.01bar (e.g. 150 = 1.50 bar ppO2) | |
111 | 239 btfsc divemode ; in divemode |
240 bra set_actual_ppo2_dive ; Yes | |
241 ; No, use simulated ambient pressure for char_I_actual_ppO2 | |
242 movff char_I_bottom_depth,WREG | |
243 mullw .100 | |
244 movlw LOW(.1000) | |
245 addwf PRODL,W | |
246 movwf xA+0 | |
247 movlw HIGH(.1000) | |
248 addwfc PRODH,W | |
249 movwf xA+1 ; P_amb in millibar (1000 = 1.00 bar). | |
250 bra set_actual_ppo2_common | |
251 set_actual_ppo2_dive: | |
0 | 252 SAFE_2BYTE_COPY amb_pressure, xA ; P_amb in millibar (1000 = 1.00 bar). |
111 | 253 set_actual_ppo2_common: |
113 | 254 movlw d'10' |
0 | 255 movwf xB+0 |
256 clrf xB+1 | |
257 call div16x16 ; xC=p_amb/10 (100 = 1.00 bar). | |
258 movff xC+0,xA+0 | |
259 movff xC+1,xA+1 | |
260 movff char_I_O2_ratio,xB+0 | |
261 clrf xB+1 | |
262 call mult16x16 ; char_I_O2_ratio * (p_amb/10) | |
263 movff xC+0,xA+0 | |
264 movff xC+1,xA+1 | |
265 movlw d'100' | |
266 movwf xB+0 | |
267 clrf xB+1 | |
268 call div16x16 ; xC=(char_I_O2_ratio * p_amb/10)/100 | |
269 | |
270 ; Copy ppO2 for CNS calculation | |
271 tstfsz xC+1 ; Is ppO2 > 2.55bar ? | |
272 setf xC+0 ; yes: bound to 2.55... better than wrap around. | |
273 | |
274 movff xC+0, char_I_actual_ppO2 ; copy last ppO2 to buffer register | |
275 btfsc is_bailout ; In Bailout? | |
276 return ; Yes, done. | |
277 ; No Bailout, check for ccr mode | |
278 btfsc FLAG_ccr_mode ; If FLAG_ccr_mode=1... | |
279 movff char_I_const_ppO2, char_I_actual_ppO2 ; ...copy last ppO2 to buffer register | |
280 return | |
281 | |
282 | |
283 calc_deko_divemode2: | |
284 bcf twosecupdate | |
285 | |
286 btfsc FLAG_apnoe_mode ; Done for Apnoe or Gauge mode | |
287 return | |
288 btfsc FLAG_gauge_mode ; Done for Apnoe or Gauge mode | |
289 return | |
290 | |
291 extern deco_setup_dive | |
292 call deco_setup_dive ; Pass all parameters to the C code | |
293 | |
294 TSTOSS opt_ccr_mode ; =0: Fixed SP, =1: Sensor | |
295 bra calc_deko_divemode2a | |
296 rcall divemode_setup_sensor_values ; Setup sensor values | |
297 | |
298 calc_deko_divemode2a: | |
299 SAFE_2BYTE_COPY amb_pressure,int_I_pres_respiration ; C-code needs the ambient pressure | |
300 clrf WREG | |
301 movff WREG,char_I_step_is_1min ; Force 2 second deco mode | |
302 | |
303 clrf TMR5L | |
304 clrf TMR5H ; 30,51757813µs/bit in TMR5L:TMR5H | |
305 call deco_calc_hauptroutine ; calc_tissue | |
306 movlb .1 | |
307 | |
308 movff char_O_deco_status,WREG ; Is a compute cycle finished ? | |
309 iorwf WREG,F | |
310 btfss STATUS,Z | |
311 return ; Return is status <> 0 | |
312 | |
313 ; Check if deco stops are necessary ? | |
314 movff char_O_first_deco_depth,wait_temp ; copy ceiling to temp register | |
315 tstfsz wait_temp ; Ceiling<0m? | |
316 bra calc_deko_divemode3 ; Yes! | |
317 | |
318 btfsc decostop_active ; Already in nodeco mode ? | |
319 call TFT_display_ndl_mask ; No, Clear deco data, display nostop time | |
320 bcf decostop_active ; clear flag (again) | |
321 | |
322 ; Copy for profile recording | |
323 clrf decodata+0 | |
324 movff char_O_nullzeit,decodata+1 ; NDL | |
325 | |
326 call TFT_display_ndl ; display no deco limit | |
327 return | |
328 | |
329 calc_deko_divemode3: | |
330 btfss decostop_active ; Already in deco mode ? | |
331 call TFT_display_deko_mask ; No, clear nostop time, display decodata | |
332 bsf decostop_active ; Set flag (again) | |
333 | |
334 ; Copy for profile recording | |
335 movff char_O_first_deco_depth,decodata+0 ; ceiling | |
336 movff char_O_first_deco_time,decodata+1 ; length of first stop in minues | |
337 call TFT_display_deko ; display decodata | |
338 call TFT_show_TTS_divemode ; display TTS | |
339 | |
340 movff char_I_extra_time,WREG | |
341 tstfsz WREG ; extra time = 0? | |
342 bra calc_deko_divemode4 ; No, compute it | |
343 return | |
344 | |
345 calc_deko_divemode4: | |
346 ; Check if extra cycles are needed to compute @5 variant: | |
347 decfsz apnoe_mins,F ; Reached count-down ? | |
348 return ; No: don't compute yet. | |
349 | |
350 movlw .6 | |
351 movff WREG,char_O_deco_status ; Stole next cycles for @5 variant. | |
352 | |
353 movlw .2 ; Restart countdown. | |
354 movwf apnoe_mins | |
355 return ; done. | |
356 | |
357 ;----------------------------------------------------------------------------- | |
358 | |
359 divemodemode_togglegf: ; Toggle aGF/GF | |
360 bcf toggle_gf ; clear flag | |
361 btg use_agf ; Toggle GF | |
362 call TFT_gf_mask ; Setup Mask | |
363 clrf WREG | |
364 movff WREG,char_O_deco_status ; Restart decoplan computation | |
365 return | |
366 | |
367 divemode_setup_sensor_values: | |
368 ; sum up sensor values (in xA:2) and active sensors in (xB:2) | |
369 clrf xB+0 | |
370 clrf xB+1 | |
371 clrf xA+0 | |
372 clrf xA+1 | |
113 | 373 btfss sensor1_active ; Sensor1 active? |
0 | 374 bra divemode_setup_sensor_values2 ; No |
375 movf o2_ppo2_sensor1,W | |
376 addwf xA+0 | |
377 movlw .0 | |
378 addwfc xA+1 ; Add into xA:2 | |
379 incf xB+0,F ; Add a sensor | |
380 divemode_setup_sensor_values2: | |
113 | 381 btfss sensor2_active ; Sensor2 active? |
0 | 382 bra divemode_setup_sensor_values3 ; No |
383 movf o2_ppo2_sensor2,W | |
384 addwf xA+0 | |
385 movlw .0 | |
386 addwfc xA+1 ; Add into xA:2 | |
387 incf xB+0,F ; Add a sensor | |
388 divemode_setup_sensor_values3: | |
113 | 389 btfss sensor3_active ; Sensor3 active? |
0 | 390 bra divemode_setup_sensor_values4 ; No |
391 movf o2_ppo2_sensor3,W | |
392 addwf xA+0 | |
393 movlw .0 | |
394 addwfc xA+1 ; Add into xA:2 | |
395 incf xB+0,F ; Add a sensor | |
396 divemode_setup_sensor_values4: | |
397 call div16x16 ; xA/xB=xC with xA+0 as remainder | |
398 movff xC+0,sensor_setpoint ; Copy result | |
399 movff sensor_setpoint,char_I_const_ppO2 ; use sensor ppO2 | |
400 return | |
401 | |
402 calc_velocity: ; called every two seconds | |
403 btfss divemode | |
404 bra do_not_display_velocity ; display velocity only in divemode (Not at the surface after dive) | |
405 | |
406 calc_velocity2: | |
407 SAFE_2BYTE_COPY amb_pressure, sub_a | |
408 movff last_pressure_velocity+0,sub_b+0 | |
409 movff last_pressure_velocity+1,sub_b+1 | |
410 movff sub_a+0,last_pressure_velocity+0 ; store old value for velocity | |
411 movff sub_a+1,last_pressure_velocity+1 | |
412 | |
413 call subU16 ; sub_c = amb_pressure - last_pressure | |
414 | |
415 movff sub_c+0,xA+0 | |
416 movff sub_c+1,xA+1 | |
417 movlw d'39' ; 77 when called every second.... | |
418 movwf xB+0 | |
419 clrf xB+1 | |
420 call mult16x16 ; differential pressure in mbar*77... | |
421 movff xC+0,divA+0 | |
422 movff xC+1,divA+1 | |
423 movlw d'7' | |
424 movwf divB+0 | |
425 call div16 ; devided by 2^7 equals velocity in m/min | |
426 | |
427 movlw d'99' | |
428 cpfsgt divA+0 ; limit to 99m/min | |
429 bra calc_velocity3 | |
430 movwf divA+0 ; divA=99 | |
431 | |
432 calc_velocity3: | |
433 movlw velocity_warning_level_1 ; lowest threshold for display vertical velocity | |
434 subwf divA+0,W ; | |
435 btfss STATUS,C | |
436 bra do_not_display_velocity | |
437 | |
438 bsf display_velocity | |
439 call TFT_display_velocity ; With divA+0 = m/min... | |
440 return | |
441 | |
442 do_not_display_velocity: | |
443 btfss display_velocity ; Velocity was not displayed, do not delete | |
444 return | |
445 bcf display_velocity ; Velocity was displayed, delete velocity now | |
446 call TFT_display_velocity_clear | |
447 return | |
448 | |
449 ;============================================================================= | |
450 | |
104
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
451 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
|
452 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
|
453 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
|
454 |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
455 btfsc decostop_active ; Is a deco stop displayed? |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
456 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
|
457 ; 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
|
458 SAFE_2BYTE_COPY rel_pressure, lo |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
459 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
|
460 movff lo,sub_a+0 |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
461 movff hi,sub_a+1 |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
462 movlw LOW safety_stop_reset |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
463 movwf sub_b+0 |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
464 movlw HIGH safety_stop_reset |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
465 movwf sub_b+1 |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
466 call subU16 ; sub_c = sub_a - sub_b |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
467 btfss neg_flag |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
468 bra reset_safety_stop ; Below 10m, reset safety stop |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
469 |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
470 ; Above "safety_stop_end"? Clear flag. |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
471 SAFE_2BYTE_COPY rel_pressure, lo |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
472 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
|
473 movff lo,sub_a+0 |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
474 movff hi,sub_a+1 |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
475 movlw LOW safety_stop_end |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
476 movwf sub_b+0 |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
477 movlw HIGH safety_stop_end |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
478 movwf sub_b+1 |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
479 call subU16 ; sub_c = sub_a - sub_b |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
480 btfsc neg_flag |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
481 bra delete_safety_stop ; Above 3m, remove safety stop |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
482 |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
483 ; Above "safety_stop_start"? Activate safety stop |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
484 SAFE_2BYTE_COPY rel_pressure, lo |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
485 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
|
486 movff lo,sub_a+0 |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
487 movff hi,sub_a+1 |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
488 movlw LOW safety_stop_start |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
489 movwf sub_b+0 |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
490 movlw HIGH safety_stop_start |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
491 movwf sub_b+1 |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
492 call subU16 ; sub_c = sub_a - sub_b |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
493 btfsc neg_flag |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
494 bra acivate_safety_stop ; Above 5m, activate safety stop |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
495 bra reset_safety_stop2 ; Pause safety stop |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
496 |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
497 acivate_safety_stop: |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
498 tstfsz safety_stop_countdown ; Countdown at zero? |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
499 bsf show_safety_stop ; No, Set flag! |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
500 return |
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 delete_safety_stop: |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
503 clrf safety_stop_countdown ; reset timer |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
504 bra reset_safety_stop2 ; Remove safety stop from display |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
505 |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
506 reset_safety_stop: |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
507 movlw safety_stop_length ;[s] |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
508 movwf safety_stop_countdown ; reset timer |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
509 reset_safety_stop2: |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
510 bcf show_safety_stop ; Clear flag |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
511 btfss safety_stop_active ; Safety stop shown |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
512 return ; No, don't delete it |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
513 bcf safety_stop_active ; Clear flag |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
514 call TFT_display_ndl_mask ; Show NDL again |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
515 call TFT_display_ndl |
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: | |
1326 btfss secs,1 ; Every four seconds | |
1327 return | |
1328 | |
1329 movf warning_counter_backup,W | |
1330 cpfseq warning_counter ; warning_counter_backup = warning_counter? | |
1331 call TFT_clear_warning_text ; No, clear all warnings | |
1332 movff warning_counter,warning_counter_backup ; copy warning_counter | |
1333 | |
1334 bcf warning_active ; Clear flag | |
1335 clrf warning_counter ; Clear counter | |
1336 | |
1337 ; Warnings for all modes | |
1338 call check_warn_battery ; Check if the battery level should be displayed/warned | |
55 | 1339 call check_divetimeout ; Not actually a warning. Check and show the divemode timeout |
0 | 1340 |
1341 btfsc FLAG_apnoe_mode ; Done for Apnoe or Gauge mode | |
1342 bra divemode_check_for_warnings2 | |
1343 btfsc FLAG_gauge_mode ; Done for Apnoe or Gauge mode | |
1344 bra divemode_check_for_warnings2 | |
1345 | |
1346 ; Warnings only in deco modes | |
1347 btfss FLAG_ccr_mode ; Don't check in CCR mode | |
1348 rcall check_ppO2 ; check ppO2 and displays warning, if required | |
1349 btfsc is_bailout ; But check in Bailout case... | |
1350 rcall check_ppO2 ; check ppO2 and displays warning, if required | |
1351 rcall check_cns_violation ; Check CNS value and display it, if required | |
1352 btfsc decostop_active ; In deco mode? | |
1353 rcall check_and_store_gf_violation ; Yes, Sets warnings, if required | |
1354 btfsc decostop_active ; In deco mode? | |
1355 call TFT_ftts ; Show @+x time | |
1356 btfsc use_agf ; In aGF mode? | |
1357 rcall warn_agf ; Yes, show a warning for it | |
1358 | |
1359 divemode_check_for_warnings2: | |
1360 ; Display the warning icon? | |
1361 btfsc warning_active ; Any warning active? | |
1362 call TFT_divemode_warning ; Yes | |
1363 btfss warning_active ; Any warning active? | |
1364 call TFT_divemode_warning_clear ; No, clear warning icon | |
1365 | |
1366 ; Setup warning_page number | |
1367 incf warning_page,F | |
1368 bcf STATUS,C | |
1369 rlcf warning_page,W ; *2 | |
1370 cpfsgt warning_counter ; > warning_counter | |
1371 clrf warning_page ; No, clear | |
1372 | |
1373 ; Clear 2nd row of warnings if there is nothing to show (on this page) | |
1374 btfss second_row_warning ; =1: The second row contains a warning | |
1375 call TFT_clear_warning_text_2nd_row ; No, clear this row | |
1376 return ; Done. | |
1377 | |
1378 global check_warn_battery | |
1379 check_warn_battery: | |
1380 movff batt_percent,lo | |
1381 movlw battery_show_level+1 | |
1382 cpfslt lo | |
1383 return ; No Display, no warning | |
1384 ; Display Battery, but warn? | |
1385 incf warning_counter,F ; increase counter | |
1386 call TFT_update_batt_percent_divemode ; Show percent | |
1387 | |
86 | 1388 movff batt_percent,lo |
0 | 1389 movlw color_code_battery_low+1 |
1390 cpfslt lo ; | |
1391 return ; No warning | |
1392 bsf warning_active ; Set Warning flag | |
1393 return | |
1394 | |
55 | 1395 check_divetimeout: |
1396 btfsc divemode2 | |
1397 return ; displayed divetime is not running | |
1398 incf warning_counter,F ; increase counter | |
1399 call TFT_divetimeout ; Show timeout counter | |
1400 return | |
1401 | |
1402 | |
0 | 1403 check_ppO2: ; check current ppO2 and display warning if required |
1404 SAFE_2BYTE_COPY amb_pressure, xA | |
1405 movlw d'10' | |
1406 movwf xB+0 | |
1407 clrf xB+1 | |
1408 call div16x16 ; xC=p_amb/10 | |
1409 | |
1410 movff xC+0,xA+0 | |
1411 movff xC+1,xA+1 | |
1412 movff char_I_O2_ratio,xB+0 ; =O2 ratio | |
1413 clrf xB+1 | |
1414 call mult16x16 ; char_I_O2_ratio * p_amb/10 | |
1415 | |
1416 ; Check very high ppO2 manually | |
1417 tstfsz xC+2 ; char_I_O2_ratio * p_amb/10 > 65536, ppO2>6,55bar? | |
1418 bra check_ppO2_1 ; Yes, display Value! | |
1419 ; Check if ppO2>3,30bar | |
1420 btfsc xC+1,7 | |
1421 bra check_ppO2_1 ; Yes! | |
1422 | |
1423 ; Check for low ppo2 | |
1424 movff xC+0,sub_b+0 | |
1425 movff xC+1,sub_b+1 | |
1426 movff opt_ppO2_min,WREG | |
1427 mullw d'100' ; opt_ppO2_min*100 | |
1428 movff PRODL,sub_a+0 | |
1429 movff PRODH,sub_a+1 | |
1430 call subU16 | |
1431 btfsc neg_flag | |
1432 bra check_ppO2_0 ; Not too low | |
1433 ; ppO2 low | |
1434 incf warning_counter,F ; increase counter | |
1435 call TFT_display_ppo2 ; Show ppO2 | |
1436 movlw d'4' ; Type of Alarm (ppO2 low) | |
1437 movwf AlarmType ; Copy to Alarm Register | |
1438 bsf event_occured ; Set Event Flag | |
1439 bsf warning_active ; Set Warning flag | |
1440 return ; Done. | |
1441 | |
1442 check_ppO2_0: | |
1443 ; Check if ppO2 should be displayed | |
1444 movlw ppo2_display_high | |
1445 mullw d'100' ; ppo2_display_high*100 | |
1446 movff PRODL,sub_a+0 | |
1447 movff PRODH,sub_a+1 | |
1448 call subU16 | |
1449 btfss neg_flag | |
1450 return ; No Display, no warning | |
1451 ; Display ppO2, but warn? | |
1452 incf warning_counter,F ; increase counter | |
1453 call TFT_display_ppo2 ; Show ppO2 | |
1454 | |
1455 ;check if we are within our warning thresholds! | |
1456 movff xC+0,sub_b+0 | |
1457 movff xC+1,sub_b+1 | |
1458 movff opt_ppO2_max,WREG ; PPO2 Max for MOD calculation and color coding in divemode | |
69 | 1459 addlw .1 ; e.g. >1.60 |
0 | 1460 mullw d'100' ; opt_ppO2_max*100 |
1461 movff PRODL,sub_a+0 | |
1462 movff PRODH,sub_a+1 | |
1463 call subU16 | |
1464 btfss neg_flag | |
1465 return ; Done. Not too high | |
1466 movlw d'5' ; Type of Alarm (ppO2 high) | |
1467 movwf AlarmType ; Copy to Alarm Register | |
1468 bsf event_occured ; Set Event Flag | |
1469 bsf warning_active ; Set Warning flag | |
1470 return ; Done. | |
1471 | |
1472 check_ppO2_1: ; ppO2 very high | |
1473 incf warning_counter,F ; increase counter | |
1474 call TFT_display_ppo2 ; Show ppO2 | |
1475 movlw d'5' ; Type of Alarm | |
1476 movwf AlarmType ; Copy to Alarm Register | |
1477 bsf event_occured ; Set Event Flag | |
1478 bsf warning_active ; Set Warning flag | |
1479 return ; Done. | |
1480 | |
1481 global check_cns_violation | |
1482 check_cns_violation: | |
1483 ; Check if CNS should be displayed | |
1484 movff int_O_CNS_fraction+1,lo ; copy into bank1 | |
1485 tstfsz lo ; >255% ? | |
1486 bra check_cns_violation2 ; Yes | |
1487 movff int_O_CNS_fraction+0,lo ; copy into bank1 | |
1488 | |
1489 movlw cns_warning_high ; cns_warning_high | |
1490 subwf lo,W | |
1491 btfsc STATUS,C | |
1492 bsf warning_active ; Set Warning flag | |
1493 | |
1494 movlw cns_display_high ; cns_display_high | |
1495 subwf lo,W | |
1496 btfss STATUS,C | |
1497 return ; No Display, no warning | |
1498 ; Display CNS | |
1499 incf warning_counter,F ; increase counter | |
1500 call TFT_display_cns ; Show CNS | |
1501 return | |
1502 | |
1503 check_cns_violation2: | |
1504 incf warning_counter,F ; increase counter | |
1505 call TFT_display_cns ; Show CNS | |
1506 bsf warning_active ; Set Warning flag | |
1507 return | |
1508 | |
1509 global check_and_store_gf_violation | |
1510 check_and_store_gf_violation: | |
1511 movff char_O_gradient_factor,lo ; gradient factor absolute (Non-GF model) | |
1512 movff char_I_deco_model,hi | |
1513 decfsz hi,F ; jump over next line if char_I_deco_model == 1 | |
1514 movff char_O_relative_gradient_GF,lo ; gradient factor relative (GF model) | |
1515 | |
1516 movlw gf_warning_high | |
1517 cpfsgt lo | |
1518 bra check_and_store_gf_violation2 ; No warning | |
1519 movlw d'2' ; Type of Alarm | |
1520 movwf AlarmType ; Copy to Alarm Register | |
1521 bsf event_occured ; Set Event Flag | |
1522 bsf warning_active ; Set Warning flag | |
1523 check_and_store_gf_violation2: | |
1524 movlw gf_display_high | |
1525 cpfsgt lo | |
1526 return ; No Display, no warning | |
1527 ; Display GF | |
1528 incf warning_counter,F ; increase counter | |
1529 call TFT_warning_gf ; Show GF Warning | |
1530 return | |
1531 | |
1532 warn_agf: | |
1533 incf warning_counter,F ; increase counter | |
1534 call TFT_warning_agf ; Show aGF warning | |
86 | 1535 ; bsf warning_active ; Set Warning flag |
0 | 1536 return |
1537 | |
1538 | |
1539 END |