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