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