Mercurial > public > hwos_code
annotate src/divemode.asm @ 136:9a637c9bb19a
rename Deco Planner to Simulator
author | heinrichsweikamp |
---|---|
date | Thu, 17 Jul 2014 13:29:25 +0200 |
parents | 4574aed5cd4c |
children | 28b057aa9f75 |
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 | |
831 bra divemode_option0 ; Start/Setup Divemode menu | |
832 dcfsnz WREG,F | |
833 bra divemode_option1 ; Quit Simulation? | |
834 dcfsnz WREG,F | |
835 bra divemode_option2 ; Descent 1m | |
836 dcfsnz WREG,F | |
837 bra divemode_option3 ; Ascend 1m | |
838 dcfsnz WREG,F | |
839 bra divemode_option4 ; Quit Apnoe mode | |
840 dcfsnz WREG,F | |
841 bra divemode_option5 ; Reset Stopwatch (In Gauge mode) | |
842 return | |
843 | |
844 test_switches_divemode2: | |
845 bcf switch_left | |
846 call menuview_toggle ; Menu or Simulator tasks | |
847 return | |
848 | |
849 gas_switched_common: | |
99
87cc1adfe4da
show event "bailout" in the internal logbook
heinrichsweikamp
parents:
98
diff
changeset
|
850 bcf divemode_gaschange ; Clear flag |
87cc1adfe4da
show event "bailout" in the internal logbook
heinrichsweikamp
parents:
98
diff
changeset
|
851 |
0 | 852 decf menupos,W ; 1-5 -> 0-4 |
853 btfss FLAG_ccr_mode ; Choose OC Gases | |
854 rcall setup_gas_registers ; With WREG=Gas 0-4 | |
855 btfsc FLAG_ccr_mode ; Choose CC Diluents | |
856 rcall setup_dil_registers ; With WREG=Gas 0-4 | |
857 | |
858 decf menupos,W ; 1-5 -> 0-4 | |
859 btfsc is_bailout ; Choose OC Bailouts (OC Gases) | |
860 rcall setup_gas_registers ; With WREG=Gas 0-4 | |
861 | |
862 call TFT_active_gas_divemode ; Display gas/Setpoint | |
863 clrf WREG | |
864 movff WREG,char_O_deco_status ; Restart decoplan computation | |
98 | 865 |
866 ; Set flags for profile recording | |
867 bsf event_occured ; Set global event byte | |
868 btfsc is_bailout ; Choose OC Bailouts (OC Gases) | |
869 bsf bailoutgas_event ; Bailout gas change | |
870 btfss is_bailout ; Choose OC Bailouts (OC Gases) | |
871 bsf stored_gas_changed ; OC gas change | |
0 | 872 return |
873 | |
874 global setup_gas_registers | |
875 setup_gas_registers: ; With WREG=Gas 0-4 | |
876 lfsr FSR1,opt_gas_O2_ratio+0 | |
877 movff PLUSW1,char_I_O2_ratio ; O2 (For ppO2 calculations) | |
878 lfsr FSR1,opt_gas_He_ratio+0 | |
879 movff PLUSW1,char_I_He_ratio ; He | |
880 incf WREG,W ; Gas# 1-5 | |
881 movff WREG,char_I_current_gas ; Set gas | |
882 movff WREG,active_gas ; Set for logbook and display | |
883 banksel char_I_O2_ratio | |
884 movf char_I_O2_ratio,W ; Add O2... | |
885 addwf char_I_He_ratio,W ; ...and He... | |
886 sublw .100 ; ...subtract both from 100 | |
887 movwf char_I_N2_ratio ; -> N2! | |
888 banksel common | |
889 return | |
890 | |
891 global setup_dil_registers | |
892 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
|
893 btfsc is_bailout |
53a99a2dc6a1
CHANGE: Always compute bailout plan based on all active gases
heinrichsweikamp
parents:
89
diff
changeset
|
894 return ; Ignore in bailout |
0 | 895 lfsr FSR1,opt_dil_O2_ratio+0 |
896 movff PLUSW1,char_I_O2_ratio ; O2 (For ppO2 calculations) | |
897 lfsr FSR1,opt_dil_He_ratio+0 | |
898 movff PLUSW1,char_I_He_ratio ; He | |
899 incf WREG,W ; Gas# 1-5 | |
900 movff WREG,char_I_current_gas ; Set gas | |
901 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
|
902 movff WREG,active_diluent ; As a backup when switching back from Bailout to CCR |
0 | 903 banksel char_I_O2_ratio |
904 movf char_I_O2_ratio,W ; Add O2... | |
905 addwf char_I_He_ratio,W ; ...and He... | |
906 sublw .100 ; ...subtract both from 100 | |
907 movwf char_I_N2_ratio ; -> N2! | |
908 banksel common | |
909 return | |
910 | |
911 divemode_option0: ; Start/Setup Divemode menu | |
912 call TFT_clear_divemode_menu ; Clear menu area | |
913 bcf menuview | |
914 extern do_main_divemenu | |
915 call do_main_divemenu | |
916 global divemode_option0_return | |
917 divemode_option0_return: | |
918 ; movlw .1 | |
919 ; movwf menupos ; Set to first option in divemode menu | |
920 call TFT_divemode_menu_cursor; Show the cursor | |
921 movlw divemode_menu_timeout | |
922 movwf timeout_counter3 ; timeout for divemode menu | |
923 bsf divemode_menu ; Set flag | |
924 clrf menupos2 ; Clear option counter | |
925 bra diveloop_loop4 ; Goto back to diveloop (Menuprocessor trashes STKPTR!) | |
926 | |
927 divemode_option4: | |
928 movlw d'58' ; two seconds left | |
929 movwf timeout_counter | |
930 movlw apnoe_timeout-1 ; apnoe timeout [min] | |
931 movwf apnoe_timeout_counter | |
932 btfss simulatormode_active ; in simulator mode? | |
933 return ; No | |
934 divemode_option1: ; Quit simulation mode | |
935 banksel isr_backup | |
936 movlw low .1000 | |
937 movwf sim_pressure+0 | |
938 movlw high .1000 | |
939 movwf sim_pressure+1 ; Set to 0m -> End of Dive | |
940 banksel common | |
941 call menuview_toggle_reset ; Reset to zero (Zero=no menuview) | |
942 | |
943 btfss FLAG_apnoe_mode ; In Apnoe mode? | |
944 return ; No | |
945 movlw d'58' ; two seconds left | |
946 movwf timeout_counter | |
947 movlw apnoe_timeout-1 ; apnoe timeout [min] | |
948 movwf apnoe_timeout_counter | |
949 return | |
950 | |
951 divemode_option3: ; minus 1m | |
952 banksel isr_backup | |
953 movlw d'100' | |
954 subwf sim_pressure+0 | |
955 movlw .0 | |
956 subwfb sim_pressure+1 | |
957 rcall divemode_simulator_check_limits | |
958 banksel common | |
959 return | |
960 | |
961 divemode_option2: ; plus 1m | |
962 banksel isr_backup | |
963 movlw d'100' | |
964 addwf sim_pressure+0 | |
965 movlw .0 | |
966 addwfc sim_pressure+1 | |
967 rcall divemode_simulator_check_limits | |
968 banksel common | |
969 return | |
970 | |
971 divemode_option5: | |
972 call menuview_toggle_reset ; Reset to zero (Zero=no menuview) | |
973 bsf reset_average_depth ; Set Flag | |
974 return | |
975 | |
976 divemode_simulator_check_limits: | |
977 ; Check limits (150m and 0m) | |
978 movlw LOW d'16000' ; Compare to 16bar=16000mbar (150m). | |
979 subwf sim_pressure+0,W | |
980 movlw HIGH d'16000' | |
981 subwfb sim_pressure+1,W | |
982 bnc divemode_simulator_check_limits2 ; No-carry = borrow = not deeper | |
983 | |
984 ; Too deep, limit to 150m | |
985 movlw LOW d'16000' | |
986 movwf sim_pressure+0 | |
987 movlw HIGH d'16000' | |
988 movwf sim_pressure+1 | |
989 return | |
990 divemode_simulator_check_limits2: | |
991 movlw LOW d'1000' ; Compare to 1bar == 0m == 1000 mbar. | |
992 subwf sim_pressure+0,W | |
993 movlw HIGH d'1000' | |
994 subwfb sim_pressure+1,W | |
995 btfsc STATUS,C ; No-carry = borrow = not deeper. | |
996 return ; Deeper than 0m == Ok. | |
997 ; Too shallow, limit to 0m | |
998 movlw LOW d'1000' | |
999 movwf sim_pressure+0 | |
1000 movlw HIGH d'1000' | |
1001 movwf sim_pressure+1 | |
1002 return | |
1003 | |
1004 ;============================================================================= | |
1005 ; Compare all enabled gas in list, to see if a better one is available. | |
1006 ; | |
1007 ; Output: better_gas_available, better_gas_number | |
1008 ; | |
1009 check_gas_change: ; Checks if a better gas should be selected (by user) | |
1010 bcf better_gas_available ;=1: A better gas is available and a gas change is advised in divemode | |
1011 clrf better_gas_number ; Clear better gas register | |
1012 | |
1013 SAFE_2BYTE_COPY rel_pressure,xA | |
1014 movlw d'100' | |
1015 movwf xB+0 | |
1016 clrf xB+1 | |
1017 call div16x16 ; compute depth in full m -> result in xC+0 | |
1018 | |
1019 btfss FLAG_ccr_mode ; In CCR mode... | |
1020 bra check_gas_change_OC_bail; No, check for OC or bailout | |
1021 btfsc is_bailout ; Bailout? | |
1022 bra check_gas_change_OC_bail; Yes, check for OC or bailout | |
1023 | |
1024 ; Check Diluents | |
1025 movlw .0 | |
1026 rcall check_dil_common ; With Gas 0-4 in WREG | |
1027 movlw .1 | |
1028 rcall check_dil_common ; With Gas 0-4 in WREG | |
1029 movlw .2 | |
1030 rcall check_dil_common ; With Gas 0-4 in WREG | |
1031 movlw .3 | |
1032 rcall check_dil_common ; With Gas 0-4 in WREG | |
1033 movlw .4 | |
1034 rcall check_dil_common ; With Gas 0-4 in WREG | |
1035 bra check_gas_change_exit | |
1036 | |
1037 check_gas_change_OC_bail: | |
1038 movlw .0 | |
1039 rcall check_gas_common ; With Gas 0-4 in WREG | |
1040 movlw .1 | |
1041 rcall check_gas_common ; With Gas 0-4 in WREG | |
1042 movlw .2 | |
1043 rcall check_gas_common ; With Gas 0-4 in WREG | |
1044 movlw .3 | |
1045 rcall check_gas_common ; With Gas 0-4 in WREG | |
1046 movlw .4 | |
1047 rcall check_gas_common ; With Gas 0-4 in WREG | |
1048 ; bra check_gas_change_exit | |
1049 check_gas_change_exit: | |
1050 btfss better_gas_available ; Is a better gas available | |
1051 bcf blinking_better_gas ; No, Clear blinking flag | |
1052 btfss better_gas_available ; Is a better gas available | |
1053 clrf better_gas_number ; No, Clear better_gas_number (For gaslist display) | |
1054 call TFT_active_gas_divemode ; Display gas/Setpoint | |
1055 return | |
1056 | |
1057 check_gas_common: ; With Gas 0-4 in WREG | |
1058 btfsc better_gas_available ; Better Gas already found? | |
1059 return ; Yes, return | |
1060 lfsr FSR1,opt_gas_type ; 0=Disabled, 1=First, 2=Travel, 3=Deco | |
1061 btfss PLUSW1,0 ; Test for Bit0 and 1 -> type=3 -> Deco | |
1062 return ; No | |
1063 btfss PLUSW1,1 ; Test for Bit0 and 1 -> type=3 -> Deco | |
1064 return ; No | |
1065 incf WREG,W ; 1-5 | |
1066 cpfseq active_gas ; is this gas currently selected? | |
1067 bra check_gas_common2 ; No | |
1068 return ; Yes, skip test for active gas | |
1069 check_gas_common2: | |
1070 decf WREG,W ; 0-4 | |
1071 movwf hi ; Save tested gas 0-4 | |
97
53a99a2dc6a1
CHANGE: Always compute bailout plan based on all active gases
heinrichsweikamp
parents:
89
diff
changeset
|
1072 lfsr FSR1,opt_OC_bail_gas_change |
0 | 1073 movff PLUSW1,lo ; Change depth into lo |
1074 movlw minimum_change_depth | |
1075 cpfsgt lo ; Change depth>minimum_change_depth? | |
1076 return ; No, Change depth not deep enough, skip! | |
1077 movf xC+0,W ; load depth in m into WREG | |
1078 cpfsgt lo ; gas_change_depth < current depth? | |
69 | 1079 bra check_gas_common3 ; No, check if we are within the better_gas_window_pos window |
1080 incf hi,W ; 1-5 | |
1081 movwf better_gas_number ; number (1-5) of the "better gas" in divemode, =0: no better gas available | |
1082 movlw better_gas_window_neg | |
1083 subwf lo,W ; Change depth-better_gas_window_neg | |
1084 cpfslt xC+0 ; current depth<Change depth-better_gas_window_neg? | |
1085 bsf better_gas_available ;=1: A better gas is available and a gas change is advised in divemode | |
1086 return | |
1087 | |
1088 check_gas_common3: | |
0 | 1089 incf hi,W ; 1-5 |
1090 movwf better_gas_number ; number (1-5) of the "better gas" in divemode, =0: no better gas available | |
69 | 1091 movlw better_gas_window_pos |
1092 addwf lo,W ; Change depth+better_gas_window_pos | |
1093 cpfsgt xC+0 ; current depth>Change depth+better_gas_window_pos? | |
1094 bra check_gas_common4 ; Ok, now check the better gas ppO2<opt_ppO2_max | |
1095 return | |
1096 | |
1097 check_gas_common4: | |
1098 movf hi,W ; 0-4 | |
1099 lfsr FSR1,char_I_deco_N2_ratio | |
1100 movff PLUSW1,lo ; N2 ratio into lo | |
1101 lfsr FSR1,char_I_deco_He_ratio | |
1102 movff PLUSW1,xB+0 ; He ratio into xB+0 | |
1103 movf xB+0,W | |
1104 addwf lo,F | |
1105 movlw .101 | |
1106 bcf STATUS,C | |
1107 subfwb lo,F ; O2 ratio in lo | |
1108 | |
1109 SAFE_2BYTE_COPY amb_pressure, xA | |
1110 movlw d'10' | |
1111 movwf xB+0 | |
1112 clrf xB+1 | |
1113 call div16x16 ; xC=p_amb/10 | |
1114 movff xC+0,xA+0 | |
1115 movff xC+1,xA+1 | |
1116 movff lo,xB+0 ; =O2 ratio | |
1117 clrf xB+1 | |
1118 call mult16x16 ; lo * p_amb/10 | |
1119 | |
1120 ; Check very high ppO2 manually | |
1121 tstfsz xC+2 ; char_I_O2_ratio * p_amb/10 > 65536, ppO2>6,55bar? | |
1122 return ; Done. | |
1123 ; Check if ppO2>3,30bar | |
1124 btfsc xC+1,7 | |
1125 return ; Done. | |
1126 | |
1127 ; ; Check for low ppo2 | |
1128 ; movff xC+0,sub_b+0 | |
1129 ; movff xC+1,sub_b+1 | |
1130 ; movff opt_ppO2_min,WREG | |
1131 ; mullw d'100' ; opt_ppO2_min*100 | |
1132 ; movff PRODL,sub_a+0 | |
1133 ; movff PRODH,sub_a+1 | |
1134 ; call subU16 | |
1135 ; btfss neg_flag | |
1136 ; return ; Done (Too low). | |
1137 | |
1138 ;check if we are within our warning thresholds! | |
1139 movff xC+0,sub_b+0 | |
1140 movff xC+1,sub_b+1 | |
1141 movff opt_ppO2_max,WREG ; PPO2 Max for MOD calculation and color coding in divemode | |
1142 addlw .1 ; e.g. >1.60 | |
1143 mullw d'100' ; opt_ppO2_max*100 | |
1144 movff PRODL,sub_a+0 | |
1145 movff PRODH,sub_a+1 | |
1146 call subU16 | |
1147 btfss neg_flag | |
0 | 1148 bsf better_gas_available ;=1: A better gas is available and a gas change is advised in divemode |
69 | 1149 return ; Done. |
0 | 1150 |
1151 check_dil_common: ; With Dil 0-4 in WREG | |
1152 btfsc better_gas_available ; Better Diluent already found? | |
1153 return ; Yes, return | |
1154 lfsr FSR1,opt_dil_type ; 0=Disabled, 1=First, 2=Normal | |
1155 tstfsz PLUSW1 ; =0? | |
1156 bra check_dil_common1 ; No | |
1157 return ; Yes, skip inactive diluents for test | |
1158 check_dil_common1: | |
1159 incf WREG,W ; 1-5 | |
1160 cpfseq active_gas ; is this diluent currently selected? | |
1161 bra check_dil_common2 ; No | |
1162 return ; Yes, skip test for active diluent | |
1163 check_dil_common2: | |
1164 decf WREG,W ; 0-4 | |
1165 movwf hi ; Save tested diluent 0-4 | |
1166 lfsr FSR1,char_I_dil_change | |
1167 movff PLUSW1,lo ; Change depth into lo | |
1168 movlw minimum_change_depth | |
1169 cpfsgt lo ; Change depth>minimum_change_depth? | |
1170 return ; No, Change depth not deep enough, skip! | |
1171 movf xC+0,W ; load depth in m into WREG | |
1172 cpfsgt lo ; gas_change_depth < current depth? | |
1173 return ; No, check next gas | |
1174 incf hi,W ; 1-5 | |
1175 addlw .5 ; 6-10 | |
1176 movwf better_gas_number ; number (1-5) of the "better gas" in divemode, =0: no better gas available | |
69 | 1177 movlw better_gas_window_neg |
1178 subwf lo,W ; Change depth-better_gas_window_neg | |
1179 cpfslt xC+0 ; current depth<Change depth-better_gas_window_neg? | |
0 | 1180 bsf better_gas_available ;=1: A better gas is available and a gas change is advised in divemode |
1181 return | |
1182 | |
1183 ;============================================================================= | |
1184 ; Setup everything to enter divemode. | |
1185 ; | |
1186 | |
1187 dive_boot_oc: | |
1188 extern get_first_gas_to_WREG | |
1189 call get_first_gas_to_WREG ; Gets first gas (0-4) into WREG | |
1190 movff WREG,char_I_first_gas ; Copy for compatibility | |
1191 movff WREG,active_gas ; Set for logbook and display | |
1192 rcall setup_gas_registers ; With WREG=Gas 0-4 | |
1193 return | |
1194 | |
1195 dive_boot_cc: | |
1196 rcall divemode_setup_sensor_values ; setup sensor values | |
1197 TSTOSS opt_ccr_mode ; =0: Fixed SP, =1: Sensor | |
1198 movff char_I_setpoint_cbar+0,char_I_const_ppO2 ; Setup fixed Setpoint (Always start with SP1) | |
1199 extern get_first_dil_to_WREG | |
1200 call get_first_dil_to_WREG ; Gets first gas (0-4) into WREG | |
1201 movff WREG,char_I_first_gas ; Copy for compatibility | |
1202 movff WREG,active_gas ; Set for logbook and display | |
1203 rcall setup_dil_registers ; With WREG=Gas 0-4 | |
1204 return | |
1205 | |
1206 diveloop_boot: | |
1207 call restart_set_modes_and_flags | |
1208 | |
1209 call I2C_sleep_accelerometer ; Stop accelerometer | |
1210 call I2C_sleep_compass ; Stop compass | |
1211 | |
1212 clrf WREG | |
1213 movff WREG,max_pressure+0 ; clear some variables | |
1214 movff WREG,max_pressure+1 | |
1215 | |
1216 bcf use_agf ; Start with normal GF set | |
1217 bcf divemode_menu ; clear divemode menu flag | |
1218 movlw d'1' | |
1219 movwf apnoe_max_pressure+0 | |
1220 clrf apnoe_max_pressure+1 | |
1221 clrf apnoe_surface_mins | |
1222 clrf apnoe_surface_secs | |
1223 clrf apnoe_mins | |
1224 clrf divemins+0 | |
1225 clrf divemins+1 | |
1226 bcf no_more_divesecs ; =1: Do no longer show seconds in divemode | |
1227 bcf divemode_menu_active | |
1228 clrf menupos | |
1229 clrf menupos2 ; Reset to zero (Zero=no premenu or simulator task) | |
1230 | |
1231 bcf is_bailout ; =1: Bailout | |
1232 btfss FLAG_ccr_mode | |
1233 rcall dive_boot_oc | |
1234 btfsc FLAG_ccr_mode | |
1235 rcall dive_boot_cc | |
1236 | |
1237 bcf better_gas_available ;=1: A better gas is available and a gas change is advised in divemode | |
1238 clrf better_gas_number ; Clear better gas register | |
1239 | |
104
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
1240 bcf show_safety_stop ;=1: Show the safety stop |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
1241 clrf safety_stop_countdown ; Clear count-down |
223579e905c3
Show a Safety Stop if enabled (Menu "Deco Parameters")
heinrichsweikamp
parents:
102
diff
changeset
|
1242 |
0 | 1243 clrf samplesecs |
1244 clrf apnoe_timeout_counter ; timeout in minutes | |
1245 clrf timeout_counter ; takes care of the timeout (Low byte) | |
1246 clrf timeout_counter2 ; takes care of the timeout (High byte) | |
1247 clrf AlarmType ; Clear all alarms | |
1248 bcf event_occured ; clear flag | |
98 | 1249 bcf event2_occured ; clear flag |
0 | 1250 clrf total_divetime_seconds+1 |
1251 clrf average_depth_hold_total+0 | |
1252 clrf average_depth_hold_total+1 | |
1253 clrf average_depth_hold_total+2 | |
1254 clrf average_depth_hold_total+3 ; Clear Non-Resettable Average | |
1255 rcall reset_average1 ; Reset the resettable average depth | |
1256 bcf decostop_active | |
1257 bcf better_gas_available ;=1: A better gas is available and a gas change is advised in divemode | |
1258 call ghostwriter_short_header ; Write short header with divenumber into profile memory | |
1259 | |
1260 btfsc simulatormode_active | |
1261 bra diveloop_boot_1 | |
1262 ; Normal mode = Surface pressure is the pressure 30mn before dive. | |
1263 SAFE_2BYTE_COPY last_surfpressure_30min, int_I_pres_surface ;copy surfacepressure to deco routine | |
1264 SAFE_2BYTE_COPY last_surfpressure_30min, last_surfpressure ;copy surfacepressure to last_surfpressure for correct depth | |
1265 bra diveloop_boot_2 | |
1266 | |
1267 diveloop_boot_1: | |
1268 ; Simulator mode: Surface pressure is 1bar. | |
1269 movlw LOW .1000 | |
1270 movff WREG,int_I_pres_surface+0 ; LOW copy surfacepressure to deco routine | |
1271 movlw HIGH .1000 | |
1272 movff WREG,int_I_pres_surface+1 ; HIGH copy surfacepressure to deco routine | |
1273 | |
1274 diveloop_boot_2: | |
1275 SAFE_2BYTE_COPY temperature,minimum_temperature ; Reset Min-Temp registers | |
1276 | |
1277 ; Init profile recording parameters | |
23
e402813343b6
new option to switch samplingrate between 10s and 2s
heinrichsweikamp
parents:
0
diff
changeset
|
1278 movff samplingrate,samplesecs_value ; to avoid EEPROM access in the ISR |
0 | 1279 movlw div_temperature |
1280 movwf divisor_temperature ; load divisors for profile storage | |
1281 movlw div_deco | |
1282 movwf divisor_deco | |
1283 movlw div_gf | |
1284 movwf divisor_gf | |
1285 movlw div_ppo2_sensors | |
1286 movwf divisor_ppo2_sensors | |
1287 movlw div_decoplan | |
1288 movwf divisor_decoplan | |
1289 movlw div_cns | |
1290 movwf divisor_cns | |
1291 movlw div_tank | |
1292 movwf divisor_tank | |
1293 | |
1294 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
|
1295 bra divemode_boot1 |
0 | 1296 ; Overwrite some parameters in Apnoe mode.... |
1297 movlw samplingrate_apnoe | |
1298 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
|
1299 divemode_boot1: |
37275e0fa7f5
NEW: Show End-of-Dive time together with clock during deco
heinrichsweikamp
parents:
99
diff
changeset
|
1300 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
|
1301 bra divemode_boot2 |
37275e0fa7f5
NEW: Show End-of-Dive time together with clock during deco
heinrichsweikamp
parents:
99
diff
changeset
|
1302 ; in OC Mode, disable ppO2 logging |
37275e0fa7f5
NEW: Show End-of-Dive time together with clock during deco
heinrichsweikamp
parents:
99
diff
changeset
|
1303 movlw .0 |
37275e0fa7f5
NEW: Show End-of-Dive time together with clock during deco
heinrichsweikamp
parents:
99
diff
changeset
|
1304 movwf divisor_ppo2_sensors |
37275e0fa7f5
NEW: Show End-of-Dive time together with clock during deco
heinrichsweikamp
parents:
99
diff
changeset
|
1305 divemode_boot2: |
0 | 1306 |
1307 bcf LEDg | |
1308 bcf LEDr | |
1309 bcf realdive | |
1310 btfss simulatormode_active ; do not disable in simulator mode! | |
1311 call disable_rs232 ; Disable RS232 | |
1312 btfsc enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump) | |
1313 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
|
1314 ; Reset divetime seconds |
e4e91fe8b09d
remember last customview in dive and surface mode
mh@mh-THINK.fritz.box
parents:
38
diff
changeset
|
1315 movlw .2 ; Start at 2seconds |
0 | 1316 movwf total_divetime_seconds+0 |
39
e4e91fe8b09d
remember last customview in dive and surface mode
mh@mh-THINK.fritz.box
parents:
38
diff
changeset
|
1317 movwf divesecs |
e4e91fe8b09d
remember last customview in dive and surface mode
mh@mh-THINK.fritz.box
parents:
38
diff
changeset
|
1318 movwf apnoe_secs |
0 | 1319 bsf divemode2 ; displayed divetime is running (Divetime starts HERE) |
1320 | |
1321 movff int_O_CNS_fraction+0,CNS_start+0 | |
1322 movff int_O_CNS_fraction+1,CNS_start+1 ; Save CNS value at beginning of dive | |
1323 movff char_O_relative_gradient_GF,GF_start ; Save GF value at beginning of dive | |
1324 return ; Done with divemode boot | |
1325 | |
1326 divemode_check_for_warnings: | |
131 | 1327 movlw .2 |
1328 cpfsgt warning_counter ; only two warnings active? | |
1329 bra divemode_check_for_warnings1 ; Yes, update every second | |
1330 | |
1331 btfss secs,0 ; Every two seconds... | |
1332 return | |
1333 btfss secs,1 ; Every four seconds... | |
0 | 1334 return |
1335 | |
131 | 1336 divemode_check_for_warnings1: |
0 | 1337 movf warning_counter_backup,W |
1338 cpfseq warning_counter ; warning_counter_backup = warning_counter? | |
1339 call TFT_clear_warning_text ; No, clear all warnings | |
1340 movff warning_counter,warning_counter_backup ; copy warning_counter | |
1341 | |
1342 bcf warning_active ; Clear flag | |
1343 clrf warning_counter ; Clear counter | |
1344 | |
1345 ; Warnings for all modes | |
1346 call check_warn_battery ; Check if the battery level should be displayed/warned | |
55 | 1347 call check_divetimeout ; Not actually a warning. Check and show the divemode timeout |
0 | 1348 |
1349 btfsc FLAG_apnoe_mode ; Done for Apnoe or Gauge mode | |
1350 bra divemode_check_for_warnings2 | |
1351 btfsc FLAG_gauge_mode ; Done for Apnoe or Gauge mode | |
1352 bra divemode_check_for_warnings2 | |
1353 | |
1354 ; Warnings only in deco modes | |
1355 btfss FLAG_ccr_mode ; Don't check in CCR mode | |
1356 rcall check_ppO2 ; check ppO2 and displays warning, if required | |
1357 btfsc is_bailout ; But check in Bailout case... | |
1358 rcall check_ppO2 ; check ppO2 and displays warning, if required | |
1359 rcall check_cns_violation ; Check CNS value and display it, if required | |
1360 btfsc decostop_active ; In deco mode? | |
1361 rcall check_and_store_gf_violation ; Yes, Sets warnings, if required | |
1362 btfsc decostop_active ; In deco mode? | |
1363 call TFT_ftts ; Show @+x time | |
1364 btfsc use_agf ; In aGF mode? | |
1365 rcall warn_agf ; Yes, show a warning for it | |
1366 | |
1367 divemode_check_for_warnings2: | |
1368 ; Display the warning icon? | |
1369 btfsc warning_active ; Any warning active? | |
1370 call TFT_divemode_warning ; Yes | |
1371 btfss warning_active ; Any warning active? | |
1372 call TFT_divemode_warning_clear ; No, clear warning icon | |
1373 | |
1374 ; Setup warning_page number | |
1375 incf warning_page,F | |
1376 bcf STATUS,C | |
1377 rlcf warning_page,W ; *2 | |
1378 cpfsgt warning_counter ; > warning_counter | |
1379 clrf warning_page ; No, clear | |
1380 | |
1381 ; Clear 2nd row of warnings if there is nothing to show (on this page) | |
1382 btfss second_row_warning ; =1: The second row contains a warning | |
1383 call TFT_clear_warning_text_2nd_row ; No, clear this row | |
1384 return ; Done. | |
1385 | |
1386 global check_warn_battery | |
1387 check_warn_battery: | |
1388 movff batt_percent,lo | |
1389 movlw battery_show_level+1 | |
1390 cpfslt lo | |
1391 return ; No Display, no warning | |
1392 ; Display Battery, but warn? | |
1393 incf warning_counter,F ; increase counter | |
1394 call TFT_update_batt_percent_divemode ; Show percent | |
1395 | |
86 | 1396 movff batt_percent,lo |
0 | 1397 movlw color_code_battery_low+1 |
1398 cpfslt lo ; | |
1399 return ; No warning | |
1400 bsf warning_active ; Set Warning flag | |
1401 return | |
1402 | |
55 | 1403 check_divetimeout: |
1404 btfsc divemode2 | |
1405 return ; displayed divetime is not running | |
1406 incf warning_counter,F ; increase counter | |
1407 call TFT_divetimeout ; Show timeout counter | |
1408 return | |
1409 | |
1410 | |
0 | 1411 check_ppO2: ; check current ppO2 and display warning if required |
1412 SAFE_2BYTE_COPY amb_pressure, xA | |
1413 movlw d'10' | |
1414 movwf xB+0 | |
1415 clrf xB+1 | |
1416 call div16x16 ; xC=p_amb/10 | |
1417 | |
1418 movff xC+0,xA+0 | |
1419 movff xC+1,xA+1 | |
1420 movff char_I_O2_ratio,xB+0 ; =O2 ratio | |
1421 clrf xB+1 | |
1422 call mult16x16 ; char_I_O2_ratio * p_amb/10 | |
1423 | |
1424 ; Check very high ppO2 manually | |
1425 tstfsz xC+2 ; char_I_O2_ratio * p_amb/10 > 65536, ppO2>6,55bar? | |
1426 bra check_ppO2_1 ; Yes, display Value! | |
1427 ; Check if ppO2>3,30bar | |
1428 btfsc xC+1,7 | |
1429 bra check_ppO2_1 ; Yes! | |
1430 | |
1431 ; Check for low ppo2 | |
1432 movff xC+0,sub_b+0 | |
1433 movff xC+1,sub_b+1 | |
1434 movff opt_ppO2_min,WREG | |
1435 mullw d'100' ; opt_ppO2_min*100 | |
1436 movff PRODL,sub_a+0 | |
1437 movff PRODH,sub_a+1 | |
1438 call subU16 | |
1439 btfsc neg_flag | |
1440 bra check_ppO2_0 ; Not too low | |
1441 ; ppO2 low | |
1442 incf warning_counter,F ; increase counter | |
1443 call TFT_display_ppo2 ; Show ppO2 | |
1444 movlw d'4' ; Type of Alarm (ppO2 low) | |
1445 movwf AlarmType ; Copy to Alarm Register | |
1446 bsf event_occured ; Set Event Flag | |
1447 bsf warning_active ; Set Warning flag | |
1448 return ; Done. | |
1449 | |
1450 check_ppO2_0: | |
1451 ; Check if ppO2 should be displayed | |
1452 movlw ppo2_display_high | |
1453 mullw d'100' ; ppo2_display_high*100 | |
1454 movff PRODL,sub_a+0 | |
1455 movff PRODH,sub_a+1 | |
1456 call subU16 | |
1457 btfss neg_flag | |
1458 return ; No Display, no warning | |
1459 ; Display ppO2, but warn? | |
1460 incf warning_counter,F ; increase counter | |
1461 call TFT_display_ppo2 ; Show ppO2 | |
1462 | |
1463 ;check if we are within our warning thresholds! | |
1464 movff xC+0,sub_b+0 | |
1465 movff xC+1,sub_b+1 | |
1466 movff opt_ppO2_max,WREG ; PPO2 Max for MOD calculation and color coding in divemode | |
69 | 1467 addlw .1 ; e.g. >1.60 |
0 | 1468 mullw d'100' ; opt_ppO2_max*100 |
1469 movff PRODL,sub_a+0 | |
1470 movff PRODH,sub_a+1 | |
1471 call subU16 | |
1472 btfss neg_flag | |
1473 return ; Done. Not too high | |
1474 movlw d'5' ; Type of Alarm (ppO2 high) | |
1475 movwf AlarmType ; Copy to Alarm Register | |
1476 bsf event_occured ; Set Event Flag | |
1477 bsf warning_active ; Set Warning flag | |
1478 return ; Done. | |
1479 | |
1480 check_ppO2_1: ; ppO2 very high | |
1481 incf warning_counter,F ; increase counter | |
1482 call TFT_display_ppo2 ; Show ppO2 | |
1483 movlw d'5' ; Type of Alarm | |
1484 movwf AlarmType ; Copy to Alarm Register | |
1485 bsf event_occured ; Set Event Flag | |
1486 bsf warning_active ; Set Warning flag | |
1487 return ; Done. | |
1488 | |
1489 global check_cns_violation | |
1490 check_cns_violation: | |
1491 ; Check if CNS should be displayed | |
1492 movff int_O_CNS_fraction+1,lo ; copy into bank1 | |
1493 tstfsz lo ; >255% ? | |
1494 bra check_cns_violation2 ; Yes | |
1495 movff int_O_CNS_fraction+0,lo ; copy into bank1 | |
1496 | |
1497 movlw cns_warning_high ; cns_warning_high | |
1498 subwf lo,W | |
1499 btfsc STATUS,C | |
1500 bsf warning_active ; Set Warning flag | |
1501 | |
1502 movlw cns_display_high ; cns_display_high | |
1503 subwf lo,W | |
1504 btfss STATUS,C | |
1505 return ; No Display, no warning | |
1506 ; Display CNS | |
1507 incf warning_counter,F ; increase counter | |
1508 call TFT_display_cns ; Show CNS | |
1509 return | |
1510 | |
1511 check_cns_violation2: | |
1512 incf warning_counter,F ; increase counter | |
1513 call TFT_display_cns ; Show CNS | |
1514 bsf warning_active ; Set Warning flag | |
1515 return | |
1516 | |
1517 global check_and_store_gf_violation | |
1518 check_and_store_gf_violation: | |
1519 movff char_O_gradient_factor,lo ; gradient factor absolute (Non-GF model) | |
1520 movff char_I_deco_model,hi | |
1521 decfsz hi,F ; jump over next line if char_I_deco_model == 1 | |
1522 movff char_O_relative_gradient_GF,lo ; gradient factor relative (GF model) | |
1523 | |
1524 movlw gf_warning_high | |
1525 cpfsgt lo | |
1526 bra check_and_store_gf_violation2 ; No warning | |
1527 movlw d'2' ; Type of Alarm | |
1528 movwf AlarmType ; Copy to Alarm Register | |
1529 bsf event_occured ; Set Event Flag | |
1530 bsf warning_active ; Set Warning flag | |
1531 check_and_store_gf_violation2: | |
1532 movlw gf_display_high | |
1533 cpfsgt lo | |
1534 return ; No Display, no warning | |
1535 ; Display GF | |
1536 incf warning_counter,F ; increase counter | |
1537 call TFT_warning_gf ; Show GF Warning | |
1538 return | |
1539 | |
1540 warn_agf: | |
1541 incf warning_counter,F ; increase counter | |
1542 call TFT_warning_agf ; Show aGF warning | |
86 | 1543 ; bsf warning_active ; Set Warning flag |
0 | 1544 return |
1545 | |
1546 | |
1547 END |