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