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