Mercurial > public > hwos_code
annotate src/divemode.asm @ 641:1212d39c9f6f
3.14 beta work
author | heinrichsweikamp |
---|---|
date | Sat, 21 Nov 2020 17:46:29 +0100 |
parents | 8c1f1f334275 |
children | 7d8a4c60ec1a 5b7fe7777425 |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
640 | 3 ; File divemode.asm * combined next generation V3.12.3 |
0 | 4 ; |
623 | 5 ; Dive Mode |
0 | 6 ; |
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. | |
8 ;============================================================================= | |
9 ; HISTORY | |
10 ; 2011-08-15 : [mH] moving from OSTC code | |
11 | |
604 | 12 #include "hwos.inc" ; mandatory header |
13 #include "shared_definitions.h" ; mailbox from/to p2_deco.c | |
582 | 14 #include "tft_outputs.inc" |
15 #include "strings.inc" | |
16 #include "tft.inc" | |
17 #include "eeprom_rs232.inc" | |
18 #include "math.inc" | |
19 #include "wait.inc" | |
20 #include "customview.inc" | |
21 #include "start.inc" | |
22 #include "adc_lightsensor.inc" | |
23 #include "ghostwriter.inc" | |
24 #include "i2c.inc" | |
25 #include "calibrate.inc" | |
26 #include "convert.inc" | |
623 | 27 #include "surfmode.inc" |
604 | 28 #include "rx_ops.inc" |
623 | 29 |
30 | |
582 | 31 extern do_line_menu |
32 extern do_main_divemenu | |
623 | 33 extern menu_draw_lines_divemode |
634 | 34 extern menu_draw_cursor_dive |
582 | 35 extern init_recording_params |
631 | 36 extern option_check_and_store_all |
582 | 37 |
623 | 38 IFDEF _compass |
39 extern TFT_dive_compass_heading | |
40 ENDIF | |
41 | |
631 | 42 IFDEF _cave_mode |
43 extern do_main_cavemenu | |
44 ENDIF | |
623 | 45 |
634 | 46 |
623 | 47 ;---- Private local Variables ------------------------------------------------- |
582 | 48 |
49 CBLOCK local1 ; max size is 16 Byte !!! | |
50 sensor_setpoint ; sensor ppo2 in 0.01bar for deco routine | |
604 | 51 check_gas_num ; used in search for best gas/dil: current gas/dil number (1-5) |
52 check_gas_depth ; used in search for best gas/dil: current gas/dil change depth | |
53 check_gas_type ; used in search for best gas/dil: current gas/dil type | |
54 check_gas_O2_ratio ; used in search for best gas/dil: current gas/dil O2 ratio | |
55 best_gas_num ; used in search for best gas/dil: best gas/dil number (1-5) CAUTION: there is also a variable named best_gas_number ! | |
56 best_gas_depth ; used in search for best gas/dil: best gas/dil change depth | |
623 | 57 last_pressure_velocity:2 ; cached last absolute pressure for velocity calculation |
58 TFT_output_flags_1 ; TFT update flags for output phase 1 | |
59 TFT_output_flags_2 ; TFT update flags for output phase 2 | |
60 TFT_output_flags_3 ; TFT update flags for output phase 3 | |
61 TFT_output_flags_4 ; TFT update flags for output phase 4 | |
62 DM_flags_local ; various dive mode flags | |
63 ENDC ; used: 14 byte, remaining: 2 byte | |
604 | 64 |
65 CBLOCK local2 ; max size is 16 Byte !!! | |
623 | 66 pressure_rel_accu_trip:4 ; pressure accumulator for calculating the resettable average depth |
67 pressure_rel_accu_total:4 ; pressure accumulator for calculating the total dive average depth | |
68 ppO2_min:2 ; used in search for best gas/dil: minimum ppO2 required | |
69 ppO2_max_default:2 ; used in search for best gas/dil: default maximum ppO2 | |
70 ppO2_max_deco:2 ; used in search for best gas/dil: deco maximum ppO2 | |
634 | 71 ENDC ; used: 14 byte, remaining: 2 byte |
623 | 72 |
73 | |
74 ;---- Private local Flags ---------------------------------------------------- | |
75 | |
76 ; TFT_output_flags_1 - phase 1: every second - before deco calculations, all modes | |
77 #DEFINE FLAG_TFT_depth_current TFT_output_flags_1,0 ; =1: show current depth | |
78 #DEFINE FLAG_TFT_depth_maximum TFT_output_flags_1,1 ; =1: show maximum depth | |
79 #DEFINE FLAG_TFT_active_gas_divemode TFT_output_flags_1,2 ; =1: show active gas and dive mode | |
80 #DEFINE FLAG_TFT_apnoe_surface_time TFT_output_flags_1,3 ; =1: show apnoe mode surface time | |
81 #DEFINE FLAG_TFT_depth_maximum_apnoe TFT_output_flags_1,4 ; =1: show maximum depth of last apnoe dive | |
82 #DEFINE FLAG_TFT_clear_apnoe_surface TFT_output_flags_1,5 ; =1: clear apnoe mode surface data from screen | |
83 #DEFINE FLAG_TFT_apnoe_divetime TFT_output_flags_1,6 ; =1: show apnoe mode dive times | |
631 | 84 #DEFINE FLAG_TFT_temperature TFT_output_flags_1,7 ; =1: show temperature (or resettable dive time when in compass view) |
623 | 85 |
86 ; TFT_output_flags_2 - phase 2: every second - before deco calculations, deco modes only | |
87 #DEFINE FLAG_TFT_divemode_mask TFT_output_flags_2,0 ; =1: show dive mode mask | |
88 #DEFINE FLAG_TFT_divetime TFT_output_flags_2,1 ; =1: show dive time | |
89 #DEFINE FLAG_TFT_safety_stop_show TFT_output_flags_2,2 ; =1: show safety stop | |
90 #DEFINE FLAG_TFT_safety_stop_clear TFT_output_flags_2,3 ; =1: clear safety stop | |
631 | 91 ; TFT_output_flags_2,4 ; --- unused |
623 | 92 ; TFT_output_flags_2,5 ; --- unused |
93 ; TFT_output_flags_2,6 ; --- unused | |
94 ; TFT_output_flags_2,7 ; --- unused | |
95 | |
96 ; TFT_output_flags_3 - phase 3: every second - after deco calculations, deco modes only | |
97 #DEFINE FLAG_TFT_clear_deco_data TFT_output_flags_3,0 ; =1: clear deco data (NDL or stop & TTS) | |
98 #DEFINE FLAG_TFT_display_ndl_mask TFT_output_flags_3,1 ; =1: show NDL mask | |
99 #DEFINE FLAG_TFT_display_deco_mask TFT_output_flags_3,2 ; =1: show deco mask | |
100 #DEFINE FLAG_TFT_display_ndl TFT_output_flags_3,3 ; =1: show NDL data | |
101 #DEFINE FLAG_TFT_display_deco TFT_output_flags_3,4 ; =1: show deco stop data | |
102 #DEFINE FLAG_TFT_display_tts TFT_output_flags_3,5 ; =1: show deco TTS data | |
103 ; TFT_output_flags_3,6 ; --- unused | |
104 ; TFT_output_flags_3,7 ; --- unused | |
105 | |
106 ; TFT_output_flags_4 - phase 4: every second - after deco calculations, all modes | |
631 | 107 #DEFINE FLAG_TFT_customview_callup TFT_output_flags_4,0 ; =1: show the custom view mask |
623 | 108 #DEFINE FLAG_TFT_sign_show TFT_output_flags_4,1 ; =1: show the advice / attention / warning sign |
109 #DEFINE FLAG_TFT_sign_clear TFT_output_flags_4,2 ; =1: clear the advice / attention / warning sign | |
110 #DEFINE FLAG_TFT_message_clear_both TFT_output_flags_4,3 ; =1: clear messages, both rows | |
111 #DEFINE FLAG_TFT_message_clear_2nd TFT_output_flags_4,4 ; =1: clear messages, 2nd row only | |
112 #DEFINE FLAG_TFT_velocity_show TFT_output_flags_4,5 ; =1: show vertical velocity | |
113 #DEFINE FLAG_TFT_velocity_clear TFT_output_flags_4,6 ; =1: clear vertical velocity | |
114 ; TFT_output_flags_4,7 ; --- unused | |
115 | |
116 | |
117 ; various Flags | |
631 | 118 #DEFINE new_deco_data_avail DM_flags_local,0 ; =1: new NDL or deco data available |
634 | 119 #DEFINE update_menu DM_flags_local,1 ; =1: redraw the dive menu |
120 #DEFINE FLAG_SP2_used DM_flags_local,2 ; =1: setpoint 2 has been auto-selected already | |
121 #DEFINE FLAG_SP3_used DM_flags_local,3 ; =1: setpoint 3 has been auto-selected already | |
122 #DEFINE FLAG_SP4_used DM_flags_local,4 ; =1: setpoint 4 has been auto-selected already | |
123 #DEFINE FLAG_SP5_used DM_flags_local,5 ; =1: setpoint 5 has been auto-selected already | |
124 ; DM_flags_local,6 ; --- unused | |
631 | 125 ; DM_flags_local,7 ; --- unused |
623 | 126 |
127 | |
582 | 128 ;============================================================================= |
634 | 129 dmode1 CODE |
130 ;============================================================================= | |
131 | |
132 | |
133 ;----------------------------------------------------------------------------- | |
134 ; Entry Point for Dive Mode | |
135 ; | |
0 | 136 global diveloop |
137 diveloop: | |
623 | 138 clrf STKPTR ; clear return addresses stack |
139 | |
140 ; start with a clean time base | |
141 bsf reset_timebase ; request ISR to reset the main timebase, | |
142 ; as we are in dive mode the dive timers will be reset as well | |
143 | |
144 ; reset global flags | |
145 clrf DM_flags_state ; clear all flags for dive mode status | |
146 clrf DM_flags_event ; clear all flags for data recording events | |
631 | 147 clrf DM_flags_request ; clear all flags for user requests / general |
148 IFDEF _cave_mode | |
149 clrf DM_flags_cavereq ; clear all flags for user requests / cave mode | |
150 ENDIF | |
623 | 151 clrf DM_flags_layout1 ; clear all flags for display control / layout (1) |
152 clrf DM_flags_layout2 ; clear all flags for display control / layout (2) | |
631 | 153 clrf DM_flags_layout3 ; clear all flags for display control / layout (3) |
623 | 154 clrf DM_flags_message ; clear all flags for display control / messages |
631 | 155 clrf DM_flags_gas_dil ; clear all flags for display control / gases, diluents, depth |
623 | 156 |
634 | 157 clrf DM_flags_advc_det ; clear all flags for advices detection |
158 clrf DM_flags_advc_ack ; clear all flags for advices acknowledged | |
159 | |
160 clrf DM_flags_att1_det ; clear all flags for attentions detection | |
161 clrf DM_flags_att2_det ; ... | |
162 clrf DM_flags_att3_det ; ... | |
163 | |
164 clrf DM_flags_att1_ack ; clear all flags for attentions acknowledged | |
165 clrf DM_flags_att2_ack ; ... | |
166 clrf DM_flags_att3_ack ; ... | |
167 | |
168 clrf DM_flags_war1_det ; clear all flags for warnings detection | |
169 clrf DM_flags_war2_det ; ... | |
170 | |
171 clrf DM_flags_war1_ack ; clear all flags for warnings acknowledged | |
172 clrf DM_flags_war2_ack ; ... | |
173 | |
174 clrf DM_flags_shown1 ; arm auto show-up of custom views | |
175 clrf DM_flags_shown2 ; ... | |
176 clrf DM_flags_shown3 ; ... | |
177 | |
178 bcf dive_main_menu ; clear dive main menu flag | |
179 bcf dive_pre_menu ; clear dive pre-menu flag | |
623 | 180 |
181 ; reset local flags | |
182 clrf TFT_output_flags_1 ; clear all flags for TFT output phase 1 | |
183 clrf TFT_output_flags_2 ; clear all flags for TFT output phase 2 | |
184 clrf TFT_output_flags_3 ; clear all flags for TFT output phase 3 | |
185 clrf TFT_output_flags_4 ; clear all flags for TFT output phase 4 | |
186 clrf DM_flags_local ; clear all the various other flags, too | |
187 | |
188 ; boot tasks for all modes | |
634 | 189 call diveloop_boot ; initialize dive mode |
604 | 190 |
191 ; startup tasks for all modes | |
192 call TFT_boot ; initialize TFT (includes clear screen) | |
634 | 193 call TFT_load_dive_color_pallet ; load dive color pallet |
623 | 194 call TFT_show_divemode_mask ; display static dive mode mask |
195 call TFT_Display_FadeIn ; dim up the display | |
196 | |
634 | 197 ; arm dive start timer |
623 | 198 bcf divetime_longer_1min ; the dive has just begun |
199 btfsc FLAG_apnoe_mode ; in apnea mode? | |
200 bsf divetime_longer_1min ; YES - force dive to have lasted for longer than 1 minute already | |
201 btfsc sensor_override_active ; in simulator mode? | |
202 bsf divetime_longer_1min ; YES - force dive to have lasted for longer than 1 minute already | |
203 | |
634 | 204 ; initiate initial display outputs |
623 | 205 bsf trigger_pres_cur_changed ; flag that the pressures have changed to have all data... |
206 bsf trigger_pres_max_changed ; ... written to the display on the first output round | |
207 bsf trigger_temp_changed ; flag that the temperature has changed to have the temperature ... | |
208 ; ... written to the display on the first output round | |
209 bsf new_deco_data_avail ; flag that new deco engine results are available to have the initial data ... | |
210 ; ... written to the display on the first output round | |
211 | |
634 | 212 ; initialize the resettable average depth |
213 call resettable_average_depth_init | |
214 | |
215 ; reload and redraw last custom view | |
216 movff customview_divemode,active_customview | |
217 bsf FLAG_TFT_customview_callup | |
623 | 218 |
219 btfsc FLAG_apnoe_mode ; in apnoe mode? | |
220 bra diveloop_1 ; YES - done with initialization | |
221 btfsc FLAG_gauge_mode ; NO - in gauge mode? | |
222 bra diveloop_1 ; YES - done with initialization | |
634 | 223 bsf FLAG_TFT_display_ndl_mask ; NO - request initial display of NDL mask |
623 | 224 bsf FLAG_TFT_active_gas_divemode; - request initial display of gas and setpoint |
225 | |
226 diveloop_1: | |
227 btfsc reset_timebase ; has the ISR confirmed reset of the timebase meanwhile? | |
634 | 228 bra $-2 ; NO - not yet, loop waiting for confirmation before entering the dive loop |
229 ;bra diveloop_loop ; YES - enter the dive loop | |
230 | |
231 | |
232 ;----------------------------------------------------------------------------- | |
233 ; Dive Mode Mail Loop | |
234 ; | |
623 | 235 diveloop_loop: |
236 btfsc trigger_full_second ; new 1/1 second? | |
237 bra diveloop_loop_2 ; YES - continue with tasks every 1/1 second | |
238 btfsc trigger_half_second ; NO - new 1/2 second? | |
239 bra diveloop_loop_1 ; YES - continue with tasks every 1/2 second | |
240 | |
241 ; tasks every round except every 1/1 or 1/2 second | |
242 IFDEF _compass | |
243 movlw index_compass_dm ; index of compass view | |
244 cpfseq active_customview ; in compass view? | |
245 bra diveloop_loop_11 ; NO - continue with tasks every round | |
246 call TFT_dive_compass_heading ; YES - update compass heading value | |
247 bsf FLAG_TFT_temperature ; - redraw temperature (will show resettable dive time now) | |
248 ENDIF | |
249 bra diveloop_loop_11 ; - continue tasks every round | |
250 | |
251 diveloop_loop_1: | |
252 ; tasks every 1/2 second | |
253 bcf trigger_half_second ; clear flag | |
254 btfsc FLAG_gauge_mode ; in gauge mode? | |
255 bra diveloop_loop_11 ; YES - done with 1/2 second tasks | |
256 btfsc FLAG_apnoe_mode ; NO - in apnoe mode? | |
257 bra diveloop_loop_11 ; YES - done with 1/2 second tasks | |
258 | |
259 ; tasks every 1/2 second in deco modes | |
631 | 260 call callup_deco_engine ; ##### manage and invoke the deco calculation engine ##### |
623 | 261 bra diveloop_loop_11 ; done with 1/2 second tasks |
262 | |
263 diveloop_loop_2: | |
264 ; tasks every 1/1 second (code includes tasks every 1/2 second that fall onto the full second) | |
265 bcf trigger_full_second ; clear flag for new 1/1 second | |
266 bcf trigger_half_second ; clear flag for new 1/2 second as well | |
267 | |
268 btfss trigger_temp_changed ; has the temperature changed? | |
269 bra diveloop_loop_3 ; NO - continue with tasks every 1/1 second | |
270 | |
271 bsf FLAG_TFT_temperature ; YES - display temperature | |
272 bcf trigger_temp_changed ; - clear flag | |
273 | |
274 ; "future hardware will need min temperature checked every second..." (?) | |
275 | |
276 MOVII temperature_min,sub_a ; - copy last temperature_min to sub_a | |
277 SMOVII temperature_cur,sub_b ; - ISR-safe 2 byte copy of current temperature to sub_b | |
278 call sub16 ; - sub_c = sub_a - sub_b = temperature_min - temperature | |
279 btfsc neg_flag ; - temperature > temperature_min ? | |
280 bra diveloop_loop_3 ; YES - done | |
281 MOVII sub_b,temperature_min ; NO - store new minimum temperature | |
282 | |
283 diveloop_loop_3: | |
284 ; tasks every 1/1 second | |
285 btfss trigger_pres_cur_changed ; has the pressure changed? | |
286 bra diveloop_loop_4 ; NO - continue with tasks every 1/1 second | |
287 | |
288 ; set flags | |
289 bcf trigger_pres_cur_changed ; clear flag for pressure change | |
290 bsf FLAG_TFT_depth_current ; set flag to display updated depth | |
291 | |
292 ; cache new absolute and relative pressure, ISR-safe 2 byte copies | |
293 SMOVII pressure_abs, pressure_abs_cached | |
294 SMOVII pressure_rel_cur,pressure_rel_cur_cached | |
295 | |
296 ; transfer absolute pressure to deco engine | |
297 MOVII pressure_abs_cached,int_I_pres_respiration | |
298 | |
299 ; compute absolute pressure / 10, will be used later on a couple of times | |
300 MOVII pressure_abs_cached,xA | |
301 MOVLI .10,xB | |
302 call div16x16 ; xC = xA / xB = absolute pressure / 10 | |
303 MOVII xC,pressure_abs_10 ; store result for later use | |
604 | 304 |
305 ; compute current depth in meters | |
631 | 306 MOVII pressure_rel_cur_cached,mpr ; copy current relative pressure in [mbar] to MPR |
307 call convert_pres_to_depth ; convert pressure in [mbar] to depth in [cm] | |
308 ADDLI .50,mpr ; add 50 cm for rounding up/down around 0.5 meters | |
309 MOVII mpr, xA ; copy depth in [cm] into xA | |
310 MOVLI .100,xB ; load factor 100 cm/m into xB | |
623 | 311 call div16x16 ; xC = xA / xB = depth in full meters |
631 | 312 movff xC+0,depth_meter ; store result as depth in [m], only low byte needed |
623 | 313 |
314 ; check for new max pressure | |
315 btfss trigger_pres_max_changed ; has the max pressure changed? | |
316 bra diveloop_loop_4 ; NO - continue with tasks every 1/1 second | |
317 bcf trigger_pres_max_changed ; YES - clear flag for new max pressure | |
318 bsf FLAG_TFT_depth_maximum ; - set flag for displaying new max depth | |
319 SMOVII pressure_rel_max,pressure_rel_max_cached ; - cache new max depth | |
320 | |
321 diveloop_loop_4: | |
322 ; continue tasks every 1/1 second | |
323 | |
640 | 324 IFDEF _ccr_pscr |
325 ; adjust auto-setpoint | |
326 btfsc FLAG_ccr_mode ; in CCR mode? | |
327 call check_dive_autosp ; YES - check for Auto-SP | |
328 ENDIF | |
329 | |
623 | 330 IFDEF _external_sensor |
331 btfsc FLAG_ccr_mode ; in CCR mode? | |
634 | 332 rcall calc_deko_divemode_sensor ; YES - process sensor readings |
623 | 333 btfsc FLAG_pscr_mode ; in pSCR mode? |
634 | 334 rcall calc_deko_divemode_sensor ; YES - process sensor readings |
623 | 335 ENDIF |
336 | |
631 | 337 IFDEF _cave_mode |
338 btfss cave_mode ; cave mode switched on? | |
339 bra diveloop_loop_4a ; NO - no backtracking depth recording | |
340 btfsc dive_turned ; dive turned? | |
341 bra diveloop_loop_4a ; YES - no backtracking depth recording | |
342 btfsc backtrack_entire_full ; backtracking storage entirely used up? | |
343 bra diveloop_loop_4a ; YES - no backtracking depth recording | |
344 | |
345 incf backtrack_deltatime,F ; increment time elapsed since last depth recording | |
346 movlw .59 ; load WREG with coding of last second of a minute | |
347 cpfsgt backtrack_deltatime ; time elapsed since last depth recording > 59 seconds? | |
348 bra diveloop_loop_4a ; NO - no backtracking depth recording now | |
349 rcall write_backtrack_1min_depth ; - store a backtracking depth data set | |
350 ENDIF | |
351 | |
352 diveloop_loop_4a: | |
353 ; continue tasks every 1/1 second | |
354 | |
623 | 355 btfsc FLAG_apnoe_mode ; in apnoe mode? |
356 rcall divemode_apnoe_tasks ; YES - do 1 sec. apnoe tasks | |
357 | |
358 ; display all animated (blinking) values at the beginning of each full second to have a stable timebase | |
359 rcall TFT_output_1 ; do display updates | |
360 | |
361 btfss FLAG_apnoe_mode ; in apnoe mode? | |
362 bra diveloop_loop_5 ; NO - continue with deco mode tasks every 1/1 second | |
363 | |
364 ; apnoe mode tasks every 1/1 second | |
365 call dive_customview_second ; do every second tasks for the custom view area | |
366 bra diveloop_loop_10 ; continue with common tasks every 1/1 second | |
367 | |
368 diveloop_loop_5: | |
369 ; deco mode tasks every 1/1 second | |
370 bsf FLAG_TFT_divetime ; display (new) dive time | |
371 | |
372 rcall safety_stop_show ; serve safety stop | |
373 | |
374 rcall TFT_output_2 ; do display updates | |
375 | |
376 call divemode_check_warnings ; check for warnings | |
604 | 377 |
378 IFDEF _rx_functions | |
623 | 379 btfss tr_functions_activated ; TR functions activated? |
380 bra diveloop_loop_6 ; NO - continue with deco mode tasks every 1/2 second | |
604 | 381 call get_pressure_readings ; YES - get pressure readings |
382 call configure_sac_calculation ; - set up SAC calculation | |
383 ENDIF | |
582 | 384 |
623 | 385 diveloop_loop_6: |
386 ; deco mode tasks every 1/1 second | |
387 INCI divesecs_avg_trip ; increment the resettable dive time | |
628 | 388 INCI divesecs_avg_total ; increment the total dive time |
623 | 389 |
390 btfsc FLAG_gauge_mode ; in gauge mode? | |
391 bra diveloop_loop_7 ; YES - skip deco calculations | |
392 | |
631 | 393 call callup_deco_engine ; ##### manage and invoke the deco calculation engine ##### |
623 | 394 |
395 btfsc new_deco_data_avail ; new NDL or deco data available? | |
634 | 396 call show_new_deco_data ; YES - set-up display update requests |
623 | 397 |
398 btfsc decostop_active ; in deco mode? | |
399 bsf FLAG_TFT_display_deco ; YES - update deco stop depth & time every second because of depth-dependent color-coding | |
400 | |
401 bsf FLAG_TFT_depth_current ; set flag to display depth (in next round, needed in deco modes irrespectively of a pressure change for color-coding and blinking effects) | |
402 | |
403 diveloop_loop_7: | |
404 ; deco mode tasks alternating every 2 seconds on timebase | |
405 btfss timebase_1sec ; on even second of timebase? | |
406 rcall calc_velocity ; YES - calculate velocity and display if > threshold | |
407 btfsc timebase_1sec ; on odd second of timebase? | |
408 call check_gas_best ; YES - check if a better gas cue can be given | |
409 | |
410 diveloop_loop_8: | |
411 ; deco mode tasks alternating every 2 seconds on resettable dive time | |
412 btfss divesecs_avg_trip+0,0 ; on even second of resettable dive time? | |
631 | 413 call calc_average_depth ; YES - calculate average depth |
623 | 414 btfsc divesecs_avg_trip+0,0 ; on odd second of resettable dive time? |
415 rcall safety_stop_control ; YES - exercise safety stop control | |
416 | |
417 diveloop_loop_9: | |
418 ; deco mode tasks every 1/1 second | |
628 | 419 rcall check_deco_states ; check and lock if in deco and in the deco stops region |
623 | 420 rcall TFT_output_3 ; do display updates |
421 | |
422 diveloop_loop_10: | |
423 ; common tasks every 1/1 second | |
634 | 424 rcall timeout_divemode ; check for timeout conditions |
425 call check_dive_modes_dive ; test if depth still deeper than threshold | |
623 | 426 |
427 btfsc trigger_full_minute ; has next minute begun? | |
428 rcall update_divemode60 ; YES - update clock, etc. | |
429 | |
430 btfss FLAG_oc_mode ; are we in OC mode? | |
431 bsf FLAG_TFT_active_gas_divemode; NO - have the gas and setpoint redrawn on every second to update setpoint display, animate the blinking, etc. | |
432 | |
433 btfsc dive_main_menu ; dive mode menu shown? | |
434 bsf update_menu ; YES - request update | |
435 | |
436 rcall TFT_output_4 ; do display updates | |
437 | |
438 ; tasks every round, every mode | |
439 diveloop_loop_11: | |
634 | 440 call test_switches_divemode ; check switches, in case branch into menu processor |
441 bra diveloop_loop_12 ; continue the dive loop | |
442 | |
443 | |
444 ; **** jump-in when returning from menu processor **** | |
445 ; | |
446 global divemode_option_divemenu_return | |
447 divemode_option_divemenu_return: | |
448 clrf STKPTR ; reset the stack | |
449 call menu_draw_cursor_dive ; show the cursor | |
450 bsf dive_main_menu ; set main menu is shown now | |
451 clrf active_premenu ; set pre-menu is not shown any more | |
452 bcf safety_stop_active ; set safety stop is not shown any more | |
453 movlw divemode_timeout_mainmenu ; get timeout for main menu | |
454 call restart_timeout_time ; restart the timeout | |
455 bra diveloop_loop_12 ; continue the dive loop | |
456 | |
457 | |
458 ; **** jump-in when returning from dive mode menu **** | |
459 ; | |
623 | 460 global diveloop_menu_exit |
634 | 461 diveloop_menu_exit: |
462 clrf STKPTR ; reset the stack | |
463 call divemenu_cleanup ; clean up menu area and restore dive data | |
464 ;bra diveloop_loop_12 ; continue the dive loop | |
465 | |
623 | 466 |
467 diveloop_loop_12: | |
468 bsf FLAG_TFT_active_gas_divemode; redraw gas and setpoint (eventually needed to restore the "Bailout" text) | |
469 | |
470 btfsc request_next_custview ; shall show next custom view? | |
634 | 471 call dive_customview_toggle ; YES - show next custom view |
623 | 472 |
631 | 473 btfsc request_gas_change ; shall change gas? |
474 call gas_switch_common ; YES | |
475 | |
476 btfsc request_gas_update ; shall update the gases? | |
477 call gas_update_common ; YES | |
0 | 478 |
623 | 479 btfsc request_toggle_GF ; shall toggle GF/aGF? |
634 | 480 call divemodemode_togglegf ; YES |
0 | 481 |
604 | 482 IFDEF _cave_mode |
631 | 483 btfsc request_cave_off_turned ; shall switch cave mode off and set the dive as turned? |
484 rcall cavemode_switch_off_turned ; YES | |
485 | |
486 btfsc request_cave_toggle ; shall toggle cave mode off/on? | |
487 rcall cavemode_toggle_onoff ; YES | |
488 | |
489 btfsc request_turn_turn ; shall turn the dive? | |
490 rcall cavemode_turndive_turn ; YES | |
491 | |
492 btfsc request_turn_toggle ; shall toggle the turn dive state? | |
493 rcall cavemode_turndive_toggle ; YES | |
494 | |
495 btfsc request_waypoint_set ; shall set a waypoint? | |
496 rcall cavemode_waypoint_set ; YES | |
497 | |
498 btfsc request_waypoint_out ; shall step one waypoint out of the cave? | |
499 rcall cavemode_waypoint_out ; YES | |
500 | |
501 btfsc request_waypoint_in ; shall step one waypoint into the cave? | |
502 rcall cavemode_waypoint_in ; YES | |
604 | 503 ENDIF |
504 | |
623 | 505 btfsc request_set_marker ; shall set a marker? |
582 | 506 call set_logbook_marker ; YES |
507 | |
623 | 508 btfsc trigger_sample_divedata ; shall store new sample of dive data? |
604 | 509 call store_dive_data ; YES - store profile data |
510 | |
511 btfss divemode ; dive finished? | |
623 | 512 goto ghostwriter_end_dive ; YES - dive finished |
604 | 513 |
514 IFDEF _screendump | |
623 | 515 btfsc screen_dump_avail ; screen dump function enabled? |
604 | 516 call TFT_dump_screen_check ; YES - check if requested and do it |
517 ENDIF | |
518 | |
634 | 519 bra diveloop_loop ; do next loop in dive mode |
520 | |
521 | |
522 ;----------------------------------------------------------------------------- | |
523 ; Dive Mode Tasks every 1/1 Minute | |
524 ; | |
525 update_divemode60: | |
526 bcf trigger_full_minute ; clear flag | |
527 | |
528 call get_battery_voltage ; get battery voltage | |
529 btfss battery_low_condition ; battery low condition detected? | |
530 bra update_divemode60_1 ; NO - skip next | |
531 movlw d'7' ; YES - set type of alarm = battery low | |
532 movwf alarm_type ; - copy to alarm register | |
533 bsf event_occured ; - set event flag | |
534 movlw .0 ; - coding of brightness level ECO | |
535 movff WREG,opt_brightness ; - set brightness to ECO | |
536 | |
537 update_divemode60_1: | |
538 ; max allowed runtime in simulator is 254 minutes in | |
539 ; order for the tissue calculation catch-up to work! | |
540 | |
541 btfss sensor_override_active ; in simulator mode? | |
542 return ; NO - done | |
543 movlw simulator_timeout_normal ; YES - set simulation timeout | |
544 IFDEF _cave_mode | |
545 TSTOSC opt_cave_mode ; - cave mode switched on? | |
546 movlw simulator_timeout_cave ; YES - replace with cave mode simulation timeout | |
547 ENDIF | |
548 cpfsgt counted_divetime_mins+0 ; - timeout? | |
549 return ; NO - done | |
550 IFDEF _DEBUG | |
551 return ; YES - but we do not care in debug mode... | |
552 ELSE | |
553 goto divemode_option_sim_quit ; YES - set depth to 0 m and return | |
554 ENDIF | |
555 | |
556 | |
557 ;----------------------------------------------------------------------------- | |
558 ; Helper Function - set-up Display Update Requests | |
559 ; | |
560 show_new_deco_data: | |
561 bcf new_deco_data_avail ; reset flag for new NDL or deco data available | |
562 movff char_O_deco_info,WREG ; get the deco info vector | |
563 btfsc WREG,deco_stops_norm ; deco stops found? | |
564 bra show_new_deco_data_deco ; YES - in deco | |
565 ;bra show_new_deco_data_ndl ; NO - within NDL | |
566 | |
567 show_new_deco_data_ndl: ; within NDL | |
568 btfsc decostop_active ; been in deco mode before? | |
569 bsf FLAG_TFT_clear_deco_data ; YES - clear old deco data | |
570 btfsc decostop_active ; been in deco mode before? | |
571 bsf FLAG_TFT_display_ndl_mask ; YES - display NDL data mask | |
572 bcf decostop_active ; clear flag for been in deco mode before | |
573 bsf FLAG_TFT_display_ndl ; display NDL time | |
574 return ; done | |
575 | |
576 show_new_deco_data_deco: ; in deco | |
577 btfss decostop_active ; been in deco mode before? | |
578 bsf FLAG_TFT_clear_deco_data ; NO - clear old NDL data | |
579 btfss decostop_active ; been in deco mode before? | |
580 bsf FLAG_TFT_display_deco_mask ; NO - display deco data mask | |
581 bsf decostop_active ; set flag for being in deco mode | |
582 bsf FLAG_TFT_display_tts ; display TTS time (display of stop data is managed separately) | |
583 return ; done | |
584 | |
585 | |
586 ;----------------------------------------------------------------------------- | |
587 ; Helper Function - do all Phase 1 Display Outputs | |
588 ; | |
623 | 589 TFT_output_1: ; every second - before deco calculations, all mode |
590 btfsc FLAG_TFT_clear_apnoe_surface ; shall clear apnoe mode surface data from screen? | |
591 call TFT_clear_apnoe_surface ; YES - clear apnoe mode surface data from screen | |
592 | |
593 btfsc FLAG_TFT_depth_current ; shall show depth? | |
594 call TFT_show_depth ; YES - display depth | |
595 btfsc FLAG_TFT_depth_maximum ; shall show max depth? | |
596 call TFT_show_max_depth ; YES - display max depth | |
597 btfsc FLAG_TFT_active_gas_divemode ; shall show active gas and dive mode? | |
598 call TFT_show_active_gas_divemode ; YES - display gas, setpoint and mode | |
631 | 599 btfsc FLAG_TFT_temperature ; shall show temperature? |
600 call TFT_show_temp_divemode ; YES - display temperature (or resettable dive time) | |
623 | 601 |
602 btfsc FLAG_TFT_apnoe_surface_time ; shall show apnoe mode surface time? | |
603 call TFT_show_apnoe_surface ; YES - show apnoe mode surface time | |
604 btfsc FLAG_TFT_depth_maximum_apnoe ; shall show max. depth of last dive? | |
605 call TFT_show_apnoe_max_depth ; YES - show max. depth of last dive | |
606 btfsc FLAG_TFT_apnoe_divetime ; shall show apnoe dive time? | |
607 call TFT_show_apnoe_times ; YES - show apnoe dive time? | |
608 | |
609 clrf TFT_output_flags_1 ; mark all TFT updates done | |
610 return ; done | |
611 | |
634 | 612 |
613 ;----------------------------------------------------------------------------- | |
614 ; Helper Function - do all Phase 2 Display Outputs | |
615 ; | |
623 | 616 TFT_output_2: ; every second - before deco calculations, deco modes only |
617 btfsc FLAG_TFT_divemode_mask ; shall re-draw mask? | |
618 call TFT_show_divemode_mask ; YES - re-draw mask | |
619 btfsc FLAG_TFT_divetime ; shall show dive time? | |
620 call TFT_show_divetime ; YES - show dive time | |
621 btfsc FLAG_TFT_safety_stop_show ; shall show safety stop? | |
622 call TFT_safety_stop_show ; YES - show safety stop | |
623 btfsc FLAG_TFT_safety_stop_clear ; shall clear safety stop? | |
624 call TFT_safety_stop_clear ; YES - clear safety stop | |
625 clrf TFT_output_flags_2 ; mark all TFT updates done | |
626 goto dive_customview_second ; do every-second tasks for the custom view area (in sync with the dive time) and return | |
627 | |
634 | 628 |
629 ;----------------------------------------------------------------------------- | |
630 ; Helper Function - do all Phase 3 Display Outputs | |
631 ; | |
623 | 632 TFT_output_3: ; every second - after deco calculations, deco modes only |
633 btfsc FLAG_TFT_clear_deco_data ; shall clear deco data (NDL or stop & TTS)? | |
634 call TFT_clear_deco_data ; YES - clear deco data (NDL or stop & TTS) | |
635 btfsc FLAG_TFT_display_ndl_mask ; shall show NDL mask? | |
636 call TFT_show_ndl_mask ; YES - show NDL mask | |
637 btfsc FLAG_TFT_display_ndl ; shall show NDL data? | |
638 call TFT_show_ndl ; YES - show NDL data | |
639 btfsc FLAG_TFT_display_deco_mask ; shall show deco mask? | |
640 call TFT_show_deco_mask ; YES - show deco mask | |
641 btfsc FLAG_TFT_display_deco ; shall show deco stop? | |
642 call TFT_show_deco ; YES - show deco stop | |
643 btfsc FLAG_TFT_display_tts ; shall show deco TTS? | |
644 call TFT_show_tts ; YES - show deco TTS | |
645 clrf TFT_output_flags_3 ; mark all TFT updates done | |
646 return ; done | |
647 | |
634 | 648 |
649 ;----------------------------------------------------------------------------- | |
650 ; Helper Function - do all Phase 4 Display Outputs | |
651 ; | |
623 | 652 TFT_output_4: ; every second - after deco calculations, all modes |
631 | 653 btfsc FLAG_TFT_customview_callup ; shall show a custom view? |
654 call dive_customview_callup ; YES - show a custom view | |
623 | 655 btfsc FLAG_TFT_velocity_show ; shall show vertical velocity? |
631 | 656 call TFT_velocity_show ; YES - show vertical velocity |
623 | 657 btfsc FLAG_TFT_velocity_clear ; shall clear vertical velocity? |
631 | 658 call TFT_velocity_clear ; YES - clear vertical velocity |
623 | 659 btfsc FLAG_TFT_sign_show ; shall show the advice / attention / warning sign? |
660 call TFT_divemode_sign_show ; YES - show sign | |
661 btfsc FLAG_TFT_sign_clear ; shall clear the advice / attention / warning sign? | |
662 call TFT_divemode_sign_clear ; YES - clear sign | |
663 btfsc FLAG_TFT_message_clear_both ; shall clear all messages? | |
664 call TFT_clear_message_window ; YES - clear complete message area | |
665 btfsc FLAG_TFT_message_clear_2nd ; shall clear 2nd row of message area? | |
666 call TFT_clear_message_window_row2 ; YES - clear 2nd row of message area | |
667 clrf TFT_output_flags_4 ; mark all TFT updates done | |
668 return ; done | |
582 | 669 |
634 | 670 |
671 ;----------------------------------------------------------------------------- | |
672 ; Apnoe Mode Tasks | |
673 ; | |
628 | 674 divemode_apnoe_tasks: ; 1 sec. apnoe tasks |
675 bsf FLAG_TFT_apnoe_divetime ; show apnoe dive times (current/last dive and total) | |
676 btfsc apnoe_at_surface ; at the surface? | |
677 bra divemode_apnoe_tasks_surf ; YES - at the surface | |
678 ;bra divemode_apnoe_tasks_dive ; NO - in dive phase | |
679 | |
680 divemode_apnoe_tasks_dive: ; apnoe mode, submerged | |
681 btfss apnoe_new_dive ; new dive begun? | |
682 return ; NO - done | |
683 bcf apnoe_new_dive ; YES - clear flag | |
684 bsf FLAG_TFT_clear_apnoe_surface ; - clear apnoe mode surface data from screen | |
685 return ; - done | |
686 | |
687 divemode_apnoe_tasks_surf: ; apnoe mode, at the surface | |
688 bsf FLAG_TFT_apnoe_surface_time ; show apnoe mode surface time | |
623 | 689 ; TODO: these outputs would need to be done only once after surfacing... |
628 | 690 bsf FLAG_TFT_depth_maximum_apnoe ; show max. depth of last dive |
691 bsf FLAG_TFT_depth_maximum ; show max. depth of all dives | |
692 ;bra apnoe_calc_maxdepth ; calculate overall max. depth and return | |
623 | 693 |
0 | 694 |
634 | 695 ;----------------------------------------------------------------------------- |
696 ; Helper Function - calculate Apnoe Mode overall maximum Depth | |
697 ; | |
0 | 698 global apnoe_calc_maxdepth |
699 apnoe_calc_maxdepth: | |
623 | 700 MOVII apnoe_max_pressure, sub_a ; get max depth from all dives to far |
701 MOVII pressure_rel_max_cached,sub_b ; get max depth of last dive | |
702 call cmpU16 ; sub_a - sub_b = apnoe_max_pressure - pressure_rel_max_cached | |
703 btfss neg_flag ; last dive deeper than all the others before? | |
704 return ; NO - done | |
705 MOVII pressure_rel_max_cached,apnoe_max_pressure ; YES - store new overall max depth | |
706 return ; - done | |
0 | 707 |
634 | 708 |
709 ;----------------------------------------------------------------------------- | |
710 ; Manage and invoke the Deco Calculation Engine | |
711 ; | |
712 callup_deco_engine: | |
713 | |
631 | 714 ; Any reconfiguration done here only affects the deco calculation (prediction), not the |
715 ; settings for the calculations done on the real tissues. The later ones are only altered | |
716 ; in case of a gas change, in case of a real bailout, or in case a switchback to setpoint | |
717 ; or sensor is done. | |
718 ; On event of a gas change, a diluent change, a real bailout, or a switchback, the settings | |
719 ; for the deco calculation are also automatically changed to match with the settings for the | |
720 ; real tissues. This is all done in the function 'gas_switch_common' which is triggered by | |
721 ; the flag 'request_gas_change'. | |
722 | |
723 ; Deco Engine Calculation Schedules: | |
724 ; | |
634 | 725 ; Schedule Dive Mode Bailout fTTS Gas Needs Plan Deco Mode calculated Functions |
726 ; ----------------------------------------------------------------------------------------------------- | |
631 | 727 ; |
634 | 728 ; 1a) OC no no (yes) norm OC TTS, CNS, deco plan, (gas needs) |
729 ; no alt plan | |
560 | 730 ; |
634 | 731 ; 1b) OC no YES (yes) norm OC TTS, CNS, deco plan |
732 ; alt OC fTTS, fCNS, (gas needs) | |
631 | 733 ; |
634 | 734 ; 2a) Loop no no no norm Loop TTS, CNS, deco plan |
735 ; no alt plan | |
631 | 736 ; |
634 | 737 ; 2b) Loop no yes no norm Loop TTS, CNS, deco plan |
738 ; alt Loop fTTS, fCNS | |
631 | 739 ; |
634 | 740 ; 2c) Loop no (yes) YES norm Loop TTS, CNS, deco plan |
741 ; alt OC fTTS*, fCNS*, gas needs <- "what if" BAILOUT | |
631 | 742 ; |
634 | 743 ; 3) Loop YES n/a (yes) norm OC TTS, deco plan, (gas needs) <- real BAILOUT |
744 ; no alt plan | |
745 ; _____________________________________________________________________________________________________ | |
746 ; norm: normal plan, alt: alternative plan, (): optional, n/a: not applicable | |
747 ; * the fTTS time is set to zero when in cave mode and the dive is in turned state | |
748 | |
604 | 749 |
750 ; get working copies of char_O_main_status and char_O_deco_status | |
751 movff char_O_main_status,hi ; get char_O_main_status into hi | |
752 movff char_O_deco_status,lo ; get char_O_deco_status into lo | |
753 | |
754 ; check state of deco calculations | |
631 | 755 btfsc request_restart_engine ; restart of the deco engine requested? |
756 bra calc_deco_engine_restart ; YES - start a new normal plan | |
757 btfsc lo,DECO_COMPLETED_NORM ; NO - finished calculations for normal plan? | |
758 bra calc_deco_engine_alt ; YES - eventually do an alternative plan next | |
759 btfsc lo,DECO_COMPLETED_ALT ; NO - finished calculations for alternative plan? | |
760 bra calc_deco_engine_norm ; YES - do a normal plan next | |
761 bra calc_deco_engine_exec ; NO - continue executing current calculation | |
762 | |
763 calc_deco_engine_restart: | |
764 bcf request_restart_engine ; clear request flag | |
765 bcf lo,DECO_COMPLETED_NORM ; clear completion flag from normal plan if applicable | |
766 ;bra calc_deco_engine_norm ; continue with calculating a normal plan | |
767 | |
634 | 768 |
631 | 769 ; ---- normal plans ---- |
634 | 770 ; |
623 | 771 calc_deco_engine_norm: |
631 | 772 bcf lo,DECO_COMPLETED_ALT ; clear completion flag from alternative plan |
773 IFDEF _ccr_pscr | |
774 btfsc bailout_mode ; in real bailout? | |
775 bra calc_deco_engine_norm_3 ; YES - configure real bailout schedule | |
776 btfss FLAG_oc_mode ; in OC dive mode? | |
777 bra calc_deco_engine_norm_2 ; NO - configure loop schedules | |
778 ;bra calc_deco_engine_norm_1 ; YES - configure OC schedules | |
604 | 779 ENDIF |
780 | |
631 | 781 calc_deco_engine_norm_1: |
782 ; normal OC schedules | |
783 TSTOSC char_I_extra_time ; delay mode activated? | |
784 bra calc_deco_engine_norm_1b ; YES - schedule 1b in normal plan | |
785 ;bra calc_deco_engine_norm_1a ; NO - schedule 1a in normal plan | |
786 | |
787 calc_deco_engine_norm_1a: | |
788 ; normal schedule 1a: OC with optional gas needs | |
789 ; bcf lo,DECO_BAILOUT_FLAG ; switch off bailout mode (will never be activated in this plan) | |
790 ; bcf lo,DECO_DELAY_FLAG ; switch off delay mode (will never be activated in this plan) | |
791 ; bcf hi,DECO_VOLUME_FLAG ; switch off gas needs calculation by default (if on, will always be on) | |
792 TSTOSC opt_calc_gasvolume ; shall calculate gas needs? | |
793 bsf hi,DECO_VOLUME_FLAG ; YES - switch on gas needs calculation | |
794 bra calc_deco_engine_norm_start ; start deco engine in normal plan | |
795 | |
796 calc_deco_engine_norm_1b: | |
797 ; normal schedule 1b: OC without delay and gas needs | |
798 ; bcf lo,DECO_BAILOUT_FLAG ; switch off bailout mode (will never be activated in this plan) | |
799 bcf lo,DECO_DELAY_FLAG ; switch off delay mode | |
800 bcf hi,DECO_VOLUME_FLAG ; switch off gas needs calculation | |
801 bra calc_deco_engine_norm_start ; start deco engine in normal plan | |
802 | |
623 | 803 IFDEF _ccr_pscr |
631 | 804 calc_deco_engine_norm_2: |
805 ; normal loop schedules | |
806 TSTOSC opt_calc_gasvolume ; gas needs calculation activated? | |
807 bra calc_deco_engine_norm_2c ; YES - schedule 2c in normal plan | |
808 ;bra calc_deco_engine_norm_2ab ; NO - schedules 2a and 2b in normal plan are identical | |
809 | |
810 calc_deco_engine_norm_2ab: | |
811 ; normal schedule 2a & 2b: loop without anything | |
812 bcf lo,DECO_BAILOUT_FLAG ; switch off bailout mode (may return from real bailout) | |
813 ; bcf hi,DECO_VOLUME_FLAG ; switch off gas needs calculation (will never be activated in this plans) | |
814 bcf lo,DECO_DELAY_FLAG ; switch off delay mode (may have been set in alt. plan 2b) | |
815 bra calc_deco_engine_norm_start ; start deco engine in normal plan | |
816 | |
817 calc_deco_engine_norm_2c: | |
818 ; normal schedule 2c: loop with switch-back from simulated bailout | |
819 ; switch to CCR/pSCR | |
820 movf active_dil,W ; get current diluent | |
821 call deco_setup_cc_diluents_pre ; set up deco calculation in CCR/pSCR mode with diluents | |
822 calc_deco_engine_norm_2c_XX: | |
823 bcf lo,DECO_BAILOUT_FLAG ; switch off bailout mode (may return from real bailout) | |
824 bcf hi,DECO_VOLUME_FLAG ; switch off gas needs calculation | |
825 bcf lo,DECO_DELAY_FLAG ; switch off delay mode | |
826 bra calc_deco_engine_norm_start ; start deco engine in normal plan | |
827 | |
828 calc_deco_engine_norm_3: | |
829 ; real bailout schedule | |
830 bcf lo,DECO_DELAY_FLAG ; switch off delay mode | |
831 bcf hi,DECO_VOLUME_FLAG ; switch off gas needs calculation by default | |
832 TSTOSC opt_calc_gasvolume ; shall calculate gas needs? | |
833 bsf hi,DECO_VOLUME_FLAG ; YES - switch on gas needs calculation | |
834 bsf lo,DECO_BAILOUT_FLAG ; switch on bailout mode | |
835 ;bra calc_deco_engine_norm_start ; start deco engine in normal plan | |
836 ENDIF ; _ccr_pscr | |
837 | |
838 calc_deco_engine_norm_start: | |
839 bsf lo,DECO_START_NORM ; calculate a normal plan | |
623 | 840 bra calc_deco_engine_start ; start deco engine |
841 | |
634 | 842 |
631 | 843 ; ---- alternative plans ---- |
634 | 844 ; |
623 | 845 calc_deco_engine_alt: |
631 | 846 bcf lo,DECO_COMPLETED_NORM ; clear completion flag from normal plan |
847 IFDEF _ccr_pscr | |
848 btfsc bailout_mode ; in real bailout? | |
849 bra calc_deco_engine_norm_3 ; YES - schedule 3 has no alternative plan | |
850 btfss FLAG_oc_mode ; in OC dive mode? | |
851 bra calc_deco_engine_alt_2 ; NO - loop schedules | |
852 ;bra calc_deco_engine_alt_1 ; YES - OC schedules | |
853 ENDIF ; _ccr_pscr | |
623 | 854 |
855 calc_deco_engine_alt_1: | |
631 | 856 ; alternative OC schedules |
857 TSTOSS char_I_extra_time ; delay mode activated? | |
858 bra calc_deco_engine_norm_1a ; NO - schedule 1a has no alternative plan | |
604 | 859 IFDEF _cave_mode |
631 | 860 btfsc dive_turned ; YES - in cave mode and dive turned? |
861 bra calc_deco_engine_norm_1a ; YES - suppress delay mode -> do schedule 1a in normal plan | |
604 | 862 ENDIF |
631 | 863 ;bra calc_deco_engine_alt_1b ; NO - do schedule 1b in alternative plan |
864 | |
865 calc_deco_engine_alt_1b: | |
866 ; alternative schedule 1b: OC with delay and optional gas needs | |
867 ; bcf lo,DECO_BAILOUT_FLAG ; switch off bailout mode (will never be activated in this plan) | |
868 ; bcf hi,DECO_VOLUME_FLAG ; switch off gas needs calculation by default (comes in switched off state) | |
869 TSTOSC opt_calc_gasvolume ; shall calculate gas needs? | |
870 bsf hi,DECO_VOLUME_FLAG ; YES - switch on gas needs calculation | |
871 bsf lo,DECO_DELAY_FLAG ; switch on delay mode | |
872 bra calc_deco_engine_alt_start ; start deco engine in alternative plan | |
873 | |
874 IFDEF _ccr_pscr | |
623 | 875 calc_deco_engine_alt_2: |
631 | 876 ; alternative loop schedules |
877 TSTOSC opt_calc_gasvolume ; gas needs calculation activated? | |
878 bra calc_deco_engine_alt_2c ; YES - 2c in alternative plan | |
879 TSTOSS char_I_extra_time ; NO - delay mode activated? | |
880 bra calc_deco_engine_norm_2ab ; NO - schedule 2a has no alternative plan | |
881 ;bra calc_deco_engine_alt_2b ; YES - schedule 2b in alternative plan | |
882 | |
883 calc_deco_engine_alt_2b: | |
884 ; alternative schedule 2b: loop with delay | |
885 ; bcf lo,DECO_BAILOUT_FLAG ; switch off bailout mode (will be deactivated in normal plan) | |
886 ; bcf hi,DECO_VOLUME_FLAG ; switch off gas needs calculation (will never be activated in this plan) | |
887 bsf lo,DECO_DELAY_FLAG ; switch on delay mode | |
888 bra calc_deco_engine_alt_start ; start deco engine in normal plan | |
889 | |
890 calc_deco_engine_alt_2c: | |
891 ; alternative schedule 2c: simulated bailout (if possible) | |
892 decf best_gas_number,W ; get best gas number -1 into WREG. If not available, WREG will be 255 now. If not computed yet, WREG will be 254 now. | |
893 btfsc WREG,7 ; WREG < 128 (a bailout gas is available)? | |
894 bra calc_deco_engine_alt_2c_XX ; NO - no bailout plan possible because no bailout gas available to switch to | |
895 movf best_gas_number,W ; YES - get number of best gas into WREG | |
896 call deco_setup_oc_gases_pre ; - set up deco calculation in OC mode with OC gases | |
897 ; bcf lo,DECO_DELAY_FLAG ; - switch off delay mode by default (comes in switched off state) | |
898 TSTOSC char_I_extra_time ; - delay mode activated? | |
899 bsf lo,DECO_DELAY_FLAG ; YES - switch on delay mode | |
604 | 900 IFDEF _cave_mode |
631 | 901 btfsc dive_turned ; in cave mode and dive turned? |
902 bcf lo,DECO_DELAY_FLAG ; YES - suppress delay mode | |
604 | 903 ENDIF |
631 | 904 bsf lo,DECO_BAILOUT_FLAG ; - switch on bailout mode |
905 bsf hi,DECO_VOLUME_FLAG ; - switch on gas needs calculation | |
906 bra calc_deco_engine_alt_start ; - start deco engine in alternative plan | |
907 calc_deco_engine_alt_2c_XX: | |
604 | 908 call inval_alternative_plan_data ; invalidate all alternative (bailout) plan data because they are not applicable any more |
631 | 909 bra calc_deco_engine_norm_start ; continue calculating as normal plan |
910 ENDIF ; _ccr_pscr | |
911 | |
912 calc_deco_engine_alt_start: | |
913 bsf lo,DECO_START_ALT ; calculate an alternative plan | |
914 ;bra calc_deco_engine_start ; start deco engine | |
915 | |
634 | 916 |
631 | 917 ; ---- start deco engine ---- |
634 | 918 ; |
623 | 919 calc_deco_engine_start: |
631 | 920 IFDEF _cave_mode |
921 bcf hi,DECO_CAVE_MODE ; deactivate cave mode by default | |
922 btfss cave_mode ; cave mode switched on? | |
923 bra calc_deco_engine_start_1 ; NO - keep deactivated, no backtracking depth recording | |
924 bsf hi,DECO_CAVE_MODE ; YES - activate cave mode | |
925 btfss dive_turned ; - dive turned? | |
926 call write_backtrack_deltatime ; NO - update current delta time | |
927 ENDIF | |
928 calc_deco_engine_start_1: | |
604 | 929 movff hi,char_O_main_status ; write-back char_O_main_status to deco engine interface |
560 | 930 movff lo,char_O_deco_status ; write-back char_O_deco_status to deco engine interface |
0 | 931 |
631 | 932 calc_deco_engine_exec: |
623 | 933 ; +++++++++++++++++++++++++++++++++++++ |
634 | 934 bsf tmr5_preemtion_allowed ; grant preemption allowance for timer 5 (deco engine) |
623 | 935 call deco_calc_hauptroutine ; invoke the deco engine (C-code) |
936 banksel common ; back to bank common | |
634 | 937 bcf tmr5_preemtion_allowed ; revoke preemption allowance |
623 | 938 ; +++++++++++++++++++++++++++++++++++++ |
939 | |
631 | 940 ifdef _debug_output |
623 | 941 call TFT_debug_output ; debug output of scheduling performance data |
631 | 942 endif |
604 | 943 |
944 ; check if new calculation results for normal plan mode are available | |
623 | 945 movff char_O_deco_status,WREG ; get deco status of deco engine |
946 btfsc WREG,DECO_COMPLETED_NORM ; new calculation results for normal plan available? | |
947 bsf new_deco_data_avail ; YES - set flag for new NDL or deco data available | |
631 | 948 |
634 | 949 return ; done |
950 | |
623 | 951 |
631 | 952 IFDEF _ccr_pscr |
623 | 953 IFDEF _external_sensor |
0 | 954 |
634 | 955 ;----------------------------------------------------------------------------- |
956 ; Process Sensor Readings | |
957 ; | |
560 | 958 global calc_deko_divemode_sensor |
959 calc_deko_divemode_sensor: | |
634 | 960 btfsc ext_input_optical ; do we have an optical interface? |
961 bra calc_deko_divemode_sensor_opt ; YES - process received data | |
962 btfss ext_input_s8_ana ; NO - do we have a S8/analog interface? | |
963 return ; NO - nothing to do, done | |
964 TSTOSS opt_s8_mode ; YES - shall use S8 interface? | |
965 bra calc_deko_divemode_sensor_ana ; - NO - use analog interface | |
966 ;bra calc_deko_divemode_sensor_s8 ; YES - use S8 interface | |
967 | |
968 calc_deko_divemode_sensor_s8: | |
969 btfss trigger_S8_data_update ; new data frame available? | |
970 bra calc_deko_divemode_sensor_common; NO - use old values | |
971 bcf trigger_S8_data_update ; YES - clear update flag | |
972 call compute_mvolts_from_rawdata ; - compute mV values from digital data | |
973 bra calc_deko_divemode_sensor_common; - continue with common part | |
974 | |
583 | 975 calc_deko_divemode_sensor_opt: |
634 | 976 ; sensor1_ppO2, sensor2_ppO2 and sensor3_ppO2 are already filled in ISR |
977 btfss sensor1_active ; check HUD status data and eventually clear use_O2_sensorX | |
978 bcf use_O2_sensor1 ; ... | |
979 btfss sensor2_active ; ... | |
980 bcf use_O2_sensor2 ; ... | |
981 btfss sensor3_active ; ... | |
982 bcf use_O2_sensor3 ; ... | |
983 bra check_sensor_avg ; continue with calculating sensor average | |
984 | |
985 calc_deko_divemode_sensor_ana: | |
986 call get_analog_inputs ; get the analog voltages and continue with the common part | |
987 ;bra calc_deko_divemode_sensor_common; continue with common part | |
560 | 988 |
989 calc_deko_divemode_sensor_common: | |
634 | 990 |
604 | 991 ; Check each sensor if it is calibrated and if its mV value is within min_mv and max_mv limits. |
992 ; If ok: compute o2_ppo2_sensorX = o2_mv_sensorX * opt_x_sX / 1000 | |
582 | 993 ; If not ok: reset o2_ppo2_sensorX, reset use_O2_sensorX and show the customview 1 in case the sensor was ok before |
0 | 994 |
604 | 995 ; check sensor 1 |
582 | 996 btfss sensor1_calibrated_ok ; check if sensor is usable at all |
997 bra check_sensor_1_fail ; NO - handle it as failed | |
634 | 998 SMOVII sensor1_mv,sub_a ; YES - load sensor mV value |
999 | |
604 | 1000 ; check min threshold |
634 | 1001 rcall check_min_threshold ; check if sensor mV is outside minimum |
582 | 1002 btfsc neg_flag ; check if result is negative, i.e. sensor_mv < min_mv |
1003 bra check_sensor_1_fail ; YES - declare sensor as failed | |
634 | 1004 |
604 | 1005 ; check max_threshold |
634 | 1006 rcall check_max_threshold ; check if sensor mV is outside maximum |
582 | 1007 btfss neg_flag ; check if result is negative, i.e. sensor_mv < max_mv |
1008 bra check_sensor_1_fail ; NO - declare sensor as failed | |
634 | 1009 |
604 | 1010 ; check HUD data, if available |
582 | 1011 btfss hud_connection_ok ; check if there is a HUD connected |
1012 bra check_sensor_1_ok ; NO - all checks done then and positive | |
604 | 1013 btfss sensor1_active ; YES - HUD status ok? |
1014 bra check_sensor_1_fail ; NO - HUD reports a fail | |
634 | 1015 |
560 | 1016 check_sensor_1_ok: |
623 | 1017 ; sensor1_ppO2 = sensor1_mv:2 * opt_x_s1:2 / 1000 |
634 | 1018 SMOVII sensor1_mv,xA ; get sensor mV into xA |
1019 MOVII opt_x_s1, xB ; get calibration factor into xB | |
1020 rcall compute_ppo2_helper ; compute ppO2 | |
623 | 1021 movff xC+0,sensor1_ppO2 ; result in 0.01 bar |
634 | 1022 bcf attn_det_sensor1_lost ; clear attention |
1023 bcf shown_sensor1_fail ; re-arm custom-view show-up | |
582 | 1024 bra check_sensor_2 ; continue with next sensor |
634 | 1025 |
560 | 1026 check_sensor_1_fail: |
634 | 1027 clrf WREG ; set ppO2 reading to zero |
1028 movff WREG,sensor1_ppO2 ; ... | |
1029 btfsc use_O2_sensor1 ; check if sensor is in use | |
1030 bsf attn_det_sensor1_lost ; YES - set an attention | |
582 | 1031 bcf use_O2_sensor1 ; revoke sensor from usage |
604 | 1032 |
634 | 1033 check_sensor_2: |
1034 ; check sensor 2 | |
582 | 1035 btfss sensor2_calibrated_ok ; check if sensor is usable at all |
1036 bra check_sensor_2_fail ; NO - handle it as failed | |
634 | 1037 SMOVII sensor2_mv,sub_a ; YES - load sensor mV value |
1038 | |
604 | 1039 ; check min threshold |
634 | 1040 rcall check_min_threshold ; check if sensor mV is outside minimum |
582 | 1041 btfsc neg_flag ; check if result is negative, i.e. sensor_mv < min_mv |
1042 bra check_sensor_2_fail ; YES - declare sensor as failed | |
634 | 1043 |
604 | 1044 ; check max_threshold |
634 | 1045 rcall check_max_threshold ; check if sensor mV is outside maximum |
582 | 1046 btfss neg_flag ; check if result is nagative, i.e. sensor_mv < max_mv |
1047 bra check_sensor_2_fail ; NO - declare sensor as failed | |
634 | 1048 |
604 | 1049 ; check HUD data, if available |
582 | 1050 btfss hud_connection_ok ; check if there is a HUD connected |
1051 bra check_sensor_2_ok ; NO - all checks done then and positive | |
604 | 1052 btfss sensor2_active ; YES - HUD status ok? |
1053 bra check_sensor_2_fail ; NO - HUD reports a fail | |
634 | 1054 |
560 | 1055 check_sensor_2_ok: |
623 | 1056 ; sensor2_ppO2 = sensor2_mv:2 * opt_x_s2:2 / 1000 |
634 | 1057 SMOVII sensor2_mv,xA ; get sensor mV into xA |
1058 MOVII opt_x_s2, xB ; get calibration factor into xB | |
1059 rcall compute_ppo2_helper ; compute ppO2 | |
623 | 1060 movff xC+0,sensor2_ppO2 ; result in 0.01 bar |
634 | 1061 bcf attn_det_sensor2_lost ; clear attention |
1062 bcf shown_sensor2_fail ; re-arm custom-view show-up | |
582 | 1063 bra check_sensor_3 ; continue with next sensor |
634 | 1064 |
560 | 1065 check_sensor_2_fail: |
634 | 1066 clrf WREG ; set ppO2 reading to zero |
1067 movff WREG,sensor2_ppO2 ; ... | |
1068 btfsc use_O2_sensor2 ; check if sensor is in use | |
1069 bsf attn_det_sensor2_lost ; YES - set an attention | |
582 | 1070 bcf use_O2_sensor2 ; revoke sensor from usage |
604 | 1071 |
634 | 1072 check_sensor_3: |
1073 ; check sensor 3 | |
582 | 1074 btfss sensor3_calibrated_ok ; check if sensor is usable at all |
1075 bra check_sensor_3_fail ; NO - handle it as failed | |
634 | 1076 SMOVII sensor3_mv,sub_a ; YES - load sensor mV value |
1077 | |
604 | 1078 ; check min threshold |
634 | 1079 rcall check_min_threshold ; check if sensor mV is outside minimum |
582 | 1080 btfsc neg_flag ; check if result is negative, i.e. sensor_mv < min_mv |
1081 bra check_sensor_3_fail ; YES - declare sensor as failed | |
634 | 1082 |
604 | 1083 ; check max threshold |
634 | 1084 rcall check_max_threshold ; check if sensor mV is outside maximum |
582 | 1085 btfss neg_flag ; check if result is negative, i.e. sensor_mv < max_mv |
1086 bra check_sensor_3_fail ; NO - declare sensor as failed | |
634 | 1087 |
604 | 1088 ; check HUD data, if available |
582 | 1089 btfss hud_connection_ok ; check if there is a HUD connected |
1090 bra check_sensor_3_ok ; NO - all checks done then and positive | |
604 | 1091 btfss sensor3_active ; YES - HUD status ok? |
1092 bra check_sensor_3_fail ; NO - HUD reports a fail | |
634 | 1093 |
560 | 1094 check_sensor_3_ok: |
623 | 1095 ; sensor3_ppO2 = sensor3_mv:2 * opt_x_s1:2 / 1000 |
634 | 1096 SMOVII sensor3_mv,xA ; get sensor mV into xA |
1097 MOVII opt_x_s3, xB ; get calibration factor into xB | |
1098 rcall compute_ppo2_helper ; compute ppO2 | |
623 | 1099 movff xC+0,sensor3_ppO2 ; result in 0.01 bar |
634 | 1100 bcf attn_det_sensor3_lost ; clear attention |
1101 bcf shown_sensor3_fail ; re-arm custom-view show-up | |
1102 bra check_sensor_avg ; continue with calculating sensor average | |
1103 | |
560 | 1104 check_sensor_3_fail: |
634 | 1105 clrf WREG ; set ppO2 reading to zero |
1106 movff WREG,sensor3_ppO2 ; ... | |
1107 btfsc use_O2_sensor3 ; check if sensor is in use | |
1108 bsf attn_det_sensor3_lost ; YES - set an attention | |
582 | 1109 bcf use_O2_sensor3 ; revoke sensor from usage |
604 | 1110 |
634 | 1111 check_sensor_avg: |
1112 ; calculate sensor average | |
623 | 1113 btfss divemode ; in dive mode? |
1114 return ; NO - done here if not in dive mode | |
560 | 1115 |
634 | 1116 ; compute sensor_setpoint = average of all o2_ppo2_sensorX of |
1117 ; those sensors that have use_O2_sensorX == true | |
1118 | |
1119 CLRI xA ; clear sum of sensor values | |
1120 CLRI xB ; clear number of active sensors found | |
1121 | |
1122 check_sensor_avg_1: | |
1123 btfss use_O2_sensor1 ; sensor 1 active? | |
1124 bra check_sensor_avg_2 ; NO | |
1125 movff sensor1_ppO2,WREG ; YES - get ppO2 | |
1126 addwf xA+0,F ; - add into xA:2 | |
1127 movlw .0 ; - ... | |
1128 addwfc xA+1,F ; - ... | |
1129 incf xB+0,F ; - add a sensor | |
1130 | |
1131 check_sensor_avg_2: | |
1132 btfss use_O2_sensor2 ; sensor 2 active? | |
1133 bra check_sensor_avg_3 ; NO | |
1134 movff sensor2_ppO2,WREG ; YES - get ppO2 | |
1135 addwf xA+0,F ; - add into xA:2 | |
1136 movlw .0 ; - ... | |
1137 addwfc xA+1,F ; - ... | |
1138 incf xB+0,F ; - add a sensor | |
1139 | |
1140 check_sensor_avg_3: | |
1141 btfss use_O2_sensor3 ; sensor 3 active? | |
1142 bra check_sensor_avg_compute ; NO | |
1143 movff sensor3_ppO2,WREG ; YES - get ppO2 | |
1144 addwf xA+0,F ; - add into xA:2 | |
1145 movlw .0 ; - ... | |
1146 addwfc xA+1,F ; - ... | |
1147 incf xB+0,F ; add a sensor | |
1148 | |
1149 check_sensor_avg_compute: | |
604 | 1150 ; divide sum of sensor values by number of active sensors found |
634 | 1151 clrf xC+0 ; set zero as default result |
1152 tstfsz xB+0 ; pending div/0 ? | |
1153 call div16x16 ; NO - execute xC = xA / xB = summed ppO2 / number of sensors | |
1154 movff xC+0,sensor_setpoint ; copy result (or its default) | |
604 | 1155 |
1156 ; set default value for pSCR mode: 0 => let p2_deco.c compute the ppO2 based on current dil gas and depth | |
560 | 1157 ; will be overwritten later in case we are in sensor mode and have at least one usable sensor |
634 | 1158 clrf WREG ; pre-load a zero |
1159 btfsc FLAG_pscr_mode ; check if we are in pSCR mode | |
1160 movff WREG,char_I_const_ppO2 ; YES - write 0 to char_I_const_ppo2, | |
1161 ; it will be overwritten if we have a usable sensor reading | |
1162 btfsc bailout_mode ; check if we are in bailout | |
1163 bra check_sensor_vote ; YES - no sensor data transfer to char_I_const_ppO2 in this case | |
640 | 1164 movf dive_ccr_mode,W ; NO - get mode (0: Fixed SP, 1: Sensor, 2: Auto SP) |
634 | 1165 sublw .1 ; - in sensor mode? |
1166 bnz check_sensor_vote ; NO - not in sensor mode - no transfer of sensor data to char_I_const_ppO2 | |
1167 tstfsz xB+0 ; YES - check if we have found at least one usable sensor | |
1168 bra check_sensor_avg_use ; YES - we have at least one usable sensor | |
1169 bsf warn_det_sensors_lost ; NO - we have NO usable sensors | |
1170 btfsc FLAG_ccr_mode ; - check if we are in CCR mode | |
1171 movff opt_setpoint_cbar+0,char_I_const_ppO2 ; YES - select fixed setpoint no. 1 for fallback | |
1172 bra check_sensor_vote ; - continue with voting logic flags | |
1173 | |
1174 check_sensor_avg_use: | |
604 | 1175 ; we have at least one usable sensor with a ppO2 value > 0 |
634 | 1176 bcf warn_det_sensors_lost ; clear warning |
1177 bcf shown_sensors_lost ; re-arm custom view show-up | |
560 | 1178 movff sensor_setpoint,char_I_const_ppO2 ; transfer average sensor value to p2_deco.c code |
634 | 1179 |
1180 check_sensor_vote: | |
1181 ; check if individual sensors agree with their average | |
1182 bsf voting_logic_sensor1 ; default sensor to be within voting | |
1183 movff sensor1_ppO2,WREG ; get sensor's ppO2 | |
1184 rcall check_sensor_voting_helper ; check if sensor is within +/- range around setpoint | |
604 | 1185 tstfsz WREG ; sensor within range (WREG = 0)? |
1186 bcf voting_logic_sensor1 ; NO - vote out this sensor | |
560 | 1187 |
634 | 1188 bsf voting_logic_sensor2 ; default sensor to be within voting |
1189 movff sensor2_ppO2,WREG ; get sensor's ppO2 | |
1190 rcall check_sensor_voting_helper ; check if sensor is within +/- range around setpoint | |
604 | 1191 tstfsz WREG ; sensor within range (WREG = 0)? |
1192 bcf voting_logic_sensor2 ; NO - vote out this sensor | |
560 | 1193 |
634 | 1194 bsf voting_logic_sensor3 ; default sensor to be within voting |
1195 movff sensor3_ppO2,WREG ; get sensor's ppO2 | |
1196 rcall check_sensor_voting_helper ; check if sensor is within +/- range around setpoint | |
604 | 1197 tstfsz WREG ; sensor within range (WREG = 0)? |
1198 bcf voting_logic_sensor3 ; NO - vote out this sensor | |
582 | 1199 |
560 | 1200 ; check if a warning shall be issued on sensor disagreement |
582 | 1201 btfsc FLAG_ccr_mode ; check if we are in CCR mode |
604 | 1202 bra check_warn_sensor_0 ; YES - continue with further checks |
582 | 1203 btfsc FLAG_pscr_mode ; check if we are in pSCR mode |
604 | 1204 bra check_warn_sensor_0 ; YES - continue with further checks |
1205 bra check_warn_sensor_done ; not in CCR and not in pSCR, so no warning | |
634 | 1206 |
604 | 1207 check_warn_sensor_0: ; we are in CCR or pSCR mode |
623 | 1208 btfsc bailout_mode ; check if we are in bailout |
604 | 1209 bra check_warn_sensor_done ; YES - no warning in this case |
640 | 1210 movf dive_ccr_mode,W ; get mode (0: Fixed SP, 1: Sensor, 2: Auto SP) |
604 | 1211 sublw .1 ; in sensor mode? |
1212 bnz check_warn_sensor_done ; NO - not in sensor mode - no warning in this case | |
634 | 1213 |
604 | 1214 check_warn_sensor_1: |
582 | 1215 btfss sensor1_calibrated_ok ; check if sensor has a valid calibration |
1216 bra check_warn_sensor_2 ; NO - sensor can not cause a warning then | |
1217 btfss use_O2_sensor1 ; YES - check if sensor is in use | |
604 | 1218 bra check_warn_sensor_2 ; NO - sensor can not cause a warning then |
1219 btfsc voting_logic_sensor1 ; YES - check if sensor value is within agreement range | |
1220 bra check_warn_sensor_2 ; YES - continue with next sensor | |
634 | 1221 bsf warn_det_sensors_div ; NO - sensors divergence |
1222 return ; - done | |
1223 | |
604 | 1224 check_warn_sensor_2: |
582 | 1225 btfss sensor2_calibrated_ok ; check if sensor has a valid calibration |
1226 bra check_warn_sensor_3 ; NO - sensor can not cause a warning then | |
1227 btfss use_O2_sensor2 ; YES - check if sensor is in use | |
604 | 1228 bra check_warn_sensor_3 ; NO - sensor can not cause a warning then |
1229 btfsc voting_logic_sensor2 ; YES - check if sensor value is within agreement range | |
1230 bra check_warn_sensor_3 ; YES - continue with next sensor | |
634 | 1231 bsf warn_det_sensors_div ; NO - sensors divergence |
1232 return ; - done | |
1233 | |
604 | 1234 check_warn_sensor_3: |
582 | 1235 btfss sensor3_calibrated_ok ; check if sensor has a valid calibration |
1236 bra check_warn_sensor_agree ; NO - sensor can not cause a warning then | |
1237 btfss use_O2_sensor3 ; YES - check if sensor is in use | |
604 | 1238 bra check_warn_sensor_agree ; NO - sensor can not cause a warning then |
1239 btfsc voting_logic_sensor3 ; YES - check if sensor value is within agreement range | |
1240 bra check_warn_sensor_agree ; YES - continue with next sensor | |
634 | 1241 bsf warn_det_sensors_div ; NO - set warning |
1242 return ; - done | |
1243 | |
604 | 1244 check_warn_sensor_done: |
560 | 1245 check_warn_sensor_agree: |
634 | 1246 bcf warn_det_sensors_div ; clear warning |
1247 bcf shown_sensors_diverg ; re-arm custom view show-up | |
1248 return ; done | |
1249 | |
1250 | |
1251 ;----------------------------------------------------------------------------- | |
1252 ; Helper Function - check if sensor mV is outside minimum | |
1253 ; | |
604 | 1254 check_min_threshold: |
623 | 1255 MOVLI min_mv,sub_b ; load minimum mV value |
604 | 1256 goto sub16 ; sub_c = sensor_mv - min_mv (and return) |
1257 | |
634 | 1258 |
1259 ;----------------------------------------------------------------------------- | |
1260 ; Helper Function - check if sensor mV is outside maximum | |
1261 ; | |
604 | 1262 check_max_threshold: |
623 | 1263 MOVLI max_mv,sub_b ; load maximum mV value |
604 | 1264 goto sub16 ; sub_c = sensor_mv - max_mv (and return) |
1265 | |
634 | 1266 |
1267 ;----------------------------------------------------------------------------- | |
1268 ; Helper Function - compute ppO2 from sensor mV and calibration factor | |
1269 ; | |
560 | 1270 compute_ppo2_helper: |
623 | 1271 call mult16x16 ; xC:4 = xA:2 * xB:2 |
634 | 1272 MOVLI .1000,xB ; load scaling factor |
623 | 1273 call div32x16 ; xC:4 = xC:4 / xB:2 with xA as remainder |
1274 tstfsz xC+1 ; is the ppO2 higher than 2.55 bar? | |
1275 setf xC+0 ; YES - set result to 255 aka 2.55 bar | |
634 | 1276 return ; done |
1277 | |
1278 | |
1279 ;----------------------------------------------------------------------------- | |
1280 ; Helper Function - check if sensor is within +/- range around setpoint | |
1281 ; | |
560 | 1282 check_sensor_voting_helper: |
634 | 1283 subwf sensor_setpoint,W ; deviation = setpoint - sensor ppO2 |
1284 btfsc STATUS,N ; result negative? | |
1285 negf WREG,W ; YES - negate deviation | |
1286 sublw sensor_voting_logic_threshold ; WREG = threshold - deviation | |
1287 btfss STATUS,N ; result negative? | |
1288 retlw .0 ; NO - within range | |
1289 retlw .1 ; YES - out of range | |
1290 | |
1291 ; cpfsgt sensor_setpoint ; sensor ppO2 > setpoint? | |
1292 ; bra check_sensor_voting_helper_2 ; NO | |
1293 ; ;bra check_sensor_voting_helper_1 ; YES | |
1294 ; | |
1295 ;check_sensor_voting_helper_1: | |
1296 ; subwf sensor_setpoint,W ; WREG = setpoint - sensor ppO2 | |
1297 ; bra check_sensor_voting_helper_com ; continue with common part | |
1298 ; | |
1299 ;check_sensor_voting_helper_2: | |
1300 ; movwf lo ; copy sensor ppO2 to lo | |
1301 ; movf sensor_setpoint,W ; copy setpoint to WREG | |
1302 ; subwf lo,W ; WREG = sensor ppO2 - setpoint | |
1303 ; ;bra check_sensor_voting_helper_com ; continue with common part | |
1304 ; | |
1305 ;check_sensor_voting_helper_com: | |
1306 ; movwf lo ; copy deviation to lo | |
1307 ; movlw sensor_voting_logic_threshold ; load threshold in 0.01 bar | |
1308 ; cpfsgt lo ; deviation > threshold ? | |
1309 ; retlw .0 ; NO - within range | |
1310 ; retlw .1 ; YES - out of range | |
582 | 1311 |
623 | 1312 ENDIF ; _external_sensor |
631 | 1313 ENDIF ; _ccr_pscr |
623 | 1314 |
560 | 1315 |
604 | 1316 IFDEF _cave_mode |
623 | 1317 |
634 | 1318 ;----------------------------------------------------------------------------- |
1319 ; Cave Mode - on/off Switching | |
1320 ; | |
631 | 1321 cavemode_toggle_onoff: |
1322 bcf request_cave_toggle ; clear request flag | |
1323 btg cave_mode ; toggle the on/off state | |
1324 return ; done | |
1325 | |
634 | 1326 |
1327 ;----------------------------------------------------------------------------- | |
1328 ; Cave Mode - switch off and set Dive as turned | |
1329 ; | |
631 | 1330 cavemode_switch_off_turned: |
1331 bcf request_cave_off_turned ; clear request flag | |
1332 bcf cave_mode ; switch cave mode off | |
1333 bra cavemode_turndive_turn_exec ; set dive as turned (and return) | |
1334 | |
1335 | |
634 | 1336 ;----------------------------------------------------------------------------- |
1337 ; Cave Mode - check if 'turn dive' is allowed | |
1338 ; | |
631 | 1339 global cavemode_turndive_check |
1340 cavemode_turndive_check: | |
1341 btfss cave_mode ; cave mode switched on? | |
1342 retlw 1 ; NO - signal not allowed | |
1343 btfss dive_turned ; YES - is the dive currently turned? | |
1344 retlw 0 ; NO - command is allowed | |
1345 movf backtrack_waypoint_turn,W ; YES - copy turn point number to WREG | |
1346 cpfslt backtrack_waypoint_num ; - current waypoint number < turn point number ? | |
1347 retlw 1 ; NO - signal not allowed | |
1348 retlw 0 ; YES - command is allowed | |
1349 | |
634 | 1350 |
1351 ;----------------------------------------------------------------------------- | |
1352 ; Cave Mode - execute 'turn dive' toggle | |
1353 ; | |
631 | 1354 cavemode_turndive_toggle: |
1355 bcf request_turn_toggle ; clear request flag | |
1356 rcall cavemode_turndive_check ; check if command is allowed | |
1357 tstfsz WREG ; command allowed? | |
1358 return ; NO - abort | |
1359 btfss dive_turned ; YES - is the dive currently turned? | |
1360 bra cavemode_turndive_turn_exec ; NO - turn the dive | |
634 | 1361 bcf dive_turned ; YES - set dive as not turned any more |
1362 bcf backtrack_shutdown ; - set backtracking as not shut down any more | |
1363 call set_logbook_marker ; - set a logbook marker | |
1364 goto resume_backtrack_recording ; - append further logging after current waypoint and return | |
1365 | |
1366 | |
1367 ;----------------------------------------------------------------------------- | |
1368 ; Cave Mode - set the dive as turned | |
1369 ; | |
631 | 1370 cavemode_turndive_turn: |
1371 bcf request_turn_turn ; clear request flag | |
1372 btfss cave_mode ; cave mode switched on? | |
1373 return ; NO - abort | |
1374 btfsc dive_turned ; YES - is the dive already turned? | |
1375 return ; YES - nothing to do any more | |
1376 cavemode_turndive_turn_exec: | |
634 | 1377 bsf dive_turned ; NO - set dive as turned |
1378 call set_logbook_marker ; - set a logbook marker | |
1379 goto write_backtrack_turnpoint ; - write a turn-point waypoint and return | |
1380 | |
1381 | |
1382 ;----------------------------------------------------------------------------- | |
1383 ; Cave Mode - check if setting a Waypoint is allowed | |
1384 ; | |
631 | 1385 global cavemode_waypoint_set_check |
1386 cavemode_waypoint_set_check: | |
1387 btfss cave_mode ; cave mode switched on? | |
1388 retlw 1 ; NO - command not allowed | |
1389 btfsc dive_turned ; YES - is the dive turned? | |
1390 retlw 1 ; YES - no setting of waypoints on way out, command not allowed | |
1391 btfsc backtrack_entire_full ; NO - storage entirely used up? | |
1392 retlw 1 ; YES - out of storage capacity, command not allowed | |
1393 movlw backtrack_waypoint_max ; NO - get highest allowed waypoint number | |
1394 cpfslt backtrack_waypoint_num ; - current waypoint number < max allowed number? | |
1395 retlw 1 ; NO - command not allowed | |
1396 retlw 0 ; YES - command is allowed | |
1397 | |
634 | 1398 |
1399 ;----------------------------------------------------------------------------- | |
1400 ; Cave Mode - set a Waypoint | |
1401 ; | |
631 | 1402 cavemode_waypoint_set: |
1403 bcf request_waypoint_set ; clear request flag | |
1404 rcall cavemode_waypoint_set_check ; check if command is allowed to execute | |
1405 tstfsz WREG ; command allowed? | |
1406 return ; NO - no waypoint setting possible, abort | |
1407 call set_logbook_marker ; YES - set a logbook marker | |
1408 goto write_backtrack_waypoint ; - execute command (and return) | |
1409 | |
1410 | |
634 | 1411 ;----------------------------------------------------------------------------- |
1412 ; Cave Mode - check if stepping one Waypoint outwards is allowed | |
1413 ; | |
631 | 1414 global cavemode_waypoint_out_check |
1415 cavemode_waypoint_out_check: | |
1416 btfss cave_mode ; cave mode switched on? | |
1417 retlw 1 ; NO - command not allowed | |
1418 btfss dive_turned ; YES - is the dive turned? | |
1419 retlw 1 ; NO - no stepping back on way in, command not allowed | |
1420 btfsc waypoint_reached_first ; YES - already at first waypoint? | |
1421 retlw 1 ; YES - command not allowed | |
1422 retlw 0 ; NO - command is allowed | |
1423 | |
634 | 1424 |
1425 ;----------------------------------------------------------------------------- | |
1426 ; Cave Mode - step one Waypoint outwards | |
1427 ; | |
631 | 1428 cavemode_waypoint_out: |
1429 bcf request_waypoint_out ; clear request flag | |
1430 rcall cavemode_waypoint_out_check ; check if command is allowed to execute | |
1431 tstfsz WREG ; command allowed? | |
1432 return ; NO - no further out possible, abort | |
1433 goto backtrack_waypoint_go_out ; YES - execute the command (and return) | |
1434 | |
1435 | |
634 | 1436 ;----------------------------------------------------------------------------- |
1437 ; Cave Mode - check if stepping one Waypoint inwards is allowed | |
1438 ; | |
631 | 1439 global cavemode_waypoint_in_check |
1440 cavemode_waypoint_in_check: | |
1441 btfss cave_mode ; cave mode switched on? | |
1442 retlw 1 ; NO - command not allowed | |
1443 btfss dive_turned ; YES - is the dive turned? | |
1444 retlw 1 ; NO - no stepping forward on way in, command not allowed | |
1445 btfsc waypoint_reached_last ; YES - already at last waypoint? | |
1446 retlw 1 ; YES - command not allowed | |
1447 retlw 0 ; NO - command is allowed | |
1448 | |
634 | 1449 |
1450 ;----------------------------------------------------------------------------- | |
1451 ; Cave Mode - step one Waypoint inwards | |
1452 ; | |
631 | 1453 cavemode_waypoint_in: |
1454 bcf request_waypoint_in ; clear request flag | |
1455 rcall cavemode_waypoint_in_check ; check if command is allowed to execute | |
1456 tstfsz WREG ; command allowed? | |
1457 return ; NO - no further in possible, abort | |
1458 goto backtrack_waypoint_go_in ; YES - execute command (and return) | |
623 | 1459 |
634 | 1460 |
1461 ;----------------------------------------------------------------------------- | |
1462 ; Cave Mode - store current Delta Time | |
1463 ; | |
1464 write_backtrack_deltatime: | |
1465 rcall setup_backtrack_index ; setup writing position | |
1466 bra write_backtrack_datum_deltatime ; store the current delta time (and return) | |
1467 | |
1468 | |
1469 ;----------------------------------------------------------------------------- | |
1470 ; Cave Mode - store a Backtracking Depth Data Set | |
1471 ; | |
1472 write_backtrack_1min_depth: | |
1473 rcall setup_backtrack_index ; setup writing position | |
1474 rcall write_backtrack_datum_depth ; store depth | |
1475 rcall write_backtrack_datum_zerotime ; reset the time elapsed since last depth recording and store it | |
1476 bra write_backtrack_datum_check ; store new writing position, check remaining storage capacity ()and return) | |
1477 | |
1478 | |
1479 ;----------------------------------------------------------------------------- | |
1480 ; Cave Mode - store a Waypoint | |
1481 ; | |
1482 write_backtrack_waypoint: | |
1483 rcall setup_backtrack_index ; setup writing position | |
1484 rcall write_backtrack_datum_deltatime ; store the time elapsed since last depth recording | |
1485 movf POSTINC1,W ; dummy read to increment the writing position index | |
1486 rcall write_backtrack_datum_depth ; store depth | |
1487 rcall write_backtrack_datum_gas ; store gas availability vector | |
1488 rcall write_backtrack_datum_waypoint ; store waypoint number | |
1489 rcall write_backtrack_datum_zerotime ; reset the time elapsed since last depth recording and store it | |
1490 bra write_backtrack_datum_check ; store new writing position, check remaining storage capacity (and return) | |
1491 | |
1492 | |
1493 ;----------------------------------------------------------------------------- | |
1494 ; Cave Mode - store a Turn Point | |
1495 write_backtrack_turnpoint: | |
1496 rcall write_backtrack_waypoint ; write a waypoint (see above) | |
1497 movf POSTDEC1,W ; dummy read to decrement the position index to the waypoint number datum | |
1498 movff FSR1L,char_I_backtrack_index ; store updated writing position | |
1499 movff backtrack_waypoint_num,backtrack_waypoint_turn; memorize this waypoint as turn point | |
1500 return ; done | |
1501 | |
1502 | |
1503 ;----------------------------------------------------------------------------- | |
1504 ; Cave Mode - append further Logging after current Waypoint | |
1505 ; | |
1506 resume_backtrack_recording: | |
1507 clrf backtrack_waypoint_turn ; clear turn point reference | |
1508 bsf waypoint_reached_last ; declare to be at last waypoint now | |
1509 rcall setup_backtrack_index ; setup index position | |
1510 movf POSTINC1,W ; dummy read to increment the position index to the delta time datum | |
1511 rcall write_backtrack_datum_zerotime ; reset the time elapsed since last depth recording and store it | |
1512 bra write_backtrack_datum_check ; store new writing position, check remaining storage capacity (and return) | |
1513 | |
1514 | |
1515 ;----------------------------------------------------------------------------- | |
1516 ; Cave Mode - execute stepping one Waypoint outwards | |
1517 ; | |
1518 backtrack_waypoint_go_out: | |
1519 bcf waypoint_reached_last ; not at last waypoint (or turn point) any more | |
1520 rcall setup_backtrack_index ; setup index position | |
1521 movlw b'11100000'-.1 ; a waypoint datum has bits 5-7 set, -1 because of cpfsgt | |
1522 backtrack_waypoint_go_out_loop: | |
1523 movff POSTDEC1,lo ; dummy read current datum and go to previous datum (there is no PREDEC) | |
1524 cpfsgt INDF1 ; read datum, is it a waypoint datum? | |
1525 bra backtrack_waypoint_go_out_loop ; NO - try next datum | |
1526 movff FSR1L,char_I_backtrack_index ; store new index position | |
1527 movf INDF1,W ; copy waypoint datum to WREG | |
1528 andlw b'00011111' ; remove waypoint tag | |
1529 movwf backtrack_waypoint_num ; store new waypoint number | |
1530 movlw .1 ; number of first waypoint | |
1531 cpfsgt backtrack_waypoint_num ; current waypoint number > number of first waypoint ? | |
1532 bsf waypoint_reached_first ; NO - reached first waypoint | |
1533 goto restart_deco_engine_wo_norm ; invalidate all alternative plan data and restart deco engine | |
1534 | |
1535 | |
1536 ;----------------------------------------------------------------------------- | |
1537 ; Cave Mode - execute stepping one Waypoint inwards | |
1538 ; | |
1539 backtrack_waypoint_go_in: | |
1540 bcf waypoint_reached_first ; not at first waypoint any more | |
1541 rcall setup_backtrack_index ; setup index position | |
1542 movlw b'11100000'-.1 ; a waypoint datum has bits 5-7 set, -1 because of cpfsgt | |
1543 backtrack_waypoint_go_in_loop: | |
1544 cpfsgt PREINC1 ; go to next datum, read it, is it a waypoint datum? | |
1545 bra backtrack_waypoint_go_in_loop ; NO - try next datum | |
1546 movff FSR1L,char_I_backtrack_index ; store new index position | |
1547 movf INDF1,W ; copy waypoint datum to WREG | |
1548 andlw b'00011111' ; remove waypoint tag | |
1549 movwf backtrack_waypoint_num ; store new waypoint number | |
1550 movf backtrack_waypoint_turn,W ; load WREG with waypoint number of turn point | |
1551 cpfslt backtrack_waypoint_num ; new waypoint number < number of turn point ? | |
1552 bsf waypoint_reached_last ; NO - reached last waypoint | |
1553 goto restart_deco_engine_wo_norm ; invalidate all alternative plan data and restart deco engine | |
1554 | |
1555 | |
1556 ;----------------------------------------------------------------------------- | |
1557 ; Cave Mode Helper Function - set up Index Position | |
1558 ; | |
1559 setup_backtrack_index: | |
1560 lfsr FSR1,char_I_backtrack_storage ; load FSR1 with base address of the backtracking storage | |
1561 movff char_I_backtrack_index,FSR1L ; adjust FSR1 to the current index position | |
1562 return | |
1563 | |
1564 | |
1565 ;----------------------------------------------------------------------------- | |
1566 ; Cave Mode Helper Function - reset Time since last Depth Recording and store it | |
1567 ; | |
1568 write_backtrack_datum_zerotime: | |
1569 clrf backtrack_deltatime ; reset the time elapsed since last depth recording | |
1570 ;bra write_backtrack_datum_deltatime ; store the time | |
1571 | |
1572 | |
1573 ;----------------------------------------------------------------------------- | |
1574 ; Cave Mode Helper Function - store Time elapsed since last Depth Recording | |
1575 ; | |
1576 write_backtrack_datum_deltatime: | |
1577 movf backtrack_deltatime,W ; get the time elapsed since last depth recording | |
1578 bsf WREG,7 ; add the time marker (bit 7 set) to the time stored in WREG | |
1579 movwf INDF1 ; write the time and keep the writing position index pointing on it | |
1580 return ; done | |
1581 | |
1582 | |
1583 ;----------------------------------------------------------------------------- | |
1584 ; Cave Mode Helper Function - store Depth | |
1585 ; | |
1586 write_backtrack_datum_depth: | |
1587 movf depth_meter,W ; get current depth in meters into WREG | |
1588 btfsc WREG,7 ; current depth < 128 m ? | |
1589 movlw .127 ; NO - clip depth to 127 meters (protect time marker bit) | |
1590 movwf POSTINC1 ; write the depth entry and increment the writing position index | |
1591 return ; done | |
1592 | |
1593 | |
1594 ;----------------------------------------------------------------------------- | |
1595 ; Cave Mode Helper Function - store Gas Availability Vector | |
1596 ; | |
1597 write_backtrack_datum_gas: | |
1598 ; Cave mode is currently only available with gas needs calculation enabled, | |
1599 ; so deco mode is either OC anyhow or CCR/pSCR in bailout mode. Hence it is | |
1600 ; always the OC (bailout) gases whose staging status needs to be stored. | |
1601 lfsr FSR2,opt_gas_type ; load base address of the OC/bailout gas types | |
1602 movlw NUM_GAS ; load number of gases | |
1603 movwf lo ; initialize loop counter | |
1604 movlw b'00000001' ; load gas bit pattern for the first gas | |
1605 movwf hi ; store gas bit pattern in hi | |
1606 movlw b'11000000' ; initialize WREG with the gas staging status tag | |
1607 write_backtrack_datum_gas_loop: | |
1608 movff POSTINC2,up ; get gas type and increment index | |
1609 btfsc up,gas_staged ; gas staged? | |
1610 iorwf hi,W ; YES - set respective gas bit | |
1611 rlncf hi,F ; rotate gas bit pattern to match the next gas | |
1612 decfsz lo,F ; decrement loop counter, did it became zero? | |
1613 bra write_backtrack_datum_gas_loop ; NO - loop | |
1614 movwf POSTINC1 ; YES - write the gas staging status entry and increment the writing position index | |
1615 return ; - done | |
1616 | |
1617 | |
1618 ;----------------------------------------------------------------------------- | |
1619 ; Cave Mode Helper Function - store a Waypoint Number | |
1620 ; | |
1621 write_backtrack_datum_waypoint: | |
1622 incf backtrack_waypoint_num,F ; increment the waypoint number | |
1623 movf backtrack_waypoint_num,W ; copy waypoint number to WREG | |
1624 iorlw b'11100000' ; add the waypoint marker (bit 7-5 set) to the number stored in WREG | |
1625 movwf POSTINC1 ; write the waypoint datum and increment the writing position index | |
1626 movlw .2 ; load a 2 into WREG | |
1627 cpfslt backtrack_waypoint_num ; new waypoint number >= 2 ? | |
1628 bcf waypoint_reached_first ; YES - not at first waypoint any more | |
1629 return ; done | |
1630 | |
1631 | |
1632 ;----------------------------------------------------------------------------- | |
1633 ; Cave Mode Helper Function - store new writing position and check remaining storage capacity | |
1634 ; | |
1635 write_backtrack_datum_check: | |
1636 movff FSR1L,char_I_backtrack_index ; store new index position | |
1637 movlw backtrack_almost_full_threshold ; load threshold for backtracking storage almost full | |
1638 bcf backtrack_almost_full ; clear almost full state | |
1639 cpfslt FSR1L ; index < threshold ? | |
1640 bsf backtrack_almost_full ; NO - flag backtracking storage is almost full | |
1641 movlw backtrack_entire_full_threshold ; load threshold for backtracking storage entirely full | |
1642 bcf backtrack_entire_full ; clear entirely full state | |
1643 cpfslt FSR1L ; index < threshold ? | |
1644 bsf backtrack_entire_full ; NO - flag backtracking storage is entirely full | |
1645 return ; done | |
1646 | |
1647 ENDIF ; _cave_mode | |
1648 | |
1649 | |
1650 ;----------------------------------------------------------------------------- | |
1651 ; Calculate vertical Velocity | |
1652 ; | |
623 | 1653 calc_velocity: ; called every two seconds |
1654 btfsc velocity_active_num ; was velocity shown in last cycle? | |
1655 bra calc_velocity_1 ; YES - always update if shown before | |
1656 btfss count_divetime ; NO - is the dive time counted, i.e. deeper than dive threshold? | |
1657 return ; NO - display velocity only if deeper than 1m, | |
1658 ; i.e. not at the surface after the dive | |
1659 calc_velocity_1: | |
1660 ; calculate pressure difference | |
1661 MOVII pressure_abs_cached, sub_a; current pressure | |
1662 MOVII last_pressure_velocity,sub_b; last pressure | |
1663 call subU16 ; do an unsigned subtraction | |
1664 | |
1665 ; decide if ascending or descending | |
1666 bcf neg_flag_velocity ; set to ascending by default | |
1667 btfsc neg_flag ; pressure differential negative? | |
1668 bsf neg_flag_velocity ; YES - descending | |
1669 | |
1670 ; store current pressure as last pressure for next round | |
1671 MOVII pressure_abs_cached,last_pressure_velocity | |
1672 | |
1673 ; calculate velocity in m/min | |
1674 MOVII sub_c,xA ; copy pressure differential to xA | |
1675 MOVLI .39,xB ; put scale coefficient into xB (use 77 when called every second) | |
628 | 1676 call mult16x16 ; compute differential pressure in mbar * scale coefficient |
623 | 1677 MOVII xC,divA ; copy result to divA |
631 | 1678 ADDLI .64,divA ; add some round-up |
623 | 1679 movlw .7 ; divide by 2^7 |
1680 call div16 ; divA = divA / 2^WREG, yields velocity in m/min | |
1681 | |
1682 movlw .99 ; load a 99 | |
1683 cpfslt divA+0 ; velocity < 99 m/min ? | |
1684 movwf divA+0 ; NO - limit to 99 m/min | |
1685 | |
1686 bcf STATUS,C ; clear carry flag | |
1687 movlw velocity_display_threshold ; get threshold for displaying vertical velocity | |
1688 subwf divA+0,W ; subtract threshold from velocity | |
1689 btfss STATUS,C ; above threshold? | |
1690 bsf FLAG_TFT_velocity_clear ; NO - don't show / request to clear | |
1691 btfsc STATUS,C ; above threshold? | |
1692 bsf FLAG_TFT_velocity_show ; YES - request to show | |
1693 return ; done | |
0 | 1694 |
1695 | |
634 | 1696 ;----------------------------------------------------------------------------- |
1697 ; Check and Memorize if Dive went into Deco & Deco Region | |
1698 ; | |
628 | 1699 check_deco_states: |
1700 btfsc deco_region ; been within the deco stops region before? | |
1701 return ; YES - been in deco then before too, done | |
1702 movff char_O_deco_info,WREG ; NO - get deco info vector | |
631 | 1703 btfss WREG,deco_stops_norm ; do we have a deco obligation right now? |
628 | 1704 return ; NO - done |
1705 bsf deco_locked ; YES - memorize dive was in deco | |
1706 movff char_O_deco_depth+0,WREG ; - get depth of first stop in meters into WREG | |
1707 addlw deco_region_distance+.1 ; - add deco region start distance + 1 meter for the negative test to work | |
631 | 1708 subwf depth_meter,W ; - compute current depth - (first stop depth + deco region distance) |
628 | 1709 btfss STATUS,C ; - result negative? |
1710 bsf deco_region ; YES - memorize to have entered the deco stops region | |
1711 return ; - done | |
1712 | |
634 | 1713 |
1714 ;----------------------------------------------------------------------------- | |
1715 ; Exercise Safety Stop Control | |
1716 ; | |
623 | 1717 safety_stop_control: |
631 | 1718 TSTOSS opt_safetystop ; safety stop enabled? (=1: show safety stop) |
623 | 1719 return ; NO - done |
1720 | |
1721 btfsc FLAG_gauge_mode ; in gauge mode? | |
1722 return ; YES - omit (well, else fix collision of safety stop output with avg depth label) | |
1723 | |
1724 ; setup | |
1725 bcf safety_stop_enabled ; disable safety stop by default | |
1726 | |
1727 ; check for deco | |
1728 btfsc decostop_active ; in deco mode? | |
1729 bra safety_stop_finish ; YES - shut down safety stop | |
1730 | |
1731 ; below "opt_safety_stop_reset"? | |
631 | 1732 MOVII pressure_rel_cur_cached,mpr ; get current pressure into MPR |
1733 call convert_pres_to_depth ; convert pressure in [mbar] to depth in [cm] | |
1734 MOVII mpr,sub_a ; move depth in [cm] to sub_a | |
1735 movff opt_safety_stop_reset,WREG ; load safety stop reset threshold [dm] | |
1736 mullw .10 ; convert threshold from [dm] to [cm] | |
1737 MOVII PROD,sub_b ; move threshold in [cm] to sub_b | |
623 | 1738 call cmpU16 ; sub_a - sub_b |
634 | 1739 btfsc neg_flag ; below threshold depth? |
1740 bra safety_stop_control_chk ; NO - check if above end threshold | |
1741 ;bra safety_stop_reset ; YES - reset safety stop | |
1742 | |
1743 safety_stop_reset: | |
1744 movff opt_safety_stop_length,safety_stop_countdown ; rearm safety stop (load timer) | |
1745 incf safety_stop_countdown,F ; +1 because safety_stop_show decrements first | |
1746 bsf FLAG_TFT_safety_stop_clear ; request to clear safety stop | |
1747 return ; done | |
1748 | |
1749 safety_stop_control_chk: | |
623 | 1750 ; above "opt_safety_stop_end"? |
631 | 1751 movff opt_safety_stop_end,WREG ; load safety stop end threshold [dm] |
1752 mullw .10 ; convert threshold from [dm] to [cm] | |
1753 MOVII PROD,sub_b ; move threshold in [cm] to sub_b | |
623 | 1754 call cmpU16 ; sub_a - sub_b |
1755 btfsc neg_flag ; above or at threshold depth? | |
634 | 1756 bra safety_stop_finish ; YES - finish with safety stop and return |
1757 | |
623 | 1758 ; above "opt_safety_stop_start"? |
631 | 1759 movff opt_safety_stop_start,WREG ; load safety stop start threshold [dm] |
1760 mullw .10 ; convert threshold from [dm] to [cm] | |
1761 MOVII PROD,sub_b ; move threshold in [cm] to sub_b | |
623 | 1762 call cmpU16 ; sub_a - sub_b |
1763 btfss neg_flag ; above or at threshold depth? | |
1764 return ; NO - pause safety stop | |
1765 tstfsz safety_stop_countdown ; YES - safety stop armed? | |
1766 bsf safety_stop_enabled ; YES - enable safety stop | |
634 | 1767 return ; - done |
1768 | |
1769 | |
1770 ;----------------------------------------------------------------------------- | |
1771 ; Show Safety Stop | |
1772 ; | |
623 | 1773 safety_stop_show: |
1774 btfss safety_stop_enabled ; safety stop enabled? | |
1775 return ; NO - done | |
1776 dcfsnz safety_stop_countdown,F ; YES - decrement remaining stop time, reached zero? | |
634 | 1777 bra safety_stop_finish ; YES - finished with safety stop and return |
623 | 1778 bsf FLAG_TFT_safety_stop_show ; NO - request to show safety stop |
1779 return ; - done | |
1780 | |
634 | 1781 |
1782 ;----------------------------------------------------------------------------- | |
1783 ; Finish Safety Stop | |
1784 ; | |
623 | 1785 safety_stop_finish: |
634 | 1786 clrf safety_stop_countdown ; disarm safety stop |
1787 bcf safety_stop_enabled ; disable safety stop | |
1788 bsf FLAG_TFT_safety_stop_clear ; request to clear safety stop | |
1789 return ; done | |
1790 | |
1791 | |
1792 ;----------------------------------------------------------------------------- | |
1793 ; Check for Timeouts (called by tasks every 1/1 second) | |
1794 ; | |
1795 timeout_divemode: | |
1796 btfss dive_main_menu ; main dive menu shown? | |
1797 bra timeout_divemode_1 ; NO - skip | |
1798 btfsc trigger_timeout ; YES - timeout occurred? | |
1799 rcall divemenu_cleanup ; YES - clean up main menu and restore dive data | |
1800 | |
1801 timeout_divemode_1: | |
1802 btfss dive_pre_menu ; pre-menu shown? | |
1803 bra timeout_divemode_2 ; NO - skip | |
1804 btfsc trigger_timeout ; YES - timeout occurred? | |
1805 call menuview_toggle_reset ; YES - terminate the pre-menu | |
1806 | |
1807 timeout_divemode_2: | |
640 | 1808 INCI dive_timeout_timer ; increment timeout timer |
1809 | |
634 | 1810 btfss divetime_longer_1min ; does the dive already last for longer than one minute? |
640 | 1811 bra timeout_divemode_sub_1min ; NO - use a short timeout to achieve some extra hysteris when starting the dive |
634 | 1812 |
1813 btfsc FLAG_apnoe_mode ; in apnoe mode? | |
1814 bra timeout_divemode_apnoe ; YES - use apnoe timeout | |
1815 | |
1816 IFNDEF _DEBUG | |
1817 btfsc sensor_override_active ; in simulator mode? | |
1818 bra timeout_divemode_sim ; YES - use simulator timeout | |
1819 ENDIF | |
1820 | |
1821 movff opt_diveTimeout,WREG ; get dive timeout in minutes into WREG | |
1822 bra timeout_divemode_com_min ; continue with common part for minutes | |
1823 | |
1824 timeout_divemode_apnoe: | |
1825 movlw apnoe_timeout ; get apnoe timeout in minutes into WREG | |
1826 bra timeout_divemode_com_min ; continue with common part for minutes | |
1827 | |
1828 timeout_divemode_sim: | |
1829 MOVLI simulator_timeout,sub_a ; get simulator timeout in seconds directly into sub_a | |
1830 bra timeout_divemode_com_sec ; continue with common part for seconds | |
1831 | |
640 | 1832 timeout_divemode_sub_1min: |
1833 MOVLI divetime_less_1min_timeout,sub_a ; use a short timeout as an extra hysteresis during the descent | |
1834 bra timeout_divemode_com_sec ; continue with common part for seconds | |
1835 | |
634 | 1836 timeout_divemode_com_min: |
1837 mullw .60 ; multiply with 60 to convert minutes in WREG to seconds | |
1838 MOVII PRODL,sub_a ; copy resulting seconds to sub_a | |
1839 | |
1840 timeout_divemode_com_sec: | |
1841 MOVII dive_timeout_timer,sub_b ; copy current timeout timer value to sub_b | |
1842 call cmpU16 ; check sub_a - sub_b | |
1843 btfsc neg_flag ; result negative, i.e. timeout? | |
1844 bcf divemode ; YES - terminate dive mode | |
1845 return ; done | |
1846 | |
1847 | |
1848 ;----------------------------------------------------------------------------- | |
1849 ; Clean up Dive Menu Area and restore Dive Data | |
1850 ; | |
1851 divemenu_cleanup: | |
631 | 1852 bcf dive_main_menu ; clear flag for dive mode menu shown |
1853 call TFT_clear_divemode_menu ; clear menu area | |
1854 | |
1855 btfss custom_view_locked ; was the custom view locked by the menu system? | |
634 | 1856 bra divemenu_cleanup_1 ; NO - continue with redrawing the lower display |
1857 bcf custom_view_locked ; YES - release locked | |
631 | 1858 movf backup_customview,W ; - get previous custom view into WREG |
1859 cpfseq active_customview ; - compare with current custom view, equal? | |
1860 call dive_customview_recall ; NO - redraw previous custom view | |
1861 | |
634 | 1862 divemenu_cleanup_1: |
1863 bsf FLAG_TFT_active_gas_divemode; request redraw of gas/setpoint/diluent | |
1864 bsf FLAG_TFT_temperature ; request redraw of temperature (or resettable dive) | |
631 | 1865 bcf better_gas_blinking ; stop better gas cue |
1866 bcf better_dil_blinking ; stop better dil cue | |
634 | 1867 ;bra request_redraw_NDL_deco_data; request redraw of NDL/deco data and return |
1868 | |
1869 | |
1870 ;----------------------------------------------------------------------------- | |
1871 ; Request redraw of NDL/Deco Data | |
1872 ; | |
623 | 1873 request_redraw_NDL_deco_data: |
1874 btfsc FLAG_gauge_mode ; in gauge mode? | |
1875 return ; YES - done | |
1876 btfss decostop_active ; NO - in deco mode? | |
1877 bra timeout_divemode_menu_ndl ; NO - show NDL again | |
1878 ;bra timeout_divemode_menu_deco ; YES - show deco again | |
1879 | |
1880 timeout_divemode_menu_deco: | |
1881 bsf FLAG_TFT_display_deco_mask ; show deco mask | |
1882 bsf FLAG_TFT_display_deco ; show deco stop | |
1883 bsf FLAG_TFT_display_tts ; show TTS time | |
1884 return ; done | |
582 | 1885 |
1886 timeout_divemode_menu_ndl: | |
623 | 1887 bsf FLAG_TFT_display_ndl_mask ; show NDL mask |
1888 bsf FLAG_TFT_display_ndl ; show NDL time | |
1889 return ; done | |
0 | 1890 |
634 | 1891 |
1892 ;----------------------------------------------------------------------------- | |
1893 ; Check if Dive Mode needs to be started (called from Surface Mode) | |
1894 ; | |
1895 global check_dive_modes_surf | |
1896 check_dive_modes_surf: | |
1897 SMOVII pressure_rel_cur,sub_a ; ISR-safe 2 byte copy of current relative pressure to sub_a | |
1898 bcf divetime_longer_1min ; not diving when in surface mode | |
1899 bra check_dive_modes ; continue with common part | |
1900 | |
1901 | |
1902 ;----------------------------------------------------------------------------- | |
1903 ; Check if Dive Mode needs to be finished (called from Dive Loop) | |
1904 ; | |
1905 check_dive_modes_dive: | |
1906 MOVII pressure_rel_cur_cached,sub_a ; copy cached relative pressure to sub_a | |
1907 ;bra check_dive_modes ; continue with common part | |
1908 | |
1909 | |
1910 ;----------------------------------------------------------------------------- | |
1911 ; Check for Dive Mode Start/Finish - common Part | |
1912 ; | |
1913 check_dive_modes: | |
1914 btfss high_altitude_mode ; in high altitude mode? | |
1915 bra check_dive_modes_norm ; NO - use normal start-dive threshold | |
1916 btfsc divetime_longer_1min ; YES - diving since > one minute? | |
1917 bra check_dive_modes_norm ; YES - this is a real dive -> use normal start-dive threshold | |
1918 ;bra check_dive_modes_high ; NO - use hight-altitude start-dive threshold | |
1919 | |
1920 check_dive_modes_high: | |
1921 ; high altitude start/end dive thresholds | |
1922 btfss count_divetime ; dive time counting, i.e. already in the dive? | |
1923 bra check_dive_modes_high_start ; NO - select start threshold | |
1924 ;bra check_dive_modes_high_end ; YES - select end threshold | |
1925 | |
1926 check_dive_modes_high_end: | |
1927 MOVLI dive_threshold_high_alt_end,sub_b ; load high altitude end threshold | |
1928 bra check_dive_modes_comm ; continue with common part | |
1929 | |
1930 check_dive_modes_high_start: | |
1931 MOVLI dive_threshold_high_alt_start,sub_b ; load high altitude start threshold | |
1932 bra check_dive_modes_comm ; continue with common part | |
1933 | |
1934 check_dive_modes_norm: | |
1935 ; normal altitude start/end dive thresholds | |
1936 btfss count_divetime ; dive time counting, i.e. already in the dive? | |
1937 bra check_dive_modes_norm_start ; NO - select start threshold | |
1938 ;bra check_dive_modes_norm_end ; YES - select end threshold | |
1939 | |
1940 check_dive_modes_norm_end: | |
1941 MOVLI dive_threshold_norm_alt_end,sub_b ; load normal altitude end threshold | |
1942 bra check_dive_modes_comm ; continue with common part | |
1943 | |
1944 check_dive_modes_norm_start | |
1945 MOVLI dive_threshold_norm_alt_start,sub_b ; load normal altitude start threshold | |
1946 ;bra check_dive_modes_comm ; continue with common part | |
1947 | |
1948 check_dive_modes_comm: | |
1949 call cmpU16 ; sub_a - sub_b = pressure_rel_cur - start-dive threshold | |
1950 btfsc neg_flag ; pressure_rel_cur > dive_threshold, i.e. deeper than threshold? | |
1951 bra check_dive_modes_shallow ; NO - shallower than threshold | |
1952 btfsc divetime_longer_1min ; YES - diving > one minute? | |
1953 CLRI dive_timeout_timer ; YES - reset timeout counter | |
1954 bsf divemode ; - set dive mode flag | |
1955 bsf count_divetime ; - count dive time | |
1956 return ; - done | |
1957 | |
1958 check_dive_modes_shallow: | |
1959 bcf count_divetime ; stop counting dive time | |
640 | 1960 ; btfss divetime_longer_1min ; diving > one minute? |
1961 ; bcf divemode ; NO - quit dive mode as this was no real dive | |
1962 return ; done mH | |
631 | 1963 |
634 | 1964 |
1965 ;----------------------------------------------------------------------------- | |
1966 ; Initialize the resettable Depth and Timer | |
1967 ; | |
1968 resettable_average_depth_init: | |
1969 CLRI pressure_rel_avg_trip ; prime the resettable average depth with 0 | |
1970 bra resettable_average_depth_common ; clear pressure accumulator and timer | |
1971 | |
1972 | |
1973 ;----------------------------------------------------------------------------- | |
1974 ; Reset the resettable Depth and Timer | |
1975 ; | |
1976 resettable_average_depth_reset: | |
1977 bcf request_reset_avg ; clear request | |
1978 MOVII pressure_rel_cur_cached,pressure_rel_avg_trip ; prime the resettable average depth | |
1979 ; with the current relative pressure (depth) | |
1980 ;bra resettable_average_depth_common ; clear pressure accumulator and timer | |
1981 | |
1982 | |
1983 ;----------------------------------------------------------------------------- | |
1984 ; Helper Function - common Part for resettable Depth and Timer init/reset | |
1985 ; | |
1986 resettable_average_depth_common: | |
1987 clrf pressure_rel_accu_trip+0 ; clear the resettable depth accumulator | |
1988 clrf pressure_rel_accu_trip+1 ; .... | |
1989 clrf pressure_rel_accu_trip+2 ; .... | |
1990 clrf pressure_rel_accu_trip+3 ; .... | |
1991 CLRI divesecs_avg_trip ; clear the resettable time accumulator | |
1992 return ; done | |
1993 | |
1994 | |
1995 ;----------------------------------------------------------------------------- | |
1996 ; Calculate Average Depth | |
1997 ; | |
0 | 1998 calc_average_depth: |
623 | 1999 ; 1. compute pressure_rel_cur_cached x 2, because this routine is called every 2nd second only |
634 | 2000 MOVII pressure_rel_cur_cached,xB ; copy current rel pressure to xB |
2001 bcf STATUS,C ; multiply rel pressure x 2 (via shift left) | |
2002 rlcf xB+0,F ; ... | |
2003 rlcf xB+1,F ; ... | |
623 | 2004 |
2005 ; 2a add (pressure_rel_cur_cached x 2) to the resettable depth accumulator | |
2006 ; will work up to 9999 mbar * 60 * 60 * 24 = 863913600 mbar (24h @ 90 m depth) | |
634 | 2007 movf xB+0,W ; pressure_rel_accu_trip += xB |
2008 addwf pressure_rel_accu_trip+0,F ; ... | |
2009 movf xB+1,W ; ... | |
2010 addwfc pressure_rel_accu_trip+1,F ; ... | |
2011 movlw .0 ; ... | |
2012 addwfc pressure_rel_accu_trip+2,F ; ... | |
2013 addwfc pressure_rel_accu_trip+3,F ; ... | |
623 | 2014 |
2015 ; 2b add (pressure_rel_cur_cached x 2) to the total depth accumulator | |
2016 ; will work up to 9999 mbar * 60 * 60 * 24 = 863913600 mbar (24h @ 90 m depth) | |
634 | 2017 movf xB+0,W ; pressure_rel_accu_total += xB |
2018 addwf pressure_rel_accu_total+0,F ; ... | |
2019 movf xB+1,W ; ... | |
2020 addwfc pressure_rel_accu_total+1,F ; ... | |
2021 movlw .0 ; ... | |
2022 addwfc pressure_rel_accu_total+2,F ; ... | |
2023 addwfc pressure_rel_accu_total+3,F ; ... | |
623 | 2024 |
2025 ; 3a compute the resettable average depth | |
634 | 2026 movff pressure_rel_accu_trip+0,xC+0 ; get the accumulated depth |
2027 movff pressure_rel_accu_trip+1,xC+1 ; ... | |
2028 movff pressure_rel_accu_trip+2,xC+2 ; ... | |
2029 movff pressure_rel_accu_trip+3,xC+3 ; ... | |
2030 MOVII divesecs_avg_trip,xB ; get the accumulated time | |
623 | 2031 |
2032 ; divide accumulated depth by accumulated time | |
604 | 2033 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder |
623 | 2034 |
2035 ; store result | |
2036 MOVII xC,pressure_rel_avg_trip ; resettable average depth | |
2037 btfss count_divetime ; is dive time counted? | |
604 | 2038 return ; NO (e.g. too shallow) |
2039 | |
623 | 2040 ; 3b compute the dive total average depth |
634 | 2041 movff pressure_rel_accu_total+0,xC+0 ; get accumulated depth |
2042 movff pressure_rel_accu_total+1,xC+1 ; ... | |
2043 movff pressure_rel_accu_total+2,xC+2 ; ... | |
2044 movff pressure_rel_accu_total+3,xC+3 ; ... | |
2045 MOVII divesecs_avg_total,xB ; get accumulated time | |
623 | 2046 |
2047 ; divide accumulated depth by accumulated time | |
2048 call div32x16 ; xC:4 = xC:4 / xB:2 with xA as remainder | |
2049 | |
2050 ; store result | |
2051 MOVII xC,pressure_rel_avg_total ; total dive average depth | |
2052 | |
2053 btfsc request_reset_avg ; shall reset the resettable average depth? | |
634 | 2054 rcall resettable_average_depth_reset ; YES - reset the resettable average depth |
623 | 2055 |
2056 TSTOSC opt_2ndDepthDisp ; drawing average depth instead of max depth? | |
2057 bsf FLAG_TFT_depth_maximum ; YES - flag to update display | |
2058 | |
2059 btfsc FLAG_gauge_mode ; in gauge mode? | |
2060 bsf FLAG_TFT_depth_maximum ; YES - flag to update display (needed for alternative layout) | |
2061 | |
2062 return ; done | |
2063 | |
2064 | |
634 | 2065 ;----------------------------------------------------------------------------- |
2066 ; Check Switches, execute Pre-Menu Items (called every second) | |
2067 ; | |
2068 test_switches_divemode: | |
623 | 2069 btfsc dive_main_menu ; dive mode menu shown? |
604 | 2070 bra test_switches_divemode_menu ; YES - use menu processor |
2071 btfsc switch_left ; NO - left button pressed? | |
634 | 2072 goto menuview_toggle ; YES - step through pre-menu |
604 | 2073 btfss switch_right ; NO - right button pressed? |
2074 return ; NO - done | |
623 | 2075 bcf switch_right ; YES - clear button event |
2076 tstfsz active_premenu ; - any pre-menu task selected? | |
634 | 2077 bra test_switches_divemode1 ; YES - execute a pre-menu item |
623 | 2078 bsf request_next_custview ; NO - request next custom view |
604 | 2079 return ; - done |
0 | 2080 |
2081 test_switches_divemode_menu: | |
623 | 2082 btfsc switch_left ; left button pressed? |
2083 bra test_switches_divemode_menu2 ; YES - move cursor | |
2084 btfsc switch_right ; NO - right button pressed? | |
634 | 2085 bra test_switches_divemode_menu3 ; YES - do a menu operation |
623 | 2086 btfss update_menu ; NO - shall update the menu? |
2087 return ; NO - done | |
2088 bcf update_menu ; YES - clear request | |
2089 goto menu_draw_lines_divemode ; - redraw the menu (to update color coding) and return | |
0 | 2090 |
2091 test_switches_divemode_menu1: | |
634 | 2092 clrf menu_pos_cur ; reset menu item number to zero |
0 | 2093 test_switches_divemode_menu2: |
634 | 2094 bcf switch_left ; clear left button event |
2095 incf menu_pos_cur,F ; increment menu item number | |
2096 incf menu_pos_max,W ; get number of items + 1 into WREG | |
2097 cpfslt menu_pos_cur ; incremented item number > number of items ? | |
2098 bra test_switches_divemode_menu1 ; YES - restart from first item | |
2099 call menu_draw_cursor_dive ; draw cursor at new position | |
623 | 2100 movlw divemode_timeout_mainmenu ; get timeout for main menu |
634 | 2101 call restart_timeout_time ; restart the timeout |
2102 return ; done | |
2103 | |
2104 test_switches_divemode_menu3: | |
2105 bcf switch_right ; clear right button event | |
2106 goto do_line_menu ; Warning! trashes STKPTR and returns to | |
2107 ; divemode_option_divemenu_return | |
0 | 2108 |
2109 test_switches_divemode1: | |
634 | 2110 movlw divemode_timeout_premenu ; get timeout for pre-menu |
2111 call restart_timeout_time ; restart the timeout | |
2112 movf active_premenu,W ; get active pre-menu item | |
0 | 2113 dcfsnz WREG,F |
634 | 2114 bra divemode_option_gaschange ; 1: switch to the the "better gas" / "better diluent" |
137 | 2115 dcfsnz WREG,F |
634 | 2116 bra divemode_option_ackn ; 2: acknowledge current advice, attention, or warning |
2117 dcfsnz WREG,F | |
2118 bra divemode_option_divemenu ; 3: enter dive mode menu | |
0 | 2119 dcfsnz WREG,F |
631 | 2120 IFDEF _cave_mode |
634 | 2121 bra divemode_option_cavemenu ; 4: enter cave mode menu |
631 | 2122 ELSE |
634 | 2123 return ; 4: (no cave mode compiled in) |
2124 ENDIF | |
2125 dcfsnz WREG,F | |
2126 bra divemode_option_sim_quit ; 5: quit simulator mode | |
2127 dcfsnz WREG,F | |
2128 bra divemode_option_sim_down ; 6: simulator mode - descent | |
2129 dcfsnz WREG,F | |
2130 bra divemode_option_sim_up ; 7: simulator mode - ascend | |
2131 dcfsnz WREG,F | |
2132 bra divemode_option_sim_time ; 8: simulator mode - +5 min | |
2133 dcfsnz WREG,F | |
2134 bra divemode_option_apnoe_quit ; 9: quit apnoe dive | |
2135 dcfsnz WREG,F | |
2136 bra divemode_option_gauge_reset ; 10: reset stopwatch and avg depth (gauge mode) | |
2137 dcfsnz WREG,F | |
2138 IFDEF _compass | |
2139 bra divemode_option_course ; 11: set bearing | |
2140 ELSE | |
2141 return ; 11: (no compass compiled in) | |
631 | 2142 ENDIF |
0 | 2143 dcfsnz WREG,F |
634 | 2144 bra divemode_option_layout ; 12: switch layout |
2145 return ; catch illegal item number | |
2146 | |
2147 | |
2148 ; item 1: switch to the the "better gas" / "better diluent" | |
2149 ; | |
2150 divemode_option_gaschange: | |
2151 IFDEF _ccr_pscr | |
2152 btfsc FLAG_oc_mode ; in OC mode? | |
2153 bra divemode_option_gaschange_oc ; YES | |
2154 btfsc bailout_mode ; in bailout? | |
2155 bra divemode_option_gaschange_oc ; YES | |
2156 | |
2157 ; in CCR/pSCR mode and not in bailout | |
2158 movff best_dil_number,menu_pos_cur ; select best diluent | |
2159 bcf better_dil_available ; clear flag immediately | |
2160 bra divemode_option_gaschange3 ; continue with common part | |
2161 ENDIF | |
2162 divemode_option_gaschange_oc: | |
2163 movff best_gas_number,menu_pos_cur ; select best gas | |
2164 bcf better_gas_available ; clear better gas cue | |
2165 | |
2166 divemode_option_gaschange3 | |
2167 bsf request_gas_change ; request a gas/diluent change | |
2168 goto menuview_toggle_reset ; terminate the pre-menu (and return) | |
2169 | |
2170 | |
2171 ; item 2: acknowledge current advice, attention, or warning | |
2172 ; | |
2173 divemode_option_ackn: | |
2174 btfss sign_warning ; any warning active? | |
2175 bra divemode_option_ackn_attn ; NO - check for active attentions | |
2176 movff DM_flags_war1_det,DM_flags_war1_ack ; YES - memorize active warnings as acknowledged | |
2177 movff DM_flags_war2_det,DM_flags_war2_ack ; - ... | |
2178 bra divemode_option_ackn_common ; - update screen | |
2179 | |
2180 divemode_option_ackn_attn: | |
2181 btfss sign_attention ; any attention active? | |
2182 bra divemode_option_ackn_advc ; NO - must be active advice then | |
2183 movff DM_flags_att1_det,DM_flags_att1_ack ; YES - memorize active attentions as acknowledged | |
2184 movff DM_flags_att2_det,DM_flags_att2_ack ; - ... | |
2185 movff DM_flags_att3_det,DM_flags_att3_ack ; - ... | |
2186 bra divemode_option_ackn_common ; - update screen | |
2187 | |
2188 divemode_option_ackn_advc: | |
2189 movff DM_flags_advc_det,DM_flags_advc_ack ; memorize active advices as acknowledged | |
2190 ;bra divemode_option_ackn_common ; update screen | |
2191 | |
2192 divemode_option_ackn_common: | |
2193 call menuview_toggle_reset ; terminate pre-menu | |
2194 call divemode_check_sign ; compute if the advice / attention / warning sign shall be shown | |
2195 btfsc FLAG_TFT_sign_show ; shall show the advice / attention / warning sign? | |
2196 goto TFT_divemode_sign_show ; YES - show sign and return | |
2197 goto TFT_divemode_sign_clear ; NO - clear sign and return | |
2198 | |
2199 | |
2200 ; item 3: enter dive mode menu | |
2201 ; | |
2202 divemode_option_divemenu: | |
2203 btfss divemode ; in dive mode? | |
2204 goto menuview_toggle_reset ; NO - block menu, terminate the pre-menu | |
2205 call TFT_clear_divemode_menu ; YES - clear menu area | |
2206 bcf dive_pre_menu ; - set pre-menu as not shown anymore | |
2207 goto do_main_divemenu ; - hand over to menu processor | |
2208 | |
2209 | |
2210 ; item 4: enter cave mode menu | |
2211 ; | |
2212 IFDEF _cave_mode | |
2213 divemode_option_cavemenu: | |
2214 btfss divemode ; in dive mode? | |
2215 goto menuview_toggle_reset ; NO - block menu, terminate the pre-menu | |
2216 call TFT_clear_divemode_menu ; YES - clear menu area | |
2217 bcf dive_pre_menu ; - set pre-menu as not shown anymore | |
2218 goto do_main_cavemenu ; - hand over to menu processor | |
2219 ENDIF | |
2220 | |
2221 | |
2222 ; item 5: quit simulator mode | |
2223 ; | |
2224 divemode_option_sim_quit: | |
2225 clrf simulatormode_depth ; set target depth to zero | |
2226 bsf quit_simulatormode ; request ISR to end simulator mode | |
2227 call menuview_toggle_reset ; terminate the pre-menu | |
2228 btfsc FLAG_apnoe_mode ; in apnoe mode? | |
2229 bcf divemode ; YES - force end of dive mode | |
2230 return ; done | |
2231 | |
2232 | |
2233 ; item 6: simulator mode - descent 1 meter | |
2234 ; | |
2235 divemode_option_sim_down: | |
2236 movlw ostc_depth_max-1 ; load depth limit into WREG | |
2237 cpfsgt simulatormode_depth ; simulated depth < limit ? | |
2238 incf simulatormode_depth,F ; YES - increment simulated depth | |
2239 return ; done | |
2240 | |
2241 | |
2242 ; item 7: simulator mode - ascent 1 meter | |
2243 ; | |
2244 divemode_option_sim_up: | |
2245 tstfsz simulatormode_depth ; simulated depth > 0 ? | |
2246 decf simulatormode_depth,F ; YES - decrement simulated depth | |
2247 return ; done | |
2248 | |
2249 | |
2250 ; item 8: simulator mode - +5 min | |
2251 ; | |
2252 divemode_option_sim_time: | |
2253 movff char_I_sim_advance_time,WREG ; get mailbox content | |
2254 tstfsz WREG ; mailbox clear (=0) ? | |
2255 return ; NO - still having a pending +5' request, refuse new request | |
2256 bra advance_time ; YES - advance time and return | |
2257 | |
2258 | |
2259 ; item 9: quit apnoe dive | |
2260 ; | |
2261 divemode_option_apnoe_quit: | |
2262 btfsc sensor_override_active ; in simulator mode? | |
2263 bra divemode_option_sim_quit ; YES - use simulator quit procedure | |
2264 bcf divemode ; NO - force end of dive mode | |
2265 return ; - done | |
2266 | |
2267 | |
2268 ; item 10: reset stopwatch and avg depth (gauge mode only) | |
2269 ; | |
2270 divemode_option_gauge_reset: | |
2271 bsf request_reset_avg ; request reset of average depth | |
2272 goto menuview_toggle_reset ; terminate pre-menu and return | |
2273 | |
2274 | |
2275 ; item 11: set bearing | |
2276 ; | |
623 | 2277 IFDEF _compass |
634 | 2278 divemode_option_course: |
2279 MOVII compass_heading_shown,compass_bearing | |
2280 bsf compass_bearing_set ; set flag to show heading | |
2281 goto menuview_toggle_reset ; terminate the pre-menu and return | |
623 | 2282 ENDIF |
634 | 2283 |
2284 | |
2285 ; item 12: switch layout | |
2286 ; | |
2287 divemode_option_layout: | |
2288 call menuview_toggle_reset ; terminate the pre-menu | |
2289 call TFT_ClearScreen ; clear the whole screen | |
2290 btg alt_layout_active ; toggle layout | |
2291 | |
2292 bcf depth_color_last ; set warning or attention on the depth not shown | |
2293 bcf depth_inverse_last ; set depth displayed in inverse as not shown | |
2294 bcf sign_shown ; set warning/attention/advice sign not shown | |
2295 bcf velocity_active_num ; set numerical vertical velocity display not shown | |
2296 bcf velocity_active_vsi ; set vertical vertical velocity display not shown | |
2297 bcf safety_stop_active ; set safety stop not shown | |
2298 | |
2299 bsf FLAG_TFT_divemode_mask ; request redraw of dive screen mask | |
2300 bsf FLAG_TFT_divetime ; request redraw of dive time | |
2301 bsf FLAG_TFT_depth_current ; request redraw of current depth | |
2302 bsf FLAG_TFT_depth_maximum ; request redraw of maximum depth | |
2303 bsf FLAG_TFT_active_gas_divemode; request redraw of gas and setpoint | |
2304 bsf FLAG_TFT_temperature ; request redraw of temperature | |
2305 bsf FLAG_TFT_customview_callup ; request redraw of custom view | |
2306 | |
2307 goto request_redraw_NDL_deco_data; request redraw of NDL/deco data and return | |
2308 | |
2309 | |
2310 ;----------------------------------------------------------------------------- | |
2311 ; Helper Function - advance Time by 5 Minutes (Simulator Mode) | |
2312 ; | |
2313 advance_time: | |
2314 ; advance tissues pressures and deco obligation by 5 minutes | |
2315 movlw .5 ; + 5 minutes | |
2316 movff WREG,char_I_sim_advance_time ; copy to mailbox | |
2317 call restart_deco_engine ; condition deco engine to execute the +5 minutes | |
2318 | |
2319 bcf count_divetime ; stop dive time incrementing in ISR | |
2320 ADDLI .5,counted_divetime_mins ; add 5 minutes to counted_divetime_mins | |
2321 ADDLI .300,total_divetime_secs ; add 5 minutes (300 seconds) to total_divetime_secs | |
2322 bsf count_divetime ; continue dive time incrementing in ISR | |
2323 | |
2324 ADDLI .300,divesecs_avg_trip ; add 5 minutes (300 seconds) to resettable time accumulator | |
2325 ADDLI .300,divesecs_avg_total ; add 5 minutes (300 seconds) to total time accumulator | |
2326 | |
2327 MOVII pressure_rel_cur_cached,xB ; calculate 300 x depth in mbar (300 = 5 min * 60 sec/min) | |
2328 MOVLI .300,xA ; ... | |
2329 call mult16x16 ; xC = xA * xB | |
2330 | |
2331 movf xC+0,W ; add to the resettable depth accumulator | |
2332 addwf pressure_rel_accu_trip+0,F ; ... | |
2333 movf xC+1,W ; ... | |
2334 addwfc pressure_rel_accu_trip+1,F ; ... | |
2335 movf xC+2,W ; ... | |
2336 addwfc pressure_rel_accu_trip+2,F ; ... | |
2337 movf xC+3,W ; ... | |
2338 addwfc pressure_rel_accu_trip+3,F ; ... | |
2339 | |
2340 movf xC+0,W ; add to the total depth accumulator | |
2341 addwf pressure_rel_accu_total+0,F ; ... | |
2342 movf xC+1,W ; ... | |
2343 addwfc pressure_rel_accu_total+1,F ; ... | |
2344 movf xC+2,W ; ... | |
2345 addwfc pressure_rel_accu_total+2,F ; ... | |
2346 movf xC+3,W ; ... | |
2347 addwfc pressure_rel_accu_total+3,F ; ... | |
2348 | |
2349 IFDEF _cave_mode | |
2350 ; update backtracking data | |
2351 btfss cave_mode ; cave mode switched on? | |
2352 bra divemode_option_sim_time_exit ; NO - skip backtracking depth recording | |
2353 btfsc dive_turned ; YES - dive turned? | |
2354 bra divemode_option_sim_time_exit ; YES - skip backtracking depth recording | |
2355 ;bra divemode_option_sim_time_exec ; NO - update backtracking depth recording | |
2356 | |
2357 divemode_option_sim_time_exec: | |
2358 movff backtrack_deltatime,hi ; backup time elapsed since last depth recording | |
2359 movlw .5 ; configure 5 minutes | |
2360 movwf lo ; use lo as loop counter | |
2361 | |
2362 divemode_option_sim_time_loop: | |
2363 call write_backtrack_1min_depth ; store a backtracking depth data set | |
2364 btfsc backtrack_entire_full ; backtracking storage entirely used up? | |
2365 bra divemode_option_sim_time_exit ; YES - abort backtracking depth recording | |
2366 decfsz lo,F ; NO - decrement loop counter, did it became zero? | |
2367 bra divemode_option_sim_time_loop ; NO - loop | |
2368 ;bra divemode_option_sim_time_done ; YES - done | |
2369 | |
2370 divemode_option_sim_time_done: | |
2371 movff hi,backtrack_deltatime ; restore time elapsed since last depth recording | |
2372 ENDIF ; _cave_mode | |
2373 | |
2374 divemode_option_sim_time_exit: | |
2375 return ; done (leaving option avail for repeated selection) | |
2376 | |
2377 | |
2378 ;----------------------------------------------------------------------------- | |
2379 ; Change Gas / Diluent | |
2380 ; | |
631 | 2381 gas_switch_common: |
634 | 2382 bcf request_gas_change ; clear request flag |
623 | 2383 IFDEF _ccr_pscr |
634 | 2384 btfss request_back_to_loop ; is a switchback from OC bailout to loop requested? |
2385 bra gas_switched_common0 ; NO - continue with checking if selected gas is valid | |
2386 bcf request_back_to_loop ; YES - clear flag | |
2387 movff active_dil,menu_pos_cur ; - reload last diluent | |
2388 bra gas_switched_common1 ; - continue with common part | |
623 | 2389 ENDIF |
582 | 2390 gas_switched_common0: |
634 | 2391 tstfsz menu_pos_cur ; menu_pos_cur = 0 ? |
2392 bra gas_switched_common1 ; NO - valid gas | |
2393 return ; YES - something went wrong, invalid gas, abort | |
560 | 2394 gas_switched_common1: |
634 | 2395 movf menu_pos_cur,W ; get selected gas into WREG (1-5) |
623 | 2396 IFDEF _ccr_pscr |
634 | 2397 btfsc FLAG_oc_mode ; in OC mode? |
2398 bra gas_switched_common_OC ; YES | |
2399 btfsc bailout_mode ; in bailout? | |
2400 bra gas_switched_common_OC ; YES | |
2401 gas_switched_common_loop: ; NO to both - must be loop mode then | |
2402 call setup_dil_registers ; set up real tissues with WREG = diluent 1-6 | |
2403 call deco_setup_cc_diluents ; set up deco planning with WREG = diluent 1-6 | |
2404 bra gas_switched_common3 ; continue with common part | |
631 | 2405 ENDIF ; _ccr_pscr |
634 | 2406 |
604 | 2407 gas_switched_common_OC: |
634 | 2408 call setup_gas_registers ; set up real tissues with WREG = gas 1-6 |
2409 call deco_setup_oc_gases ; set up deco planning with WREG = gas 1-6 | |
2410 ;bra gas_switched_common3 ; continue with common part | |
2411 | |
560 | 2412 gas_switched_common3: |
605 | 2413 banksel int_O_breathed_ppO2 |
2414 bcf int_O_breathed_ppO2+1,int_low_flag ; | clear all flags that control color-coding | |
2415 bcf int_O_breathed_ppO2+1,int_high_flag ; | to have the new gas initially displayed in | |
2416 bcf int_O_breathed_ppO2+1,int_attention_flag ; | memo color instead of a warning or attention | |
2417 bcf int_O_breathed_ppO2+1,int_warning_flag ; | color that belonged to the previous gas | |
2418 banksel common | |
631 | 2419 bsf FLAG_TFT_active_gas_divemode ; redraw gas/setpoint/diluent |
2420 bsf FLAG_TFT_temperature ; redraw temperature | |
2421 bsf event_occured ; set global event flag | |
623 | 2422 IFDEF _ccr_pscr |
631 | 2423 btfsc bailout_mode ; in bailout mode? |
2424 bsf event_bailout ; YES - set bailout event | |
2425 btfss bailout_mode ; in bailout mode? | |
623 | 2426 ENDIF |
631 | 2427 bsf event_gas_change ; (NO) - set gas change event (normal change) |
2428 goto restart_deco_engine_wo_ceiling ; abort running deco calculations and restart (and return) | |
2429 | |
2430 | |
634 | 2431 ;----------------------------------------------------------------------------- |
2432 ; Reload the current Gas / Diluent | |
2433 ; | |
631 | 2434 gas_update_common: |
2435 bcf request_gas_update ; reset the request flag | |
2436 movf active_gas,W ; load WREG with currently used gas | |
2437 IFDEF _ccr_pscr | |
2438 btfsc FLAG_oc_mode ; in OC mode? | |
2439 bra gas_switched_common_OC ; YES - reload OC gases | |
2440 btfsc bailout_mode ; NO - in bailout? | |
2441 bra gas_switched_common_OC ; YES - reload OC gases | |
2442 movf active_dil,W ; NO - load WREG with currently used diluent | |
2443 bra gas_switched_common_loop ; - set up diluent gases | |
2444 ELSE | |
2445 bra gas_switched_common_OC ; reload OC gases | |
2446 ENDIF | |
560 | 2447 |
634 | 2448 |
2449 ;----------------------------------------------------------------------------- | |
2450 ; Toggle GF/aGF (finalization) | |
2451 ; | |
2452 divemodemode_togglegf: | |
2453 bcf request_toggle_GF ; clear request flag | |
2454 goto restart_deco_engine ; restart the deco engine and return | |
2455 | |
2456 | |
2457 ;----------------------------------------------------------------------------- | |
2458 ; Set a Marker in the Dive Profile | |
2459 ; | |
2460 set_logbook_marker: | |
2461 bcf request_set_marker ; clear request flag | |
2462 movlw d'6' ; set type of alarm: manual marker | |
2463 movwf alarm_type ; copy to alarm register | |
2464 bsf event_occured ; set event flag | |
631 | 2465 return ; done |
0 | 2466 |
634 | 2467 |
2468 ;----------------------------------------------------------------------------- | |
604 | 2469 ; Find the best gas and diluent for the current depth |
2470 ; and check if a gas/diluent change is to be advised. | |
2471 ; | |
2472 ; Output: best_gas_number : number of best gas, 0= none avail, 255= not computed | |
2473 ; best_dil_number : number of best dil, 0= none avail, 255= not computed | |
2474 ; better_gas_available : flag indicating if a change is advised | |
2475 ; better_dil_available : flag indicating if a change is advised | |
2476 ; | |
2477 ; | |
2478 ; in CCR and pSCR mode: - checks both, gases and diluents for respective best gas / best diluent | |
2479 ; - if not in bailout, sets better_dil_available on diluents | |
2480 ; - if in bailout, sets better_gas_available on OC gases | |
2481 ; | |
2482 ; in OC mode : - checks only gases for best gas | |
2483 ; - sets better_gas_available on OC gases | |
0 | 2484 ; |
628 | 2485 global check_gas_best |
604 | 2486 check_gas_best: |
623 | 2487 btfsc FLAG_gauge_mode ; in gauge mode? |
2488 return ; YES - done | |
2489 | |
2490 MOVII pressure_abs_10,xA ; copy absolute pressure / 10 into xA:2, will be used by ppO2 min/max checks later | |
2491 | |
2492 ; compute max. allowed deco ppO2 | |
2493 movff char_I_ppO2_max_deco,WREG ; max ppO2 [cbar] for deco phase | |
2494 mullw .100 ; compute max ppO2 * 100, result is in 0.1 mbar | |
2495 ADDLI ppO2_margin_on_max,PROD ; add ppO2 margin on max value to compensate for surface pressures > 1000 hPa | |
2496 MOVII PROD,ppO2_max_deco ; store as deco ppO2 max | |
2497 | |
2498 ; compute max. allowed default ppO2 | |
604 | 2499 movff char_O_deco_info,lo ; bank-safe copy of deco info vector |
628 | 2500 btfss lo,deco_mode ; is the ppO2 deco limit enabled? |
623 | 2501 bra check_gas_best_1 ; NO - compute default ppO2 max |
2502 MOVII ppO2_max_deco,ppO2_max_default ; YES - copy default ppO2 max from deco max. | |
2503 bra check_gas_best_2 ; - continue with common part | |
2504 | |
2505 check_gas_best_1: | |
2506 movff char_I_ppO2_max_work,WREG ; max ppO2 [cbar] for working phase | |
2507 mullw .100 ; compute max ppO2 * 100, result is in 0.1 mbar | |
2508 ADDLI ppO2_margin_on_max,PROD ; add ppO2 margin on max value to compensate for surface pressures > 1000 hPa | |
2509 MOVII PROD,ppO2_max_default ; store as default ppO2 max | |
2510 | |
2511 check_gas_best_2: | |
2512 | |
2513 IFDEF _ccr_pscr | |
604 | 2514 ; check dive mode |
2515 btfsc FLAG_oc_mode ; in OC mode? | |
2516 bra check_gas_best_gas ; YES - skip diluents, check for best gas only | |
2517 | |
2518 check_gas_best_dil: | |
2519 ; set minimum ppO2 required | |
2520 movff char_I_ppO2_min,WREG ; min ppO2 for pure diluent in CCR mode (default) | |
2521 btfsc FLAG_pscr_mode ; in pSCR mode? | |
623 | 2522 movff char_I_ppO2_min_loop,WREG ; YES - replace by min ppO2 for pure diluent in pSCR mode |
2523 mullw .100 ; min ppO2 * 100, result in 0.1 mbar | |
2524 MOVII PROD,ppO2_min ; store in ppO2_min | |
631 | 2525 ; check diluents |
604 | 2526 lfsr FSR1,opt_dil_O2_ratio ; set base address for diluent arrays |
631 | 2527 movff active_dil,lo ; set number of currently used diluent |
2528 ; preset result to nothing found | |
2529 clrf best_gas_num ; initialize best diluent to 0 = none found yet | |
2530 setf best_gas_depth ; initialize change depth to 255 = any one will be better | |
2531 ; check if current diluent is usable | |
2532 movff lo,check_gas_num ; check if the current diluent is usable | |
2533 rcall check_gas_best_common ; if yes, the current diluent will become the best diluent found so far | |
2534 rcall check_gas_best_all ; check if any other diluent is better | |
604 | 2535 ; store result |
2536 movff best_gas_num,best_dil_number ; store new best diluent found (1-5 or 0 of no usable diluent available) | |
2537 ; check if change advices shall be given in general | |
623 | 2538 btfsc bailout_mode ; in bailout? |
604 | 2539 bra check_gas_best_gas ; YES - no better diluent advice when in bailout |
2540 check_gas_best_dil1: | |
2541 ; check if a change advice shall be given right now | |
631 | 2542 bcf better_dil_available ; default to no better diluent found |
604 | 2543 movf best_dil_number,W ; load number of best diluent into WREG (1-5) |
2544 bz check_gas_best_dil3 ; has a best diluent been found at all? NO - nothing to signal for | |
2545 cpfseq active_dil ; is this the currently used diluent? | |
631 | 2546 bra check_gas_best_dil2 ; NO - a better diluent has been found |
604 | 2547 bra check_gas_best_dil3 ; YES - no need to signal a better diluent if this diluent is already in use |
2548 check_gas_best_dil2: | |
634 | 2549 btfsc warn_det_sensors_lost ; all sensors lost? |
604 | 2550 bra check_gas_best_dil3 ; YES - suppress better diluent prompt in this case |
2551 ; not using the best gas - show better diluent hint whenever a better diluent is available | |
2552 bsf better_dil_available ; signal that a better diluent is available | |
2553 bsf FLAG_TFT_active_gas_divemode ; redraw gas/setpoint/diluent | |
2554 check_gas_best_dil3: | |
2555 btfss better_dil_available ; shall a better diluent be signaled for? | |
623 | 2556 bcf better_dil_blinking ; NO - clear blinking flag |
631 | 2557 ;bra check_gas_best_gas ; ; continue with checking for best bailout gas |
623 | 2558 ENDIF ; _ccr_pscr |
2559 | |
631 | 2560 |
604 | 2561 check_gas_best_gas: |
2562 ; set minimum ppO2 required | |
628 | 2563 movff char_I_ppO2_min,WREG ; min ppO2 for OC and bailout |
623 | 2564 mullw .100 ; min ppO2 * 100, result in 0.1 mbar |
2565 MOVII PROD,ppO2_min ; store in ppO2_min | |
631 | 2566 ; check gases |
604 | 2567 lfsr FSR1,opt_gas_O2_ratio ; set base address for gas arrays |
631 | 2568 movff active_gas,lo ; set number of currently used gas |
2569 ; preset result to nothing found | |
2570 clrf best_gas_num ; initialize best gas to 0 = none found yet | |
2571 setf best_gas_depth ; initialize change depth to 255 = any one will be better | |
2572 ; check if current gas is usable | |
2573 movff lo,check_gas_num ; check if the current gas is usable | |
2574 rcall check_gas_best_common ; if yes, the current gas will become the best gas found so far | |
2575 rcall check_gas_best_all ; check if any other gas is better | |
604 | 2576 ; store result |
2577 movff best_gas_num,best_gas_number ; store new best gas found (1-5 or 0 of no usable gas available) | |
631 | 2578 IFDEF _ccr_pscr |
604 | 2579 ; check if change advices shall be given in general |
2580 btfsc FLAG_oc_mode ; in OC mode? | |
631 | 2581 bra check_gas_best_gas1 ; YES - give advice |
2582 btfsc bailout_mode ; NO - in bailout? | |
2583 bra check_gas_best_gas1 ; YES - give advice | |
2584 return ; NO - no better (OC) gas advice when not in OC or bailout mode | |
2585 ENDIF ; _ccr_pscr | |
604 | 2586 check_gas_best_gas1: ; check if we are already on the best gas |
2587 ; check if a change advice shall be given right now | |
631 | 2588 bcf better_gas_available ; default to no better gas found |
604 | 2589 movf best_gas_number,W ; load number of best gas into WREG (1-5) |
2590 bz check_gas_best_gas3 ; has a best gas been found at all? NO - nothing to signal for | |
2591 cpfseq active_gas ; is this the currently used gas? | |
631 | 2592 bra check_gas_best_gas2 ; NO - a better gas has been found |
604 | 2593 bra check_gas_best_gas3 ; YES - no need to signal a better gas if this gas is already in use |
2594 check_gas_best_gas2: | |
2595 ; not using the best gas - show better gas hint whenever a better gas is available | |
2596 bsf better_gas_available ; YES - signal that a better gas is available | |
2597 bsf FLAG_TFT_active_gas_divemode ; YES - redraw gas/setpoint/diluent | |
2598 check_gas_best_gas3: | |
2599 btfss better_gas_available ; shall a better gas be signaled for? | |
623 | 2600 bcf better_gas_blinking ; NO - clear blinking flag |
582 | 2601 return |
0 | 2602 |
631 | 2603 |
2604 check_gas_best_all: | |
2605 clrf check_gas_num ; increment comes first, so initialize with zero | |
2606 check_gas_best_loop: | |
2607 incf check_gas_num,F ; increment number of gas to check | |
2608 movf lo,W ; copy number of currently used gas to WREG | |
2609 cpfseq check_gas_num ; gas to be checked = currently used gas ? | |
2610 rcall check_gas_best_common ; NO - check the gas | |
2611 movlw NUM_GAS ; get total number of gases | |
2612 cpfseq check_gas_num ; reached last gas? | |
2613 bra check_gas_best_loop ; NO - loop | |
2614 return ; YES - done | |
2615 | |
2616 | |
604 | 2617 check_gas_best_common: ; with gas to be checked in check_gas_num (1-5) |
634 | 2618 ; and current gas in lo (1-5) |
604 | 2619 ; |
2620 ; Memory Map: | |
2621 ; --------------------------------------------------------------------------------------- | |
2622 ; opt_gas_O2_ratio res 5 ; base address for gases | |
2623 ; opt_dil_O2_ratio res 5 ; base address for diluents | |
2624 ; opt_gas_He_ratio res 5 ; (not needed here) | |
2625 ; opt_dil_He_ratio res 5 ; (not needed here) | |
2626 ; opt_gas_type res 5 ; has offset of 20 bytes from base address for gases | |
2627 ; opt_dil_type res 5 ; has offset of 20 bytes from base address for diluents | |
2628 ; opt_gas_change res 5 ; has offset of 10 bytes from opt_gas_type | |
2629 ; opt_dil_change res 5 ; has offset of 10 bytes from opt_dil_type | |
2630 | |
2631 ; get gas data | |
2632 decf check_gas_num,W ; (1-5) -> (0-4) into WREG to be used as index | |
623 | 2633 movff PLUSW1,check_gas_O2_ratio ; copy O2 ratio (%) of current gas/dil to check_gas_O2_ratio |
604 | 2634 addlw .20 ; add offset of 20 bytes to index type in opt_gas_type/opt_dil_type |
623 | 2635 movff PLUSW1,check_gas_type ; copy type of current gas/dil to check_gas_type (0=disabled, 1=first, 2=travel/normal, 3=deco/-) |
604 | 2636 addlw .10 ; add offset of 10 bytes to index change depth in opt_gas_change/opt_dil_change |
623 | 2637 movff PLUSW1,check_gas_depth ; copy change depth of current gas/dil to check_gas_depth |
2638 MOVII ppO2_max_default,sub_b ; select default ppO2 max for first / travel / normal gas | |
628 | 2639 ; check if the gas is the current gas |
2640 movf check_gas_num,W ; get the number of the gas to be checked (1-5) | |
2641 cpfseq lo ; is this the currently used gas? | |
2642 bra check_gas_best_common0 ; NO - do the disabled & deco gas checks | |
2643 bra check_gas_best_common3 ; YES - a gas in use overrides disabled and deco status | |
2644 check_gas_best_common0: | |
623 | 2645 ; check if gas is available (i.e. not disabled) |
631 | 2646 btfsc check_gas_type,gas_lost ; gas/dil lost? |
2647 return ; YES - skip as not available any more | |
2648 btfsc check_gas_type,gas_staged ; gas/dil staged? | |
2649 return ; YES - skip as currently not available | |
623 | 2650 tstfsz check_gas_type ; type = disabled (0) ? |
2651 bra check_gas_best_common1 ; NO - continue checks | |
631 | 2652 return ; YES - skip as not available at all |
623 | 2653 check_gas_best_common1: |
2654 ; skip deco gases (type=3) if there are no stops, but include them when in bailout mode | |
2655 movlw .3 ; coding for deco gas | |
2656 cpfseq check_gas_type ; type = deco (3) ? | |
2657 bra check_gas_best_common3 ; NO - first or travel/normal then, ok to use | |
631 | 2658 IFDEF _ccr_pscr |
623 | 2659 btfsc bailout_mode ; YES - in bailout? |
2660 bra check_gas_best_common2 ; YES - ok to use (using deco gases is always allowed when in bailout) | |
631 | 2661 ENDIF |
2662 TSTOSS opt_ext_stops ; NO - extended stops enabled? | |
2663 bra check_gas_best_common1b ; NO - only ok if in deco region | |
2664 ;bra check_gas_best_common1a ; YES - only ok if in deco mode | |
623 | 2665 check_gas_best_common1a: |
628 | 2666 movff char_O_deco_info,WREG ; get deco info vector |
2667 btfss WREG,deco_mode ; are we in deco mode? | |
2668 return ; NO - skip deco gas while not in deco mode | |
2669 bra check_gas_best_common2 ; YES - deco gases allowed | |
2670 check_gas_best_common1b: | |
2671 btfss deco_region ; are we in the deco region? | |
2672 return ; NO - skip deco gas while not in the deco region | |
2673 ;bra check_gas_best_common2 ; YES - deco gases allowed | |
623 | 2674 check_gas_best_common2: |
2675 MOVII ppO2_max_deco,sub_b ; replace by ppO2 max for a deco gas | |
2676 check_gas_best_common3: | |
604 | 2677 ; check if gas is usable, i.e. its change depth is below or equal to the current depth |
623 | 2678 movf depth_meter,W ; load current depth (in m) into WREG |
604 | 2679 cpfslt check_gas_depth ; change depth of checked gas < (shallower than) current depth? |
623 | 2680 bra check_gas_best_common4 ; NO - gas is usable |
604 | 2681 return ; YES - gas is not usable |
623 | 2682 check_gas_best_common4: |
604 | 2683 ; check if this gas is the first best gas candidate |
2684 movf best_gas_num,W ; get best gas found so far (1-5) or 0 if none found yet | |
2685 tstfsz WREG ; has a best gas candidate been found yet? | |
623 | 2686 bra check_gas_best_common5 ; YES - check if the new one is better than the one we have so far |
2687 bra check_gas_best_common6 ; NO - no need to do the above mentioned check | |
2688 check_gas_best_common5: | |
631 | 2689 ; check if the change depth of the checked gas is < (shallower) than the change depth of the best gas found so far |
604 | 2690 movf best_gas_depth,W ; load change depth of best gas so far into WREG |
631 | 2691 cpfslt check_gas_depth ; change depth of checked gas < (shallower than) change depth of best gas so far? |
2692 return ; NO - this gas is not better than the best already found | |
2693 ;bra check_gas_best_common6 ; YES - this gas is better, continue | |
623 | 2694 check_gas_best_common6: |
604 | 2695 ; check if the gas fits into the ppO2 limits |
623 | 2696 movff check_gas_O2_ratio,xB+0 ; xB = O2 ratio, xA is still loaded with (absolute pressure / 10) |
69 | 2697 clrf xB+1 |
623 | 2698 call mult16x16 ; xC = O2 ratio * (absolute pressure / 10), result in 0.1 mbar |
604 | 2699 ; check for very high ppO2 |
623 | 2700 tstfsz xC+2 ; O2_ratio * absolute pressure / 10 > 65536, i.e. ppO2 > 6.55 bar ? |
604 | 2701 return ; YES - gas is not usable |
623 | 2702 btfsc xC+1,7 ; ppO2 > 3.30 bar ? |
604 | 2703 return ; YES - gas is not usable |
623 | 2704 MOVII xC,sub_a ; NO - gas may be usable |
2705 ; check for high ppO2 | |
2706 call cmpU16 ; sub_a - sub_b | |
2707 btfss neg_flag ; within limit? | |
2708 return ; NO - too high, gas is not usable | |
604 | 2709 ; check for low ppO2 |
623 | 2710 MOVII ppO2_min,sub_b ; copy minimum ppO2 to sub_b |
2711 call cmpU16 ; sub_a - sub_b | |
604 | 2712 btfsc neg_flag ; within limit? |
2713 return ; NO - too low, gas is not usable | |
2714 ; we have a (new) best gas | |
631 | 2715 movff check_gas_num, best_gas_num ; YES - set checked gas (1-5) as best gas |
2716 movff check_gas_depth,best_gas_depth ; - memorize its change depth | |
2717 return ; - done | |
0 | 2718 |
634 | 2719 IFDEF _ccr_pscr |
2720 | |
2721 | |
2722 ;----------------------------------------------------------------------------- | |
338
2811932b4e99
NEW: Mode Auto SP: Automatically switches the SP during descent (CC Mode)
heinrichsweikamp
parents:
337
diff
changeset
|
2723 ; Check for Auto-SP |
2811932b4e99
NEW: Mode Auto SP: Automatically switches the SP during descent (CC Mode)
heinrichsweikamp
parents:
337
diff
changeset
|
2724 ; |
634 | 2725 check_dive_autosp: |
640 | 2726 movf dive_ccr_mode,W ; =0: Fixed SP, =1: Sensor, =2: Auto SP |
2727 sublw .2 ; dive_ccr_mode = 2 (Auto SP)? | |
604 | 2728 bz check_dive_autosp2 ; YES - check |
2729 return ; NO - return for sensor or fixed mode | |
634 | 2730 |
338
2811932b4e99
NEW: Mode Auto SP: Automatically switches the SP during descent (CC Mode)
heinrichsweikamp
parents:
337
diff
changeset
|
2731 check_dive_autosp2: |
640 | 2732 ; check for restart request |
2733 btfss restart_auto_sp ; shall restart from 1st SP? | |
2734 bra check_dive_autosp2a ; NO - skip next | |
2735 bcf restart_auto_sp ; YES - clear request flag | |
2736 bcf FLAG_SP2_used ; - flag SP 2, ... | |
2737 bcf FLAG_SP3_used ; - flag SP 3, ... | |
2738 bcf FLAG_SP4_used ; - flag SP 4, ... | |
2739 bcf FLAG_SP5_used ; - flag SP 5 as unused so far | |
2740 | |
2741 check_dive_autosp2a: | |
631 | 2742 ; check SP2 |
623 | 2743 btfsc FLAG_SP2_used ; SP 2 used so far? |
604 | 2744 bra check_dive_autosp3 ; YES - continue with SP 3 |
623 | 2745 movff opt_setpoint_change+1,lo ; NO - get depth in m |
604 | 2746 tstfsz lo ; - SP change depth = 0 ? |
640 | 2747 bra check_dive_autosp2b ; NO - continue |
604 | 2748 bra check_dive_autosp3 ; YES - continue with SP 3 |
640 | 2749 check_dive_autosp2b: |
604 | 2750 decf lo,W ; SP change depth -1 -> WREG |
623 | 2751 cpfsgt depth_meter ; current depth > change depth - 1 ? |
604 | 2752 bra check_dive_autosp3 ; NO - continue with SP 3 |
582 | 2753 ; auto switch to SP2 |
623 | 2754 movff opt_setpoint_cbar+1,char_I_const_ppO2 ; YES - use SP |
604 | 2755 rcall xmit_sp_set_flag ; - send SP to external devices |
623 | 2756 bsf FLAG_SP2_used ; - set SP 2 used flag |
634 | 2757 |
338
2811932b4e99
NEW: Mode Auto SP: Automatically switches the SP during descent (CC Mode)
heinrichsweikamp
parents:
337
diff
changeset
|
2758 check_dive_autosp3: |
631 | 2759 ; check SP3 |
623 | 2760 btfsc FLAG_SP3_used ; SP 3 used so far? |
604 | 2761 bra check_dive_autosp4 ; YES - continue with SP 4 |
623 | 2762 movff opt_setpoint_change+2,lo ; NO - get depth in m |
604 | 2763 tstfsz lo ; - SP change depth = 0 ? |
2764 bra check_dive_autosp3a ; NO - continue | |
2765 bra check_dive_autosp4 ; YES - continue with SP 4 | |
560 | 2766 check_dive_autosp3a: |
604 | 2767 decf lo,W ; SP change depth -1 -> WREG |
623 | 2768 cpfsgt depth_meter ; current depth > change depth - 1 ? |
604 | 2769 bra check_dive_autosp4 ; NO - continue with SP 4 |
582 | 2770 ; auto switch to SP3 |
623 | 2771 movff opt_setpoint_cbar+2,char_I_const_ppO2 ; YES - use SP |
604 | 2772 rcall xmit_sp_set_flag ; - send SP to external devices |
623 | 2773 bsf FLAG_SP3_used ; - set SP 3 used flag |
634 | 2774 |
338
2811932b4e99
NEW: Mode Auto SP: Automatically switches the SP during descent (CC Mode)
heinrichsweikamp
parents:
337
diff
changeset
|
2775 check_dive_autosp4: |
631 | 2776 ; check SP4 |
623 | 2777 btfsc FLAG_SP4_used ; SP 4 used so far? |
604 | 2778 bra check_dive_autosp5 ; YES - continue with SP 5 |
623 | 2779 movff opt_setpoint_change+3,lo ; NO - get depth in m |
604 | 2780 tstfsz lo ; - SP change depth = 0 ? |
2781 bra check_dive_autosp4a ; NO - continue | |
623 | 2782 bra check_dive_autosp5 ; YES - continue with SP 5 |
560 | 2783 check_dive_autosp4a: |
604 | 2784 decf lo,W ; SP change depth -1 -> WREG |
623 | 2785 cpfsgt depth_meter ; current depth > change depth - 1 ? |
604 | 2786 bra check_dive_autosp5 ; NO - continue with SP 5 |
582 | 2787 ; auto switch to SP4 |
623 | 2788 movff opt_setpoint_cbar+3,char_I_const_ppO2 ; YES - use SP |
604 | 2789 rcall xmit_sp_set_flag ; - send SP to external devices |
623 | 2790 bsf FLAG_SP4_used ; - set SP 4 used flag |
634 | 2791 |
338
2811932b4e99
NEW: Mode Auto SP: Automatically switches the SP during descent (CC Mode)
heinrichsweikamp
parents:
337
diff
changeset
|
2792 check_dive_autosp5: |
631 | 2793 ; check SP5 |
623 | 2794 btfsc FLAG_SP5_used ; SP 5 used so far? |
604 | 2795 bra check_dive_autosp6 ; YES - done |
623 | 2796 movff opt_setpoint_change+4,lo ; NO - get depth in m |
604 | 2797 tstfsz lo ; - SP change depth = 0 ? |
2798 bra check_dive_autosp5a ; NO - continue | |
2799 bra check_dive_autosp6 ; YES - done | |
560 | 2800 check_dive_autosp5a: |
604 | 2801 decf lo,W ; SP change depth -1 -> WREG |
623 | 2802 cpfsgt depth_meter ; current depth > change depth - 1 ? |
604 | 2803 bra check_dive_autosp6 ; NO - done |
582 | 2804 ; auto switch to SP5 |
623 | 2805 movff opt_setpoint_cbar+4,char_I_const_ppO2 ; YES - use SP |
604 | 2806 rcall xmit_sp_set_flag ; - send SP to external devices |
623 | 2807 bsf FLAG_SP5_used ; - set SP 5 used flag |
634 | 2808 |
352
5c6da9fa5cb0
add setpoint change to first sample in CCR mode
heinrichsweikamp
parents:
339
diff
changeset
|
2809 check_dive_autosp6: |
634 | 2810 return ; done |
2811 | |
2812 | |
2813 ;----------------------------------------------------------------------------- | |
2814 ; Helper Function - transmit new Setpoint to external Electronics and flag Change | |
2815 ; | |
352
5c6da9fa5cb0
add setpoint change to first sample in CCR mode
heinrichsweikamp
parents:
339
diff
changeset
|
2816 xmit_sp_set_flag: |
623 | 2817 IFDEF _external_sensor |
604 | 2818 call transmit_setpoint ; transmit current setpoint from WREG (in cbar) to external electronics |
623 | 2819 ENDIF |
2820 bsf event_occured ; set global event flag | |
2821 bsf event_SP_change ; set setpoint event flag | |
582 | 2822 return |
2823 | |
623 | 2824 ENDIF ; _ccr_pscr |
2825 | |
338
2811932b4e99
NEW: Mode Auto SP: Automatically switches the SP during descent (CC Mode)
heinrichsweikamp
parents:
337
diff
changeset
|
2826 |
0 | 2827 ;============================================================================= |
634 | 2828 dmode2 CODE |
2829 ;============================================================================= | |
2830 | |
2831 | |
2832 ;----------------------------------------------------------------------------- | |
2833 ; Setup everything to enter OC Dive Mode | |
0 | 2834 ; |
604 | 2835 global dive_boot_oc |
0 | 2836 dive_boot_oc: |
631 | 2837 rcall get_first_gas_to_WREG ; get first gas (1-5) into WREG |
2838 rcall setup_gas_registers ; set-up of gas parameters of currently breathed gas (with WREG = gas 1-5) | |
2839 rcall deco_setup_oc_gases ; set-up of gas list for deco calculations (with WREG = gas 1-5) | |
634 | 2840 return ; done |
2841 | |
2842 | |
2843 ;----------------------------------------------------------------------------- | |
2844 ; Helper Function - get first Gas (1-5) into WREG | |
2845 ; | |
2846 global get_first_gas_to_WREG | |
2847 get_first_gas_to_WREG: | |
2848 lfsr FSR1,opt_gas_type ; load base address of the gas types | |
2849 clrf lo ; start with gas 0 | |
2850 get_first_gas_to_WREG2: | |
2851 movf lo,W ; set index | |
2852 movf PLUSW1,W ; get type of gas (0=Disabled, 1=First, 2=Travel, 3=Deco) | |
2853 sublw .1 ; is it of type First? | |
2854 bz get_first_gas_to_WREG3 ; YES - found the First gas | |
2855 incf lo,F ; NO - increment index | |
2856 movlw NUM_GAS+1 ; - get highest index+1 | |
2857 cpfseq lo ; - all gases checked? | |
2858 bra get_first_gas_to_WREG2 ; NO - not yet | |
2859 movlw .1 ; YES - default to gas 1 | |
2860 movff WREG,opt_gas_type+0 ; - force it to be of type First | |
2861 return ; - done | |
2862 get_first_gas_to_WREG3: | |
2863 movf lo,W ; copy index of gas found to be the First to WREG | |
2864 incf WREG,W ; turn index into gas number (0-4 -> 1-5) | |
2865 return ; done | |
2866 | |
2867 | |
2868 ;----------------------------------------------------------------------------- | |
2869 ; Helper Function - load currently breathed Gas into Deco Engine | |
2870 ; | |
2871 global setup_gas_registers | |
2872 setup_gas_registers: | |
2873 movwf active_gas ; set as current gas | |
2874 movlw .6 ; gas = gas6 ? | |
2875 cpfseq active_gas ; ... | |
2876 bra setup_gas_registers_15 ; NO - load gas 1-5 | |
2877 | |
2878 ; load gas 6 | |
2879 movff opt_gas6_O2_ratio,char_I_O2_ratio ; copy gas6 O2 ratio to deco engine | |
2880 IFDEF _helium | |
2881 movff opt_gas6_He_ratio,char_I_He_ratio ; copy gas6 H2 ratio to deco engine | |
2882 ENDIF | |
2883 movlw .3 ; declare gas6 as a deco gas | |
2884 movff WREG,char_I_current_gas_type ; copy gas type to deco engine | |
2885 movff depth_meter,char_I_gas6_depth ;set current depth as change depth | |
2886 bra setup_gas_registers_com ; continue with common part | |
2887 | |
2888 setup_gas_registers_15: | |
2889 lfsr FSR1,opt_gas_O2_ratio ; load base address of gas data | |
2890 decf active_gas,W ; set index to O2 ratio of current gas (1-5 -> 0-4) | |
2891 movff PLUSW1,char_I_O2_ratio ; copy O2 ratio to deco engine | |
2892 addlw .10 ; advance index from O2 ratio to He ratio | |
2893 IFDEF _helium | |
2894 movff PLUSW1,char_I_He_ratio ; copy He ratio to deco engine | |
2895 ENDIF | |
2896 addlw .10 ; advance index from He ratio to gas type | |
2897 movff PLUSW1,char_I_current_gas_type ; copy gas type (0=Disabled, 1=First, 2=Travel, 3=Deco) | |
2898 setup_gas_registers_com: | |
2899 movff char_O_main_status,lo ; working copy of char_O_main_status in bank common | |
2900 bcf lo,DECO_MODE_PSCR_FLAG ; clear the pSCR-mode flag (if applicable) | |
2901 bcf lo,DECO_MODE_LOOP_FLAG ; clear the loop/CCR-mode flag | |
2902 movff lo,char_O_main_status ; bank safe write-back of char_O_main_status | |
2903 movf active_gas,W ; reload WREG with gas 1-5 or 6 (important!) | |
2904 return ; done | |
2905 | |
2906 | |
2907 ;----------------------------------------------------------------------------- | |
2908 ; Helper Function - load OC Gases into Deco Engine (currently breathed gas in WREG) | |
2909 ; | |
2910 global deco_setup_oc_gases | |
2911 deco_setup_oc_gases: | |
2912 movff char_O_deco_status,lo ; get working copy of char_O_deco_status in bank common | |
2913 deco_setup_oc_gases_pre: ; entry point with lo preloaded | |
2914 movff WREG,char_I_current_gas_num ; set gas to start with when doing the deco calculations | |
2915 ; | |
2916 ; Memory Map: | |
2917 ; --------------------------------------------------------------------------------- | |
2918 ; opt_gas_O2_ratio res NUM_GAS | char_I_deco_O2_ratio res NUM_GAS | |
2919 ; opt_dil_O2_ratio res NUM_GAS | | |
2920 ; opt_gas_He_ratio res NUM_GAS | char_I_deco_He_ratio res NUM_GAS | |
2921 ; opt_dil_He_ratio res NUM_GAS | | |
2922 ; opt_gas_type res NUM_GAS | char_I_deco_gas_type res NUM_GAS | |
2923 ; opt_dil_type res NUM_GAS | | |
2924 ; opt_gas_change res NUM_GAS | char_I_deco_gas_change res NUM_GAS | |
2925 ; opt_dil_change res NUM_GAS | | |
2926 ; | |
2927 lfsr FSR2,char_I_deco_O2_ratio ; load FSR2 with base address of char_I_deco_O2_ratio | |
2928 ; FSR2 will step through all char_I_deco_... vars | |
2929 lfsr FSR1,opt_gas_O2_ratio ; load FSR1 with base address of opt_gas_O2_ratio | |
2930 rcall deco_setup_copy ; copy all OC O2 ratios | |
2931 lfsr FSR1,opt_gas_He_ratio ; load FSR1 with base address of opt_gas_He_ratio | |
2932 rcall deco_setup_copy ; copy all OC He ratios | |
2933 lfsr FSR1,opt_gas_type ; load FSR1 with base address of opt_gas_type | |
2934 rcall deco_setup_copy ; copy all gas types | |
2935 lfsr FSR1,opt_gas_change ; load FSR1 with base address of opt_gas_change | |
2936 rcall deco_setup_copy ; copy all gas change depths | |
2937 | |
2938 ; switch deco engine to oc mode | |
2939 bcf lo,DECO_MODE_PSCR_FLAG ; clear the pSCR-mode flag (may not be set, but never mind) | |
2940 bcf lo,DECO_MODE_LOOP_FLAG ; clear the loop/CCR-mode flag | |
2941 movff lo,char_O_deco_status ; bank safe write-back of char_O_deco_status | |
2942 return ; done | |
2943 | |
2944 | |
2945 ;----------------------------------------------------------------------------- | |
2946 ; Helper Function - dedicated Memory Copy | |
2947 deco_setup_copy: | |
2948 movlw NUM_GAS ; load loop counter with number of gases (5) | |
2949 deco_setup_copy_loop: | |
2950 movff POSTINC1,POSTINC2 ; copy from (FSR1) to (FSR2) | |
2951 decfsz WREG ; decrement loop counter and check if it became 0 | |
2952 bra deco_setup_copy_loop ; NO - not yet, loop | |
2953 return ; YES - done | |
2954 | |
0 | 2955 |
623 | 2956 |
2957 IFDEF _ccr_pscr | |
2958 | |
634 | 2959 ;----------------------------------------------------------------------------- |
2960 ; Setup everything to enter CCR/pSCR Dive Mode - Part 1 | |
2961 ; | |
604 | 2962 global dive_boot_cc |
0 | 2963 dive_boot_cc: |
631 | 2964 rcall get_first_dil_to_WREG ; get first diluent (1-5) into WREG |
2965 rcall setup_dil_registers ; set-up of diluent parameters for currently breathed diluent (with WREG = current diluent 1-5) | |
2966 rcall deco_setup_cc_diluents ; set-up of diluent list for deco calculations (with WREG = current diluent 1-5) | |
634 | 2967 return ; done |
2968 | |
2969 | |
2970 ;----------------------------------------------------------------------------- | |
2971 ; Helper Function - get first Diluent (1-5) into WREG | |
2972 ; | |
2973 global get_first_dil_to_WREG | |
2974 get_first_dil_to_WREG: ; gets first dil (1-5) into WREG | |
2975 lfsr FSR1,opt_dil_type ; load base address of the dil types | |
2976 clrf lo ; start with dil 0 | |
2977 get_first_dil_to_WREG2: | |
2978 movf lo,W ; set index | |
2979 movf PLUSW1,W ; get type of Dil (0=Disabled, 1=First, 2=Normal) | |
2980 sublw .1 ; is it of type First? | |
2981 bz get_first_dil_to_WREG3 ; YES - found the First dil | |
2982 incf lo,F ; NO - increment index | |
2983 movlw NUM_GAS+1 ; - get highest index+1 | |
2984 cpfseq lo ; - dils checked? | |
2985 bra get_first_dil_to_WREG2 ; NO - not yet | |
2986 movlw .1 ; YES - default to dil 1 | |
2987 movff WREG,opt_dil_type+0 ; - force it to be of type First | |
2988 return ; - done | |
2989 get_first_dil_to_WREG3: | |
2990 movf lo,W ; copy index of dil found to be the First to WREG | |
2991 incf WREG,W ; turn index into dil number (0-4 -> 1-5) | |
2992 return ; done | |
2993 | |
2994 | |
2995 ;----------------------------------------------------------------------------- | |
2996 ; Helper Function - load currently breathed Diluent into Deco Engine | |
2997 ; | |
2998 global setup_dil_registers | |
2999 setup_dil_registers: | |
3000 btfsc bailout_mode ; check if in bailout condition | --------------- FOR SAFETY ONLY -------------- | |
3001 bra setup_gas_registers ; revert to setting up OC gases in bailout condition | This branch should never happen to be taken... | |
3002 movwf active_dil ; set as current diluent | |
3003 movlw .6 ; diluent = gas6 ? | |
3004 cpfseq active_dil ; ... | |
3005 bra setup_dil_registers_15 ; NO - load diluent 1-5 | |
3006 | |
3007 ; load gas 6 | |
3008 movff opt_gas6_O2_ratio,char_I_O2_ratio ; copy gas6 O2 ratio to deco engine | |
3009 IFDEF _helium | |
3010 movff opt_gas6_He_ratio,char_I_He_ratio ; copy gas6 He ratio to deco engine | |
3011 ENDIF | |
3012 movlw .2 ; declare gas6 as a normal diluent | |
3013 movff WREG,char_I_current_gas_type ; copy gas type to deco engine | |
3014 movff depth_meter,char_I_gas6_depth ;set current depth as change depth | |
3015 bra setup_dil_registers_com ; continue with common part | |
3016 | |
3017 setup_dil_registers_15: | |
3018 lfsr FSR1,opt_dil_O2_ratio ; load base address of diluent data | |
3019 decf active_dil,W ; set index to O2 ratio of current diluent (1-5 -> 0-4) | |
3020 movff PLUSW1,char_I_O2_ratio ; copy O2 ratio to deco engine | |
3021 addlw .10 ; advance index from O2 ratio to He ratio | |
3022 IFDEF _helium | |
3023 movff PLUSW1,char_I_He_ratio ; copy He ratio to deco engine | |
3024 ENDIF | |
3025 addlw .10 ; advance index from He ratio to diluent type | |
3026 movff PLUSW1,char_I_current_gas_type ; copy diluent type (0=Disabled, 1=First, 2=Normal) | |
3027 setup_dil_registers_com: | |
3028 movff char_O_main_status,lo ; working copy of char_O_main_status in bank common | |
3029 bsf lo,DECO_MODE_LOOP_FLAG ; loop flag is set in both, CCR and pSCR mode | |
3030 bcf lo,DECO_MODE_PSCR_FLAG ; clear pSCR mode flag by default | |
3031 btfsc FLAG_pscr_mode ; check if we are in pSCR mode | |
3032 bsf lo,DECO_MODE_PSCR_FLAG ; YES - set additional flag for pSCR mode | |
3033 movff lo,char_O_main_status ; bank safe write-back of char_O_main_status | |
3034 movf active_dil,W ; reload WREG with diluent 1-5 or 6 (important!) | |
3035 return ; done | |
3036 | |
3037 | |
3038 ;----------------------------------------------------------------------------- | |
3039 ; Helper Function - load Diluents into Deco Engine (currently breathed dil in WREG) | |
3040 ; | |
3041 global deco_setup_cc_diluents | |
3042 deco_setup_cc_diluents: | |
3043 movff char_O_deco_status,lo ; working copy of char_O_deco_status in bank common | |
3044 deco_setup_cc_diluents_pre: ; entry point with lo preloaded | |
3045 btfsc bailout_mode ; check if in bailout condition | --------------- FOR SAFETY ONLY -------------- | |
3046 bra deco_setup_oc_gases_pre ; YES - revert to setting up OC gases | This branch should never happen to be taken... | |
3047 movff WREG,char_I_current_gas_num ; NO - set diluent to start with when doing the deco calculations | |
3048 ; | |
3049 ; Memory Map: | |
3050 ; --------------------------------------------------------------------------------- | |
3051 ; opt_gas_O2_ratio res NUM_GAS | | |
3052 ; opt_dil_O2_ratio res NUM_GAS | char_I_deco_O2_ratio res NUM_GAS | |
3053 ; opt_gas_He_ratio res NUM_GAS | | |
3054 ; opt_dil_He_ratio res NUM_GAS | char_I_deco_He_ratio res NUM_GAS | |
3055 ; opt_gas_type res NUM_GAS | | |
3056 ; opt_dil_type res NUM_GAS | char_I_deco_gas_type res NUM_GAS | |
3057 ; opt_gas_change res NUM_GAS | | |
3058 ; opt_dil_change res NUM_GAS | char_I_deco_gas_change res NUM_GAS | |
3059 ; | |
3060 lfsr FSR2,char_I_deco_O2_ratio ; load FSR2 with base address of char_I_deco_O2_ratio. | |
3061 ; FSR2 will step through all char_I_deco_... vars. | |
3062 lfsr FSR1,opt_dil_O2_ratio ; load FSR1 with base address of opt_dil_O2_ratio | |
3063 rcall deco_setup_copy ; copy all dil O2 ratios | |
3064 lfsr FSR1,opt_dil_He_ratio ; load FSR1 with base address of opt_dil_He_ratio | |
3065 rcall deco_setup_copy ; copy all dil He ratios | |
3066 lfsr FSR1,opt_dil_type ; load FSR1 with base address of opt_dil_type | |
3067 rcall deco_setup_copy ; copy all dil types | |
3068 lfsr FSR1,opt_dil_change ; load FSR1 with base address of opt_dil_change | |
3069 rcall deco_setup_copy ; copy all dil change depths | |
3070 ; switch to CCR / pSCR mode: | |
3071 bsf lo,DECO_MODE_LOOP_FLAG ; - loop flag is set in both, CCR and pSCR mode | |
3072 bcf lo,DECO_MODE_PSCR_FLAG ; - clear pSCR mode flag by default | |
3073 btfsc FLAG_pscr_mode ; - check if we are in pSCR mode | |
3074 bsf lo,DECO_MODE_PSCR_FLAG ; YES - set additional flag for pSCR mode | |
3075 movff lo,char_O_deco_status ; - bank safe write-back of char_O_deco_status | |
3076 return ; done | |
3077 | |
3078 | |
3079 ;----------------------------------------------------------------------------- | |
3080 ; Setup everything to enter CCR / pSCR Dive Mode - Part 2 | |
3081 ; | |
604 | 3082 dive_boot_cc_part2: |
560 | 3083 ; revoke sensors from usage if they do not have a valid calibration |
3084 bsf use_O2_sensor1 | |
3085 btfss sensor1_calibrated_ok | |
3086 bcf use_O2_sensor1 | |
634 | 3087 |
3088 bsf use_O2_sensor2 | |
560 | 3089 btfss sensor2_calibrated_ok |
3090 bcf use_O2_sensor2 | |
634 | 3091 |
3092 bsf use_O2_sensor3 | |
560 | 3093 btfss sensor3_calibrated_ok |
3094 bcf use_O2_sensor3 | |
623 | 3095 |
3096 IFDEF _external_sensor | |
604 | 3097 ; check for external HUD/ppO2 Monitor |
634 | 3098 btfss ext_input_optical ; do we have an optical input? |
604 | 3099 bra dive_boot_cc_part2_1 ; NO |
634 | 3100 btfsc sensor1_active ; YES - process flags from HUD/ppO2 Monitor |
623 | 3101 bsf use_O2_sensor1 ; - ... |
3102 btfsc sensor2_active ; - ... | |
3103 bsf use_O2_sensor2 ; - ... | |
3104 btfsc sensor3_active ; - ... | |
3105 bsf use_O2_sensor3 ; - ... | |
3106 ENDIF | |
3107 | |
604 | 3108 dive_boot_cc_part2_1: |
560 | 3109 ; In pSCR mode, only settings 0 (calculated ppO2) and 1 (ppO2 from sensors) are defined. |
604 | 3110 ; In case we still have 3 (auto SP) selected out of previous CCR mode, we reset to 0. |
634 | 3111 btfss FLAG_pscr_mode ; in pSCR mode? |
3112 bra dive_boot_cc_part2_2 ; NO | |
640 | 3113 movf dive_ccr_mode,W ; YES - get mode (=0: Fixed SP (CCR) / calculated SP (pSCR), =1: Sensor, =2: Auto SP) |
3114 sublw .2 ; dive_ccr_mode = 1 (Auto SP)? | |
634 | 3115 bnz dive_boot_cc_part2_2 ; NO - ok |
640 | 3116 clrf dive_ccr_mode ; YES - revert to calculated SP |
634 | 3117 |
604 | 3118 dive_boot_cc_part2_2: |
623 | 3119 bsf event_SP_change ; set setpoint event flag |
3120 | |
560 | 3121 ; Start with SP1 (CCR) or 0 (pSCR) as default. |
3122 ; If in sensor mode, this value will be overwritten by calc_deko_divemode_sensor | |
623 | 3123 clrf WREG ; pre-load WREG with setpoint value 0 for pSCR calculated |
3124 btfsc FLAG_ccr_mode ; in CCR mode? | |
3125 movff opt_setpoint_cbar+0,WREG ; YES - get value of setpoint 1 into WREG | |
582 | 3126 movff WREG,char_I_const_ppO2 ; write setpoint to deco engine |
634 | 3127 |
623 | 3128 IFDEF _external_sensor |
582 | 3129 call transmit_setpoint ; transmit current setpoint from WREG (in cbar) to external electronics |
634 | 3130 goto calc_deko_divemode_sensor ; process sensor readings and return |
623 | 3131 ELSE |
3132 return ; done | |
3133 ENDIF | |
3134 | |
3135 ENDIF ; _ccr_pscr | |
3136 | |
634 | 3137 |
623 | 3138 ;============================================================================= |
634 | 3139 dmode3 CODE |
3140 ;============================================================================= | |
3141 | |
3142 | |
3143 ;----------------------------------------------------------------------------- | |
3144 ; Initialize Dive Mode | |
3145 ; | |
0 | 3146 diveloop_boot: |
604 | 3147 ; do the basic initialization |
634 | 3148 call restart_set_modes_and_flags ; basic settings depending on deco mode |
3149 | |
3150 ; save on energy | |
3151 call I2C_sleep_compass ; stop accelerometer and compass | |
604 | 3152 |
623 | 3153 ; do an early initialization of all deco engine output variables to |
3154 ; avoid glitches in the display outputs during deco engine start-up | |
3155 call deco_init_output_vars; ; (C-code) | |
3156 banksel common ; back to bank common | |
3157 | |
634 | 3158 ; configure screen layout |
3159 TSTOSC opt_layout ; alternative layout enabled? | |
3160 bsf alt_layout_active ; YES - start with alternative layout | |
3161 | |
3162 ; configure tissue graphics | |
635
9a64914a8fca
3.10 re-release addressing some minor issues and language fixes
heinrichsweikamp
parents:
634
diff
changeset
|
3163 TSTOSC opt_tissue_graphics ; shall show: 0= pres+sat, 1= N2+He |
634 | 3164 bsf tissue_graphic_layout ; YES - show press+sat |
3165 TSTOSC char_I_model ; GF factors enabled? | |
3166 bsf tissue_graphic_gf ; YES - show GF lines | |
3167 | |
623 | 3168 ; reset max relative pressure (max depth) |
3169 bsf reset_max_pressure ; request ISR to reset the max pressure | |
3170 | |
640 | 3171 ; make working copy of opt_ccr_mode |
3172 movff opt_ccr_mode,dive_ccr_mode ; copy option setting | |
3173 | |
3174 | |
623 | 3175 IFDEF _min_depth_option |
3176 ; reset the resettable min/max relative pressure (trip-wise min/max depth) | |
3177 bsf reset_trip_pressure ; request ISR to reset the resettable min/max pressure | |
3178 ENDIF | |
3179 | |
604 | 3180 IFDEF _cave_mode |
623 | 3181 ; initialize the cave mode |
631 | 3182 bcf cave_mode ; disable cave mode by default |
3183 TSTOSC opt_cave_mode ; cave mode switched on? | |
3184 bsf cave_mode ; YES - enable cave mode | |
3185 | |
3186 bcf dive_turned ; dive is not turned yet | |
3187 bcf backtrack_almost_full ; backtracking storage is not almost full yet | |
3188 bcf backtrack_entire_full ; backtracking storage is not entirely full yet | |
3189 bsf waypoint_reached_first ; current waypoint is the first recorded waypoint | |
3190 bsf waypoint_reached_last ; current waypoint is the last recorded waypoint | |
3191 | |
3192 clrf backtrack_waypoint_num ; initialize the waypoint number | |
3193 clrf backtrack_waypoint_turn ; no turn point yet | |
3194 | |
3195 movlw .0 ; initialize backtracking index to first position in storage | |
3196 movff WREG,char_I_backtrack_index ; ... | |
3197 | |
3198 clrf depth_meter ; store initial depth data set with depth = surface | |
3199 call write_backtrack_1min_depth ; ... | |
3200 ENDIF ; _cave_mode | |
3201 | |
3202 ; base configuration of the deco engine | |
623 | 3203 clrf hi ; start with everything disabled |
631 | 3204 TSTOSC opt_ext_stops ; shall make extended stops? |
623 | 3205 bsf hi,DECO_EXTENDED_STOPS ; YES - enable extended stops |
604 | 3206 IFDEF _rx_functions |
623 | 3207 btfsc tr_functions_activated ; TR functions activated? |
3208 bsf hi,DECO_TR_FUNCTIONS ; YES - enable TR functions | |
604 | 3209 ENDIF |
631 | 3210 IFDEF _gas_contingency |
3211 ; set contingency mode on/off | |
3212 TSTOSC opt_gas_contingency_dive ; gas contingency for dive mode switched on? | |
3213 bsf hi,DECO_GAS_CONTINGENCY ; YES - activate gas contingency mode | |
3214 ENDIF ; _gas_contingency | |
604 | 3215 movff hi,char_O_main_status ; bank-safe copy to deco engine |
3216 | |
631 | 3217 clrf lo ; start with everything disabled |
3218 bsf lo,DECO_START_NORM ; set flag for doing a normal plan | |
3219 bsf lo,DECO_INITIALIZE ; set flag for initializing the deco engine | |
604 | 3220 movff lo,char_O_deco_status ; bank-safe copy back to deco engine |
0 | 3221 |
623 | 3222 ; disable "fast forward" function |
634 | 3223 movlw .0 ; set fast forward to zero |
3224 movff WREG,char_I_sim_advance_time; ... | |
623 | 3225 |
3226 ; write last stop depth to deco engine | |
631 | 3227 movff opt_last_stop,char_I_last_stop_depth |
623 | 3228 |
3229 ; initialize max depth for apnoe mode | |
634 | 3230 CLRI apnoe_max_pressure ; reset to zero |
623 | 3231 |
3232 ; reset minimum temperature, ISR-safe 2 byte copy | |
3233 SMOVII temperature_cur,temperature_min | |
3234 | |
3235 ; ISR-safe copy of start-of-dive date and time for logbook (6 bytes in total) | |
3236 SMOVSS rtc_year,start_year | |
3237 | |
3238 MOVII int_O_CNS_current,CNS_start ; save current CNS at beginning of dive, but | |
3239 bcf CNS_start+1,int_warning_flag ; without warning flag | |
3240 bcf CNS_start+1,int_attention_flag ; without attention flag | |
3241 | |
3242 ; save supersaturation at beginning of dive (only lower byte is used for value) | |
3243 movff int_O_lead_supersat+0,supersat_start | |
3244 | |
631 | 3245 clrf menu_pos_cur ; reset current menu position |
3246 clrf active_premenu ; no pre-menu task active | |
623 | 3247 |
3248 clrf safety_stop_countdown ; clear safety stop count-down | |
3249 | |
3250 CLRI last_pressure_velocity ; initialize last pressure for velocity calculation | |
3251 CLRI dive_timeout_timer ; initialize timeout counter | |
3252 | |
3253 movlw .1 ; initialize the sampling timer such that the 1st sampling ... | |
3254 movwf sampling_timer ; ... trigger will be given as soon as possible | |
3255 | |
3256 clrf message_page ; initialize message page counter | |
3257 clrf alarm_type ; clear all alarms | |
3258 | |
3259 ; clear the total dive average depth | |
3260 CLRI pressure_rel_avg_total ; average depth | |
3261 CLRI divesecs_avg_total ; time accumulator | |
3262 clrf pressure_rel_accu_total+0 ; depth accumulator | |
631 | 3263 clrf pressure_rel_accu_total+1 ; ... |
3264 clrf pressure_rel_accu_total+2 ; ... | |
3265 clrf pressure_rel_accu_total+3 ; ... | |
604 | 3266 |
3267 IFDEF _rx_functions | |
623 | 3268 |
3269 btfss tr_functions_activated ; TR functions activated? | |
604 | 3270 bra diveloop_boot_0 ; NO - skip TR function initialization |
623 | 3271 |
604 | 3272 banksel int_IO_pressure_value |
634 | 3273 |
3274 clrf WREG ; set WREG to coding for integer numbers -> data not available | |
3275 bsf WREG,int_not_avail_flag ; ... | |
623 | 3276 clrf int_IO_pressure_value+0 ; clear low byte of 1st pressure reading value |
3277 movwf int_IO_pressure_value+1 ; copy to high byte of 1st pressure reading value | |
3278 clrf int_IO_pressure_value+2 ; clear low byte of 2nd pressure reading value | |
3279 movwf int_IO_pressure_value+3 ; copy to high byte of 2nd pressure reading value | |
3280 clrf int_I_pressure_drop+0 ; clear low byte of 1st pressure drop value | |
3281 movwf int_I_pressure_drop+1 ; copy to high byte of 1st pressure drop value | |
3282 clrf int_I_pressure_drop+2 ; clear low byte of 2nd pressure drop value | |
3283 movwf int_I_pressure_drop+3 ; copy to high byte of 1st pressure drop value | |
604 | 3284 clrf char_I_pressure_gas+0 ; clear gas selection of 1st pressure reading |
3285 clrf char_I_pressure_gas+1 ; clear gas selection of 2nd pressure reading | |
3286 clrf char_I_pressure_age+0 ; clear age of 1st pressure reading | |
3287 clrf char_I_pressure_age+1 ; clear age of 2nd pressure reading | |
3288 clrf char_I_pressure_stat+0 ; clear status of 1st pressure reading | |
3289 clrf char_I_pressure_stat+1 ; clear status of 2nd pressure reading | |
623 | 3290 |
604 | 3291 banksel gas__last_1st ; select bank with vars for pressure drop calculation |
3292 setf gas__last_1st ; invalidate last gas of 1st reading | |
623 | 3293 setf gas__last_2nd ; invalidate last gas of 2nd reading |
3294 | |
604 | 3295 banksel common ; back to bank common |
623 | 3296 |
3297 ENDIF ; _rx_functions | |
3298 | |
604 | 3299 |
3300 diveloop_boot_0: | |
3301 setf best_gas_number ; initialize best gas as not computed yet (255) | |
623 | 3302 IFDEF _ccr_pscr |
604 | 3303 setf best_dil_number ; initialize best diluent as not computed yet (255) |
623 | 3304 ENDIF |
604 | 3305 |
3306 btfsc FLAG_oc_mode ; in OC mode? | |
634 | 3307 call dive_boot_oc ; YES - add OC mode settings |
604 | 3308 |
623 | 3309 IFDEF _ccr_pscr |
604 | 3310 btfsc FLAG_ccr_mode ; in CCR mode? |
634 | 3311 call dive_boot_cc ; YES - add CC mode settings |
604 | 3312 btfsc FLAG_ccr_mode ; in CCR mode? |
634 | 3313 call dive_boot_cc_part2 ; YES - add CC sensor and SP settings |
604 | 3314 |
3315 btfsc FLAG_pscr_mode ; in pSCR mode? | |
634 | 3316 call dive_boot_cc ; YES - add CC mode settings |
604 | 3317 btfsc FLAG_pscr_mode ; in pSCR mode? |
634 | 3318 call dive_boot_cc_part2 ; YES - add CC sensor and SP settings |
623 | 3319 ENDIF |
604 | 3320 |
631 | 3321 bcf bailout_mode ; not in bailout mode |
3322 | |
604 | 3323 call ghostwriter_short_header ; write short header with dive number into profile memory |
623 | 3324 call init_recording_params ; set up all the divisors for dive data recording |
3325 | |
3326 ; setup gas selector flag (required to have better gas working) | |
3327 bsf is_diluent_menu ; default to using diluents | |
3328 btfsc FLAG_ccr_mode ; in CCR mode? | |
3329 bra diveloop_boot_3 ; YES - default was right | |
3330 btfsc FLAG_pscr_mode ; in pSCR mode? | |
3331 bra diveloop_boot_3 ; YES - default was right | |
3332 bcf is_diluent_menu ; NO to both - revert to using OC gases | |
604 | 3333 |
3334 diveloop_boot_3: | |
582 | 3335 bcf LEDg ; switch off green LED / release reset to RX circuitry |
604 | 3336 bcf LEDr ; switch off red LED |
623 | 3337 |
3338 btfss sensor_override_active ; in simulator mode? | |
604 | 3339 call disable_rs232 ; NO - disable RS232 |
3340 | |
3341 IFDEF _screendump | |
623 | 3342 btfsc screen_dump_avail ; screen dump function enabled? |
3343 call enable_rs232 ; enable interface (also sets CPU speed to normal) | |
604 | 3344 ENDIF |
3345 | |
623 | 3346 clrf apnoe_surface_mins ; clear apnoe surface time, minutes (8 bit) |
3347 clrf apnoe_surface_secs ; clear apnoe surface time, seconds (8 bit) | |
3348 clrf apnoe_dive_mins ; clear apnoe dive time, minutes (8 bit) | |
3349 clrf apnoe_dive_secs ; clear apnoe dive time, seconds (8 bit) | |
604 | 3350 |
3351 return ; done with dive mode boot | |
3352 | |
3353 | |
3354 ;============================================================================= | |
634 | 3355 dmode4 CODE |
3356 ;============================================================================= | |
3357 | |
3358 | |
3359 ;----------------------------------------------------------------------------- | |
3360 ; Check all Sorts of Parameters and issue Warnings and Attentions if applicable | |
3361 ; | |
623 | 3362 divemode_check_warnings: |
604 | 3363 movlw .1 ; one message at a time in alternative layout |
623 | 3364 btfss alt_layout_active ; in alternative layout? |
3365 movlw .2 ; NO - two messages at a time in normal layout | |
634 | 3366 cpfsgt message_counter ; had more than 1 / 2 messages in the last round? |
623 | 3367 bra divemode_check_warnings1 ; NO - update messages every second |
3368 | |
3369 ; ; YES - update every 4 seconds: | |
631 | 3370 ; btfss timebase_1sec ; - on second 1 or 3 ? |
623 | 3371 ; return ; NO - no update in this cycle |
3372 ; btfss timebase_2sec ; YES - on second 3 ? | |
3373 ; return ; NO - no update in this cycle | |
3374 ; ;bra divemode_check_warnings1 ; YES - update messages | |
3375 | |
634 | 3376 ; YES - update every 2 seconds |
623 | 3377 btfsc timebase_1sec ; - on even second? |
3378 return ; NO - done | |
3379 ;bra divemode_check_warnings1 ; YES - update messages | |
3380 | |
3381 divemode_check_warnings1: | |
604 | 3382 clrf message_counter ; clear message counter |
3383 | |
3384 ; messages sorted by severity: highest severity warnings first, then attentions, advices and last info | |
3385 | |
3386 ; warnings for all modes | |
634 | 3387 call check_battery ; check battery status |
3388 rcall check_depth_limit ; check current depth | |
3389 call check_divetimeout ; check dive timeout | |
604 | 3390 |
623 | 3391 btfsc FLAG_apnoe_mode ; in apnoe mode? |
634 | 3392 bra divemode_check_warnings2 ; YES - skip deco mode checks |
623 | 3393 |
604 | 3394 btfsc FLAG_gauge_mode ; in gauge mode? |
634 | 3395 bra divemode_check_warnings2 ; YES - skip deco mode checks |
604 | 3396 |
3397 ; warnings applicable only in deco modes | |
631 | 3398 |
3399 IFDEF _cave_mode | |
3400 rcall check_cavemode ; check cave mode status | |
3401 ENDIF | |
3402 | |
634 | 3403 rcall check_display_ftts ; show fTTS time (or cave mode cTTS) |
3404 rcall check_ppO2 ; check ppO2 | |
0 | 3405 |
623 | 3406 IFDEF _external_sensor |
634 | 3407 rcall check_ext_sensors ; check external sensors |
623 | 3408 ENDIF |
582 | 3409 |
604 | 3410 rcall check_outside ; check of ZHL16 model violation |
560 | 3411 |
634 | 3412 IFDEF _ccr_pscr |
623 | 3413 btfsc FLAG_ccr_mode ; in CCR mode? |
3414 rcall check_OC_gas_avail ; YES - check if a breathable OC (bailout) gas is available | |
3415 btfsc FLAG_pscr_mode ; in pSCR mode? | |
3416 rcall check_OC_gas_avail ; YES - check if a breathable OC (bailout) gas is available | |
634 | 3417 ENDIF |
604 | 3418 |
3419 btfsc decostop_active ; in deco mode? | |
634 | 3420 rcall check_saturation ; YES - check tissue saturation |
604 | 3421 |
3422 rcall check_mbubbles ; check for micro bubbles | |
634 | 3423 rcall check_cns_violation_now ; check current CNS value |
3424 rcall check_cns_violation_eod ; check end-of-dive CNS value (needs to be done after check_cns_violation_now) | |
3425 rcall check_gas_needs ; check for gas needs | |
3426 rcall check_gas_change ; check for diluent or gas change advice | |
3427 | |
3428 IFDEF _ccr_pscr | |
3429 btfsc FLAG_ccr_mode ; in CCR mode? | |
3430 rcall check_gas_density ; YES - check gas density | |
3431 btfsc FLAG_pscr_mode ; in pSCR mode? | |
3432 rcall check_gas_density ; YES - check gas density | |
3433 ENDIF | |
604 | 3434 |
623 | 3435 btfsc use_aGF ; using alternative GF factors? |
634 | 3436 rcall remind_agf_in_use ; YES - show reminder |
582 | 3437 |
623 | 3438 divemode_check_warnings2: |
634 | 3439 |
604 | 3440 IFDEF _rx_functions |
623 | 3441 btfss tr_functions_activated ; TR functions activated? |
3442 bra divemode_check_warnings3 ; NO - skip | |
3443 call check_tr_functions ; YES - check transmitter functions | |
3444 call check_tr_messages ; - check SAC attention and switch advice | |
604 | 3445 ENDIF |
3446 | |
623 | 3447 divemode_check_warnings3: |
634 | 3448 |
3449 ; compute if an advice / attention / warning sign shall be shown | |
3450 rcall divemode_check_sign | |
3451 | |
3452 ; increment message page number | |
623 | 3453 incf message_page,F ; increment page number |
3454 bcf STATUS,C ; clear carry bit | |
3455 movf message_page,W ; get page number into WREG | |
3456 btfss alt_layout_active ; in alternative layout? | |
3457 rlcf WREG,W ; NO - each page can take two messages | |
3458 cpfsgt message_counter ; number of actual messages > message capacity ? | |
3459 clrf message_page ; NO - all messages could be shown, restart from first page next time | |
604 | 3460 |
634 | 3461 ; clear both rows of messages if there is nothing to show at all |
623 | 3462 tstfsz message_counter ; any message to show? |
3463 bra divemode_check_warnings4 ; YES - look if second row needs to be cleared | |
3464 bsf FLAG_TFT_message_clear_both ; NO - request clearing of left-over messages | |
3465 return ; - done | |
3466 | |
3467 divemode_check_warnings4: | |
634 | 3468 ; clear 2nd row of messages if there is nothing to show (on this page) |
623 | 3469 btfss message_2nd_row_used ; does the 2nd row contain a message? |
3470 bsf FLAG_TFT_message_clear_2nd ; NO - set flag to clear the 2nd row | |
3471 return ; done | |
3472 | |
634 | 3473 |
623 | 3474 ;----------------------------------------------------------------------------- |
634 | 3475 ; Helper Function - check if an Advice / Attention / Warning Sign shall be shown |
3476 ; | |
3477 divemode_check_sign: | |
3478 ; clear sign flags | |
3479 bcf sign_advice ; clear flag for showing advice sign | |
3480 bcf sign_attention ; clear flag for showing attention sign | |
3481 bcf sign_warning ; clear flag for showing warning sign | |
3482 | |
3483 ; check for new advices | |
3484 movf DM_flags_advc_det,W ; get current advices | |
3485 andwf DM_flags_advc_ack,W ; keep only those acknowledgments that have current advices | |
3486 movwf DM_flags_advc_ack ; store updated acknowledgments | |
3487 xorwf DM_flags_advc_det,W ; find advices that have not been acknowledged yet | |
3488 tstfsz WREG ; any new advice? | |
3489 bsf sign_advice ; YES - set flag for showing advice sign | |
3490 | |
3491 ; check for new attentions (1) | |
3492 movf DM_flags_att1_det,W ; get current attentions | |
3493 andwf DM_flags_att1_ack,W ; keep only those acknowledgments that have current attentions | |
3494 movwf DM_flags_att1_ack ; store updated acknowledgments | |
3495 xorwf DM_flags_att1_det,W ; find attentions that have not been acknowledged yet | |
3496 tstfsz WREG ; any new attention? | |
3497 bsf sign_attention ; YES - set flag for showing attention sign | |
3498 | |
3499 ; check for new attentions (2) | |
3500 movf DM_flags_att2_det,W ; get current attentions | |
3501 andwf DM_flags_att2_ack,W ; keep only those acknowledgments that have current attentions | |
3502 movwf DM_flags_att2_ack ; store updated acknowledgments | |
3503 xorwf DM_flags_att2_det,W ; find attentions that have not been acknowledged yet | |
3504 tstfsz WREG ; any new attention? | |
3505 bsf sign_attention ; YES - set flag for showing attention sign | |
3506 | |
3507 ; check for new attentions (3) | |
3508 movf DM_flags_att3_det,W ; get current attentions | |
3509 andwf DM_flags_att3_ack,W ; keep only those acknowledgments that have current attentions | |
3510 movwf DM_flags_att3_ack ; store updated acknowledgments | |
3511 xorwf DM_flags_att3_det,W ; find attentions that have not been acknowledged yet | |
3512 tstfsz WREG ; any new attention? | |
3513 bsf sign_attention ; YES - set flag for showing attention sign | |
3514 | |
3515 ; check for new warnings (1) | |
3516 movf DM_flags_war1_det,W ; get current warnings | |
3517 andwf DM_flags_war1_ack,W ; keep only those acknowledgments that have current warnings | |
3518 movwf DM_flags_war1_ack ; store updated acknowledgments | |
3519 xorwf DM_flags_war1_det,W ; find warnings that have not been acknowledged yet | |
3520 tstfsz WREG ; any new warning? | |
3521 bsf sign_warning ; YES - set flag for showing warning sign | |
3522 | |
3523 ; check for new warnings (2) | |
3524 movf DM_flags_war2_det,W ; get current warnings | |
3525 andwf DM_flags_war2_ack,W ; keep only those acknowledgments that have current warnings | |
3526 movwf DM_flags_war2_ack ; store updated acknowledgments | |
3527 xorwf DM_flags_war2_det,W ; find warnings that have not been acknowledged yet | |
3528 tstfsz WREG ; any new warning? | |
3529 bsf sign_warning ; YES - set flag for showing warning sign | |
3530 | |
3531 ; show or clear the advice / attention / warning sign | |
3532 btfsc sign_advice ; shall show advice sign? | |
3533 bsf FLAG_TFT_sign_show ; YES - show sign | |
3534 btfsc sign_attention ; shall show attention sign? | |
3535 bsf FLAG_TFT_sign_show ; YES - show sign | |
3536 btfsc sign_warning ; shall show warning sign? | |
3537 bsf FLAG_TFT_sign_show ; YES - show sign | |
3538 btfss FLAG_TFT_sign_show ; shall show any sign? | |
3539 bsf FLAG_TFT_sign_clear ; NO - then clear the sign | |
3540 | |
3541 return ; done | |
3542 | |
3543 | |
3544 ;----------------------------------------------------------------------------- | |
3545 ; Check Battery Power | |
3546 ; | |
3547 global check_battery | |
3548 check_battery: | |
3549 bcf warn_det_batt_low ; clear warning for battery low | |
623 | 3550 movlw battery_show_level+1 ; get threshold for showing battery level, incremented by 1 |
628 | 3551 cpfslt batt_percent ; battery percentage ok? |
634 | 3552 return ; YES - done |
3553 btfsc battery_low_condition ; NO - battery low condition detected? | |
3554 bsf warn_det_batt_low ; YES - set warning for battery low | |
3555 movf active_customview,W ; - get current custom view | |
3556 xorlw index_clock_batt_surfpress ; - battery shown in custom view? | |
3557 bnz check_battery_mesg ; NO - show message | |
3558 return ; YES - do not show twice, done | |
3559 | |
3560 check_battery_mesg: | |
3561 incf message_counter,F ; increase message counter | |
3562 goto TFT_message_battery_percent ; show message for battery low (battery percent) and return | |
3563 | |
3564 | |
3565 ;----------------------------------------------------------------------------- | |
3566 ; Show Dive Timeout Counter if Dive Time is not counted | |
3567 ; | |
55 | 3568 check_divetimeout: |
623 | 3569 btfsc count_divetime ; is dive time counted? |
634 | 3570 return ; YES - nothing to do, done |
3571 incf message_counter,F ; NO - increase message counter | |
3572 goto TFT_message_divetimeout ; - show timeout counter and return | |
3573 | |
3574 | |
3575 ;----------------------------------------------------------------------------- | |
3576 ; Check ppO2 of all Gases / Diluents in use | |
3577 ; | |
560 | 3578 check_ppO2: |
623 | 3579 IFDEF _ccr_pscr |
634 | 3580 ; check if breathing from the loop |
3581 btfsc FLAG_oc_mode ; in OC mode? | |
604 | 3582 bra check_ppO2_1 ; YES - continue with breathed gas |
623 | 3583 btfsc bailout_mode ; NO - in bailout? |
604 | 3584 bra check_ppO2_1 ; YES - continue with breathed gas |
634 | 3585 ; CCR / pSCR mode - check the pure diluent |
3586 bcf warn_det_ppO2_diluent ; clear warning for pure diluent ppO2 | |
3587 bcf attn_det_ppo2_diluent ; clear attention for pure diluent ppO2 | |
623 | 3588 MOVII int_O_pure_ppO2,mpr ; get value and attention/warning flags for the pure diluent |
634 | 3589 btfsc hi,int_warning_flag ; ppO2 of the pure diluent in warning state? |
3590 bra check_ppO2_dil_warn ; YES - show warning | |
604 | 3591 btfsc hi,int_attention_flag ; ppO2 of the pure diluent in attention state? |
634 | 3592 bra check_ppO2_dil_attn ; YES - show attention |
3593 bra check_ppO2_1 ; continue with checking breathed gas | |
3594 | |
3595 check_ppO2_dil_warn: | |
3596 bsf warn_det_ppO2_diluent ; set warning for pure diluent ppO2 | |
3597 rcall check_ppO2_show_mesg ; show ppO2 message | |
3598 bra check_ppO2_1 ; continue with checking breathed gas | |
3599 | |
3600 check_ppO2_dil_attn: | |
3601 bsf attn_det_ppo2_diluent ; set attention for pure diluent ppO2 | |
3602 rcall check_ppO2_show_mesg ; show ppO2 message | |
3603 ;bra check_ppO2_1 ; continue with checking breathed gas | |
3604 ENDIF ; _ccr_pscr | |
3605 | |
604 | 3606 check_ppO2_1: |
634 | 3607 ; all modes - check breathed gas (OC or loop) |
3608 bcf attn_det_ppo2_breathed ; clear attention for breathed ppO2 | |
3609 bcf warn_det_ppO2_breathed ; clear warning for breathed ppO2 | |
623 | 3610 MOVII int_O_breathed_ppO2,mpr ; get value and attention/warning flags for the breathed gas |
604 | 3611 btfsc hi,int_attention_flag ; breathed ppO2 in attention state (when in loop mode, no attention will be generated)? |
634 | 3612 bra check_ppO2_breath_attn ; YES - set attention flag and show ppO2 |
3613 btfsc hi,int_low_flag ; NO - breathed ppO2 too low? | |
3614 bra check_ppO2_breath_warn_low ; YES - record the warning and show ppO2 | |
3615 btfsc hi,int_high_flag ; NO - breathed ppO2 too high? | |
3616 bra check_ppO2_breath_warn_high ; YES - record the warning and show ppO2 | |
3617 bra check_ppO2_breath_ok ; NO - ppO2 is ok | |
3618 | |
3619 check_ppO2_breath_attn: | |
3620 bsf attn_det_ppo2_breathed ; set attention for breathed ppO2 | |
3621 bra check_ppO2_show ; show ppO2 message | |
3622 | |
3623 check_ppO2_breath_warn_low: | |
582 | 3624 movlw d'4' ; set type of alarm (ppO2 low) |
634 | 3625 bra check_ppO2_breath_common ; continue with common part |
3626 | |
3627 check_ppO2_breath_warn_high: | |
560 | 3628 movlw d'5' ; set type of alarm (ppO2 high) |
634 | 3629 ;bra check_ppO2_breath_common ; continue with common part |
3630 | |
3631 check_ppO2_breath_common: | |
623 | 3632 movwf alarm_type ; copy alarm type to alarm register |
634 | 3633 bsf event_occured ; set event flag |
3634 bsf warn_det_ppO2_breathed ; set warning for breathed ppO2 | |
3635 bra check_ppO2_show ; show ppO2 message | |
3636 | |
3637 check_ppO2_breath_ok: | |
3638 TSTOSS opt_showppo2 ; shall always show ppO2 (0 = no, 1 = yes) | |
3639 return ; NO - done | |
3640 ;bra check_ppO2_show ; YES - show ppO2 message | |
3641 | |
3642 check_ppO2_show: | |
631 | 3643 IFDEF _ccr_pscr |
634 | 3644 btfsc FLAG_oc_mode ; in OC mode? |
3645 bra check_ppO2_show_1 ; YES - show ppO2 message | |
3646 btfsc bailout_mode ; in bailout mode? | |
3647 bra check_ppO2_show_1 ; YES - show ppO2 message | |
604 | 3648 return ; NO - in loop mode, ppO2 is already shown via setpoint display |
634 | 3649 ENDIF |
3650 check_ppO2_show_1: | |
3651 movf active_customview,W ; get current custom view | |
3652 xorlw index_ppo2_ead_end_cns ; ppO2 shown already via custom view? | |
3653 bz check_ppO2_done ; YES - done | |
3654 movf active_customview,W ; get current custom view (again) | |
3655 xorlw index_pscr_info ; ppO2 shown already via custom view? | |
3656 bz check_ppO2_done ; YES - done | |
3657 ;bra check_ppO2_show_mesg ; NO - show ppO2 message | |
3658 | |
3659 check_ppO2_show_mesg: | |
3660 incf message_counter,F ; increase message counter | |
3661 goto TFT_message_ppo2 ; show ppO2 message and return | |
3662 | |
3663 check_ppO2_done: | |
3664 return ; done | |
3665 | |
3666 | |
3667 ;----------------------------------------------------------------------------- | |
3668 ; Show fTTS Message | |
3669 ; | |
604 | 3670 check_display_ftts: |
631 | 3671 IFDEF _ccr_pscr |
3672 btfsc bailout_mode ; in bailout mode? | |
3673 return ; YES - in bailout no fTTS is computed, done | |
3674 ENDIF | |
623 | 3675 btfss count_divetime ; is dive time counted? |
631 | 3676 return ; NO - omit, done |
623 | 3677 movff char_I_extra_time,lo ; YES - get extra time |
3678 tstfsz lo ; - extra time > 0 ? | |
634 | 3679 bra check_display_ftts_mesg ; YES - show fTTS |
631 | 3680 return ; NO - no fTTS computed, done |
634 | 3681 |
3682 check_display_ftts_mesg: | |
631 | 3683 incf message_counter,F ; increase counter |
634 | 3684 goto TFT_message_ftts ; show @+x time |
3685 | |
3686 | |
3687 ;----------------------------------------------------------------------------- | |
3688 ; check current CNS Value | |
3689 ; | |
3690 global check_cns_violation_now | |
3691 check_cns_violation_now: | |
3692 bcf warn_det_cns_current ; clear warning for CNS | |
3693 bcf attn_det_cns_current ; clear attention for CNS | |
623 | 3694 movff int_O_CNS_current+1,WREG ; get current CNS, high byte |
582 | 3695 btfsc WREG,int_warning_flag ; warning flag set? |
634 | 3696 bra check_cns_violation_now_warn; YES - show a warning |
3697 btfsc WREG,int_attention_flag ; attention flag set? | |
3698 bra check_cns_violation_now_attn; YES - show an attention | |
3699 return ; NO - done | |
3700 | |
3701 check_cns_violation_now_warn: | |
3702 bsf warn_det_cns_current ; set warning for CNS | |
3703 bra check_cns_violation_now_mesg; show message | |
3704 | |
3705 check_cns_violation_now_attn: | |
3706 bsf attn_det_cns_current ; set attention for CNS | |
3707 ;bra check_cns_violation_now_mesg; show message | |
3708 | |
3709 check_cns_violation_now_mesg: | |
628 | 3710 IFNDEF _helium |
634 | 3711 movf active_customview,W ; get current custom view |
3712 xorlw index_ppo2_ead_end_cns ; CNS shown? | |
3713 bz check_cns_violation_now_done; YES - done | |
628 | 3714 ENDIF |
634 | 3715 movf active_customview,W ; get current custom view (again) |
3716 xorlw index_CNS ; CNS shown? | |
3717 bz check_cns_violation_now_done; YES - done | |
3718 incf message_counter,F ; NO - increase counter | |
3719 goto TFT_message_cns ; - show message and return | |
3720 | |
3721 check_cns_violation_now_done: | |
3722 return ; done | |
3723 | |
3724 | |
3725 ;----------------------------------------------------------------------------- | |
3726 ; check end-of-Dive CNS Value | |
3727 ; | |
3728 global check_cns_violation_eod | |
3729 check_cns_violation_eod: | |
3730 bcf attn_det_cns_eod ; clear attention for end-of-dive CNS | |
3731 btfsc warn_det_cns_current ; current CNS value in warning state? | |
3732 return ; YES - inhibit end-of-dive CNS checks if current CNS is already in warning | |
3733 ;bra check_cns_violation_eod_norm; NO - check normal plan | |
3734 | |
3735 check_cns_violation_eod_norm: | |
623 | 3736 movff int_O_CNS_norm+1,WREG ; get CNS at end of dive in normal plan, high byte |
560 | 3737 btfsc WREG,int_invalid_flag ; flag for invalid value set? |
634 | 3738 bra check_cns_violation_eod_alt ; YES - continue with checking alternative plan |
582 | 3739 btfsc WREG,int_warning_flag ; NO - flag for warning set? |
634 | 3740 bra check_cns_violation_eod_warn; YES - show message |
3741 ;bra check_cns_violation_eod_alt ; NO - check alternative plan | |
3742 | |
3743 check_cns_violation_eod_alt: | |
623 | 3744 movff int_O_CNS_alt+1,WREG ; get CNS at end of dive in alternative plan, high byte |
560 | 3745 btfsc WREG,int_invalid_flag ; flag for invalid value set? |
634 | 3746 return ; YES - done |
560 | 3747 btfsc WREG,int_warning_flag ; NO - flag for warning set? |
634 | 3748 bra check_cns_violation_eod_warn; YES - show message |
3749 return ; NO - done | |
3750 | |
3751 check_cns_violation_eod_warn: | |
3752 bsf attn_det_cns_eod ; set attention(!) for end-of-dive CNS | |
3753 movf active_customview,W ; get current custom view | |
3754 xorlw index_CNS ; CNS shown? | |
3755 bz check_cns_violation_eod_done; YES - done | |
3756 incf message_counter,F ; NO - increase message counter | |
3757 goto TFT_message_cns_eod ; - show message for end-of-dive CNS and return | |
3758 | |
3759 check_cns_violation_eod_done: | |
3760 return ; done | |
3761 | |
3762 | |
3763 ;----------------------------------------------------------------------------- | |
3764 ; Check current Tissue Supersaturation | |
3765 ; | |
3766 global check_saturation | |
3767 check_saturation: | |
3768 bcf attn_det_saturation ; clear attention for saturation | |
3769 bcf warn_det_saturation ; clear warning for saturation | |
3770 bcf attn_det_ibcd ; clear attention for IBCD | |
3771 movff int_O_lead_supersat+1,WREG ; get upper byte of leading tissue's supersaturation | |
3772 btfss WREG,int_warning_flag ; warning flag set? | |
3773 bra check_saturation_1 ; NO - continue with checking for attention flag | |
3774 movlw d'2' ; YES - set type of alarm | |
3775 movwf alarm_type ; - copy to alarm register | |
3776 bsf event_occured ; - set event flag | |
3777 bsf warn_det_saturation ; - set warning | |
3778 bra check_saturation_mesg ; - show saturation message | |
3779 | |
3780 check_saturation_1: | |
3781 btfss WREG,int_attention_flag ; attention flag set? | |
3782 bra check_saturation_2 ; NO - continue with checking for IBCD | |
3783 bsf attn_det_saturation ; YES - set attention | |
3784 bra check_saturation_mesg ; - show saturation message | |
3785 | |
3786 check_saturation_2: | |
3787 IFDEF _helium | |
3788 TSTOSS opt_enable_IBCD ; IBCD warning activated? | |
3789 bra check_saturation_3 ; NO - continue with checking deco info | |
3790 movff char_O_deco_warnings,WREG ; YES - get the deco warnings vector | |
3791 btfss WREG,IBCD_warning ; - IBCD warning flag set? | |
3792 bra check_saturation_3 ; NO - continue with checking deco info | |
3793 bsf attn_det_ibcd ; YES - set attention | |
3794 bra check_saturation_mesg ; - show saturation message | |
3795 ENDIF | |
3796 | |
3797 check_saturation_3: | |
3798 btfss divemode ; in dive mode? | |
3799 return ; NO - done | |
631 | 3800 IFDEF _ccr_pscr |
634 | 3801 btfsc bailout_mode ; YES - in bailout mode? |
3802 return ; YES - done (deco zone flag is not updated when in bailout mode) | |
631 | 3803 ENDIF |
634 | 3804 movff char_O_deco_info,WREG ; NO - get the deco info vector |
3805 btfss WREG,deco_zone ; deco zone flag set? | |
3806 return ; NO - done | |
3807 btfsc use_aGF ; YES - using alternative GF factors? | |
3808 return ; YES - suppress deco zone info | |
3809 btfsc alt_layout_active ; NO - in alternative layout? | |
3810 return ; YES - suppress deco zone info | |
3811 incf message_counter,F ; NO - increase message counter | |
3812 goto TFT_message_deco_info ; - show deco info and return | |
3813 | |
3814 check_saturation_mesg: | |
3815 IFDEF _helium | |
3816 btfss attn_det_ibcd ; IBCD detected? | |
3817 bra check_saturation_mesg_1 ; NO - show saturation message | |
3818 incf message_counter,F ; YES - increase message counter | |
3819 call TFT_message_IBCD ; - show IBCD message | |
3820 ENDIF | |
3821 check_saturation_mesg_1: | |
3822 incf message_counter,F ; increase message counter | |
3823 goto TFT_message_saturation ; show saturation message and return | |
3824 | |
3825 | |
3826 ;----------------------------------------------------------------------------- | |
3827 ; Check Depth Limit | |
3828 ; | |
623 | 3829 check_depth_limit: |
634 | 3830 bcf warn_det_depth_limit ; clear warning by default |
623 | 3831 movff opt_max_depth,WREG ; get depth limit |
3832 cpfsgt depth_meter ; current depth > depth limit? | |
634 | 3833 return ; NO - done |
3834 bsf warn_det_depth_limit ; YES - set warning | |
3835 incf message_counter,F ; - increase message counter | |
3836 goto TFT_message_depth_limit ; - show message | |
3837 | |
3838 | |
3839 ;----------------------------------------------------------------------------- | |
3840 ; Check Bühlmann Model Violation | |
3841 ; | |
604 | 3842 check_outside: |
634 | 3843 bcf warn_det_outside ; clear warning |
3844 bcf attn_det_outside ; clear attention | |
604 | 3845 movff char_O_deco_warnings,WREG ; bank-safe copy of deco warnings |
634 | 3846 btfss WREG,outside_warning ; currently outside the ZH-L16 model? |
3847 bra check_outside_1 ; NO | |
3848 bsf warn_det_outside ; YES - set warning | |
3849 bra check_outside_mesg ; - show message | |
3850 | |
3851 check_outside_1: | |
3852 btfss WREG,outside_warning_lock ; had been outside of the ZH-L16 model? | |
604 | 3853 return ; NO - done |
634 | 3854 bsf attn_det_outside ; YES - set attention |
3855 ;bra check_outside_mesg ; - show message | |
3856 | |
3857 check_outside_mesg: | |
3858 incf message_counter,F ; increase message counter | |
3859 goto TFT_message_outside ; show message and return | |
3860 | |
3861 | |
3862 ;----------------------------------------------------------------------------- | |
3863 ; Check raised Probability for Micro-Bubbles | |
3864 ; | |
604 | 3865 global check_mbubbles |
3866 check_mbubbles: | |
634 | 3867 bcf warn_det_microbubble ; clear warning |
3868 bcf attn_det_microbubble ; clear attention | |
604 | 3869 movff char_O_deco_warnings,WREG ; bank-safe copy for deco warnings |
634 | 3870 btfss WREG,mbubble_warning ; currently in micro bubbling zone? |
3871 bra check_mbubbles_1 ; NO | |
3872 bsf warn_det_microbubble ; YES - set warning | |
3873 bra check_mbubbles_mesg ; - show message | |
3874 | |
3875 check_mbubbles_1 | |
3876 btfss WREG,mbubble_warning_lock ; had been in micro bubbling zone? | |
604 | 3877 return ; NO - done |
634 | 3878 bsf attn_det_microbubble ; YES - set attention |
3879 ;bra check_mbubbles_mesg ; - show message | |
3880 | |
3881 check_mbubbles_mesg: | |
3882 incf message_counter,F ; increase message counter | |
3883 goto TFT_message_mbubbles ; show message and return | |
3884 | |
3885 | |
3886 IFDEF _ccr_pscr | |
3887 ;----------------------------------------------------------------------------- | |
3888 ; Check Gas Density | |
3889 ; | |
3890 check_gas_density: | |
3891 TSTOSS opt_gas_density_check ; shall check gas density? | |
3892 return ; NO - done | |
3893 bcf warn_det_gas_density ; YES - clear attention for gas density by default | |
3894 bcf attn_det_gas_density ; - clear warning for gas density by default | |
3895 movff int_O_gas_density+1,WREG ; - get upper byte of current gas density | |
3896 btfsc WREG,int_warning_flag ; - warning flag set? | |
3897 bra check_gas_density_warn ; YES - generate a warning | |
3898 btfsc WREG,int_attention_flag ; NO - attention flag set? | |
3899 bra check_gas_density_attn ; YES - generate an attention | |
3900 ;bra check_gas_density_ok ; NO - gas density ok | |
3901 | |
3902 check_gas_density_ok: | |
3903 bcf shown_gas_density_attn ; re-arm custom view show-up for warning | |
3904 bcf shown_gas_density_warn ; re-arm custom view show-up for attention | |
3905 return ; done | |
3906 | |
3907 check_gas_density_warn: | |
3908 bsf warn_det_gas_density ; set warning | |
3909 bcf shown_gas_density_attn ; re-arm custom view show-up for attention | |
3910 btfsc shown_gas_density_warn ; has the custom view been shown before on warning level? | |
3911 bra check_gas_density_mesg ; YES - do not show the gas needs custom view again | |
3912 btfsc custom_view_locked ; NO - custom view locked? | |
3913 bra check_gas_density_mesg ; YES - do not show it now | |
3914 bsf shown_gas_density_warn ; NO - set custom view as shown now | |
3915 bra check_gas_density_cv ; - show gas needs custom view | |
3916 | |
3917 check_gas_density_attn: | |
3918 bsf attn_det_gas_density ; set attention | |
3919 bcf shown_gas_density_warn ; re-arm custom view show-up for warning | |
3920 btfsc shown_gas_density_attn ; has the custom view been shown before on attention level? | |
3921 bra check_gas_density_mesg ; YES - do not show the gas needs custom view again | |
3922 btfsc custom_view_locked ; NO - custom view locked? | |
3923 bra check_gas_density_mesg ; YES - do not show it now | |
3924 bsf shown_gas_density_attn ; NO - set custom view as shown now | |
3925 ;bra check_gas_density_cv ; - show gas needs custom view | |
3926 | |
3927 check_gas_density_cv: | |
3928 movlw index_ppo2_ead_end_cns ; get custom view number of gas density | |
3929 call dive_customview_show ; show custom view | |
3930 ;bra check_gas_density_mesg ; show message | |
3931 | |
3932 check_gas_density_mesg: | |
3933 incf message_counter,F ; increase message counter | |
3934 goto TFT_message_gas_density ; show gas density message and return | |
3935 | |
3936 | |
3937 ;----------------------------------------------------------------------------- | |
3938 ; Check if an OC Bailout Gas is available | |
3939 ; | |
3940 check_OC_gas_avail: | |
3941 bcf warn_det_no_bo_gas ; clear warning by default | |
3942 tstfsz best_gas_number ; is a breathable OC (bailout) gas available? | |
3943 return ; YES - a breathable gas is available, done | |
3944 btfsc bailout_mode ; NO - in bailout? | |
3945 return ; YES - suppress warning, done | |
3946 bsf warn_det_no_bo_gas ; NO - set warning for no bailout gas | |
3947 incf message_counter,F ; - increase message counter | |
3948 goto TFT_message_no_BO_gas ; - show message and return | |
3949 | |
3950 ENDIF ; _ccr_pscr | |
631 | 3951 |
604 | 3952 |
3953 IFDEF _cave_mode | |
631 | 3954 |
634 | 3955 ;----------------------------------------------------------------------------- |
3956 ; Check Cave Profile Storage Usage | |
3957 ; | |
604 | 3958 check_cavemode: |
634 | 3959 bcf warn_det_cave_shut_down ; clear warning by default |
3960 bcf attn_det_cave_shut_down ; clear attention by default | |
631 | 3961 btfsc backtrack_entire_full ; is the backtracking storage entirely used up? |
3962 bra check_cavemode_full ; YES - turn dive, switch off cave mode and show warning message | |
3963 btfsc backtrack_almost_full ; NO - backtracking storage almost full? | |
3964 bra check_cavemode_almost_full ; YES - show attention message that cave mode will stop soon | |
634 | 3965 btfss cave_mode ; NO - cave mode switched on? |
3966 return ; NO - do not show info | |
3967 btfsc alt_layout_active ; YES - alternative layout active? | |
3968 return ; YES - suppress info message | |
3969 ;bra check_cavemode_mesg ; NO - show cave mode active info | |
3970 | |
3971 check_cavemode_mesg: | |
3972 incf message_counter,F ; increase message counter | |
3973 goto TFT_message_cave_mode ; show cave mode message | |
631 | 3974 |
3975 check_cavemode_full: | |
3976 btfss backtrack_shutdown ; backtracking shut down already? | |
3977 bsf request_cave_off_turned ; NO - request to switch cave mode off and to set the dive as turned | |
3978 bsf backtrack_shutdown ; remember shut down as been executed (anyhow) | |
634 | 3979 btfss cave_mode ; has the cave mode been switched on again meanwhile? |
3980 bsf warn_det_cave_shut_down ; NO - set warning level | |
631 | 3981 btfsc cave_mode ; has the cave mode been switched on again meanwhile? |
634 | 3982 bsf attn_det_cave_shut_down ; YES - set attention level |
3983 bra check_cavemode_mesg ; show message | |
631 | 3984 |
3985 check_cavemode_almost_full: | |
3986 btfss cave_mode ; cave mode switched on? | |
3987 return ; NO - suppress message | |
634 | 3988 bsf attn_det_cave_shut_down ; YES - set an attention |
3989 bra check_cavemode_mesg ; - show message | |
631 | 3990 |
3991 ENDIF ; _cave_mode | |
3992 | |
604 | 3993 |
634 | 3994 ;----------------------------------------------------------------------------- |
3995 ; Show aGF Reminder | |
3996 ; | |
3997 remind_agf_in_use: | |
3998 incf message_counter,F ; increase message counter | |
3999 goto TFT_message_agf ; show aGF reminder and return | |
4000 | |
4001 | |
4002 ;----------------------------------------------------------------------------- | |
4003 ; Check better Gas / Diluent Advice | |
4004 ; | |
4005 check_gas_change: | |
4006 bcf advc_det_change_gas ; clear advice by default | |
4007 IFDEF _ccr_pscr | |
4008 btfsc better_dil_available ; is a better diluent available? | |
4009 bra check_gas_change_mesg ; YES - show a gas change advice | |
4010 ENDIF | |
4011 btfsc better_gas_available ; is a better gas available? | |
4012 bra check_gas_change_mesg ; YES - show a gas change advice | |
4013 return ; NO - done | |
4014 | |
4015 check_gas_change_mesg: | |
4016 bsf advc_det_change_gas ; set advice | |
4017 incf message_counter,F ; increase message counter | |
4018 goto TFT_message_gas_change ; show advice and return | |
4019 | |
604 | 4020 |
4021 IFDEF _rx_functions | |
4022 | |
634 | 4023 ;----------------------------------------------------------------------------- |
4024 ; Check SAC and Swap-Tank Advice | |
4025 ; | |
604 | 4026 check_tr_messages: |
634 | 4027 bcf attn_det_sac_rate ; clear SAC attention by default |
4028 bcf advc_det_switch_tank ; clear switch advice by default | |
623 | 4029 btfss count_divetime ; is the dive time counted, i.e. deeper than dive threshold? |
634 | 4030 return ; NO - suppress check |
623 | 4031 movff int_O_SAC_measured+1,WREG ; YES - bank-safe copy of measured SAC rate |
4032 btfss WREG,int_attention_flag ; - attention flag set? | |
634 | 4033 bra check_tr_messages_chk_swap ; NO - continue with checking for swap advice |
623 | 4034 btfsc WREG,int_not_avail_flag ; SAC rate available? |
634 | 4035 bra check_tr_messages_chk_swap ; NO - continue with checking for swap advice |
4036 bsf attn_det_sac_rate ; YES - set attention for SAC rate | |
4037 movf active_customview,W ; - get current custom view | |
4038 xorlw index_pressures_SAC ; - SAC rate shown? | |
4039 bz check_tr_messages_chk_swap ; YES - do not show twice, continue with swap advice | |
4040 ;bra check_tr_messages_mesg_sac ; NO - show SAC message | |
4041 | |
4042 check_tr_messages_mesg_sac: | |
4043 incf message_counter,F ; increase message counter | |
4044 call TFT_message_sac ; show message for SAC rate | |
4045 ;bra check_tr_messages_chk_swap ; continue with switch advice | |
4046 | |
4047 check_tr_messages_chk_swap: | |
604 | 4048 movff char_O_deco_info,WREG ; bank-safe copy of deco info vector |
4049 btfss WREG,ind_double_switch ; swap tank flag set? | |
634 | 4050 return ; NO - done |
4051 ;bra check_tr_messages_mesg_swap ; YES - show swap message | |
4052 | |
4053 check_tr_messages_mesg_swap: | |
4054 bsf advc_det_switch_tank ; set advice | |
4055 incf message_counter,F ; increase message counter | |
4056 goto TFT_message_switch_tanks ; show message for switching tanks and return | |
4057 | |
4058 | |
4059 ;----------------------------------------------------------------------------- | |
4060 ; Check Transmitter States | |
4061 ; | |
604 | 4062 check_tr_functions: |
634 | 4063 ; check transmitter 1 |
604 | 4064 movff char_I_pressure_stat+0,WREG ; get status of 1st pressure reading |
4065 rcall check_tr_functions_helper1 ; check for transmitter 1 lost | |
4066 rcall check_tr_functions_helper2 ; check for transmitter 1 low battery | |
4067 movff int_IO_pressure_value+1,WREG ; get high byte of 1st pressure reading | |
4068 rcall check_tr_functions_helper3 ; check for transmitter 1 pressure warning | |
4069 rcall check_tr_functions_helper4 ; check for transmitter 1 pressure attention | |
634 | 4070 ; check transmitter 2 |
604 | 4071 movff char_I_pressure_stat+1,WREG ; get status of 2nd pressure reading |
4072 rcall check_tr_functions_helper5 ; check for transmitter 2 lost | |
4073 rcall check_tr_functions_helper6 ; check for transmitter 2 low battery | |
4074 movff int_IO_pressure_value+3,WREG ; get high byte of 2nd pressure reading | |
4075 rcall check_tr_functions_helper7 ; check for transmitter 2 pressure warning | |
4076 rcall check_tr_functions_helper8 ; check for transmitter 2 pressure attention | |
634 | 4077 |
4078 ; results for transmitter | |
4079 btfsc attn_det_xmit1_bat ; do we have a transmitter 1 attention? | |
4080 bra check_tr_functions_xmitter_mesg ; YES - show transmitter message | |
4081 btfsc attn_det_xmit2_bat ; do we have a transmitter 2 attention? | |
4082 bra check_tr_functions_xmitter_mesg ; YES - show transmitter message | |
4083 check_tr_functions_1: | |
4084 btfsc warn_det_pressure1 ; do we have a pressure 1 warning? | |
4085 bra check_tr_functions_pres_mesg ; YES - show pressure message | |
4086 btfsc warn_det_pressure2 ; do we have a pressure 2 warning? | |
4087 bra check_tr_functions_pres_mesg ; YES - show pressure message | |
4088 btfsc attn_det_pressure1 ; do we have a pressure 1 attention? | |
4089 bra check_tr_functions_pres_mesg ; YES - show pressure message | |
4090 btfsc attn_det_pressure2 ; do we have a pressure 2 attention? | |
4091 bra check_tr_functions_pres_mesg ; YES - show pressure message | |
4092 return ; done | |
4093 | |
4094 check_tr_functions_xmitter_mesg: | |
4095 incf message_counter,F ; increase message counter | |
4096 call TFT_message_transmitter ; show transmitter message | |
4097 bra check_tr_functions_1 ; continue with pressure messages | |
4098 | |
4099 check_tr_functions_pres_mesg: | |
4100 incf message_counter,F ; increase message counter | |
4101 goto TFT_message_pressure ; show pressure message and return | |
604 | 4102 |
4103 check_tr_functions_helper1: | |
4104 btfsc WREG,char_transmitter_lost ; transmitter 1 lost? | |
4105 bra check_tr_functions_helper1a ; YES - show transmitter attention message | |
634 | 4106 bcf shown_xmit1_lost ; NO - clear flag for old message |
604 | 4107 return ; - done |
4108 check_tr_functions_helper1a: | |
634 | 4109 btfsc shown_xmit1_lost ; is it a new message? |
604 | 4110 return ; NO - do not show the pressure readings custom view again |
634 | 4111 bsf shown_xmit1_lost ; YES - memorize it's an old message now |
4112 rcall check_tr_functions_show_cv ; - show custom view | |
604 | 4113 |
4114 check_tr_functions_helper2: | |
4115 btfsc WREG,char_transmitter_low_bat ; transmitter 1 low battery? | |
4116 bra check_tr_functions_helper2a ; YES - show transmitter attention message | |
634 | 4117 bcf shown_xmit1_battery ; NO - clear flag for old message |
4118 bcf attn_det_xmit1_bat ; - clear transmitter 1 attention | |
604 | 4119 return ; - done |
4120 check_tr_functions_helper2a: | |
634 | 4121 bsf attn_det_xmit1_bat ; set transmitter 1 attention |
4122 btfsc shown_xmit1_battery ; is it a new message? | |
604 | 4123 return ; NO - do not show the pressure readings custom view again |
634 | 4124 bsf shown_xmit1_battery ; YES - memorize it's an old message now |
4125 rcall check_tr_functions_show_cv ; - show custom view | |
604 | 4126 |
4127 check_tr_functions_helper3: | |
4128 btfsc WREG,int_warning_flag ; transmitter 1 pressure warning? | |
4129 bra check_tr_functions_helper3a ; YES - show pressure reading message as warning | |
634 | 4130 bcf shown_xmit1_pres_warn ; NO - clear flag for old message |
4131 bcf warn_det_pressure1 ; - clear pressure 1 warning | |
604 | 4132 return ; - done |
4133 check_tr_functions_helper3a: | |
634 | 4134 bsf warn_det_pressure1 ; set pressure 1 warning |
4135 btfsc shown_xmit1_pres_warn ; is it a new message? | |
604 | 4136 return ; NO - do not show the pressure readings custom view again |
634 | 4137 bsf shown_xmit1_pres_warn ; YES - memorize it's an old message now |
604 | 4138 bra check_tr_functions_show_cv ; - show custom view |
4139 | |
4140 check_tr_functions_helper4: | |
4141 btfsc WREG,int_attention_flag ; transmitter 1 pressure attention? | |
4142 bra check_tr_functions_helper4a ; YES - show pressure reading message as attention | |
634 | 4143 bcf shown_xmit1_pres_attn ; NO - clear flag for old message |
4144 bcf attn_det_pressure1 ; - clear pressure 1 attention | |
604 | 4145 return ; - done |
4146 check_tr_functions_helper4a | |
634 | 4147 bsf attn_det_pressure1 ; set pressure 1 attention |
4148 btfsc shown_xmit1_pres_attn ; is it a new message? | |
604 | 4149 return ; NO - do not show the pressure readings custom view again |
634 | 4150 bsf shown_xmit1_pres_attn ; YES - memorize it's an old message now |
604 | 4151 bra check_tr_functions_show_cv ; - show custom view |
4152 | |
4153 check_tr_functions_helper5: | |
4154 btfsc WREG,char_transmitter_lost ; transmitter 2 lost? | |
4155 bra check_tr_functions_helper5a ; YES - show transmitter attention message | |
634 | 4156 bcf shown_xmit2_lost ; NO - clear flag for old lost message |
604 | 4157 return ; - done |
4158 check_tr_functions_helper5a: | |
634 | 4159 btfsc shown_xmit2_lost ; is it a new message? |
604 | 4160 return ; NO - do not show the pressure readings custom view again |
634 | 4161 bsf shown_xmit2_lost ; YES - memorize it's an old message now |
604 | 4162 bra check_tr_functions_show_cv ; - show custom view |
4163 | |
4164 check_tr_functions_helper6: | |
4165 btfsc WREG,char_transmitter_low_bat ; transmitter 2 low battery? | |
4166 bra check_tr_functions_helper6a ; YES - show transmitter attention message | |
634 | 4167 bcf shown_xmit2_battery ; NO - clear flag for old battery message |
4168 bcf attn_det_xmit2_bat ; - clear transmitter 2 attention | |
604 | 4169 return ; - done |
4170 check_tr_functions_helper6a: | |
634 | 4171 bsf attn_det_xmit2_bat ; set transmitter 2 attention |
4172 btfsc shown_xmit2_battery ; is it a new message? | |
604 | 4173 return ; NO - do not show the pressure readings custom view again |
634 | 4174 bsf shown_xmit2_battery ; YES - memorize it's an old message now |
604 | 4175 bra check_tr_functions_show_cv ; - show custom view |
4176 | |
4177 check_tr_functions_helper7: | |
4178 btfsc WREG,int_warning_flag ; transmitter 2 pressure warning? | |
4179 bra check_tr_functions_helper7a ; YES - show pressure reading message as warning | |
634 | 4180 bcf shown_xmit2_pres_warn ; NO - clear flag for old message |
4181 bcf warn_det_pressure2 ; - clear pressure 2 warning | |
604 | 4182 return ; - done |
4183 check_tr_functions_helper7a: | |
634 | 4184 bsf warn_det_pressure2 ; set pressure 2 warning |
4185 btfsc shown_xmit2_pres_warn ; is it a new message? | |
604 | 4186 return ; NO - do not show the pressure readings custom view again |
634 | 4187 bsf shown_xmit2_pres_warn ; YES - memorize it's an old message now |
604 | 4188 bra check_tr_functions_show_cv ; - show custom view |
4189 | |
4190 check_tr_functions_helper8: | |
4191 btfsc WREG,int_attention_flag ; transmitter 2 pressure attention? | |
4192 bra check_tr_functions_helper8a ; YES - show pressure reading message as attention | |
634 | 4193 bcf shown_xmit2_pres_attn ; NO - clear flag for old message |
4194 bcf attn_det_pressure2 ; - clear pressure 2 attention | |
604 | 4195 return ; - done |
4196 check_tr_functions_helper8a | |
634 | 4197 bsf attn_det_pressure2 ; set pressure 2 attention |
4198 btfsc shown_xmit2_pres_attn ; is it a new message? | |
604 | 4199 return ; NO - do not show the pressure readings custom view again |
634 | 4200 bsf shown_xmit2_pres_attn ; YES - memorize it's an old message now |
604 | 4201 ;bra check_tr_functions_show_cv ; - show custom view |
4202 | |
4203 check_tr_functions_show_cv: | |
634 | 4204 btfsc custom_view_locked ; NO - custom view locked? |
4205 return ; YES - do not show now | |
4206 movlw index_pressures_SAC ; NO - get custom view number of pressure readings | |
4207 goto dive_customview_show ; - show custom view and return | |
4208 | |
4209 ENDIF ; _rx_functions | |
4210 | |
4211 | |
4212 ;----------------------------------------------------------------------------- | |
4213 ; Check Gas Needs | |
4214 ; | |
631 | 4215 check_gas_needs: |
634 | 4216 bcf attn_det_gas_needs ; clear attention by default |
4217 bcf warn_det_gas_needs ; clear warning by default | |
4218 banksel int_O_gas_need_pres ; switch to bank where int_O_gas_need_pres is stored | |
623 | 4219 movf int_O_gas_need_pres+1,W ; get high byte from pres need of 1st tank |
4220 iorwf int_O_gas_need_pres+3,W ; inclusive or with high byte from pres need of 2nd tank | |
4221 iorwf int_O_gas_need_pres+5,W ; inclusive or with high byte from pres need of 3rd tank | |
4222 iorwf int_O_gas_need_pres+7,W ; inclusive or with high byte from pres need of 4th tank | |
4223 iorwf int_O_gas_need_pres+9,W ; inclusive or with high byte from pres need of 5th tank | |
634 | 4224 banksel common ; back to bank common |
4225 btfsc WREG,int_invalid_flag ; any invalid flag set? | |
4226 bra check_gas_needs_ok ; YES - no further checking required | |
4227 btfsc WREG,int_warning_flag ; NO - any gas with pres_need >= pres_fill ? | |
631 | 4228 bra check_gas_needs_warn ; YES - generate a warning |
634 | 4229 btfsc WREG,int_attention_flag ; NO - any gas with pres_need >= pres_fill * threshold ? |
4230 bra check_gas_needs_attn ; YES - generate an attention | |
4231 ;bra check_gas_needs_ok ; NO - gas needs ok | |
4232 | |
4233 check_gas_needs_ok: | |
4234 bcf shown_gas_needs_warn ; re-arm custom view show-up for warning | |
4235 bcf shown_gas_needs_attn ; re-arm custom view show-up for attention | |
4236 return ; done | |
623 | 4237 |
631 | 4238 check_gas_needs_warn: |
634 | 4239 bsf warn_det_gas_needs ; set warning |
4240 bcf shown_gas_needs_attn ; re-arm custom view show-up for attention | |
4241 btfsc shown_gas_needs_warn ; has the custom view been shown before on warning level? | |
4242 bra check_gas_needs_mesg ; YES - do not show the gas needs custom view again | |
4243 btfsc custom_view_locked ; NO - custom view locked? | |
4244 bra check_gas_needs_mesg ; YES - do not show it now | |
4245 bsf shown_gas_needs_warn ; NO - set custom view as shown now | |
4246 bra check_gas_needs_cv ; - show gas needs custom view | |
4247 | |
4248 check_gas_needs_attn: | |
4249 bsf attn_det_gas_needs ; set attention | |
4250 bcf shown_gas_needs_warn ; re-arm custom view show-up for warning | |
4251 btfsc shown_gas_needs_attn ; has the custom view been shown before on attention level? | |
4252 bra check_gas_needs_mesg ; YES - do not show the gas needs custom view again | |
4253 btfsc custom_view_locked ; NO - custom view locked? | |
4254 bra check_gas_needs_mesg ; YES - do not show it now | |
4255 bsf shown_gas_needs_attn ; NO - set custom view as shown now | |
4256 ;bra check_gas_needs_cv ; - show gas needs custom view | |
4257 | |
4258 check_gas_needs_cv: | |
4259 movlw index_gas_needs_ascent ; get custom view number of gas needs | |
4260 call dive_customview_show ; show custom view | |
4261 ;bra check_gas_needs_mesg ; show message | |
4262 | |
4263 check_gas_needs_mesg: | |
4264 incf message_counter,F ; increase message counter | |
4265 goto TFT_message_gas_needs ; show message for gas needs and return | |
4266 | |
623 | 4267 |
4268 IFDEF _external_sensor | |
582 | 4269 |
634 | 4270 ;----------------------------------------------------------------------------- |
4271 ; Check external Sensors for Loss and Divergence | |
4272 ; | |
4273 check_ext_sensors: | |
4274 btfsc warn_det_sensors_lost ; all sensors lost? | |
4275 bra check_ext_sensors_lost_all ; YES - show a warning and return | |
4276 | |
4277 btfsc attn_det_sensor1_lost ; sensor 1 lost? | |
4278 rcall check_ext_sensors_lost_1 ; YES - show an attention | |
4279 | |
4280 btfsc attn_det_sensor2_lost ; sensor 2 lost? | |
4281 rcall check_ext_sensors_lost_2 ; YES - show an attention | |
4282 | |
4283 btfsc attn_det_sensor3_lost ; sensor 3 lost? | |
4284 rcall check_ext_sensors_lost_3 ; YES - show an attention | |
4285 | |
4286 btfsc warn_det_sensors_div ; sensor values divergence? | |
4287 bra check_ext_sensors_diverg ; YES - show a warning and return | |
4288 | |
4289 return ; done | |
4290 | |
4291 check_ext_sensors_lost_all: | |
4292 btfsc shown_sensors_lost ; has the custom view been shown before? | |
4293 bra warn_sensors_lost_mesg ; YES - do not show the sensor custom view again | |
4294 btfsc custom_view_locked ; NO - custom view locked? | |
4295 bra warn_sensors_lost_mesg ; YES - do not show it now | |
4296 bsf shown_sensors_lost ; NO - set it as shown now | |
4297 movlw index_ppo2_sensors ; - get custom view number of sensors | |
4298 call dive_customview_show ; - show custom view | |
4299 ;bra warn_sensors_lost_mesg ; - show message | |
4300 | |
4301 warn_sensors_lost_mesg: | |
4302 incf message_counter,F ; increase message counter | |
4303 goto TFT_message_fallback ; show message and return | |
4304 | |
4305 check_ext_sensors_lost_1: | |
4306 btfsc shown_sensor1_fail ; has the custom view been shown before for sensor 1? | |
4307 return ; YES - do not show the sensor custom view again | |
4308 btfsc custom_view_locked ; NO - custom view locked? | |
4309 return ; YES - do not show it now | |
4310 bsf shown_sensor1_fail ; NO - set it as shown now | |
4311 bra check_ext_sensors_show_cv ; - show sensor custom view | |
4312 | |
4313 check_ext_sensors_lost_2: | |
4314 btfsc shown_sensor2_fail ; has the custom view been shown before for sensor 2? | |
4315 return ; YES - do not show the sensor custom view again | |
4316 btfsc custom_view_locked ; NO - custom view locked? | |
4317 return ; YES - do not show it now | |
4318 bsf shown_sensor2_fail ; NO - set it as shown now | |
4319 bra check_ext_sensors_show_cv ; - show sensor custom view | |
4320 | |
4321 check_ext_sensors_lost_3: | |
4322 btfsc shown_sensor3_fail ; has the custom view been shown before for sensor 3? | |
4323 return ; YES - do not show the sensor custom view again | |
4324 btfsc custom_view_locked ; NO - custom view locked? | |
4325 return ; YES - do not show it now | |
4326 bsf shown_sensor3_fail ; NO - set it as shown now | |
4327 ;bra check_ext_sensors_show_cv ; - show sensor custom view | |
4328 | |
4329 check_ext_sensors_show_cv: | |
4330 movlw index_ppo2_sensors ; get custom view number of sensors | |
4331 goto dive_customview_show ; show custom view and return | |
4332 | |
4333 check_ext_sensors_diverg: | |
4334 btfsc shown_sensors_diverg ; has the custom view been shown before for divergence? | |
4335 bra check_ext_sensors_diverg_mesg ; YES - do not show the sensor custom view again | |
4336 btfsc custom_view_locked ; NO - custom view locked? | |
4337 bra check_ext_sensors_diverg_mesg ; YES - do not show it now | |
4338 bsf shown_sensors_diverg ; NO - set it as shown now | |
4339 movlw index_ppo2_sensors ; - get custom view number of sensors | |
4340 call dive_customview_show ; - show custom view | |
4341 ;bra check_ext_sensors_diverg_mesg ; - show message | |
4342 | |
4343 check_ext_sensors_diverg_mesg: | |
4344 incf message_counter,F ; increase message counter | |
4345 goto TFT_message_divergence ; show message and return | |
4346 | |
4347 ENDIF ; _external_sensor | |
4348 | |
623 | 4349 |
4350 ;============================================================================= | |
634 | 4351 dmode5 CODE |
623 | 4352 ;============================================================================= |
560 | 4353 |
634 | 4354 |
4355 ;----------------------------------------------------------------------------- | |
4356 ; Restart the Deco Engine | |
4357 ; | |
560 | 4358 global restart_deco_engine |
4359 global restart_deco_engine_wo_ceiling | |
4360 restart_deco_engine: | |
623 | 4361 banksel int_O_ceiling ; switch to bank where the shared "_O_" variables are stored |
4362 bsf int_O_ceiling+1,char_invalid_flag ; invalidate ceiling (int_O_ceiling has its invalid flag on a char's position!) | |
560 | 4363 |
4364 restart_deco_engine_wo_ceiling: | |
634 | 4365 banksel char_O_deco_gas ; switch to bank where the stops table is stored |
623 | 4366 bsf char_O_deco_gas+0,char_invalid_flag ; invalidate deco data (stop table data) |
634 | 4367 banksel int_O_NDL_norm ; switch to bank where the shared "_O_" variables are stored |
631 | 4368 bsf int_O_NDL_norm+1,int_invalid_flag ; invalidate NDL time (normal plan) |
4369 bsf int_O_TTS_norm+1,int_invalid_flag ; invalidate TTS time (normal plan) | |
4370 bsf int_O_TST_norm+1,int_invalid_flag ; invalidate TST time (normal plan) | |
623 | 4371 bsf int_O_CNS_norm+1,int_invalid_flag ; invalidate CNS at end of dive in normal plan |
631 | 4372 |
4373 restart_deco_engine_wo_norm: | |
4374 banksel common ; bank to bank common | |
4375 bsf request_restart_engine ; request restart of the deco engine | |
604 | 4376 |
4377 inval_alternative_plan_data: | |
634 | 4378 banksel int_O_NDL_alt ; switch to bank where the shared "_O_" variables are stored |
631 | 4379 bsf int_O_NDL_alt+1,int_invalid_flag ; invalidate NDL time (alternative plan) |
4380 bsf int_O_TTS_alt+1,int_invalid_flag ; invalidate TTS time (alternative plan) | |
4381 bsf int_O_TST_alt+1,int_invalid_flag ; invalidate TST time (alternative plan) | |
623 | 4382 bsf int_O_CNS_alt+1,int_invalid_flag ; invalidate CNS at end of dive in alternative plan |
4383 bsf int_O_gas_need_pres+1,int_invalid_flag ; invalidate ascent gas needs | |
604 | 4384 |
4385 IFDEF _rx_functions | |
623 | 4386 bsf int_O_pressure_need+1,int_not_avail_flag ; invalidate pressure needs to reading 1 (TR functions) |
4387 bsf int_O_pressure_need+3,int_not_avail_flag ; invalidate pressure needs to reading 2 (TR functions) | |
604 | 4388 ENDIF |
4389 | |
623 | 4390 banksel common ; bank to bank common |
4391 bsf new_deco_data_avail ; set flag for new NDL and deco data available to have the display updated | |
582 | 4392 |
634 | 4393 return ; done |
4394 | |
582 | 4395 |
4396 ;============================================================================= | |
634 | 4397 dmode6 CODE |
4398 ;============================================================================= | |
4399 | |
4400 | |
4401 ;----------------------------------------------------------------------------- | |
4402 ; Start-up Simulator Mode | |
582 | 4403 ; |
634 | 4404 global demo_divemode |
4405 demo_divemode: | |
631 | 4406 call TFT_ClearScreen ; blank screen |
4407 | |
4408 ; leaving menu mode, so have option values in EEPROM up-to-date | |
634 | 4409 btfsc option_changed ; do the options need to be stored to EEPROM ? |
631 | 4410 call option_check_and_store_all ; YES - check and store all option values in EEPROM |
604 | 4411 |
4412 ; +++ COMMENT OUT FOR TESTING PURPOSE ONLY !!! +++ | |
631 | 4413 bsf simulatormode ; restore tissue pressures and CNS value after finishing simulator use |
604 | 4414 ; +++ DO NOT COMMENT OUT IN OPERATIONAL USE !!! +++ |
560 | 4415 |
623 | 4416 call deco_push_tissues_to_vault ; back-up the tissue pressures (C-code) |
4417 banksel common ; back to bank common | |
4418 | |
4419 ; set simulated target depth | |
4420 movff char_I_bottom_depth,simulatormode_depth | |
4421 | |
4422 ; set initial simulated depth (needed to overcome end-of-dive detection) | |
4423 banksel pressure_rel_sim | |
4424 MOVLI simulator_startdepth,pressure_rel_sim | |
4425 banksel common | |
4426 | |
4427 ; switch ISR pressure calculations to simulator mode | |
4428 bcf quit_simulatormode ; clear flag for fast abort request | |
4429 bcf sensor_override_active ; make sure ISR mode switch confirmation is not older than from now on | |
4430 bsf sensor_override_request ; request ISR to switch to simulator mode | |
4431 btfss sensor_override_active ; has the ISR confirmed switch to simulator mode? | |
4432 bra $-2 ; NO - not yet, loop waiting for the ISR to kick in | |
4433 | |
4434 ; branch into dive mode | |
4435 bsf divemode ; activate dive mode (to be done after simulator mode is activated) | |
634 | 4436 goto diveloop ; start dive mode |
4437 | |
4438 ;----------------------------------------------------------------------------- | |
623 | 4439 |
4440 END |