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