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