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