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