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