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