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