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