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