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